Exemplo n.º 1
0
        internal Procedure(Interp interp, NamespaceCmd.Namespace ns, string name, TclObject args, TclObject b, string sFileName, int sLineNumber)
        {
            this.NS       = ns;
            srcFileName   = sFileName;
            srcLineNumber = sLineNumber;

            // Break up the argument list into argument specifiers, then process
            // each argument specifier.

            int numArgs = TclList.getLength(interp, args);

            ArgList = new TclObject[numArgs][];
            for (int i = 0; i < numArgs; i++)
            {
                ArgList[i] = new TclObject[2];
            }

            for (int i = 0; i < numArgs; i++)
            {
                // Now divide the specifier up into name and default.

                TclObject argSpec = TclList.index(interp, args, i);
                int       specLen = TclList.getLength(interp, argSpec);

                if (specLen == 0)
                {
                    throw new TclException(interp, "procedure \"" + name + "\" has argument with no name");
                }
                if (specLen > 2)
                {
                    throw new TclException(interp, "too many fields in argument " + "specifier \"" + argSpec + "\"");
                }

                ArgList[i][0] = TclList.index(interp, argSpec, 0);
                ArgList[i][0].Preserve();
                if (specLen == 2)
                {
                    ArgList[i][1] = TclList.index(interp, argSpec, 1);
                    ArgList[i][1].Preserve();
                }
                else
                {
                    ArgList[i][1] = null;
                }
            }


            if (numArgs > 0 && (ArgList[numArgs - 1][0].ToString().Equals("args")))
            {
                isVarArgs = true;
            }
            else
            {
                isVarArgs = false;
            }


            body        = new CharPointer(b.ToString());
            body_length = body.Length();
        }
Exemplo n.º 2
0
        public void Dispose()
        {
            //body.release();
            body = null;
            for (int i = 0; i < ArgList.Length; i++)
            {
                ArgList[i][0].Release();
                ArgList[i][0] = null;

                if (ArgList[i][1] != null)
                {
                    ArgList[i][1].Release();
                    ArgList[i][1] = null;
                }
            }
            ArgList = null;
        }
Exemplo n.º 3
0
        internal static ParseResult parseNestedCmd(Interp interp, string inString, int index, int length)
        {
            CharPointer script;
            TclObject   obj;

            // Check for the easy case where the last character in the string is '['.
            if (index == length)
            {
                throw new TclException(interp, "missing close-bracket");
            }

            script        = new CharPointer(inString);
            script._index = index;

            interp._evalFlags |= Parser.TCL_BRACKET_TERM;
            Parser.eval2(interp, script._array, script._index, length - index, 0);
            obj = interp.GetResult();
            obj.Preserve();
            return(new ParseResult(obj, index + interp._termOffset + 1));
        }
Exemplo n.º 4
0
        internal static ParseResult ParseQuotes(Interp interp, string inString, int index, int length)
        {
            TclObject   obj;
            TclParse    parse = null;
            TclToken    token;
            CharPointer script;

            try
            {
                script        = new CharPointer(inString);
                script._index = index;

                parse = new TclParse(interp, script._array, length, null, 0);

                System.Diagnostics.Debug.WriteLine("string is \"" + inString + "\"");
                System.Diagnostics.Debug.WriteLine("script.array is \"" + new string(script._array) + "\"");

                System.Diagnostics.Debug.WriteLine("index is " + index);
                System.Diagnostics.Debug.WriteLine("length is " + length);

                System.Diagnostics.Debug.WriteLine("parse.endIndex is " + parse.endIndex);


                parse.commandStart = script._index;
                token              = parse.getToken(0);
                token.type         = Parser.TCL_TOKEN_WORD;
                token.script_array = script._array;
                token.script_index = script._index;
                parse.numTokens++;
                parse.numWords++;
                parse = Parser.parseTokens(script._array, script._index, Parser.TYPE_QUOTE, parse);

                // Check for the error condition where the parse did not end on
                // a '"' char. Is this happened raise an error.

                if (script._array[parse.termIndex] != '"')
                {
                    throw new TclException(interp, "missing \"");
                }

                // if there was no error then parsing will continue after the
                // last char that was parsed from the string

                script._index = parse.termIndex + 1;

                // Finish filling in the token for the word and check for the
                // special case of a word consisting of a single range of
                // literal text.

                token               = parse.getToken(0);
                token.size          = script._index - token.script_index;
                token.numComponents = parse.numTokens - 1;
                if ((token.numComponents == 1) && (parse.getToken(1).type == Parser.TCL_TOKEN_TEXT))
                {
                    token.type = Parser.TCL_TOKEN_SIMPLE_WORD;
                }
                parse.commandSize = script._index - parse.commandStart;
                if (parse.numTokens > 0)
                {
                    obj = Parser.evalTokens(interp, parse.tokenList, 1, parse.numTokens - 1);
                }
                else
                {
                    throw new TclRuntimeError("parseQuotes error: null obj result");
                }
            }
            finally
            {
                parse.release();
            }

            return(new ParseResult(obj, script._index));
        }