PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/nddrylliog/ooc
Java | 70 lines | 50 code | 20 blank | 0 comment | 9 complexity | 483328e6d690efe6f2f75d796a3c7a8f 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.OocCompilationError;
 8import org.ooc.middle.hobgoblins.Resolver;
 9
10public class TypeAccess extends VariableAccess {
11
12	private Type type;
13
14	public TypeAccess(Type type, Token startToken) {
15		super((String) null, startToken);
16		this.type = type;
17	}
18	
19	@Override
20	public String getName() {
21		return type.getName();
22	}
23	
24	@Override
25	public Type getType() {
26		return type;
27	}
28	
29	@Override
30	public Declaration getRef() {
31		return type.getRef();
32	}
33	
34	@Override
35	public boolean hasChildren() {
36		return true;
37	}
38	
39	@Override
40	public void acceptChildren(Visitor visitor) throws IOException {
41		type.accept(visitor);
42	}
43	
44	@Override
45	public Response resolve(NodeList<Node> stack, Resolver res, boolean fatal) {
46		
47		if(type.isResolved()) return Response.OK;
48		
49		type.resolve(stack, res, fatal);
50		
51		if(type.isFlat() && type.getTypeParams().isEmpty()) {
52			VariableDecl var = getVariable(type.getName(), stack, null);
53			if(var != null && var.getType() != null && var.getType().getName().equals("Class")) {
54				type.setRef(var);
55			}
56		}
57		
58		if(fatal) throw new OocCompilationError(this, stack, "Can't resolve type access to "+type);
59		return Response.LOOP; 
60		
61	}
62	
63	@Override
64	public String toString() {
65		return type.toString();
66	}
67	
68}
69
70