public override ASTNode VisitEnumdef([NotNull] llangParser.EnumdefContext context) { string name = context.Iden().GetText(); var items = new Dictionary <string, long>(); long curval = 0; if (context.enumDeclList() != null) { var ctx = context.enumDeclList().GetChild <llangParser.EnumDeclItemContext>(0); for (int i = 1; ctx != null; i++) { VarDeclNode v = (VarDeclNode)Visit(ctx); if (v.rhs != null) { curval = v.rhs.IntValue + 1; } else { v.rhs = new IntExprNode(curval++, v.sourceLoc); } items.Add(v.name, v.rhs.IntValue); ctx = context.enumDeclList().GetChild <llangParser.EnumDeclItemContext>(i); } } return(new EnumDefNode(name, TypeSymbol.ENUM_SYMBOL(name, items), MakeSourceLoc(context))); }
public object VisitVarDeclNode(VarDeclNode n) { WriteLine(n.kind + " - " + n.name + ":" + n.Type.Name); Indent(); Visit(n.rhs); Dedent(); return(null); }
public override object VisitVarDeclNode(VarDeclNode n) { TypeSymbol ts = MakeTypeSymbolForString(n.Type.Name); Visit(n.rhs); if (ts == null) { ts = n.rhs.Type; } n.Type = ts; varTypes.PutInScope(n.name, ts); return(null); }
public override ASTNode VisitStructdef([NotNull] llangParser.StructdefContext context) { string name = context.Iden().GetText(); List <Expression> defaultValues = new List <Expression>(); var fields = new Dictionary <string, (TypeSymbol, int)>(); if (context.structDeclList() != null) { for (int i = 0; i < context.structDeclList().ChildCount; i++) { VarDeclNode s = (VarDeclNode)Visit(context.structDeclList().GetChild(i)); fields.Add(s.name, (s.Type, 0)); defaultValues.Add(s.rhs); } } TypeSymbol ownType = TypeSymbol.STRUCT_SYMBOL(name, 0, fields); return(new StructDefNode(name, ownType, defaultValues, MakeSourceLoc(context))); // Technically useless for Codegen }
public override MIPSRegister VisitVarDeclNode(VarDeclNode n) { var varloc = vars.IsInScope(n.name); if (n.rhs != null) { var rhs = Gen(n.rhs); if (varloc.SecondSet) { // store the value to the stack emit.EmitLoadStore("sw", rhs, varloc.Second, rm.FP); } else { // store the value in the register emit.Emit("add", varloc.First, rhs, rm.ZERO); } } return(null); }
public override ASTNode VisitGlobalVar([NotNull] llangParser.GlobalVarContext context) { VarDeclNode n = (VarDeclNode)Visit(context.varDeclStmt()); return(new GlobalVarDefNode(n.name, n.rhs, n.Type, MakeSourceLoc(context))); }
public override LLVMRegister VisitVarDeclNode(VarDeclNode n) { throw new NotImplementedException(); }
public override object VisitVarDeclNode(VarDeclNode n) { Visit(n.rhs); semanticChecker.CheckAndReport(varTypes.PutInScope(n.name, n.Type), n.sourceLoc, $"Variable {n.name} already declared"); return(null); }
public override LData VisitVarDeclNode(VarDeclNode n) { Vars.PutInScope(n.name, Visit(n.rhs)); return(null); }
public override int VisitVarDeclNode(VarDeclNode n) { return(1); }
public virtual T VisitVarDeclNode(VarDeclNode n) { T a = n.rhs.Accept(this); return(default(T)); }