internal void EnsureParameters(FunctionAnalysisUnit unit) { var astParams = Function.FunctionDefinition.Parameters; for (int i = 0; i < astParams.Count; ++i) { VariableDef param; if (!TryGetVariable(astParams[i].Name, out param)) { var n = (Node)astParams[i].NameExpression ?? astParams[i]; if (astParams[i].Kind == ParameterKind.List) { param = _seqParameters = _seqParameters ?? new ListParameterVariableDef(unit, n); } else if (astParams[i].Kind == ParameterKind.Dictionary) { param = _dictParameters = _dictParameters ?? new DictParameterVariableDef(unit, n); } else { param = new LocatedVariableDef(unit.ProjectEntry, n); } AddVariable(astParams[i].Name, param); } } }
internal void EnsureParameters(FunctionAnalysisUnit unit) { var astParams = Function.FunctionObject.ParameterDeclarations; if (astParams != null) { for (int i = 0; i < astParams.Length; ++i) { VariableDef param; if (!TryGetVariable(astParams[i].Name, out param)) { param = new LocatedVariableDef(unit.ProjectEntry, astParams[i]); AddVariable(astParams[i].Name, param); } } } }
private static VariableDef CopyVariableDef(VariableDef original) { LocatedVariableDef locVarDef = original as LocatedVariableDef; if (locVarDef != null) { return(new LocatedVariableDef( locVarDef.Entry, locVarDef.Node )); } return(new VariableDef()); }
internal void EnsureParameters(FunctionAnalysisUnit unit, bool usePlaceholders) { var astParams = Function.FunctionDefinition.ParametersInternal; for (int i = 0; i < astParams.Length; ++i) { var p = astParams[i]; var name = p?.Name; if (string.IsNullOrEmpty(name)) { continue; } var node = (Node)astParams[i].NameExpression ?? astParams[i]; if (astParams[i].Kind == ParameterKind.List) { if (_seqParameters == null) { _seqParameters = new ListParameterVariableDef(unit, p, name); AddParameter(unit, name, p, usePlaceholders ? null : _seqParameters); } } else if (astParams[i].Kind == ParameterKind.Dictionary) { if (_dictParameters == null) { _dictParameters = new DictParameterVariableDef(unit, p, name); AddParameter(unit, name, p, usePlaceholders ? null : _dictParameters); } } else if (!_parameters.ContainsKey(name)) { var v = _parameters[name] = new LocatedVariableDef(unit.ProjectEntry, new EncodedLocation(unit, p)); if (i == 0 && p.Kind == ParameterKind.Normal && !Function.IsStatic && Function.FunctionDefinition.Parent is ClassDefinition) { AddParameter(unit, name, p, v); } else { AddParameter(unit, name, p, usePlaceholders ? null : v); } } } }
internal void EnsureParameters(FunctionAnalysisUnit unit) { var astParams = Function.FunctionDefinition.Parameters; for (int i = 0; i < astParams.Count; ++i) { VariableDef param; if (!TryGetVariable(astParams[i].Name, out param)) { if (astParams[i].Kind == ParameterKind.List) { param = _seqParameters = _seqParameters ?? new ListParameterVariableDef(unit, astParams[i]); } else if (astParams[i].Kind == ParameterKind.Dictionary) { param = _dictParameters = _dictParameters ?? new DictParameterVariableDef(unit, astParams[i]); } else { param = new LocatedVariableDef(unit.ProjectEntry, astParams[i]); } AddVariable(astParams[i].Name, param); } } }
internal void EnsureParameters(FunctionAnalysisUnit unit) { var astParams = Function.FunctionObject.ParameterDeclarations; if (astParams != null) { for (int i = 0; i < astParams.Length; ++i) { VariableDef param; if (!TryGetVariable(astParams[i].Name, out param)) { param = new LocatedVariableDef(unit.ProjectEntry, astParams[i]); AddVariable(astParams[i].Name, param); } } } }
private IEnumerable <IAnalysisVariable> ToVariables(IReferenceable referenceable) { LocatedVariableDef locatedDef = referenceable as LocatedVariableDef; if (locatedDef != null) { yield return(new AnalysisVariable(VariableType.Definition, new LocationInfo(locatedDef.Entry, locatedDef.Node.Start.Line, locatedDef.Node.Start.Column, locatedDef.Node.Span.Length))); } foreach (var reference in referenceable.Definitions) { yield return(new AnalysisVariable(VariableType.Definition, new LocationInfo(reference.Key, reference.Value.Line, reference.Value.Column, reference.Value.Length))); } foreach (var reference in referenceable.References) { yield return(new AnalysisVariable(VariableType.Reference, new LocationInfo(reference.Key, reference.Value.Line, reference.Value.Column, reference.Value.Length))); } }
public VariableDef AddLocatedVariable(string name, Node location, AnalysisUnit unit) { if (!TryGetVariable(name, out var value)) { var def = new LocatedVariableDef(unit.DeclaringModule.ProjectEntry, new EncodedLocation(unit, location)); return(AddVariable(name, def)); } if (value is LocatedVariableDef lv) { lv.Location = new EncodedLocation(unit, location); lv.DeclaringVersion = unit.ProjectEntry.AnalysisVersion; } else { var def = new LocatedVariableDef(unit.DeclaringModule.ProjectEntry, new EncodedLocation(unit, location), value); return(AddVariable(name, def)); } return(value); }
public VariableDef AddLocatedVariable(string name, Node location, ProjectEntry projectEntry) { VariableDef value; if (!TryGetVariable(name, out value)) { VariableDef def = new LocatedVariableDef(projectEntry, location); return(AddVariable(name, def)); } else if (!(value is LocatedVariableDef)) { VariableDef def = new LocatedVariableDef(projectEntry, location, value); return(AddVariable(name, def)); } else { ((LocatedVariableDef)value).Node = location; ((LocatedVariableDef)value).DeclaringVersion = projectEntry.AnalysisVersion; } return(value); }
public VariableDef AddLocatedVariable(string name, Node location, AnalysisUnit unit, ParameterKind paramKind = ParameterKind.Normal) { VariableDef value; if (!TryGetVariable(name, out value)) { VariableDef def; switch (paramKind) { case ParameterKind.List: def = new ListParameterVariableDef(unit, location); break; case ParameterKind.Dictionary: def = new DictParameterVariableDef(unit, location); break; default: def = new LocatedVariableDef(unit.DeclaringModule.ProjectEntry, location); break; } return(AddVariable(name, def)); } else if (!(value is LocatedVariableDef)) { VariableDef def; switch (paramKind) { case ParameterKind.List: def = new ListParameterVariableDef(unit, location, value); break; case ParameterKind.Dictionary: def = new DictParameterVariableDef(unit, location, value); break; default: def = new LocatedVariableDef(unit.DeclaringModule.ProjectEntry, location, value); break; } return(AddVariable(name, def)); } else { ((LocatedVariableDef)value).Node = location; ((LocatedVariableDef)value).DeclaringVersion = unit.ProjectEntry.AnalysisVersion; } return(value); }
internal bool UpdateParameters( FunctionAnalysisUnit unit, ArgumentSet others, bool enqueue = true, FunctionScope scopeWithDefaultParameters = null, bool usePlaceholders = false ) { EnsureParameters(unit, usePlaceholders); var astParams = Function.FunctionDefinition.ParametersInternal; var added = false; var entry = unit.DependencyProject; var state = unit.State; var limits = state.Limits; for (int i = 0; i < others.Args.Length && i < astParams.Length; ++i) { var name = astParams[i].Name; VariableDef param; if (string.IsNullOrEmpty(name)) { continue; } if (name == _seqParameters?.Name) { param = _seqParameters; } else if (name == _dictParameters?.Name) { param = _dictParameters; } else if (!_parameters.TryGetValue(name, out param)) { Debug.Fail($"Parameter {name} has no variable in this function"); _parameters[name] = param = new LocatedVariableDef(Function.AnalysisUnit.ProjectEntry, new EncodedLocation(unit, (Node)astParams[i].NameExpression ?? astParams[i])); } var arg = others.Args[i].Resolve(unit); param.MakeUnionStrongerIfMoreThan(limits.NormalArgumentTypes, arg); added |= param.AddTypes(entry, arg, enqueue, unit.ProjectEntry); } if (_seqParameters != null) { var arg = others.SequenceArgs.Resolve(unit); _seqParameters.List.MakeUnionStrongerIfMoreThan(limits.ListArgumentTypes, arg); added |= _seqParameters.List.AddTypes(unit, new[] { arg }); } if (_dictParameters != null) { var arg = others.DictArgs.Resolve(unit); _dictParameters.Dict.MakeUnionStrongerIfMoreThan(limits.DictArgumentTypes, arg); added |= _dictParameters.Dict.AddTypes(Function.FunctionDefinition, unit, state.GetConstant(""), arg); } if (scopeWithDefaultParameters != null) { for (int i = 0; i < others.Args.Length && i < astParams.Length; ++i) { VariableDef defParam, param; if (TryGetVariable(astParams[i].Name, out param) && !param.HasTypes && scopeWithDefaultParameters.TryGetVariable(astParams[i].Name, out defParam)) { param.MakeUnionStrongerIfMoreThan( limits.NormalArgumentTypes, defParam.GetTypesNoCopy(unit, AnalysisValue.DeclaringModule) ); added |= param.AddTypes(entry, defParam.GetTypesNoCopy(unit, AnalysisValue.DeclaringModule), enqueue, unit.ProjectEntry); } } } if (enqueue && added) { unit.Enqueue(); } return(added); }
public VariableDef AddLocatedVariable(string name, Node location, AnalysisUnit unit, ParameterKind paramKind = ParameterKind.Normal) { VariableDef value; if (!TryGetVariable(name, out value)) { VariableDef def; switch (paramKind) { case ParameterKind.List: def = new ListParameterVariableDef(unit, location); break; case ParameterKind.Dictionary: def = new DictParameterVariableDef(unit, location); break; default: def = new LocatedVariableDef(unit.DeclaringModule.ProjectEntry, location); break; } return AddVariable(name, def); } else if (!(value is LocatedVariableDef)) { VariableDef def; switch (paramKind) { case ParameterKind.List: def = new ListParameterVariableDef(unit, location, value); break; case ParameterKind.Dictionary: def = new DictParameterVariableDef(unit, location, value); break; default: def = new LocatedVariableDef(unit.DeclaringModule.ProjectEntry, location, value); break; } return AddVariable(name, def); } else { ((LocatedVariableDef)value).Node = location; ((LocatedVariableDef)value).DeclaringVersion = unit.ProjectEntry.AnalysisVersion; } return value; }
public VariableDef AddLocatedVariable(string name, Node location, ProjectEntry projectEntry) { VariableDef value; if (!TryGetVariable(name, out value)) { VariableDef def = new LocatedVariableDef(projectEntry, location); return AddVariable(name, def); } else if (!(value is LocatedVariableDef)) { VariableDef def = new LocatedVariableDef(projectEntry, location, value); return AddVariable(name, def); } else { ((LocatedVariableDef)value).Node = location; ((LocatedVariableDef)value).DeclaringVersion = projectEntry.AnalysisVersion; } return value; }
internal void EnsureParameters(FunctionAnalysisUnit unit, FunctionScope scopeWithDefaultParameters = null) { var astParams = Function.FunctionDefinition.Parameters; for (int i = 0; i < astParams.Count; ++i) { VariableDef param, defParam; if (!Variables.TryGetValue(astParams[i].Name, out param)) { if (astParams[i].Kind == ParameterKind.List) { param = _seqParameters = _seqParameters ?? new ListParameterVariableDef(unit, astParams[i]); } else if (astParams[i].Kind == ParameterKind.Dictionary) { param = _dictParameters = _dictParameters ?? new DictParameterVariableDef(unit, astParams[i]); } else { param = new LocatedVariableDef(unit.ProjectEntry, astParams[i]); } if (scopeWithDefaultParameters != null && scopeWithDefaultParameters != this && scopeWithDefaultParameters.Variables.TryGetValue(astParams[i].Name, out defParam)) { defParam.CopyTo(param); } AddVariable(astParams[i].Name, param); } } }