public override object VisitFunctionDeclaration([NotNull] CMinusParser.FunctionDeclarationContext context) { this.inGlobalScope = false; this.writer.DisableGlobalBuffer(); string functionLabel = this.labelGenerator.GenerateFunctionLabel(context.ID().GetText()); this.writer.WriteLabel(functionLabel); this.writer.WriteNoOperation("PSP"); this.EnterContext(); this.Visit(context.parameters()); this.Visit(context.compoundStatement()); this.ExitContext(); this.writer.WriteLabel(this.labelGenerator.FunctionReturnLabel()); this.writer.WriteFunctionExit(); this.writer.EnableGlobalBuffer(); this.inGlobalScope = true; return(null); }
public override object VisitFunctionDeclaration([NotNull] CMinusParser.FunctionDeclarationContext context) { string functionName = context.ID().GetText(); SymbolTable.Symbol functionSymbol = this.symbolTable.GetSymbol(functionName); this.internalScope++; this.symbolTable.EnterScope(); foreach (SymbolTable.Symbol member in functionSymbol.submembers) { bool success = this.symbolTable.AddSymbol(member); if (!success) { this.EmitSemanticErrorMessage($"Symbol {member.id} already in symbol table as a {this.symbolTable.GetSymbol(member.id).construct}", context); } } this.Visit(context.compoundStatement()); this.symbolTable.ExitScope(); this.internalScope--; return(true); }
public override object VisitFunctionDeclaration([NotNull] CMinusParser.FunctionDeclarationContext context) { this.writer.EnterFunction(context.ID().GetText(), context.typeSpecifier().GetText()); this.Visit(context.compoundStatement()); this.writer.ExitFunction(); return(null); }