Exemplo n.º 1
0
 public static Intermediate.Symbol FindNamedSymbol(
     this Intermediate.IScope scope,
     CompoundName name,
     Intermediate.Type type,
     bool requireConst = false)
 {
     for (int i = 0; i < name.Count - 1; i++)
     {
         if (!scope.TryGetSymbol(new Signature(Type.ModuleType.Signature, name[i]), out Intermediate.Symbol scopeSym))
         {
             return(null);
         }
         if (!scopeSym.IsConst) // don't try to resolve actual module variables!
         {
             return(null);
         }
         scope = scopeSym.GetValue <Intermediate.Module>()?.Symbols;
         if (scope == null)
         {
             return(null);
         }
     }
     // TODO: Implement alias-types here or just use the direct type?
     if (scope.TryGetSymbol(new Signature(type, name.Identifier), out Intermediate.Symbol modSym) == false)
     {
         return(null);
     }
     if (requireConst && !modSym.IsConst)
     {
         return(null);
     }
     return(modSym);
 }
Exemplo n.º 2
0
        public static bool TryGetSymbol(this Intermediate.IScope scope, Intermediate.Signature name, out Intermediate.Symbol sym)
        {
            var good = scope.HasSymbol(name);

            if (good)
            {
                sym = scope[name];
            }
            else
            {
                sym = default(Intermediate.Symbol);
            }
            return(good);
        }