Beispiel #1
0
 public FunctionScope(FunctionInfo function, Node node, InterpreterScope declScope)
     : base(function, node, declScope)
 {
     ReturnValue = new VariableDef();
     if (Function.FunctionDefinition.IsGenerator) {
         Generator = new GeneratorInfo(function.ProjectState, Function.FunctionDefinition);
         ReturnValue.AddTypes(function.ProjectEntry, Generator.SelfSet, false);
     }
 }
Beispiel #2
0
        internal FunctionAnalysisUnit(FunctionInfo function, AnalysisUnit declUnit, InterpreterScope declScope)
            : base(function.FunctionDefinition, null)
        {
            _declUnit = declUnit;
            Function = function;
            _decoratorCalls = new Dictionary<Node, Expression>();

            var scope = new FunctionScope(Function, Function.FunctionDefinition, declScope);
            scope.EnsureParameters(this, null);
            _scope = scope;

            AnalysisLog.NewUnit(this);
        }
Beispiel #3
0
        public FunctionAnalysisUnit(FunctionAnalysisUnit originalUnit, CallChain callChain, ArgumentSet callArgs)
            : base(originalUnit.Ast, null)
        {
            _originalUnit = originalUnit;
            _declUnit = originalUnit._declUnit;
            Function = originalUnit.Function;
            _decoratorCalls = originalUnit._decoratorCalls;

            CallChain = callChain;

            var scope = new FunctionScope(Function, Ast, originalUnit.Scope.OuterScope);
            scope.UpdateParameters(this, callArgs, false, originalUnit.Scope as FunctionScope);
            _scope = scope;

            var walker = new OverviewWalker(originalUnit.ProjectEntry, this);
            if (Ast.Body != null) {
                Ast.Body.Walk(walker);
            }

            AnalysisLog.NewUnit(this);
            Enqueue();
        }
Beispiel #4
0
 private object GenerateProperty(FunctionInfo prop)
 {
     return new Dictionary<string, object>() {
         {"doc", MemoizeString(prop.Documentation) },
         {"type", GenerateTypeName( GetFunctionReturnTypes(prop)) },
         {"location", GenerateLocation(prop.Location) }
     };
 }
Beispiel #5
0
 private object[] GenerateOverloads(FunctionInfo fi)
 {
     List<object> overloads = new List<object>();
     var types = GetFunctionReturnTypes(fi);
     if (types.Count > 0) {
         foreach (var retType in types) {
             overloads.Add(
                 new Dictionary<string, object>() {
                     {"args", GenerateArgInfo(fi) },
                     {"ret_type", GenerateTypeName(retType) },
                 }
             );
         }
     } else {
         overloads.Add(
             new Dictionary<string, object>() {
                 {"args", GenerateArgInfo(fi) }
             }
         );
     }
     return overloads.ToArray();
 }
Beispiel #6
0
 private Dictionary<string, object> GenerateFunction(FunctionInfo fi)
 {
     return new Dictionary<string, object>() {
         {"doc", fi.Documentation },
         {"overloads", GenerateOverloads(fi) },
         {"builtin", false},
         {"static", fi.IsStatic},
         {"location", GenerateLocation(fi.Location) }
     };
 }
Beispiel #7
0
 private List<object> GenerateArgInfo(FunctionInfo fi)
 {
     var res = new List<object>(fi.FunctionDefinition.Parameters.Count);
     var parameters = fi.GetParameterTypes();
     for (int i = 0; i < fi.FunctionDefinition.Parameters.Count && i < parameters.Length; i++) {
         res.Add(GenerateParameter(fi.FunctionDefinition.Parameters[i], parameters[i]));
     }
     return res;
 }
Beispiel #8
0
 private static INamespaceSet GetFunctionReturnTypes(FunctionInfo func)
 {
     return func.GetReturnValue();
 }
Beispiel #9
0
 public BoundMethodInfo(FunctionInfo function, Namespace instance)
 {
     _function = function;
     _instanceInfo = instance;
 }
Beispiel #10
0
        internal static FunctionInfo AddFunction(FunctionDefinition node, AnalysisUnit outerUnit, InterpreterScope prevScope)
        {
            InterpreterScope scope;
            if (!prevScope.TryGetNodeScope(node, out scope)) {
                if (node.Body == null || node.Name == null) {
                    return null;
                }

                var func = new FunctionInfo(node, outerUnit, prevScope);
                var unit = func.AnalysisUnit;
                scope = unit.Scope;

                prevScope.Children.Add(scope);
                prevScope.AddNodeScope(node, scope);

                if (!node.IsLambda && node.Name != "<genexpr>") {
                    // lambdas don't have their names published

                    var funcVar = prevScope.AddLocatedVariable(node.Name, node.NameExpression, unit);
                    // Decorated functions don't have their type set yet
                    if (node.Decorators == null) {
                        funcVar.AddTypes(unit, func.SelfSet);
                    }
                }

                unit.Enqueue();
            }
            return scope.Namespace as FunctionInfo;
        }