public override void visit(ConstDeclaration n) { try { int stackLocation = tables[scope].Lookup(n.Name.Name).StackLocation; n.RHS.accept(this); //Add(new Move(new RegisterOffset(Global.Registers.STACKBASEPOINTER, extraStackSize++), regRAX)); Add(new Move(stack.Pop(), new RegisterOffset(Global.Registers.STACKBASEPOINTER, -stackLocation))); } catch (NoSuchKeyException) { // Do nothing, emit the declaration of the constant, normally because the constant was unreferenced and thus unused } }
public override void visit(ConstDeclaration n) { Table scope = n.Scope; if (n.Type == null) n.Type = n.accept(new TypeVisitor()); ConstantSymbol sym = new ConstantSymbol(n.Name.Name, n.Type, n.RHS); scope.Insert(sym); }
public abstract void visit(ConstDeclaration n);
public void visit(ConstDeclaration n) { throw new NotImplementedException(); }
public virtual void visit(ConstDeclaration n) { // Do nothing; leave the implementation to the main class }
public override void visit(ConstDeclaration n) { n.Scope = Scope; n.RHS.accept(this); }
/// <summary> /// Parses a declaration (eg, var a, let b) /// </summary> /// <param name="tokens">A list of tokens containing only the whole declaration</param> /// <param name="context">A list of ILineContext corresponding to the tokens supplied</param> /// <returns></returns> private void EatDeclaration() { if (tokens[1].type != Global.DataType.IDENTIFIER) { Swift.error(new IdentifierExpectedException(context[1], "identifier expected")); } if (tokens[0].type == Global.DataType.VAR) { if (tokens.Count >= 4) { if (tokens[1].type != Global.DataType.IDENTIFIER) Swift.error(new IdentifierExpectedException(context[1], "identifier expected after keyword \"var\"")); if (tokens[2].type == Global.DataType.OPERATOR && tokens[2].value == "=") { VarDeclaration node = new VarDeclaration(context[0]); node.Name = new Identifier(tokens[1].value); astBase.Children.Add(node); CutData(1); node.TypeByAssignment = EatAssignment(); while (tokens.Count > 0) { if (tokens[0].type == Global.DataType.COMMA) { node = new VarDeclaration(context[0]); node.Name = new Identifier(tokens[1].value); astBase.Children.Add(node); if (tokens[2].type == Global.DataType.OPERATOR && tokens[2].value == "=") { CutData(1); node.TypeByAssignment = EatAssignment(); } } } } else if (tokens[2].type == Global.DataType.COLON) { VarDeclaration node = new VarDeclaration(context[1]); node.Name = new Identifier(tokens[1].value); if (tokens.Count < 3) Swift.error(new TypeExpectedException(context[2], "type expected after the colon")); node.Type = getASTTypeFromToken(tokens[3], context[3]); astBase.Children.Add(node); if (tokens.Count == 4) Swift.error(new AssignmentExpectedException(context[3], "assignment expected after \"=\" token")); if (tokens.Count > 4 && tokens[4].type == Global.DataType.OPERATOR && tokens[4].value == "=") { CutData(1); CutData(1, 2); EatAssignment(); } else { CutData(4); } } else { Swift.error(new AssignmentExpectedException(context[2], "assignment expected after a declaration without a type specification")); } } else { Swift.error(new NoTypeSpecifiedException(context[1], "assignment expected after a declaration without a type specification on line " + context[1].Line + ", column " + context[1].Pos)); } } else if (tokens[0].type == Global.DataType.LET) { if (tokens.Count <= 2) Swift.error(new UninitializedConstantException(context[0])); if (tokens.Count >= 4) { if (tokens[2].type == Global.DataType.OPERATOR && tokens[2].value == "=") { string tmpToken = tokens[1].value; CutData(3); ConstDeclaration node = new ConstDeclaration(context[0], EatExpression()); node.Name = new Identifier(tmpToken); astBase.Children.Add(node); while (tokens.Count > 0) { if (tokens[0].type == Global.DataType.COMMA) { tmpToken = tokens[1].value; if (tokens[2].type == Global.DataType.OPERATOR && tokens[2].value == "=") { CutData(3); node = new ConstDeclaration(context[0], EatExpression()); node.Name = new Identifier(tmpToken); astBase.Children.Add(node); } else Swift.error(new UninitializedConstantException(context[0].Line, context[0].Pos)); } else Swift.error(new UnexpectedCodeException(context[0].Line, context[0].Pos, "unexpected code after constant declaration")); } } else if (tokens[2].type == Global.DataType.COLON) { string tmpToken = tokens[1].value; ASTType type = getASTTypeFromToken(tokens[3], context[3]); CutData(5); ConstDeclaration node = new ConstDeclaration(context[0], EatExpression()); node.Name = new Identifier(tmpToken); node.Type = type; astBase.Children.Add(node); } else { Swift.error(new UninitializedConstantException(context[0].Line, context[0].Pos)); } } } else { Swift.error(new InternalError("Internal error parsing the variable declaration: " + tokens)); return; } //if (tokens.Count > 2) // node.SetChildren(); //return EatAssignment(tokens.GetRange(1, tokens.Count - 1), context.GetRange(1, context.Count - 1)); }
public ASTType visit(ConstDeclaration n) { if (n.Type == null) return n.RHS.accept(this); else return n.Type; }