PageRenderTime 549ms CodeModel.GetById 282ms app.highlight 6ms RepoModel.GetById 240ms app.codeStats 0ms

/src/org/ooc/frontend/model/FuncType.java

http://github.com/nddrylliog/ooc
Java | 76 lines | 58 code | 17 blank | 1 comment | 4 complexity | d21514506e9c371d329476f41e67f6d5 MD5 | raw file
 1package org.ooc.frontend.model;
 2
 3import java.io.IOException;
 4
 5import org.ooc.frontend.Visitor;
 6import org.ooc.frontend.model.tokens.Token;
 7import org.ooc.middle.hobgoblins.Resolver;
 8
 9public class FuncType extends Type {
10
11	private FunctionDecl decl;
12	
13	private FuncType(Token startToken) {
14		super("Func", startToken);
15	}
16	
17	public FuncType(Token startToken, FunctionDecl decl) {
18		this(startToken);
19		this.decl = decl;
20		for(TypeParam typeParam: decl.getTypeParams().values()) {
21			typeParams.add(new VariableAccess(typeParam.getName(), typeParam.startToken));
22		}
23		setRef(decl);
24	}
25	
26	public FuncType(Token startToken, NodeList<Access> typeParams) {
27		this(startToken);
28		decl = new FunctionDecl("<function pointer>", "", false, false, false, true, startToken, null);
29		decl.setFromPointer(true);
30		
31		if(typeParams != null) {
32			typeParams.addAll(typeParams);
33			for(Access typeParam: typeParams) {
34				String name = ((VariableAccess) typeParam).getName();
35				decl.getTypeParams().put(name, new TypeParam(name, typeParam.startToken));
36			}
37		}
38		
39		setRef(decl);
40	}
41
42	public FunctionDecl getDecl() {
43		return decl;
44	}
45	
46	@Override
47	public Response resolve(NodeList<Node> stack, Resolver res, boolean fatal) {
48		
49		// hah nothing to worry about =)
50		return Response.OK;
51		
52	}
53	
54	@Override
55	public void acceptChildren(Visitor visitor) throws IOException {
56		super.acceptChildren(visitor);
57		decl.accept(visitor);
58	}
59	
60	@Override
61	public boolean hasChildren() {
62		return true;
63	}
64	
65	@Override
66	public Type clone() {
67		FuncType copy =  new FuncType(startToken, typeParams);
68		copy.decl = decl;
69		return copy;
70	}
71	
72	@Override
73	public String toString() {
74		return "FuncType|"+super.toString();
75	}
76}