private VariableDef CreateVariableInDeclaredScope(Lookup name) {
            var reference = name.VariableField;

            if (reference != null) {
                var declNode = reference.Scope;
                var declScope = _scope.EnumerateTowardsGlobal.FirstOrDefault(s => s is DeclarativeEnvironmentRecord && ((DeclarativeEnvironmentRecord)s).Node == declNode);
                if (declScope != null) {
                    return declScope.CreateVariable(name, _curUnit, name.Name, false);
                }
            }

            return _scope.CreateVariable(name, _curUnit, name.Name, false);
        }
 internal void AddNamedParameterReferences(AnalysisUnit caller, Lookup[] names) {
     ((FunctionEnvironmentRecord)Environment).AddParameterReferences(caller, names);
 }
 internal void AddParameterReferences(AnalysisUnit caller, Lookup[] names) {
     foreach (var name in names) {
         VariableDef param;
         if (name != null && TryGetVariable(name.Name, out param)) {
             param.AddReference(name, caller);
         }
     }
 }
Beispiel #4
0
 public virtual void ReportUndefined(Lookup lookup) {
 }
 public override bool Walk(Lookup node) { AddNode(node); return true; }
Beispiel #6
0
        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;
        }
 public override bool Walk(Lookup node)
 {
     if (node != null)
     {
         // add the lookup node to the current lexical scope, because
         // that's the starting point for this node's lookup resolution.
         CurrentLexicalScope.ScopeLookups.Add(node);
     }
     return false;
 }
 private void ResolveLookup(ActivationObject scope, Lookup lookup)
 {
     // resolve lookup via the lexical scope
     lookup.VariableField = scope.FindReference(lookup.Name);
     if (lookup.VariableField.FieldType == FieldType.UndefinedGlobal)
     {
         
             _errorSink.HandleUndeclaredVariable(
                 lookup.Name,
                 lookup.GetSpan(_locationResolver),
                 _locationResolver
             );
             
     }
 }