public override void EnterArray_varDeclaration(NewDecafParser.Array_varDeclarationContext context) { IType varType = (IType)currentScope.resolve(context.varType().GetText()); int arraySize = Convert.ToInt32(context.Num().GetText()); VariableSymbol vs = new VariableSymbol(context.Id().GetText(), varType, theSize: arraySize, theVariableType: VariableType.vField); currentScope.define(vs); setNodeScope(context, currentScope); }
public override void ExitArray_varDeclaration(NewDecafParser.Array_varDeclarationContext context) { FieldDeclaration FD = new FieldDeclaration(); VarType currentTypeName = getNodeCommand(context.varType()) as VarType; FD.TypeName = currentTypeName; FD.FieldId = context.Id().GetText(); FD.IsArray = true; mainClass.addCommand(FD); ArrayDeclaration AD = new ArrayDeclaration { Type = currentTypeName.getGenCode(), Name = FD.FieldId, ArraySize = Convert.ToInt32(context.Num().GetText()) }; mainClass.addCommand(AD); }
public override void ExitInt_literal_expression(NewDecafParser.Int_literal_expressionContext context) { Template selfTemplate = stg.GetInstanceOf("LoadIntConstant"); selfTemplate.Add("constant", context.Num().GetText()); setNodeTemplate(context, selfTemplate); }