public override bool Walk(NameExpression node) { // Called for the sublist parameters. The elements of the tuple become regular // local variables, therefore don't make the parameters (DefineParameter), but // regular locals (DefineName) _binder.DefineName(node.Name); node.Reference = _binder.Reference(node.Name); return false; }
public override bool Walk(NameExpression node) { if (currentAssignStatement != null) { string nodeName = node.Name; if (nodeName == variableName) { foundVariableAssignment = true; } } return base.Walk(node); }
// decorators ::= // decorator+ // decorator ::= // "@" dotted_name ["(" [argument_list [","]] ")"] NEWLINE private List<Expression> ParseDecorators() { List<Expression> decorators = new List<Expression>(); while (MaybeEat(TokenKind.At)) { var start = GetStart(); Expression decorator = new NameExpression(ReadName()); decorator.SetLoc(_globalParent, start, GetEnd()); while (MaybeEat(TokenKind.Dot)) { string name = ReadNameMaybeNone(); decorator = new MemberExpression(decorator, name); decorator.SetLoc(_globalParent, GetStart(), GetEnd()); } decorator.SetLoc(_globalParent, start, GetEnd()); if (MaybeEat(TokenKind.LeftParenthesis)) { if (_sink != null) { _sink.StartParameters(GetSourceSpan()); } Arg[] args = FinishArgumentList(null); decorator = FinishCallExpr(decorator, args); } decorator.SetLoc(_globalParent, start, GetEnd()); EatNewLine(); decorators.Add(decorator); } return decorators; }
// primary: atom | attributeref | subscription | slicing | call // atom: identifier | literal | enclosure // enclosure: // parenth_form | // list_display | // generator_expression | // dict_display | // string_conversion | // yield_atom private Expression ParsePrimary() { Token t = PeekToken(); Expression ret; switch (t.Kind) { case TokenKind.LeftParenthesis: // parenth_form, generator_expression, yield_atom NextToken(); return FinishTupleOrGenExp(); case TokenKind.LeftBracket: // list_display NextToken(); return FinishListValue(); case TokenKind.LeftBrace: // dict_display NextToken(); return FinishDictOrSetValue(); case TokenKind.BackQuote: // string_conversion NextToken(); return FinishStringConversion(); case TokenKind.Name: // identifier NextToken(); string name = (string)t.Value; if (_sink != null) { _sink.StartName(GetSourceSpan(), name); } ret = new NameExpression(FixName(name)); ret.SetLoc(_globalParent, GetStart(), GetEnd()); return ret; case TokenKind.Constant: // literal NextToken(); var start = GetStart(); object cv = t.Value; string cvs = cv as string; if (cvs != null) { cv = FinishStringPlus(cvs); } else { Bytes bytes = cv as Bytes; if (bytes != null) { cv = FinishBytesPlus(bytes); } } if (t is UnicodeStringToken) { ret = ConstantExpression.MakeUnicode((string)cv); } else { ret = new ConstantExpression(cv); } ret.SetLoc(_globalParent, start, GetEnd()); return ret; default: ReportSyntaxError(_lookahead.Token, _lookahead.Span, ErrorCodes.SyntaxError, _allowIncomplete || _tokenizer.EndContinues); // error node ret = new ErrorExpression(); ret.SetLoc(_globalParent, _lookahead.Span.Start, _lookahead.Span.End); return ret; } }
public override bool Walk(NameExpression node) { node.Parent = _currentScope; node.Reference = Reference(node.Name); return true; }
internal Name(NameExpression expr, expr_context ctx) : this(expr.Name, ctx) { }
// NameExpression public virtual bool Walk(NameExpression node) { return true; }
public override void PostWalk(NameExpression node) { }
public override void PostWalk(NameExpression node) { }
internal Name(NameExpression expr, expr_context ctx) : this(expr.Name, ctx) { GetSourceLocation(expr); }
public override bool Walk(NameExpression node) { node.Parent = _currentScope; node.Reference = Reference(node.Name); return(true); }
public override bool Walk(NameExpression node) { _fc.Delete(node.Name); return(false); }
public override bool Walk(NameExpression node) { _binder.DefineName(node.Name); return(false); }
private static bool GetPropertyAccessors(CallExpression rhsCall, ref NameExpression ne, ref string get, ref string set) { bool fCantEmit = false; for (int i = 0; i < rhsCall.Args.Count; i++) { // fget, fset, fdel, doc if (rhsCall.Args[i].Name != SymbolTable.Empty) { switch (rhsCall.Args[i].Name.GetString()) { case "fget": ne = rhsCall.Args[i].Expression as NameExpression; if (ne == null) { fCantEmit = true; break; } get = ne.Name.GetString(); break; case "fset": ne = rhsCall.Args[i].Expression as NameExpression; if (ne == null) { fCantEmit = true; break; } set = ne.Name.GetString(); break; default: fCantEmit = true; break; } } else { switch (i) { case 0: ne = rhsCall.Args[i].Expression as NameExpression; if (ne == null) { fCantEmit = true; break; } get = ne.Name.GetString(); break; case 1: ne = rhsCall.Args[i].Expression as NameExpression; if (ne == null) { fCantEmit = true; break; } set = ne.Name.GetString(); break; default: fCantEmit = true; break; } } } return fCantEmit; }
public virtual void PostWalk(NameExpression node) { }
public override bool Walk(NameExpression node) { binder.Deleted(node.Name); return false; }
// NameExpression public bool Walk(NameExpression node) { return Process(node); }
public override bool Walk(NameExpression node) { node.Reference = Reference(node.Name); return true; }
public override bool Walk(NameExpression node) { if (null == node) { throw new ArgumentNullException("node"); } Define(node.Name); return false; }
public void PostWalk(NameExpression node) { PostProcess(node); }
public override bool Walk(NameExpression node) { binder.DefineParameter(node.Name); return false; }
// NameExpression public override bool Walk(NameExpression node) { if (null == node) { throw new ArgumentNullException("node"); } Reference(node.Name); return true; }
/// <summary> /// Sets the property value that is referenced by this field expression. /// </summary> /// <remarks> /// This method checks that the name expression matches a created instance before /// converting the name expression as a string and setting the property value. /// </remarks> public bool SetPropertyValue(IComponentCreator componentCreator, NameExpression nameExpression) { object component = GetComponent(componentCreator); PropertyDescriptor property = GetProperty(component, memberName); if (property != null) { string name = nameExpression.Name; if (property.PropertyType != typeof(bool)) { if ("self" == name) { return SetPropertyValue(component, memberName, componentCreator.RootComponent); } else { object instance = componentCreator.GetInstance(name); if (instance != null) { return SetPropertyValue(component, memberName, instance); } } } return SetPropertyValue(component, memberName, name); } return false; }
public override bool Walk(NameExpression node) { if (!(Parent(0) is CallExpression) || !functionNameMapping.ContainsKey(node.Name)) { CheckForIllegalWords(node, node.Name); } Content(node.Name); return false; }
public override void PostWalk(NameExpression node) { base.PostWalk(node); Console.WriteLine("NODE NAME: "+node.Name); }
public override bool Walk(NameExpression node) { if (!FoundInitializeComponentMethod) { return false; } fieldExpression.SetPropertyValue(componentCreator, node); return false; }
// NameExpr public override bool Walk(NameExpression node) { Binding binding; if (bindings.TryGetValue(node.Name, out binding)) { int index = binding.Index * 2; node.IsDefined = bits.Get(index); if (!node.IsDefined) { binding.UninitializedUse(); } if (!bits.Get(index + 1)) { // Found an unbound use of the name => need to initialize to Uninitialized.instance binding.UnassignedUse(); } } return true; }
public override bool Walk(NameExpression node) { _binder.DefineName(node.Name); return false; }
public override bool Walk(NameExpression node) { _fc.Delete(node.Name); return false; }
// parameter ::= // identifier | "(" sublist ")" Expression ParseSublistParameter(Dictionary<string, object> names) { Token t = NextToken(); Expression ret = null; switch (t.Kind) { case TokenKind.LeftParenthesis: // sublist ret = ParseSublist(names); Eat(TokenKind.RightParenthesis); break; case TokenKind.Name: // identifier string name = FixName((string)t.Value); NameExpression ne = new NameExpression(name); CompleteParameterName(ne, name, names); return ne; default: ReportSyntaxError(_token); ret = new ErrorExpression(); ret.SetLoc(GetStart(), GetEnd()); break; } return ret; }
// NameExpr public override bool Walk(NameExpression node) { PythonVariable binding; if (_variables.TryGetValue(node.Name, out binding)) { node.Assigned = IsAssigned(binding); if (!IsInitialized(binding)) { binding.ReadBeforeInitialized = true; } } return true; }
// parameter ::= // identifier | "(" sublist ")" private Expression ParseSublistParameter(HashSet<string> names) { Token t = NextToken(); Expression ret = null; switch (t.Kind) { case TokenKind.LeftParenthesis: // sublist ret = ParseSublist(names); Eat(TokenKind.RightParenthesis); break; case TokenKind.Name: // identifier string name = FixName((string)t.Value); NameExpression ne = new NameExpression(name); CompleteParameterName(ne, name, names); return ne; default: ReportSyntaxError(_token); ret = Error(); break; } return ret; }
/// <summary> /// Deserializes expressions of the form: /// /// 1) self /// </summary> object Deserialize(NameExpression nameExpression) { string name = nameExpression.Name; if ("self" == name.ToLowerInvariant()) { return componentCreator.RootComponent; } else { bool result; if (Boolean.TryParse(name, out result)) { return result; } } return componentCreator.GetInstance(name); }
// genexpr_for ::= "for" target_list "in" or_test [genexpr_iter] // genexpr_iter ::= (genexpr_for | genexpr_if) * // // "for" has NOT been eaten before entering this method private Expression ParseGeneratorExpression(Expression expr) { ForStatement root = ParseGenExprFor(); Statement current = root; for (; ; ) { if (PeekToken(Tokens.KeywordForToken)) { current = NestGenExpr(current, ParseGenExprFor()); } else if (PeekToken(Tokens.KeywordIfToken)) { current = NestGenExpr(current, ParseGenExprIf()); } else { // Generator Expressions have an implicit function definition and yield around their expression. // (x for i in R) // becomes: // def f(): // for i in R: yield (x) ExpressionStatement ys = new ExpressionStatement(new YieldExpression(expr)); ys.Expression.SetLoc(_globalParent, expr.IndexSpan); ys.SetLoc(_globalParent, expr.IndexSpan); NestGenExpr(current, ys); break; } } // We pass the outermost iterable in as a parameter because Python semantics // say that this one piece is computed at definition time rather than iteration time const string fname = "<genexpr>"; Parameter parameter = new Parameter("__gen_$_parm__", 0); FunctionDefinition func = new FunctionDefinition(fname, new Parameter[] { parameter }, root); func.IsGenerator = true; func.SetLoc(_globalParent, root.StartIndex, GetEnd()); func.HeaderIndex = root.EndIndex; // Transform the root "for" statement Expression outermost = root.List; NameExpression ne = new NameExpression("__gen_$_parm__"); ne.SetLoc(_globalParent, outermost.IndexSpan); root.List = ne; GeneratorExpression ret = new GeneratorExpression(func, outermost); ret.SetLoc(_globalParent, expr.StartIndex, GetEnd()); return ret; }
public string Visit(PyAst.NameExpression node) => node.Name;