예제 #1
0
        public override AstVisitAction VisitFunctionMember(FunctionMemberAst functionMemberAst)
        {
            _memberScopeStack.Push(functionMemberAst);

            var body = functionMemberAst.Body;
            if (body.ParamBlock != null)
            {
                _parser.ReportError(body.ParamBlock.Extent, () => ParserStrings.ParamBlockNotAllowedInMethod);
            }

            if (body.BeginBlock != null ||
                body.ProcessBlock != null ||
                body.DynamicParamBlock != null ||
                !body.EndBlock.Unnamed)
            {
                _parser.ReportError(Parser.ExtentFromFirstOf(body.DynamicParamBlock, body.BeginBlock, body.ProcessBlock, body.EndBlock),
                    () => ParserStrings.NamedBlockNotAllowedInMethod);
            }

            if (functionMemberAst.IsConstructor && functionMemberAst.ReturnType != null)
            {
                _parser.ReportError(functionMemberAst.ReturnType.Extent, () => ParserStrings.ConstructorCantHaveReturnType);
            }

            // Analysis determines if all paths return and do data flow for variables.
            var allCodePathsReturned = VariableAnalysis.AnalyzeMemberFunction(functionMemberAst);
            if (!allCodePathsReturned && !functionMemberAst.IsReturnTypeVoid())
            {
                _parser.ReportError(functionMemberAst.NameExtent ?? functionMemberAst.Extent, () => ParserStrings.MethodHasCodePathNotReturn);
            }

            return AstVisitAction.Continue;
        }
예제 #2
0
 /// <summary>
 /// Check if it is a Set method with correct return type and signature
 /// </summary>
 /// <param name="functionMemberAst">The function member AST</param>
 /// <param name="hasSet">True if it is a Set method with qualified return type and signature; otherwise, false.</param>
 private static void CheckSet(FunctionMemberAst functionMemberAst, ref bool hasSet)
 {
     if (hasSet) return;
     hasSet = (functionMemberAst.Name.Equals("Set", StringComparison.OrdinalIgnoreCase) &&
             functionMemberAst.Parameters.Count == 0 &&
             functionMemberAst.IsReturnTypeVoid());
 }