public ILSLTreePreePass EnterFunctionScope(LSLParser.FunctionDeclarationContext context, LSLPreDefinedFunctionSignature functionSignature) { _parameterScopeVariables.Clear(); CurrentEventHandlerContext = null; CurrentEventHandlerSignature = null; CurrentFunctionBodySignature = functionSignature; CurrentFunctionContext = context; if (functionSignature.ParameterListNode != null) { //define all the parameters in the local scope, they are not considered constant in the analysis foreach (var parameter in functionSignature.ParameterListNode.Parameters) { //parameter references are implicitly not constant var parameterRef = LSLVariableDeclarationNode.CreateParameter(parameter); _parameterScopeVariables.Add(parameter.Name, parameterRef); } } return(DoLabelCollectorPrePass(context)); }
public override bool VisitFunctionDeclaration(LSLParser.FunctionDeclarationContext context) { if (context == null || Utility.AnyNull(context.function_name, context.code)) { throw LSLCodeValidatorInternalException.VisitContextInvalidState("VisitFunctionDeclaration", true); } if (_validatorStrategies.LibraryDataProvider.LibraryFunctionExist(context.function_name.Text)) { GenSyntaxError().RedefinedStandardLibraryFunction( new LSLSourceCodeRange(context.function_name), context.function_name.Text, _validatorStrategies.LibraryDataProvider.GetLibraryFunctionSignatures( context.function_name.Text)); return(false); } if (_scopingManager.FunctionIsPreDefined(context.function_name.Text)) { GenSyntaxError().RedefinedFunction( new LSLSourceCodeRange(context.function_name), _scopingManager.ResolveFunctionPreDefine(context.function_name.Text)); return(false); } var parameterListNode = LSLParameterListNode.BuildFromParserContext( context.parameters, LSLParameterListType.FunctionParameters, _validatorStrategies); if (parameterListNode.HasErrors) { return(false); } var returnType = LSLType.Void; if (context.return_type != null) { returnType = LSLTypeTools.FromLSLTypeName(context.return_type.Text); } var func = new LSLPreDefinedFunctionSignature(returnType, context.function_name.Text, parameterListNode); _scopingManager.PreDefineFunction(func); base.VisitFunctionDeclaration(context); return(true); }
private LSLLabelCollectorPrePass DoLabelCollectorPrePass( LSLParser.FunctionDeclarationContext context) { var r = new LSLLabelCollectorPrePass(this, ValidatorStrategies); r.Visit(context); return(r); }
/// <exception cref="ArgumentNullException"> /// <paramref name="parameterList" /> or <paramref name="code" /> /// is <c>null</c>. /// </exception> internal LSLFunctionDeclarationNode(LSLParser.FunctionDeclarationContext context, LSLParameterListNode parameterList, LSLCodeScopeNode code) { if (parameterList == null) { throw new ArgumentNullException("parameterList"); } if (code == null) { throw new ArgumentNullException("code"); } if (context.return_type != null) { ReturnTypeName = context.return_type.Text; ReturnType = LSLTypeTools.FromLSLTypeName(ReturnTypeName); SourceRangeReturnType = new LSLSourceCodeRange(context.return_type); } else { ReturnTypeName = ""; ReturnType = LSLType.Void; } Name = context.function_name.Text; ParameterList = parameterList; ParameterList.Parent = this; Code = code; Code.Parent = this; Code.CodeScopeType = LSLCodeScopeType.Function; SourceRange = new LSLSourceCodeRange(context); SourceRangeName = new LSLSourceCodeRange(context.function_name); SourceRangesAvailable = true; }
/// <summary> /// Exit a parse tree produced by <see cref="LSLParser.functionDeclaration"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitFunctionDeclaration([NotNull] LSLParser.FunctionDeclarationContext context) { }
/// <summary> /// Visit a parse tree produced by <see cref="LSLParser.functionDeclaration"/>. /// <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 VisitFunctionDeclaration([NotNull] LSLParser.FunctionDeclarationContext context) { return(VisitChildren(context)); }