Example #1
0
            public override Evaluation Analyze(LambdaFunctionExpr node, Analyzer analyzer, ExInfoFromParent info)
            {
                // construct fake signature containing both - use params and regular params
                var allparams = new List <FormalParam>(node.Signature.FormalParams);

                if (node.UseParams != null)
                {
                    allparams.InsertRange(0, node.UseParams);
                }
                var signature = new Signature(false, allparams);

                //
                function = new PhpLambdaFunction(signature, analyzer.SourceUnit, node.Span);
                function.WriteUp(new TypeSignature(FormalTypeParam.EmptyList).ToPhpRoutineSignature(function));

                SignatureCompiler.AnalyzeMembers(signature, analyzer, function);

                //attributes.Analyze(analyzer, this);

                // ensure 'use' parameters in parent scope:
                if (node.UseParams != null)
                {
                    foreach (var p in node.UseParams)
                    {
                        analyzer.CurrentVarTable.Set(p.Name, p.PassedByRef);
                    }
                }

                // function is analyzed even if it is unreachable in order to discover more errors at compile-time:
                analyzer.EnterFunctionDeclaration(function);

                //typeSignature.Analyze(analyzer);
                SignatureCompiler.Analyze(signature, analyzer);

                node.Body.Analyze(analyzer);

                // validate function and its body:
                function.ValidateBody(analyzer.ErrorSink);

                analyzer.LeaveFunctionDeclaration();

                return(new Evaluation(node));
            }
Example #2
0
        public LambdaFunctionExpr(SourceUnit /*!*/ sourceUnit,
                                  Position position, Position entireDeclarationPosition, ShortPosition headingEndPosition, ShortPosition declarationBodyPosition,
                                  Scope scope, NamespaceDecl ns,
                                  bool aliasReturn, List <FormalParam> /*!*/ formalParams, List <FormalParam> useParams,
                                  List <Statement> /*!*/ body)
            : base(position)
        {
            Debug.Assert(formalParams != null && body != null);

            // inject use parameters at the begining of formal parameters
            if (useParams != null && useParams.Count > 0)
            {
                if (formalParams.Count == 0)
                {
                    formalParams = useParams;   // also we don't want to modify Parser.emptyFormalParamListIndex singleton.
                }
                else
                {
                    formalParams.InsertRange(0, useParams);
                }
            }

            //this.ns = ns;
            this.signature = new Signature(aliasReturn, formalParams);
            this.useParams = useParams;
            //this.typeSignature = new TypeSignature(genericParams);
            //this.attributes = new CustomAttributes(attributes);
            this.body = body;
            this.entireDeclarationPosition = entireDeclarationPosition;
            this.headingEndPosition        = headingEndPosition;
            this.declarationBodyPosition   = declarationBodyPosition;

            //QualifiedName qn = (ns != null) ? new QualifiedName(this.name, ns.QualifiedName) : new QualifiedName(this.name);
            //function = new PhpFunction(qn, memberAttributes, signature, typeSignature, isConditional, scope, sourceUnit, position);
            function = new PhpLambdaFunction(this.signature, sourceUnit, position);
            function.WriteUp(new TypeSignature(FormalTypeParam.EmptyList).ToPhpRoutineSignature(function));
        }