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.InterpreterScope; (unit as FunctionAnalysisUnit)?.EnsureParameters(); prevScope.Children.Add(scope); prevScope.AddNodeScope(node, scope); if (!node.IsLambda && node.Name != "<genexpr>") { // Create the variable (except for lambdas) but do not add any // values yet. (This happens in FunctionAnalysisUnit.) prevScope.AddLocatedVariable(node.Name, node.NameExpression, unit); } unit.Enqueue(); } return(scope.AnalysisValue as FunctionInfo); }
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.AnalysisValue as FunctionInfo); }
/// <summary> /// Makes sure we create a scope for a comprehension (generator, set, dict, or list comprehension in 3.x) where /// the variables which are assigned will be stored. /// </summary> private void EnsureComprehensionScope(Comprehension node, Func <Comprehension, ComprehensionScope> makeScope) { InterpreterScope scope, declScope = _scope; if (!declScope.TryGetNodeScope(node, out scope)) { scope = makeScope(node); declScope.AddNodeScope(node, scope); declScope.Children.Add(scope); } _scope = scope; }
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.AnalysisValue as FunctionInfo; }