Example #1
0
 public ListComprehensionAnalysisUnit(Comprehension node, PythonAst parent, AnalysisUnit outerUnit, InterpreterScope outerScope)
     : base(node, parent,
            new ComprehensionScope(new ListInfo(VariableDef.EmptyArray, outerUnit.ProjectState.ClassInfos[BuiltinTypeId.List], node), node, outerScope),
            outerUnit)
 {
 }
Example #2
0
 public DictionaryComprehensionAnalysisUnit(Comprehension node, PythonAst parent, AnalysisUnit outerUnit, InterpreterScope outerScope)
     : base(node, parent,
            new ComprehensionScope(new DictionaryInfo(outerUnit.ProjectEntry, node), node, outerScope),
            outerUnit)
 {
 }
Example #3
0
 public SetComprehensionAnalysisUnit(Comprehension node, PythonAst parent, AnalysisUnit outerUnit, InterpreterScope outerScope)
     : base(node, parent,
            new ComprehensionScope(new SetInfo(outerUnit.ProjectState, node), node, outerScope),
            outerUnit)
 {
 }
Example #4
0
        public ComprehensionAnalysisUnit(Comprehension node, PythonAst parent, InterpreterScope scope, AnalysisUnit outerUnit)
            : base(node, parent, scope, false)
        {
            _outerUnit = outerUnit;
            _parent    = parent;

            AnalysisLog.NewUnit(this);
        }
Example #5
0
 public ClassBaseAnalysisUnit(ClassDefinition node, InterpreterScope scope, int indexInBasesList, Expression baseClassNode, AnalysisUnit outerUnit)
     : base(node, scope)
 {
     _indexInBasesList = indexInBasesList;
     _outerUnit        = outerUnit;
     _baseClassNode    = baseClassNode;
 }
Example #6
0
        internal static FunctionInfo AddFunction(FunctionDefinition node, AnalysisUnit outerUnit)
        {
            InterpreterScope scope;

            if (!outerUnit.DeclaringModule.NodeScopes.TryGetValue(node, out scope))
            {
                if (node.Body == null || node.Name == null)
                {
                    return(null);
                }

                var scopes = new InterpreterScope[outerUnit.Scopes.Length + 1];
                outerUnit.Scopes.CopyTo(scopes, 0);

                var unit     = new FunctionAnalysisUnit(node, scopes);
                var function = new FunctionInfo(unit);

                if (node.Decorators != null)
                {
                    foreach (var d in node.Decorators)
                    {
                        NameExpression ne = d as NameExpression;
                        if (ne != null)
                        {
                            if (ne.Name == "property")
                            {
                                function.IsProperty = true;
                            }
                            else if (ne.Name == "staticmethod")
                            {
                                function.IsStatic = true;
                            }
                            else if (ne.Name == "classmethod")
                            {
                                function.IsClassMethod = true;
                            }
                        }
                    }
                }
                var funcScope = new FunctionScope(function, node);
                outerUnit.DeclaringModule.NodeScopes[node] = funcScope;

                var declScope = outerUnit.Scopes[outerUnit.Scopes.Length - 1];
                declScope.Children.Add(funcScope);
                scopes[scopes.Length - 1] = funcScope;
                scope = funcScope;

                if (!node.IsLambda)
                {
                    // lambdas don't have their names published
                    declScope.SetVariable(node, unit, node.Name, function.SelfSet);
                }

                var newParams = new VariableDef[node.Parameters.Count];
                int index     = 0;
                foreach (var param in node.Parameters)
                {
                    newParams[index++] = funcScope.DefineVariable(param, unit);
                }
                function.SetParameters(newParams);
                unit.Enqueue();
            }
            return(scope.Namespace as FunctionInfo);
        }