public CartesianLocalVariable(string name, EnvironmentRecord definingScope, VariableDef specialized, VariableDef shared) { Specialized = specialized; Shared = shared; DefiningScope = definingScope; Name = name; }
public override bool Walk(Block node) { var prevScope = _scope; var prevSuite = _curSuite; _curSuite = node; try { // recursively walk the statements in the suite for (int i = 0; i < node.Count; i++) { if (DDG.IsGwtCode(node, i)) { return(false); } node[i].Walk(this); } } finally { _curSuite = prevSuite; while (_scope != prevScope) { StatementEnvironmentRecord stmtRec = _scope as StatementEnvironmentRecord; if (stmtRec != null) { stmtRec.EndIndex = node.GetEndIndex(_tree.LocationResolver); } _scope = _scope.Parent; } } return(false); }
protected EnvironmentRecord(EnvironmentRecord cloned, bool isCloned) { Debug.Assert(isCloned); if (cloned.HasChildren) { _children = new List<EnvironmentRecord>(); _children.AddRange(cloned.Children); } }
private static void ProcessVariablesForScope(EnvironmentRecord scope, List <CartesianLocalVariable> specLocals) { foreach (var variable in scope.LocalVariables) { specLocals.Add( new CartesianLocalVariable( variable.Key, scope, CopyVariableDef(variable.Value), variable.Value ) ); } if (scope.HasChildren) { foreach (var childScope in scope.Children) { if (!(childScope is DeclarativeEnvironmentRecord)) { ProcessVariablesForScope(childScope, specLocals); } } } }
public OverviewWalker(ProjectEntry entry, AnalysisUnit topAnalysis, JsAst tree, bool isNested = false) { _entry = entry; _curUnit = topAnalysis; _isNested = isNested; _tree = tree; _scope = topAnalysis.Environment; }
protected EnvironmentRecord(EnvironmentRecord cloned, bool isCloned) { Debug.Assert(isCloned); if (cloned.HasChildren) { _children = new List <EnvironmentRecord>(); _children.AddRange(cloned.Children); } }
public OverviewWalker(ProjectEntry entry, AnalysisUnit topAnalysis, JsAst tree, bool isNested = false) { _entry = entry; _curUnit = topAnalysis; _isNested = isNested; _tree = tree; _scope = topAnalysis.Environment; }
public override void PostWalk(FunctionObject node) { if (node.Body != null) { Debug.Assert(_scope is DeclarativeEnvironmentRecord && ((DeclarativeEnvironmentRecord)_scope).Node == node); Debug.Assert(!(_scope.Parent is DeclarativeEnvironmentRecord) || ((DeclarativeEnvironmentRecord)_scope.Parent).Node != node); _scope = _scope.Parent; _curUnit = _analysisStack.Pop(); Debug.Assert(_scope.EnumerateTowardsGlobal.Contains(_curUnit.Environment)); } }
private bool WalkFunction(FunctionObject node, bool isExpression) { var functionAnalysis = AddFunction(node, _curUnit, isExpression); if (functionAnalysis != null) { _analysisStack.Push(_curUnit); _curUnit = functionAnalysis; Debug.Assert(_scope.EnumerateTowardsGlobal.Contains(functionAnalysis.Environment.Parent)); _scope = functionAnalysis.Environment; return true; } return false; }
public CartesianProductFunctionAnalysisUnit(UserFunctionValue funcInfo, EnvironmentRecord environment, AnalysisUnit outerUnit, UserFunctionValue.CallArgs callArgs, VariableDef returnValue) : base(funcInfo, outerUnit, environment.Parent, outerUnit.ProjectEntry, environment) { _callArgs = callArgs; _returnValue = returnValue; _this = new VariableDef(); var funcScope = environment as FunctionEnvironmentRecord; var specLocals = new List<CartesianLocalVariable>(); ProcessVariablesForScope(funcScope, specLocals); _specializedLocals = specLocals.ToArray(); }
internal FunctionAnalysisUnit( UserFunctionValue function, AnalysisUnit declUnit, EnvironmentRecord declScope, IJsProjectEntry declEntry, EnvironmentRecord scope ) : base(function.FunctionObject, declUnit.Tree, null) { _declUnit = declUnit; Function = function; _env = scope; }
internal FunctionAnalysisUnit( UserFunctionValue function, AnalysisUnit declUnit, EnvironmentRecord declScope, IJsProjectEntry declEntry, EnvironmentRecord scope ) : base(function.FunctionObject, declUnit.Tree, null) { _declUnit = declUnit; Function = function; _env = scope; }
internal FunctionAnalysisUnit( UserFunctionValue function, AnalysisUnit declUnit, EnvironmentRecord declScope, IJsProjectEntry declEntry ) : base(function.FunctionObject, declUnit.Tree, null) { _declUnit = declUnit; Function = function; var scope = new FunctionEnvironmentRecord(Function, this, Function.FunctionObject, declScope, declEntry); scope.EnsureParameters(this); _env = scope; }
public CartesianProductFunctionAnalysisUnit(UserFunctionValue funcInfo, EnvironmentRecord environment, AnalysisUnit outerUnit, UserFunctionValue.CallArgs callArgs, VariableDef returnValue) : base(funcInfo, outerUnit, environment.Parent, outerUnit.ProjectEntry, environment) { _callArgs = callArgs; _returnValue = returnValue; _this = new VariableDef(); var funcScope = environment as FunctionEnvironmentRecord; var specLocals = new List <CartesianLocalVariable>(); ProcessVariablesForScope(funcScope, specLocals); _specializedLocals = specLocals.ToArray(); }
private bool WalkFunction(FunctionObject node, bool isExpression) { var functionAnalysis = AddFunction(node, _curUnit, isExpression); if (functionAnalysis != null) { _analysisStack.Push(_curUnit); _curUnit = functionAnalysis; Debug.Assert(_scope.EnumerateTowardsGlobal.Contains(functionAnalysis.Environment.Parent)); _scope = functionAnalysis.Environment; return(true); } return(false); }
internal FunctionAnalysisUnit( UserFunctionValue function, AnalysisUnit declUnit, EnvironmentRecord declScope, IJsProjectEntry declEntry ) : base(function.FunctionObject, declUnit.Tree, null) { _declUnit = declUnit; Function = function; var scope = new FunctionEnvironmentRecord(Function, this, Function.FunctionObject, declScope, declEntry); scope.EnsureParameters(this); _env = scope; }
private void PushDefiniteAssignmentEnvironmentRecord(Node node, string name) { EnvironmentRecord scope; if (!_scope.GlobalEnvironment.TryGetNodeEnvironment(node, out scope)) { // find our parent scope, it may not be just the last entry in _scopes // because that can be a StatementScope and we would start a new range. var declScope = _scope; scope = new DefinitiveAssignmentEnvironmentRecord(node.GetEndIndex(_tree.LocationResolver), name, declScope); declScope.Children.Add(scope); declScope.GlobalEnvironment.AddNodeEnvironment(node, scope); _scope = scope; } }
//public readonly GeneratorInfo Generator; public FunctionEnvironmentRecord( UserFunctionValue function, FunctionAnalysisUnit analysisUnit, Node node, EnvironmentRecord declScope, IJsProjectEntry declModule ) : base(node, declScope) { _function = function; _this = new VariableDef(); AnalysisUnit = analysisUnit; #if FALSE if (Function.FunctionObject.IsGenerator) { Generator = new GeneratorInfo(function.ProjectState, declModule); ReturnValue.AddTypes(function.ProjectEntry, Generator.SelfSet, false); } #endif }
//public readonly GeneratorInfo Generator; public FunctionEnvironmentRecord( UserFunctionValue function, FunctionAnalysisUnit analysisUnit, Node node, EnvironmentRecord declScope, IJsProjectEntry declModule ) : base(node, declScope) { _function = function; _this = new VariableDef(); AnalysisUnit = analysisUnit; #if FALSE if (Function.FunctionObject.IsGenerator) { Generator = new GeneratorInfo(function.ProjectState, declModule); ReturnValue.AddTypes(function.ProjectEntry, Generator.SelfSet, false); } #endif }
private static void ProcessVariablesForScope(EnvironmentRecord scope, List<CartesianLocalVariable> specLocals) { foreach (var variable in scope.LocalVariables) { specLocals.Add( new CartesianLocalVariable( variable.Key, scope, CopyVariableDef(variable.Value), variable.Value ) ); } if (scope.HasChildren) { foreach (var childScope in scope.Children) { if (!(childScope is DeclarativeEnvironmentRecord)) { ProcessVariablesForScope(childScope, specLocals); } } } }
public override bool AssignVariable(string name, Node location, AnalysisUnit unit, IAnalysisSet values) { if (name == _name) { // we assign to our copy of the variable var res = AssignVariableWorker(location, unit, values, _variable); // and then assign it to our parent declarative environment so that // it can be read from locations where it's not definitely assigned. EnvironmentRecord declScope = GetDeclarativeEnvironment(); while (declScope.Parent != null && (!declScope.ContainsVariable(name) || declScope is DeclarativeEnvironmentRecord)) { declScope = declScope.Parent; } declScope.AssignVariable(name, location, unit, values); return(res); } return(base.AssignVariable(name, location, unit, values)); }
public DeclarativeEnvironmentRecord(EnvironmentRecord outerScope) : this(null, outerScope) { }
public ExpressionEvaluator(AnalysisUnit unit, EnvironmentRecord scope) { _unit = unit; Scope = scope; }
public EnvironmentRecord(EnvironmentRecord outerScope) { Parent = outerScope; }
private static bool IsFirstLineOfFunction(EnvironmentRecord innerScope, EnvironmentRecord outerScope, int index) { if (innerScope.OuterScope == outerScope && innerScope is Microsoft.NodejsTools.Analysis.Analyzer.FunctionScope) { var funcScope = (Microsoft.NodejsTools.Analysis.Analyzer.FunctionScope)innerScope; var def = funcScope.Function.FunctionObject; // TODO: Use indexes rather than lines to check location int lineNo = def.GlobalParent.IndexToLocation(index).Line; if (lineNo == def.GetStart(def.GlobalParent).Line) { return true; } } return false; }
internal bool TryGetNodeEnvironment(Node node, out EnvironmentRecord scope) { return(_nodeScopes.TryGetValue(node, out scope)); }
private IEnumerable<MemberResult> GetKeywordMembers(GetMemberOptions options, EnvironmentRecord scope) { IEnumerable<string> keywords = null; if (options.ExpressionKeywords()) { // keywords available in any context keywords = _exprKeywords; } else { keywords = Enumerable.Empty<string>(); } if (options.StatementKeywords()) { keywords = keywords.Union(_stmtKeywords); } return keywords.Select(kw => new MemberResult(name: kw, documentation: kw, type: JsMemberType.Keyword)); }
internal EvalAnalysisUnit(Statement ast, JsAst tree, EnvironmentRecord scope) : base(ast, tree, scope) { }
public DefinitiveAssignmentEnvironmentRecord(int startIndex, string name, EnvironmentRecord outerRecord) : base(startIndex, outerRecord) { _name = name; _variable = new VariableDef(); }
public EnvironmentRecord(EnvironmentRecord outerScope) { Parent = outerScope; }
public DeclarativeEnvironmentRecord(EnvironmentRecord outerScope) : this(null, outerScope) { }
private void PushDefiniteAssignmentEnvironmentRecord(Node node, string name) { EnvironmentRecord scope; if (!_scope.GlobalEnvironment.TryGetNodeEnvironment(node, out scope)) { // find our parent scope, it may not be just the last entry in _scopes // because that can be a StatementScope and we would start a new range. var declScope = _scope; scope = new DefinitiveAssignmentEnvironmentRecord(node.GetEndIndex(_tree.LocationResolver), name, declScope); declScope.Children.Add(scope); declScope.GlobalEnvironment.AddNodeEnvironment(node, scope); _scope = scope; } }
public DeclarativeEnvironmentRecord(Node ast, EnvironmentRecord outerScope) : base(outerScope) { _node = ast; _variables = new AnalysisDictionary<string, VariableDef>(); }
public DeclarativeEnvironmentRecord(Node ast, EnvironmentRecord outerScope) : base(outerScope) { _node = ast; _variables = new AnalysisDictionary <string, VariableDef>(); }
public override bool Walk(Block node) { var prevScope = _scope; var prevSuite = _curSuite; _curSuite = node; try { // recursively walk the statements in the suite for (int i = 0; i < node.Count; i++) { if (DDG.IsGwtCode(node, i)) { return false; } node[i].Walk(this); } } finally { _curSuite = prevSuite; while (_scope != prevScope) { StatementEnvironmentRecord stmtRec = _scope as StatementEnvironmentRecord; if (stmtRec != null) { stmtRec.EndIndex = node.GetEndIndex(_tree.LocationResolver); } _scope = _scope.Parent; } } return false; }
public FunctionAssignmentWalker(EnvironmentRecord functionScope, ProjectEntry project) { _scope = functionScope; _projectEntry = project; }
public FunctionAssignmentWalker(EnvironmentRecord functionScope, ProjectEntry project) { _scope = functionScope; _projectEntry = project; }
public CartesianLocalVariable(string name, EnvironmentRecord definingScope, VariableDef specialized, VariableDef shared) { Specialized = specialized; Shared = shared; DefiningScope = definingScope; Name = name; }
private static void DumpScope(StringBuilder output, EnvironmentRecord curScope, int level = 0) { curScope.DumpScope(output, level); foreach (var child in curScope.Children) { DumpScope(output, child, level + 1); } }
public DefinitiveAssignmentEnvironmentRecord(int startIndex, string name, EnvironmentRecord outerRecord) : base(startIndex, outerRecord) { _name = name; _variable = new VariableDef(); }
public StatementEnvironmentRecord(int index, EnvironmentRecord outerScope) : base(outerScope) { _startIndex = _endIndex = index; }
public StatementEnvironmentRecord(int index, EnvironmentRecord outerScope) : base(outerScope) { _startIndex = _endIndex = index; }
public EnvironmentRecord AddNodeEnvironment(Node node, EnvironmentRecord scope) { return(_nodeScopes[node] = scope); }
public override void PostWalk(FunctionObject node) { if (node.Body != null) { Debug.Assert(_scope is DeclarativeEnvironmentRecord && ((DeclarativeEnvironmentRecord)_scope).Node == node); Debug.Assert(!(_scope.Parent is DeclarativeEnvironmentRecord) || ((DeclarativeEnvironmentRecord)_scope.Parent).Node != node); _scope = _scope.Parent; _curUnit = _analysisStack.Pop(); Debug.Assert(_scope.EnumerateTowardsGlobal.Contains(_curUnit.Environment)); } }
private IEnumerable<IAnalysisVariable> GetVariablesInScope(Lookup name, EnvironmentRecord scope) { var result = new List<IAnalysisVariable>(); VariableDef var; if (scope.TryGetVariable(name.Name, out var)) { result.AddRange(VariableTransformer.ScopeToVariables.ToVariables(_unit, var)); } // if a variable is imported from another module then also yield the defs/refs for the // value in the defining module. var linked = scope.GetLinkedVariablesNoCreate(name.Name); if (linked != null) { result.AddRange(linked.SelectMany(x => VariableTransformer.ScopeToVariables.ToVariables(_unit, x))); } return result; }
internal IEnumerable<MemberResult> GetMemberResults(IAnalysisSet vars, EnvironmentRecord scope, GetMemberOptions options) { IList<AnalysisValue> namespaces = new List<AnalysisValue>(); foreach (var ns in vars) { if (ns != null) { namespaces.Add(ns.Value); } } if (namespaces.Count == 1) { // optimize for the common case of only a single namespace var newMembers = namespaces[0].GetAllMembers(_unit.ProjectEntry); if (newMembers == null || newMembers.Count == 0) { return new MemberResult[0]; } return SingleMemberResult(options, newMembers); } Dictionary<string, List<AnalysisValue>> memberDict = null; Dictionary<string, List<AnalysisValue>> ownerDict = null; HashSet<string> memberSet = null; int namespacesCount = namespaces.Count; foreach (AnalysisValue ns in namespaces) { if (ProjectState._nullInst == ns) { namespacesCount -= 1; continue; } var newMembers = ns.GetAllMembers(_unit.ProjectEntry); // IntersectMembers(members, memberSet, memberDict); if (newMembers == null || newMembers.Count == 0) { namespacesCount -= 1; continue; } if (memberSet == null) { // first namespace, add everything memberSet = new HashSet<string>(newMembers.Keys); memberDict = new Dictionary<string, List<AnalysisValue>>(); ownerDict = new Dictionary<string, List<AnalysisValue>>(); foreach (var kvp in newMembers) { var tmp = new List<AnalysisValue>(kvp.Value.Select(x => x.Value)); memberDict[kvp.Key] = tmp; ownerDict[kvp.Key] = new List<AnalysisValue> { ns }; } } else { // 2nd or nth namespace, union or intersect HashSet<string> toRemove; IEnumerable<string> adding; // we're adding all of newMembers keys adding = newMembers.Keys; toRemove = null; // update memberDict foreach (var name in adding) { List<AnalysisValue> values; if (!memberDict.TryGetValue(name, out values)) { memberDict[name] = values = new List<AnalysisValue>(); } values.AddRange(newMembers[name].Select(x => x.Value)); if (!ownerDict.TryGetValue(name, out values)) { ownerDict[name] = values = new List<AnalysisValue>(); } values.Add(ns); } if (toRemove != null) { foreach (var name in toRemove) { memberDict.Remove(name); ownerDict.Remove(name); } } } } if (memberDict == null) { return new MemberResult[0]; } return MemberDictToResultList(options, memberDict, ownerDict, namespacesCount); }
public SpecializedUserFunctionValue(CallDelegate call, FunctionObject node, AnalysisUnit declUnit, EnvironmentRecord declScope, bool callBase) : base(node, declUnit, declScope) { _call = call; _callBase = callBase; }
/// <summary> /// Finds the best available analysis unit for lookup. This will be the one that is provided /// by the nearest enclosing scope that is capable of providing one. /// </summary> private AnalysisUnit GetEvalAnalysisUnit(EnvironmentRecord scope) { var projEntry = scope.GlobalEnvironment.ProjectEntry; return new EvalAnalysisUnit( projEntry.Tree, projEntry.Tree, scope ); }
internal EvalAnalysisUnit(Statement ast, JsAst tree, EnvironmentRecord scope) : base(ast, tree, scope) { }