public override object VisitFunctionDeclaration([NotNull] CMinusParser.FunctionDeclarationContext context)
        {
            string functionType = SymbolTable.Symbol.RemoveExtras(context.typeSpecifier().GetText());
            string functionName = context.ID().GetText();

            List <SymbolTable.Symbol> parameters = (List <SymbolTable.Symbol>) this.Visit(context.parameters()); // Visit parameters

            SymbolTable.Symbol functionSymbol = new SymbolTable.Symbol(
                id: functionName,
                type: functionType,
                construct: SymbolTable.Symbol.Construct.FUNCTION,
                size: (uint)parameters.Count,
                scope: this.internalScope,
                pointerCount: 0
                );

            functionSymbol.AddMembers(parameters);

            bool success = this.symbolTable.AddSymbol(functionSymbol);

            if (!success)
            {
                this.EmitSemanticErrorMessage($"Symbol {functionName} already in symbol table as a {this.symbolTable.GetSymbol(functionName).construct}", context);
            }

            return(null);
        }
Ejemplo n.º 2
0
        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);
        }