public override object VisitFunctionCallStatement([NotNull] ClepsParser.FunctionCallStatementContext context)
        {
            IValue expressionValue     = Visit(context.rightHandExpression()) as IValue;
            bool   isMembersAccessible = !expressionValue.ExpressionType.IsStaticType;

            IValue          ret            = doFunctionCall(context.functionCall(), expressionValue.ExpressionType, isMembersAccessible, true /* allowVoidReturn */);
            IMethodRegister methodRegister = CodeGenerator.GetMethodRegister(FullyQualifiedClassName, CurrMemberIsStatic, CurrMemberType, CurrMemberName);

            methodRegister.CreateFunctionCallStatement(ret);

            return(ret);
        }
示例#2
0
        public override LLVMRegister VisitFunctionCallStatement([NotNull] ClepsParser.FunctionCallStatementContext context)
        {
            string className        = String.Join(".", CurrentNamespaceAndClass);
            string fullFunctionName = String.Join(".", FunctionHierarchy);
            bool   isStatic         = ClassManager.DoesClassContainMember(className, fullFunctionName, true /* search for static members */);

            string              functionBeingCalled = context.functionCall().FunctionName.GetText();
            string              fullyQualifiedNameOfFunctionBeingCalled;
            ClepsType           functionType;
            List <LLVMValueRef> parameterPtrs;

            if (context.functionCall()._FunctionParameters.Count > 0)
            {
                throw new NotImplementedException("Passing parameters to functions is not yet supported");
            }

            if (ClassManager.DoesClassContainMember(className, functionBeingCalled, true /* check static members */))
            {
                fullyQualifiedNameOfFunctionBeingCalled = String.Format("{0}.{1}", className, functionBeingCalled);
                functionType  = ClassManager.LoadedClassesAndMembers[className].StaticMemberMethods[functionBeingCalled];
                parameterPtrs = new List <LLVMValueRef>();
            }
            else if (!isStatic && ClassManager.DoesClassContainMember(className, functionBeingCalled, false /* check non static members */))
            {
                fullyQualifiedNameOfFunctionBeingCalled = String.Format("{0}.{1}", className, functionBeingCalled);
                functionType  = ClassManager.LoadedClassesAndMembers[className].MemberMethods[functionBeingCalled];
                parameterPtrs = new List <LLVMValueRef>()
                {
                    VariableManager.GetVariable("this").LLVMPtrValueRef
                };
            }
            else
            {
                string errorMessage = String.Format("The {0}function being called {1} was not found in class {2}", isStatic? "static" : String.Empty, functionBeingCalled, className);
                Status.AddError(new CompilerError(FileName, context.Start.Line, context.Start.Column, errorMessage));
                //just assume this function returns a int to avoid stalling the compilation
                return(GetConstantIntRegisterOfClepsType(context, LLVM.Int32TypeInContext(Context), 0, "int"));
            }

            LLVMValueRef[] parameters = parameterPtrs.Select(pp => LLVM.BuildLoad(Builder, pp, "functionParam")).ToArray();
            LLVMValueRef   llvmFunctionBeingCalled = LLVM.GetNamedFunction(Module, fullyQualifiedNameOfFunctionBeingCalled);
            LLVMValueRef   retValue    = LLVM.BuildCall(Builder, llvmFunctionBeingCalled, parameters, "retValue");
            LLVMValueRef   retValuePtr = LLVM.BuildAlloca(Builder, LLVM.TypeOf(retValue), "retValuePtr");

            LLVM.BuildStore(Builder, retValue, retValuePtr);

            LLVMRegister ret = new LLVMRegister(functionType.FunctionReturnType, retValuePtr);

            return(ret);
        }
        public override object VisitFunctionCallStatement([NotNull] ClepsParser.FunctionCallStatementContext context)
        {
            IValue target;

            if (context.rightHandExpression() == null)
            {
                //if no target is specified, pretend this is called on 'this'
                target = CodeGenerator.GetThisInstanceValue(new BasicClepsType(FullyQualifiedClassName));
            }
            else
            {
                target = Visit(context.rightHandExpression()) as IValue;
            }

            IValue functionCall = doFunctionCall(context.functionCall(), target, target.ExpressionType, true /* allowVoidReturn */);

            CurrMethodGenerator.CreateFunctionCallStatement(functionCall);

            return(true);
        }
示例#4
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="ClepsParser.functionCallStatement"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitFunctionCallStatement([NotNull] ClepsParser.FunctionCallStatementContext context)
 {
 }
示例#5
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="ClepsParser.functionCallStatement"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitFunctionCallStatement([NotNull] ClepsParser.FunctionCallStatementContext context)
 {
     return(VisitChildren(context));
 }