PageRenderTime 41ms CodeModel.GetById 20ms app.highlight 4ms RepoModel.GetById 16ms app.codeStats 0ms

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

http://github.com/nddrylliog/ooc
Java | 52 lines | 38 code | 14 blank | 0 comment | 3 complexity | 9ace946d955bbfe3f5dccd00c545890d 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 MemberAssignArgument extends MemberArgument {
11
12	public MemberAssignArgument(String name, Token startToken) {
13		super(name, startToken);
14	}
15	
16	@Override
17	public boolean hasChildren() {
18		return false;
19	}
20	
21	@Override
22	public void acceptChildren(Visitor visitor) throws IOException {}
23	
24	@Override
25	public void accept(Visitor visitor) throws IOException {
26		visitor.visit(this);
27	}
28	
29	@Override
30	protected Response doReplace(NodeList<Node> stack, Resolver res, boolean fatal) {
31		
32		int funcDeclIndex = stack.find(FunctionDecl.class);
33		if(funcDeclIndex == -1) {
34			throw new OocCompilationError(this, stack, "Member-assign argument outside a function definition? wtf.");
35		}
36		FunctionDecl funcDecl = (FunctionDecl) stack.get(funcDeclIndex);
37		
38		if(!funcDecl.getName().equals("new")) {
39			funcDecl.getBody().add(0, new Line(new Assignment(
40					new MemberAccess(name, startToken),
41					new VariableAccess(this, startToken),
42					startToken
43			)));
44		}
45		
46		stack.peek().replace(this, new RegularArgument(ref.getType(), name, startToken));
47		
48		return Response.OK;
49		
50	}
51	
52}