public override bool Walk(ExpressionStatement node) { switch (node.Expression) { case ExpressionWithAnnotation ea: AssignmentHandler.HandleAnnotatedExpression(ea, null); return(false); case Comprehension comp: Eval.ProcessComprehension(comp); return(false); case CallExpression callex when callex.Target is NameExpression nex && !string.IsNullOrEmpty(nex.Name): Eval.LookupNameInScopes(nex.Name)?.AddReference(Eval.GetLocationOfName(nex)); return(true); case CallExpression callex when callex.Target is MemberExpression mex && !string.IsNullOrEmpty(mex.Name): var t = Eval.GetValueFromExpression(mex.Target)?.GetPythonType(); t?.GetMember(mex.Name)?.AddReference(Eval.GetLocationOfName(mex)); return(true); default: return(base.Walk(node)); } }
private void ProcessClassBody() { // Class is handled in a specific order rather than in the order of // the statement appearance. This is because we need all members // properly declared and added to the class type so when we process // methods, the class variables are all declared and constructors // are evaluated. // Process bases. foreach (var b in _class.Bases.Select(b => b.GetPythonType <IPythonClassType>()).ExcludeDefault()) { SymbolTable.Evaluate(b.ClassDefinition); } // Process imports foreach (var s in GetStatements <FromImportStatement>(_classDef)) { ImportHandler.HandleFromImport(s); } foreach (var s in GetStatements <ImportStatement>(_classDef)) { ImportHandler.HandleImport(s); } UpdateClassMembers(); // Process assignments so we get class variables declared. // Note that annotated definitions and assignments can be intermixed // and must be processed in order. Consider // class A: // x: int // x = 1 foreach (var s in GetStatements <Statement>(_classDef)) { switch (s) { case AssignmentStatement assignment: AssignmentHandler.HandleAssignment(assignment); break; case ExpressionStatement e: AssignmentHandler.HandleAnnotatedExpression(e.Expression as ExpressionWithAnnotation, null); break; } } UpdateClassMembers(); // Ensure constructors are processed so class members are initialized. EvaluateConstructors(_classDef); UpdateClassMembers(); // Process remaining methods. SymbolTable.EvaluateScope(_classDef); UpdateClassMembers(); }
public override bool Walk(ExpressionStatement node) { switch (node.Expression) { case ExpressionWithAnnotation ea: AssignmentHandler.HandleAnnotatedExpression(ea, null); break; case Comprehension comp: Eval.ProcessComprehension(comp); break; } return(false); }
public override bool Walk(ExpressionStatement node) { switch (node.Expression) { case ExpressionWithAnnotation ea: AssignmentHandler.HandleAnnotatedExpression(ea, null); return(false); case Comprehension comp: Eval.ProcessComprehension(comp); return(false); case CallExpression callex: Eval.ProcessCallForReferences(callex); return(true); default: return(base.Walk(node)); } }