private void AddVariable(NameExpression expMember, string expValue) { Variables.Add(expMember, expValue); }
public AssignmentScopeNode(AssignmentStatement assign, NameExpression name) { _assign = assign; _name = name; }
// NameExpression public virtual bool Walk(NameExpression node) { return(true); }
// NameExpression public override bool Walk(NameExpression node) { return(false); }
protected virtual string VisitVariableExpression(NameExpression exp, out object resultObj) { resultObj = null; return(null); }
// NameExpression public override bool Walk(NameExpression node) { return(ShouldWalkWorker(node)); }
public override abstract bool Walk(NameExpression node);
// NameExpression public override bool Walk(NameExpression node) { return false; }
/// <summary> /// Gets the variables the given expression evaluates to. Variables include parameters, locals, and fields assigned on classes, modules and instances. /// /// Variables are classified as either definitions or references. Only parameters have unique definition points - all other types of variables /// have only one or more references. /// </summary> public IEnumerable <IAnalysisVariable> GetVariables(string exprText, int lineNumber) { var expr = GetExpressionFromText(exprText); var scopes = FindScopes(lineNumber); var eval = new ExpressionEvaluator(_unit.CopyForEval(), FindScopes(lineNumber).ToArray()); NameExpression name = expr as NameExpression; if (name != null) { for (int i = scopes.Count - 1; i >= 0; i--) { VariableDef def; if (IncludeScope(scopes, i, lineNumber) && scopes[i].Variables.TryGetValue(name.Name, out def)) { foreach (var res in ToVariables(def)) { yield return(res); } if (scopes[i] is FunctionScope) { // if this is a parameter or a local indicate any values which we know are assigned to it. foreach (var type in def.Types) { if (type.Location != null) { yield return(new AnalysisVariable(VariableType.Value, type.Location)); } } } else if (scopes[i] is ModuleScope) { foreach (var type in def.Types) { if (type.Location != null) { yield return(new AnalysisVariable(VariableType.Definition, type.Location)); } foreach (var reference in type.References) { yield return(new AnalysisVariable(VariableType.Reference, reference)); } } } } } var variables = _unit.ProjectState.BuiltinModule.GetDefinitions(name.Name); foreach (var referenceable in variables) { foreach (var res in ToVariables(referenceable)) { yield return(res); } } } MemberExpression member = expr as MemberExpression; if (member != null) { var objects = eval.Evaluate(member.Target); foreach (var v in objects) { var container = v as IReferenceableContainer; if (container != null) { var defs = container.GetDefinitions(member.Name); foreach (var def in defs) { foreach (var reference in def.Definitions) { yield return(new AnalysisVariable(VariableType.Definition, new LocationInfo(reference.Key, reference.Value.Line, reference.Value.Column, reference.Value.Length))); } foreach (var reference in def.References) { yield return(new AnalysisVariable(VariableType.Reference, new LocationInfo(reference.Key, reference.Value.Line, reference.Value.Column, reference.Value.Length))); } } } } } }
public ExtractMethodResult GetExtractionResult() { bool isStaticMethod = false, isClassMethod = false; var parameters = new List <Parameter>(); NameExpression selfParam = null; if (_targetScope is ClassDefinition) { var fromScope = _scopes[_scopes.Length - 1] as FunctionDefinition; Debug.Assert(fromScope != null); // we don't allow extracting from classes, so we have to be coming from a function if (fromScope != null) { if (fromScope.Decorators != null) { foreach (var decorator in fromScope.Decorators.Decorators) { NameExpression name = decorator as NameExpression; if (name != null) { if (name.Name == "staticmethod") { isStaticMethod = true; } else if (name.Name == "classmethod") { isClassMethod = true; } } } } if (!isStaticMethod) { if (fromScope.Parameters.Count > 0) { selfParam = fromScope.Parameters[0].NameExpression; parameters.Add(new Parameter(selfParam, ParameterKind.Normal)); } } } } foreach (var param in _parameters) { var paramName = new NameExpression(param); if (parameters.Count > 0) { paramName.AddPreceedingWhiteSpace(_ast, " "); } var newParam = new Parameter(paramName, ParameterKind.Normal); parameters.Add(newParam); } // include any non-closed over parameters as well... foreach (var input in _inputVars) { var variableScope = input.Scope; var parentScope = _targetScope; // are these variables a child of the target scope so we can close over them? while (parentScope != null && parentScope != variableScope) { parentScope = parentScope.Parent; } if (parentScope == null && input.Name != selfParam?.Name) { // we can either close over or pass these in as parameters, add them to the list var paramName = new NameExpression(input.Name); if (parameters.Count > 0) { paramName.AddPreceedingWhiteSpace(_ast, " "); } var newParam = new Parameter(paramName, ParameterKind.Normal); parameters.Add(newParam); } } var body = _target.GetBody(_ast); var isCoroutine = IsCoroutine(body); // reset leading indentation to single newline + indentation, this // strips out any proceeding comments which we don't extract var leading = _newline + body.GetIndentationLevel(_ast); body.SetLeadingWhiteSpace(_ast, leading); if (_outputVars.Count > 0) { // need to add a return statement Expression retValue; Expression[] names = new Expression[_outputVars.Count]; int outputIndex = 0; foreach (var name in _outputVars) { var nameExpr = new NameExpression(name.Name); nameExpr.AddPreceedingWhiteSpace(_ast, " "); names[outputIndex++] = nameExpr; } var tuple = new TupleExpression(false, names); tuple.RoundTripHasNoParenthesis(_ast); retValue = tuple; var retStmt = new ReturnStatement(retValue); retStmt.SetLeadingWhiteSpace(_ast, leading); body = new SuiteStatement( new Statement[] { body, retStmt } ); } else { // we need a SuiteStatement to give us our colon body = new SuiteStatement(new Statement[] { body }); } DecoratorStatement decorators = null; if (isStaticMethod) { decorators = new DecoratorStatement(new[] { new NameExpression("staticmethod") }); } else if (isClassMethod) { decorators = new DecoratorStatement(new[] { new NameExpression("classmethod") }); } var res = new FunctionDefinition(new NameExpression(_name), parameters.ToArray(), body, decorators); res.IsCoroutine = isCoroutine; StringBuilder newCall = new StringBuilder(); newCall.Append(_target.IndentationLevel); var method = res.ToCodeString(_ast); // fix up indentation... for (int curScope = 0; curScope < _scopes.Length; curScope++) { if (_scopes[curScope] == _targetScope) { // this is our target indentation level. var indentationLevel = _scopes[curScope].Body.GetIndentationLevel(_ast); var lines = method.Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); int minWhiteSpace = Int32.MaxValue; for (int curLine = decorators == null ? 1 : 2; curLine < lines.Length; curLine++) { var line = lines[curLine]; for (int i = 0; i < line.Length; i++) { if (!Char.IsWhiteSpace(line[i])) { minWhiteSpace = Math.Min(minWhiteSpace, i); break; } } } StringBuilder newLines = new StringBuilder(); newLines.Append(indentationLevel); newLines.Append(lines[0]); if (decorators != null) { newLines.Append(_newline); newLines.Append(indentationLevel); newLines.Append(lines[1]); } // don't include a bunch of blank lines... int endLine = lines.Length - 1; for (; endLine >= 0 && String.IsNullOrWhiteSpace(lines[endLine]); endLine--) { } newLines.Append(_newline); for (int curLine = decorators == null ? 1 : 2; curLine <= endLine; curLine++) { var line = lines[curLine]; newLines.Append(indentationLevel); if (_insertTabs) { newLines.Append('\t'); } else { newLines.Append(' ', _indentSize); } if (line.Length > minWhiteSpace) { newLines.Append(line, minWhiteSpace, line.Length - minWhiteSpace); } newLines.Append(_newline); } newLines.Append(_newline); method = newLines.ToString(); break; } } string comma; if (_outputVars.Count > 0) { comma = ""; foreach (var outputVar in _outputVars) { newCall.Append(comma); newCall.Append(outputVar.Name); comma = ", "; } newCall.Append(" = "); } else if (_target.ContainsReturn) { newCall.Append("return "); } if (isCoroutine) { newCall.Append("await "); } if (_targetScope is ClassDefinition) { var fromScope = _scopes[_scopes.Length - 1] as FunctionDefinition; Debug.Assert(fromScope != null); // we don't allow extracting from classes, so we have to be coming from a function if (isStaticMethod) { newCall.Append(_targetScope.Name); newCall.Append('.'); } else if (fromScope != null && fromScope.Parameters.Count > 0) { newCall.Append(fromScope.Parameters[0].Name); newCall.Append('.'); } } newCall.Append(_name); newCall.Append('('); comma = ""; foreach (var param in parameters) { if (param.Name != selfParam?.Name) { newCall.Append(comma); newCall.Append(param.Name); comma = ", "; } } newCall.Append(')'); return(new ExtractMethodResult( method, newCall.ToString() )); }
/// <summary> /// Finishes importing a module or module member. /// </summary> /// <param name="module"> /// The imported module, as returned from TryImportModule. /// </param> /// <param name="attribute"> /// Attribute within the module to resolve, already split at /// dots, as returned from TryImportModule. /// </param> /// <param name="importAs"> /// The name to save the imported module or member under. /// </param> /// <param name="node"> /// If <paramref name="addRef"/> is true, this node will be /// added as a reference of the imported value. /// </param> /// <param name="addRef"> /// True to add <paramref name="node"/> as a reference of the /// imported value. /// </param> private void FinishImportModuleOrMember(ModuleReference module, IReadOnlyList <string> attribute, string name, bool addRef, Node node, NameExpression nameReference) { if (AssignImportedModuleOrMember( name, GetImportedModuleOrMember(module, attribute, addRef, node, nameReference, attribute?.Count == 1 ? name : null), addRef, node, nameReference )) { // Imports into our global scope need to enqueue modules that have imported us if (Scope == GlobalScope.Scope) { GlobalScope.ModuleDefinition.EnqueueDependents(); } } }
/// <summary> /// Resolves and returns an imported member. /// </summary> /// <param name="module"> /// The module to import or import from. /// </param> /// <param name="attribute"> /// An optional attribute (already split at the dots) to /// </param> /// <param name="node"> /// The import location. If <paramref name="addRef"/> is true, /// this location will be marked as a reference of the imported /// value. /// </param> /// <param name="addRef"> /// True to make <paramref name="node"/> a reference to the /// imported member. /// </param> /// <param name="linkToName"> /// If not null, the name in the current scope to link to the /// value in the module. This is only used when /// <paramref name="attribute"/> contains one element. /// </param> /// <returns>The imported member, or null.</returns> private IAnalysisSet GetImportedModuleOrMember(ModuleReference module, IReadOnlyList <string> attribute, bool addRef, Node node, NameExpression nameReference, string linkToName) { if (module?.Module == null) { return(null); } if (attribute == null || attribute.Count == 0) { return(module.AnalysisModule); } var value = module.Module.GetModuleMember(node, _unit, attribute[0], addRef, Scope, linkToName); if (attribute.Count == 1) { if (nameReference != null) { module.Module.GetModuleMember(nameReference, _unit, attribute[0], addRef, null, null); } } else { foreach (var n in attribute.Skip(1)) { if (value.IsNullOrEmpty()) { return(null); } value = value.GetMember(node, _unit, n); } } return(value.IsNullOrEmpty() ? null : value); }
public override bool Walk(NameExpression node) { _fc.Delete(node.Name); return(false); }
// NameExpression public override bool Walk(NameExpression node) { return Location >= node.StartIndex && Location <= node.EndIndex; }
public void SetUp(List <string> args) { if (verbose) { Console.WriteLine("import path:"); foreach (string directory in pathResolver.Directories) { Console.WriteLine(" " + directory); } } AppDomain domain = Thread.GetDomain(); rootModule = new Module(null, null); foreach (Assembly assembly in domain.GetAssemblies()) { AssemblyLoaded(assembly); } domain.AssemblyLoad += OnDomainAssemblyLoad; rootModule.SetName("null", null); rootModule.SetName("true", true); rootModule.SetName("false", false); rootModule.SetName("args", args); DefaultWhitespace.SetUp(rootModule, grammar); LineComment.SetUp(rootModule, grammar); BlockComment.SetUp(rootModule, grammar); Whitespace.SetUp(rootModule, grammar); Name.SetUp(rootModule, grammar); Name.SetUp(rootModule, grammar); Number.SetUp(rootModule, grammar); Base.String.SetUp(rootModule, grammar); Expression.SetUp(rootModule, grammar); ValueExpression.SetUp(rootModule, grammar); NameExpression.SetUp(rootModule, grammar); ParenExpression.SetUp(rootModule, grammar); MemberExpression.SetUp(rootModule, grammar); CallExpression.SetUp(rootModule, grammar); CallInParentScopeExpression.SetUp(rootModule, grammar); NewExpression.SetUp(rootModule, grammar); TypeExpression.SetUp(rootModule, grammar); IsExpression.SetUp(rootModule, grammar); AsExpression.SetUp(rootModule, grammar); UnaryExpression.SetUp(rootModule, grammar); NotExpression.SetUp(rootModule, grammar); MultiplicativeExpression.SetUp(rootModule, grammar); MultiplyExpression.SetUp(rootModule, grammar); DivideExpression.SetUp(rootModule, grammar); AdditiveExpression.SetUp(rootModule, grammar); AddExpression.SetUp(rootModule, grammar); SubtractExpression.SetUp(rootModule, grammar); ComparisonExpression.SetUp(rootModule, grammar); LessExpression.SetUp(rootModule, grammar); LessOrEqualExpression.SetUp(rootModule, grammar); EqualityExpression.SetUp(rootModule, grammar); InequalityExpression.SetUp(rootModule, grammar); GreaterExpression.SetUp(rootModule, grammar); GreaterOrEqualExpression.SetUp(rootModule, grammar); JunctionExpression.SetUp(rootModule, grammar); AndExpression.SetUp(rootModule, grammar); AssignmentExpression.SetUp(rootModule, grammar); AssignExpression.SetUp(rootModule, grammar); /* * NameExpression = ValueExpression * ParenExpression = ValueExpression * * CallExpression < ValueExpression * CallInParentScopeExpression = CallExpression * MemberExpression = CallExpression * * NewExpression < CallExpression * TypeExpression < NewExpression * UnaryExpression < TypeExpression * MultiplicativeExpression < UnaryExpression * AdditiveExpression < MultiplicativeExpression * ComparisonExpression < AdditiveExpression * JunctionExpression < ComparisonExpression * AssignmentExpression < JunctionExpression */ Precedence.SetPrecedence(NameExpression.pattern.Precedence, ValueExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(ParenExpression.pattern.Precedence, ValueExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(CallExpression.pattern.Precedence, ValueExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(CallInParentScopeExpression.pattern.Precedence, CallExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(MemberExpression.pattern.Precedence, CallExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(NewExpression.pattern.Precedence, CallExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(TypeExpression.pattern.Precedence, NewExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(UnaryExpression.pattern.Precedence, TypeExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(MultiplicativeExpression.pattern.Precedence, UnaryExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(AdditiveExpression.pattern.Precedence, MultiplicativeExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(ComparisonExpression.pattern.Precedence, AdditiveExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(JunctionExpression.pattern.Precedence, ComparisonExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(AssignmentExpression.pattern.Precedence, JunctionExpression.pattern.Precedence, Relation.Lower); Grammar.PatternChanged(ValueExpression.pattern, NameExpression.pattern, ParenExpression.pattern, MemberExpression.pattern, CallExpression.pattern, NewExpression.pattern, TypeExpression.pattern, UnaryExpression.pattern, MultiplicativeExpression.pattern, AdditiveExpression.pattern, ComparisonExpression.pattern, JunctionExpression.pattern, AssignmentExpression.pattern); PatternExpression.SetUp(rootModule, grammar); ReferencePatternExpression.SetUp(rootModule, grammar); AnyPatternExpression.SetUp(rootModule, grammar); TextPatternExpression.SetUp(rootModule, grammar); Option.SetUp(rootModule, grammar); BlockPatternExpression.SetUp(rootModule, grammar); ParenPatternExpression.SetUp(rootModule, grammar); TokenPatternExpression.SetUp(rootModule, grammar); RangePatternExpression.SetUp(rootModule, grammar); RepeatPatternExpression.SetUp(rootModule, grammar); AndPatternExpression.SetUp(rootModule, grammar); NotPatternExpression.SetUp(rootModule, grammar); LabelPatternExpression.SetUp(rootModule, grammar); SequencePatternExpression.SetUp(rootModule, grammar); AltPatternExpression.SetUp(rootModule, grammar); /* * EndPatternExpression = ReferencePatternExpression * AnyPatternExpression = ReferencePatternExpression * TextPatternExpression = ReferencePatternExpression * BlockPatternExpression = ReferencePatternExpression * ParenPatternExpression = ReferencePatternExpression * TokenPatternExpression = ReferencePatternExpression * * RangePatternExpression < ReferencePatternExpression * * AndPatternExpression < RangePatternExpression * NotPatternExpression = AndPatternExpression * RepeatPatternExpression = AndPatternExpression * * LabelPatternExpression < AndPatternExpression * SequencePatternExpression < LabelPatternExpression * AltPatternExpression < SequencePatternExpression */ Precedence.SetPrecedence(AnyPatternExpression.pattern.Precedence, ReferencePatternExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(TextPatternExpression.pattern.Precedence, ReferencePatternExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(BlockPatternExpression.pattern.Precedence, ReferencePatternExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(ParenPatternExpression.pattern.Precedence, ReferencePatternExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(TokenPatternExpression.pattern.Precedence, ReferencePatternExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(RangePatternExpression.pattern.Precedence, ReferencePatternExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(AndPatternExpression.pattern.Precedence, RangePatternExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(NotPatternExpression.pattern.Precedence, AndPatternExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(RepeatPatternExpression.pattern.Precedence, AndPatternExpression.pattern.Precedence, Relation.Equal); Precedence.SetPrecedence(LabelPatternExpression.pattern.Precedence, AndPatternExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(SequencePatternExpression.pattern.Precedence, LabelPatternExpression.pattern.Precedence, Relation.Lower); Precedence.SetPrecedence(AltPatternExpression.pattern.Precedence, SequencePatternExpression.pattern.Precedence, Relation.Lower); Grammar.PatternChanged(ReferencePatternExpression.pattern, AnyPatternExpression.pattern, TextPatternExpression.pattern, BlockPatternExpression.pattern, ParenPatternExpression.pattern, TokenPatternExpression.pattern, RangePatternExpression.pattern, RepeatPatternExpression.pattern, AndPatternExpression.pattern, NotPatternExpression.pattern, LabelPatternExpression.pattern, SequencePatternExpression.pattern, AltPatternExpression.pattern); Statement.SetUp(rootModule, grammar); ExpressionStatement.SetUp(rootModule, grammar); CompoundStatement.SetUp(rootModule, grammar); PrintStatement.SetUp(rootModule, grammar); IfStatement.SetUp(rootModule, grammar); WhileStatement.SetUp(rootModule, grammar); ReturnStatement.SetUp(rootModule, grammar); ThrowStatement.SetUp(rootModule, grammar); TryStatement.SetUp(rootModule, grammar); ModuleStatement.SetUp(rootModule, grammar); FunctionStatement.SetUp(rootModule, grammar); Member.SetUp(rootModule, grammar); PatternMember.SetUp(rootModule, grammar); FieldMember.SetUp(rootModule, grammar); ConstructorMember.SetUp(rootModule, grammar); MethodMember.SetUp(rootModule, grammar); ClassStatement.SetUp(rootModule, grammar); SetPrecedenceStatement.SetUp(rootModule, grammar); UsingStatement.SetUp(rootModule, grammar); ImportStatement.SetUp(rootModule, grammar); TopLevelStatement.SetUp(rootModule, grammar); Program.SetUp(rootModule, grammar); Grammar.PatternChanged(Member.pattern, Statement.pattern); grammar.RootPattern = Program.pattern; hasBeenSetUp = true; }
public override bool Walk(NameExpression node) { _fc.Define(node.Name); return false; }
private async Task <Expression> ParsePrimaryTailExpression() { Expression leftMost = null; if (await MaybeToken("statictype", true)) { if (!await MaybeToken("(", false)) { throw new NotImplementedException(); } leftMost = await ParseExpression(); if (leftMost == null) { throw new NotImplementedException(); } if (!await MaybeToken(")", false)) { throw new NotImplementedException(); } leftMost = new StaticTypeExpression { Expression = leftMost }; } else if (await MaybeToken("type", true)) { if (!await MaybeToken("(", false)) { throw new NotImplementedException(); } leftMost = await ParseType(); if (leftMost == null) { throw new NotImplementedException(); } if (!await MaybeToken(")", false)) { throw new NotImplementedException(); } } else if (await MaybeToken("tag", true)) { if (!await MaybeToken("(", false)) { throw new NotImplementedException(); } if (!await MaybeString()) { throw new NotImplementedException(); } string tag = LastString; if (!await MaybeToken(")", false)) { throw new NotImplementedException(); } return(new TagExpression { Tag = new StringConstant { Value = tag } }); } else if (await MaybeToken("(", false)) { // Parse a parenthetical expression leftMost = await ParseExpression(); if (leftMost == null) { throw new NotImplementedException(); } if (!await MaybeToken(")", false)) { throw new NotImplementedException(); } } else { leftMost = ParseUnary(); } if (leftMost != null) { } else if (await MaybeToken("null", true)) { // In theory, null cannot be dotwalked, called, etc. // but that might REALLY mess up our parsing leftMost = new NullExpression { }; } else if (await MaybeToken("true", true)) { leftMost = new BoolConstant { Value = true }; } else if (await MaybeToken("false", true)) { leftMost = new BoolConstant { Value = false }; } else if (await MaybeName()) { leftMost = new NameExpression { Name = LastName }; } else if (await MaybeInt()) { leftMost = new IntConstant { Value = LastInt }; } else if (await MaybeDouble()) { throw new NotImplementedException(); } else if (await MaybeString()) { leftMost = new StringConstant { Value = LastString }; } while (!eof) { if (leftMost is NameExpression ne && await MaybeToken("(", false)) { Expression[] args; if (await MaybeToken(")", false)) { args = new Expression[0]; } else { args = await ParseArgumentList(); if (!await MaybeToken(")", false)) { throw new NotImplementedException(); } } leftMost = new CallExpression { FunctionName = ne, Arguments = args }; }
// NameExpression public virtual bool Walk(NameExpression node) { return true; }
public override bool Walk(NameExpression node) => Save(node, base.Walk(node), _options.Names);
internal static string GetDefaultValue(PythonAnalyzer state, Parameter curParam, PythonAst tree) { if (curParam.DefaultValue != null) { // TODO: Support all possible expressions for default values, we should // probably have a PythonAst walker for expressions or we should add ToCodeString() // onto Python ASTs so they can round trip ConstantExpression defaultValue = curParam.DefaultValue as ConstantExpression; if (defaultValue != null) { return(defaultValue.GetConstantRepr(state.LanguageVersion)); } else { NameExpression nameExpr = curParam.DefaultValue as NameExpression; if (nameExpr != null) { return(nameExpr.Name); } else { DictionaryExpression dict = curParam.DefaultValue as DictionaryExpression; if (dict != null) { if (dict.Items.Count == 0) { return("{}"); } else { return("{...}"); } } else { ListExpression list = curParam.DefaultValue as ListExpression; if (list != null) { if (list.Items.Count == 0) { return("[]"); } else { return("[...]"); } } else { TupleExpression tuple = curParam.DefaultValue as TupleExpression; if (tuple != null) { if (tuple.Items.Count == 0) { return("()"); } else { return("(...)"); } } else { return(curParam.DefaultValue.ToCodeString(tree)); } } } } } } return(null); }
public override bool Walk(NameExpression node) { return(UpdateLineInfo(node, true)); }
public override void PostWalk(NameExpression node) { PostWalkWorker(node); }
public IMemberCompletionContext ProvideMemberCompletionContext(SourceLocation sourceLocation) { if (_scope.DataContext == null || _scope.Parameters == null) { return(new NullMemberCompletionContext(sourceLocation)); } _errorReporter.Reset(); Token token = _completionParser.GetTokenBeforeSourcePos(sourceLocation); Identifier remainingPart; if (token.Id != TokenId.Identifier) { remainingPart = null; } else { remainingPart = Identifier.InternalFromSource(token.Text); SourceLocation oneBefore = token.Range.StartLocation; oneBefore--; token = _completionParser.GetTokenBeforeSourcePos(oneBefore); } if (token.Id == TokenId.ON) { NamedTableReference[] joinedTables = _completionParser.GetTableReferencesOfJoin(sourceLocation); DeclareTableRefs(joinedTables); return(new TableRelationMemberContext(sourceLocation, remainingPart, _scope, _resolver.CurrentScope)); } else if (token.Id == TokenId.JOIN) { NamedTableReference[] joinedTables = _completionParser.GetTableReferencesOfJoin(sourceLocation); DeclareTableRefs(joinedTables); return(new JoinTableMemberContext(sourceLocation, remainingPart, _scope, _resolver.CurrentScope)); } else { ExpressionNode expressionBeforeDot = _completionParser.ParseExpressionBeforeDot(sourceLocation, out remainingPart); ThrowErrors(); DeclareTableRefs(sourceLocation); if (expressionBeforeDot == null) { return(new GlobalScopeMemberContext(sourceLocation, remainingPart, _scope, _resolver.CurrentScope)); } else { NameExpression expressionAsName = expressionBeforeDot as NameExpression; if (expressionAsName != null) { // Try to resolve a table name. foreach (NamedTableReference namedTableReference in _completionParser.GetTableReferencesOfQuery(sourceLocation)) { if (expressionAsName.Name.Matches(namedTableReference.CorrelationName)) { TableBinding[] tables = _scope.DataContext.Tables.Find(namedTableReference.TableName); if (tables != null && tables.Length == 1) { TableBinding tableBinding = tables[0]; return(new TableContext(sourceLocation, remainingPart, _scope, tableBinding, namedTableReference.CorrelationName.Text)); } break; } } } expressionBeforeDot = ResolveExpression(expressionBeforeDot); if (expressionBeforeDot != null && expressionBeforeDot.ExpressionType != null) { return(new MemberContext(sourceLocation, remainingPart, _scope, expressionBeforeDot)); } } } ThrowErrors(); return(new NullMemberCompletionContext(sourceLocation)); }
public virtual void PostWalk(NameExpression node) { }
private NamedLocation GetNamedLocation(NameExpression node) => GetNamedLocation(node.Name, node);
public override void PostWalk(NameExpression node) { }
public override bool Walk(NameExpression node) { _outer._names.Add(node.Name); return(true); }
public AssignmentScopeNode(PythonAst ast, AssignmentStatement assign, NameExpression name) { _assign = assign; _name = name; _ast = ast; }
public override bool Walk(NameExpression node) { _head.Names.Add(Tuple.Create(node.Name, Span.FromBounds(node.StartIndex, node.EndIndex))); return(base.Walk(node)); }
public override bool Walk(NameExpression node) { var reference = node.GetVariableReference(_collector._root); return(WalkName(node, reference)); }
// NameExpression public override bool Walk(NameExpression node) { return(Location >= node.StartIndex && Location <= node.EndIndex); }
public ModuleName(NameExpression[] names) : base(names) { }
public override bool Walk(NameExpression node) { writer.WriteLine("Name: " + node.Name); return(base.Walk(node)); }
// NameExpr public override bool Walk(NameExpression node) { TotemVariable binding; if (_variables.TryGetValue(node.Name, out binding)) { //node.Assigned = IsAssigned(binding); if (!IsInitialized(binding)) { binding.ReadBeforeInitialized = true; } } return true; }
/// <summary> /// Creates the variable for containing an imported member. /// </summary> /// <param name="variableName">The name of the variable.</param> /// <param name="value"></param> /// <param name="addRef">True to make <paramref name="node"/> a reference to the imported member.</param> /// <param name="node">The imported location. If <paramref name="addRef"/> is true, this location will be marked as a reference of the imported value.</param> /// <param name="nameReference"></param> private void AssignImportedModuleOrMember(string variableName, IAnalysisSet value, bool addRef, Node node, NameExpression nameReference) { var v = Scope.CreateVariable(node, _unit, variableName, addRef); if (addRef && nameReference != null) { v.AddReference(nameReference, _unit); } v.IsAlwaysAssigned = true; if (!value.IsNullOrEmpty() && v.AddTypes(_unit, value)) { GlobalScope.ModuleDefinition.EnqueueDependents(); } }
private void SetVariableForImportedMember(IModule module, NameExpression importNameExpression, string importedName, NameExpression variableExpression, string variableName, bool addRef) { var importedMember = module.GetModuleMember(importNameExpression, _unit, importedName, addRef, Scope, variableName); if (variableExpression != null) { module.GetModuleMember(variableExpression, _unit, importedName, addRef, null, null); } if (importedMember.IsNullOrEmpty()) { importedMember = null; } AssignImportedModuleOrMember(variableName, importedMember, addRef, importNameExpression, variableExpression); }
public AssignExpression(NameExpression name, IExpression right, Token<TokenType> token) { this.name = name; this.right = right; this.token = token; }