コード例 #1
0
        public override object VisitFunctionCall([NotNull] CMinusParser.FunctionCallContext context)
        {
            string functionName = context.ID().GetText();

            if (!this.symbolTable.HasSymbol(functionName))
            {
                this.EmitSemanticErrorMessage($"Function {functionName} called but not declared", context);
                return(null);
            }

            SymbolTable.Symbol foundSymbol = this.symbolTable.GetSymbol(functionName);

            if (foundSymbol.construct != SymbolTable.Symbol.Construct.FUNCTION)
            {
                this.EmitSemanticErrorMessage($"{functionName} called as function but declared as a {foundSymbol.construct}", context);
                return(null);
            }

            if (this.inAssignment && foundSymbol.type == "void")
            {
                this.EmitSemanticErrorMessage($"Void returning function in assignment", context);
            }

            return(null);
        }
コード例 #2
0
        public override object VisitFunctionCall([NotNull] CMinusParser.FunctionCallContext context)
        {
            if (context.argumentList() != null)
            {
                this.Visit(context.argumentList());
            }

            this.writer.CallFunction(context.ID().GetText());



            return(base.VisitFunctionCall(context));
        }
コード例 #3
0
        // TODO - DROP if out of expression and function called returns int
        public override object VisitFunctionCall([NotNull] CMinusParser.FunctionCallContext context)
        {
            if (context.argumentList() != null)
            {
                this.Visit(context.argumentList());
            }

            string functionName  = context.ID().GetText();
            string functionLabel = this.labelGenerator.GenerateFunctionLabel(functionName);

            this.EnterContext();
            this.writer.WriteFunctionCall(functionLabel);
            this.ExitContext();

            return(null);
        }