PageRenderTime 7ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://github.com/nddrylliog/ooc
Java | 81 lines | 65 code | 16 blank | 0 comment | 13 complexity | b285985a1e86cbf9dce4cc17960bcc37 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;
 7
 8public class Dereference extends Access {
 9
10	Type type;
11	Expression expression;
12	
13	public Dereference(Expression expression, Token startToken) {
14		super(startToken);
15		setExpression(expression);
16	}
17	
18	@Override
19    public Expression getGenericOperand() {
20        if(expression.getType().isGeneric() && expression.getType().getPointerLevel() > 0) {
21            return expression;
22        }
23        return super.getGenericOperand();
24    }
25
26	@Override
27	public boolean replace(Node oldie, Node kiddo) {
28		if(expression == oldie) {
29			expression = (Expression) kiddo;
30			return true;
31		}
32		
33		return false;
34	}
35
36	public Type getType() {
37		if(type == null) {
38			Type exprType = expression.getType();
39			if(exprType != null) {
40				type = exprType.clone();
41				type.setPointerLevel(type.getPointerLevel() - 1);
42				if(type.getPointerLevel() < 0) {
43					if(type.getRef() instanceof CoverDecl) {
44						CoverDecl cover = (CoverDecl) type.getRef();
45						if(cover.getFromType() != null && !cover.getFromType().isFlat()) {
46							type = cover.getFromType().clone();
47							type.setPointerLevel(type.getPointerLevel() - 1);
48						}
49					}
50				}
51			}
52		}
53		return type;
54	}
55	
56	public Expression getExpression() {
57		return expression;
58	}
59	
60	public void setExpression(Expression expression) {
61		this.expression = expression;
62	}
63
64	public void accept(Visitor visitor) throws IOException {
65		visitor.visit(this);
66	}
67
68	public void acceptChildren(Visitor visitor) throws IOException {
69		expression.accept(visitor);
70	}
71
72	public boolean hasChildren() {
73		return true;
74	}
75	
76	@Override
77	public boolean canBeReferenced() {
78		return true;
79	}
80
81}