public override void PostWalk(ClassDefinition node) { if (node.Body != null && node.Name != null) { Debug.Assert(_scope.Node == node); Debug.Assert(_scope.OuterScope.Node != node); _scope = _scope.OuterScope; _curUnit = _analysisStack.Pop(); Debug.Assert(_scope.EnumerateTowardsGlobal.Contains(_curUnit.Scope)); } }
public ClassScopeNode(ClassDefinition klass) { _klass = klass; }
//classdef: 'class' NAME ['(' testlist ')'] ':' suite private Statement ParseClassDef() { Eat(TokenKind.KeywordClass); string classWhiteSpace = _tokenWhiteSpace; var start = GetStart(); var name = ReadName(); var nameExpr = MakeName(name); nameExpr.SetLoc(GetStart(), GetEnd()); string nameWhiteSpace = _tokenWhiteSpace; if (name.RealName == null) { // no name, assume there's no class. return ErrorStmt(_verbatim ? (classWhiteSpace + "class") : null); } bool isParenFree = false; string leftParenWhiteSpace = null, rightParenWhiteSpace = null; List<string> commaWhiteSpace = null; Arg[] args; bool ateTerminator = true; if (MaybeEat(TokenKind.LeftParenthesis)) { leftParenWhiteSpace = _tokenWhiteSpace; commaWhiteSpace = MakeWhiteSpaceList(); if (_langVersion.Is7x()) { args = FinishArgumentList(null, commaWhiteSpace, out ateTerminator); rightParenWhiteSpace = _tokenWhiteSpace; } else { bool trailingComma; List<Expression> l = ParseTestListAsExpr(null, out commaWhiteSpace, out trailingComma); if (l.Count == 1 && l[0] is ErrorExpression) { // error handling, classes is incomplete. return ErrorStmt( _verbatim ? (classWhiteSpace + "class" + nameWhiteSpace + name.VerbatimName + leftParenWhiteSpace + "(" + ((ErrorExpression)l[0]).VerbatimImage) : null ); } args = new Arg[l.Count]; for (int i = 0; i < l.Count; i++) { args[i] = new Arg(l[i]); } ateTerminator = Eat(TokenKind.RightParenthesis); rightParenWhiteSpace = _tokenWhiteSpace; } } else { isParenFree = true; args = new Arg[0]; } var mid = GetEnd(); // Save private prefix string savedPrefix = SetPrivatePrefix(name.VerbatimName); _classDepth++; // Parse the class body Statement body = ParseClassOrFuncBody(); _classDepth--; // Restore the private prefix _privatePrefix = savedPrefix; ClassDefinition ret = new ClassDefinition(nameExpr, args, body); AddVerbatimName(name, ret); if (_verbatim) { if (isParenFree) { AddIsAltForm(ret); } AddPreceedingWhiteSpace(ret, classWhiteSpace); AddSecondPreceedingWhiteSpace(ret, nameWhiteSpace); if (leftParenWhiteSpace != null) { AddThirdPreceedingWhiteSpace(ret, leftParenWhiteSpace); } if (rightParenWhiteSpace != null) { AddFourthPreceedingWhiteSpace(ret, rightParenWhiteSpace); } if (commaWhiteSpace != null) { AddListWhiteSpace(ret, commaWhiteSpace.ToArray()); } if (!ateTerminator) { AddErrorMissingCloseGrouping(ret); } } ret.HeaderIndex = mid; ret.SetLoc(start, body.EndIndex); return ret; }
// ClassDef public override bool Walk(ClassDefinition node) { if (_scope == node) { // the class body is being analyzed, go deep: return true; } else { // analyze the class definition itself (it is visited while analyzing parent scope): Define(node.Name); foreach (var e in node.Bases) { e.Expression.Walk(this); } return false; } }
public override bool Walk(ClassDefinition node) { _scopes.Add(node); return base.Walk(node); }
public override void PostWalk(ClassDefinition node) { _scopes.RemoveAt(_scopes.Count - 1); base.PostWalk(node); }
internal ClassInfo AddClass(ClassDefinition node, AnalysisUnit outerUnit) { InterpreterScope scope; var declScope = outerUnit.Scope; if (!declScope.TryGetNodeScope(node, out scope)) { if (node.Body == null || node.Name == null) { return null; } var unit = new ClassAnalysisUnit(node, declScope, outerUnit); var classScope = (ClassScope)unit.Scope; var classVar = declScope.AddLocatedVariable(node.Name, node.NameExpression, unit); classVar.AddTypes(unit, classScope.Class.SelfSet); declScope.Children.Add(classScope); declScope.AddNodeScope(node, classScope); unit.Enqueue(); scope = classScope; } return scope.Namespace as ClassInfo; }
// ClassDefinition public override bool Walk(ClassDefinition node) { return ShouldWalkWorker(node); }
// TODO: What about names being redefined? // remember classes/functions as they start new scopes public override bool Walk(ClassDefinition node) { var cls = AddClass(node, _curUnit); if (cls != null) { _analysisStack.Push(_curUnit); _curUnit = cls.AnalysisUnit; Debug.Assert(_scope.EnumerateTowardsGlobal.Contains(cls.AnalysisUnit.Scope.OuterScope)); _scope = cls.AnalysisUnit.Scope; return true; } return false; }
public override void PostWalk(ClassDefinition node) { PostWalkWorker(node); }
public ClassScope(ClassInfo classInfo, ClassDefinition ast, InterpreterScope outerScope) : base(classInfo, ast, outerScope) { classInfo.Scope = this; }
public override bool Walk(ClassDefinition node) { return false; }
public override bool Walk(ClassDefinition node) { _define.WalkName(node.NameExpression, node.GetVariableReference(_root)); bool oldInLoop = _inLoop; _inLoop = false; var res = base.Walk(node); _inLoop = oldInLoop; return res; }
public override void PostWalk(ClassDefinition node) { _scopes.Add(node); _allWrites.Add(node.GetVariableReference(_root)); _allWrittenVariables.Add(node.Variable); base.PostWalk(node); }