Ejemplo n.º 1
0
 private void releaseToken(TclToken token)
 {
     if (interp != null && interp.parserTokensUsed > 0)
     {
         // if cache is not full put the object back in the cache
         interp.parserTokensUsed -= 1;
         interp.parserTokens[interp.parserTokensUsed] = token;
     }
 }
Ejemplo n.º 2
0
        // Creating an interpreter will cause this init method to be called

        internal static void init(Interp interp)
        {
            TclToken[] TOKEN_CACHE = new TclToken[MAX_CACHED_TOKENS];
            for (int i = 0; i < MAX_CACHED_TOKENS; i++)
            {
                TOKEN_CACHE[i] = new TclToken();
            }

            interp.parserTokens     = TOKEN_CACHE;
            interp.parserTokensUsed = 0;
        }
Ejemplo n.º 3
0
        /*
         * //uncommenting these methods will disable caching
         *
         * static void init(Interp interp) {}
         * private TclToken grabToken() {return new TclToken();}
         * private void releaseToken(TclToken token) {}
         */



        internal void expandTokenArray(int needed)
        {
            // Make sure there is at least enough room for needed tokens
            while (needed >= tokensAvailable)
            {
                tokensAvailable *= 2;
            }

            TclToken[] newList = new TclToken[tokensAvailable];
            Array.Copy((System.Array)tokenList, 0, (System.Array)newList, 0, tokenList.Length);
            tokenList = newList;
        }
Ejemplo n.º 4
0
    internal static TclObject evalTokens( Interp interp, TclToken[] tokenList, int tIndex, int count )
    {
      TclObject result, index, value;
      TclToken token;
      string p = null;
      string varName;
      BackSlashResult bs;

      // The only tricky thing about this procedure is that it attempts to
      // avoid object creation and string copying whenever possible.  For
      // example, if the value is just a nested command, then use the
      // command's result object directly.

      result = null;
      for ( ; count > 0; count-- )
      {
        token = tokenList[tIndex];

        // The switch statement below computes the next value to be
        // concat to the result, as either a range of text or an
        // object.

        value = null;
        switch ( token.type )
        {

          case TCL_TOKEN_TEXT:
            p = token.TokenString;
            break;


          case TCL_TOKEN_BS:
            bs = backslash( token.script_array, token.script_index );
            if ( bs.isWordSep )
            {
              p = "\\" + bs.c;
            }
            else
            {
              System.Char ch = bs.c;
              p = ch.ToString();
            }
            break;


          case TCL_TOKEN_COMMAND:
            interp.evalFlags |= Parser.TCL_BRACKET_TERM;
            token.script_index++;

            //should the nest level be changed???
            //interp.nestLevel++;

            eval2( interp, token.script_array, token.script_index, token.size - 2, 0 );

            token.script_index--;
            //interp.nestLevel--;
            value = interp.getResult();
            break;


          case TCL_TOKEN_VARIABLE:
            if ( token.numComponents == 1 )
            {
              index = null;
            }
            else
            {
              index = evalTokens( interp, tokenList, tIndex + 2, token.numComponents - 1 );
              if ( index == null )
              {
                return null;
              }
            }
            varName = tokenList[tIndex + 1].TokenString;

            // In order to get the existing expr parser to work with the
            // new Parser, we test the interp.noEval flag which is set
            // by the expr parser.  If it is != 0, then we do not evaluate 
            // the variable.  This should be removed when the new expr
            // parser is implemented.

            if ( interp.noEval == 0 )
            {
              if ( index != null )
              {
                try
                {

                  value = interp.getVar( varName, index.ToString(), 0 );
                }
                finally
                {
                  index.release();
                }
              }
              else
              {
                value = interp.getVar( varName, null, 0 );
              }
            }
            else
            {
              value = TclString.newInstance( "" );
              value.preserve();
            }
            count -= token.numComponents;
            tIndex += token.numComponents;
            break;


          default:
            throw new TclRuntimeError( "unexpected token type in evalTokens" );

        }

        // If value isn't null, the next piece of text comes from that
        // object; otherwise, take value of p.

        if ( result == null )
        {
          if ( value != null )
          {
            result = value;
          }
          else
          {
            result = TclString.newInstance( p );
          }
          result.preserve();
        }
        else
        {
          if ( result.Shared )
          {
            result.release();
            result = result.duplicate();
            result.preserve();
          }
          if ( value != null )
          {

            p = value.ToString();
          }
          TclString.append( result, p );
        }
        tIndex++;
      }
      return result;
    }
    /*
    //uncommenting these methods will disable caching
		
    static void init(Interp interp) {}
    private TclToken grabToken() {return new TclToken();}
    private void releaseToken(TclToken token) {}
    */



    internal void expandTokenArray( int needed )
    {
      // Make sure there is at least enough room for needed tokens
      while ( needed >= tokensAvailable )
      {
        tokensAvailable *= 2;
      }

      TclToken[] newList = new TclToken[tokensAvailable];
      Array.Copy( (System.Array)tokenList, 0, (System.Array)newList, 0, tokenList.Length );
      tokenList = newList;
    }
 private void releaseToken( TclToken token )
 {
   if ( interp != null && interp.parserTokensUsed > 0 )
   {
     // if cache is not full put the object back in the cache
     interp.parserTokensUsed -= 1;
     interp.parserTokens[interp.parserTokensUsed] = token;
   }
 }
    // Creating an interpreter will cause this init method to be called

    internal static void init( Interp interp )
    {
      TclToken[] TOKEN_CACHE = new TclToken[MAX_CACHED_TOKENS];
      for ( int i = 0; i < MAX_CACHED_TOKENS; i++ )
      {
        TOKEN_CACHE[i] = new TclToken();
      }

      interp.parserTokens = TOKEN_CACHE;
      interp.parserTokensUsed = 0;
    }