Exemple #1
0
        public DataType VisitLambda(Lambda lambda)
        {
            State env = scope.getForwarding();
            var   fun = new FunType(lambda, env);

            fun.Table.Parent = this.scope;
            fun.Table.Path   = scope.extendPath(analyzer, "{lambda}");
            fun.setDefaultTypes(ResolveList(lambda.args.Select(p => p.test)));
            analyzer.AddUncalled(fun);
            return(fun);
        }
Exemple #2
0
        public DataType VisitFunctionDef(FunctionDef f)
        {
            State   env = scope.getForwarding();
            FunType fun = new FunType(f, env);

            fun.Table.Parent = this.scope;
            fun.Table.Path   = scope.extendPath(analyzer, f.name.Name);
            fun.setDefaultTypes(ResolveList(f.parameters
                                            .Where(p => p.test != null)
                                            .Select(p => p.test)));
            analyzer.AddUncalled(fun);
            BindingKind funkind;

            if (scope.stateType == State.StateType.CLASS)
            {
                if ("__init__" == f.name.Name)
                {
                    funkind = BindingKind.CONSTRUCTOR;
                }
                else
                {
                    funkind = BindingKind.METHOD;
                }
            }
            else
            {
                funkind = BindingKind.FUNCTION;
            }

            DataType outType = scope.Type;

            if (outType is ClassType)
            {
                fun.Class = ((ClassType)outType);
            }

            scope.Bind(analyzer, f.name, fun, funkind);

            var sOld = this.scope;

            this.scope = fun.Table;
            f.body.Accept(this);
            this.scope = sOld;

            return(DataType.Cont);
        }