示例#1
0
 public override object VisitVarDecl(PParser.VarDeclContext context)
 {
     foreach (PParser.IdenContext varName in context.idenList()._names)
     {
         Variable variable = method.Scope.Put(varName.GetText(), varName, VariableRole.Local);
         variable.Type = TypeResolver.ResolveType(context.type(), method.Scope, handler);
         method.AddLocalVariable(variable);
     }
     return(null);
 }
示例#2
0
        private (VariableAccessExpr, IPStmt) SaveInTemporary(IPExpr expr, PLanguageType tempType)
        {
            Antlr4.Runtime.ParserRuleContext location = expr.SourceLocation;
            Variable temp = function.Scope.Put($"$tmp{numTemp++}", location, VariableRole.Local | VariableRole.Temp);

            Debug.Assert(tempType.IsAssignableFrom(expr.Type));
            temp.Type = tempType;
            function.AddLocalVariable(temp);
            AssignStmt stmt = new AssignStmt(location, new VariableAccessExpr(location, temp), expr);

            return(new VariableAccessExpr(location, temp), stmt);
        }