Variable FindVariable(string name, bool lookInCurrentScopeOnly)
        {
            Contract.Requires(name != null);
            VarContextNode c = varContext;
            bool           lookOnlyForConstants = false;

            do
            {
                c.VarSymbols.TryGetValue(name, out Variable var);
                if (var != null && (!lookOnlyForConstants || var is Constant))
                {
                    return(var);
                }
                // not at this level

                if (c.Opaque)
                {
                    // from here on, only constants can be looked up
                    lookOnlyForConstants = true;
                }

                if (lookInCurrentScopeOnly)
                {
                    // we're asked to look only in the current scope; hence, we're done
                    break;
                }

                c = c.ParentContext;
            } while (c != null);
            // not present in the relevant levels
            return(null);
        }
Пример #2
0
        Variable FindVariable(string name, bool ignoreTopLevelVars)
        {
            Contract.Requires(name != null);
            VarContextNode c = varContext;
            bool           lookOnlyForConstants = false;

            do
            {
                if (ignoreTopLevelVars && c.ParentContext == null)
                {
                    // this is the top level and we're asked to ignore the top level; hence, we're done
                    break;
                }

                Variable var = (Variable)c.VarSymbols[name];
                if (var != null && (!lookOnlyForConstants || var is Constant))
                {
                    return(var);
                }
                // not at this level

                if (c.Opaque)
                {
                    // from here on, only constants can be looked up
                    lookOnlyForConstants = true;
                }
                c = c.ParentContext;
            } while (c != null);

            // not present in the relevant levels
            return(null);
        }
 /// <summary>
 /// Requires there to be more than one variable context.
 /// </summary>
 public void PopVarContext()
 {
     Contract.Assert(varContext.ParentContext != null);
     varContext = varContext.ParentContext;
 }
 /// <summary>
 /// Adds an opaque variable context, that is, one that blocks all previously pushed contexts.
 /// </summary>
 public void PushOpaqueVarContext()
 {
     varContext = new VarContextNode(varContext, true);
 }
 /// <summary>
 /// Adds a variable context.
 /// </summary>
 public void PushVarContext()
 {
     varContext = new VarContextNode(varContext, false);
 }
 public VarContextNode(/*maybe null*/ VarContextNode parentContext, bool opaque)
 {
     ParentContext = parentContext;
     Opaque        = opaque;
 }
Пример #7
0
 public VarContextNode(/*maybe null*/ VarContextNode parentContext, bool opaque)
 {
     ParentContext = parentContext;
     Opaque = opaque;
 }
Пример #8
0
 /// <summary>
 /// Adds a variable context.
 /// </summary>
 public void PushVarContext()
 {
     varContext = new VarContextNode(varContext, false);
 }
Пример #9
0
 /// <summary>
 /// Adds an opaque variable context, that is, one that blocks all previously pushed contexts.
 /// </summary>
 public void PushOpaqueVarContext()
 {
     varContext = new VarContextNode(varContext, true);
 }
Пример #10
0
 /// <summary>
 /// Requires there to be more than one variable context.
 /// </summary>
 public void PopVarContext()
 {
     Contract.Assert(varContext.ParentContext != null);
       varContext = varContext.ParentContext;
 }