public override bool VisitFunctionReturnStatement_Ex([NotNull] ClepsParser.FunctionReturnStatementContext context) { IValue returnValue = null; if (context.rightHandExpression() != null) { returnValue = Visit(context.rightHandExpression()) as IValue; } var currFunctionType = CurrMethodGenerator.ExpressionType as FunctionClepsType; if (currFunctionType.ReturnType != returnValue.ExpressionType) { string errorMessage = String.Format("Expected return of {0}. Returning type {1} instead.", currFunctionType.ReturnType.GetClepsTypeString(), returnValue.ExpressionType.GetClepsTypeString()); Status.AddError(new CompilerError(FileName, context.rightHandExpression().Start.Line, context.rightHandExpression().Start.Column, errorMessage)); } CurrMethodGenerator.CreateReturnStatement(returnValue); return(true); }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////// Function Statement Implementations /////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////// #region Function Statement Implementations // Note - the return of statements are not really used. It is more used in the expression returns, which is in the next section public override LLVMRegister VisitFunctionReturnStatement([NotNull] ClepsParser.FunctionReturnStatementContext context) { LLVMValueRef returnValueRegister; ClepsType returnType; if (context.rightHandExpression() == null) { returnValueRegister = LLVM.BuildRetVoid(Builder); returnType = ClepsType.GetVoidType(); } else { var returnValuePtr = Visit(context.rightHandExpression()); returnValueRegister = LLVM.BuildLoad(Builder, returnValuePtr.LLVMPtrValueRef, "returnValue"); LLVM.BuildRet(Builder, returnValueRegister); returnType = returnValuePtr.VariableType; } var ret = new LLVMRegister(returnType, returnValueRegister); return(ret); }
public override object VisitFunctionReturnStatement_Ex([NotNull] ClepsParser.FunctionReturnStatementContext context) { IValue returnValue = null; if (context.rightHandExpression() != null) { returnValue = Visit(context.rightHandExpression()) as IValue; } var currFunctionType = CurrMemberType as FunctionClepsType; if (currFunctionType.ReturnType != returnValue.ExpressionType) { string errorMessage = String.Format("Expected return of {0}. Returning type {1} instead.", currFunctionType.ReturnType.GetClepsTypeString(), returnValue.ExpressionType.GetClepsTypeString()); Status.AddError(new CompilerError(FileName, context.rightHandExpression().Start.Line, context.rightHandExpression().Start.Column, errorMessage)); } IMethodRegister methodRegister = CodeGenerator.GetMethodRegister(FullyQualifiedClassName, CurrMemberIsStatic, CurrMemberType, CurrMemberName); methodRegister.CreateReturnStatement(returnValue); return(returnValue); }