Пример #1
0
 // Expected tree for function: ^(FUNC ID ( INT | ID ) expr)
 /** Set up a local evaluator for a nested function call. The evaluator gets the definition
  *  tree of the function; the set of all defined functions (to find locally called ones); a
  *  pointer to the global variable memory; and the value of the function parameter to be
  *  added to the local memory.
  */
 private DebugTreeGrammar(CommonTree function,
              List<CommonTree> functionDefinitions,
              IDictionary<string, BigInteger> globalMemory,
              BigInteger paramValue)
     : this(new CommonTreeNodeStream(function.GetChild(2)), functionDefinitions)
 {
     this.globalMemory = globalMemory;
     localMemory[function.GetChild(1).Text] = paramValue;
 }
Пример #2
0
 /** Set up a local evaluator for a nested function call. The evaluator gets the definition
  *  tree of the function; the set of all defined functions (to find locally called ones); a
  *  pointer to the global variable memory; and the value of the function parameter to be
  *  added to the local memory.
  */
 private ProfileTreeGrammar(CommonTree function,
              List<CommonTree> functionDefinitions,
              IDictionary<string, BigInteger> globalMemory,
              BigInteger paramValue)
     // Expected tree for function: ^(FUNC ID ( INT | ID ) expr)
     : this(new CommonTreeNodeStream(function.GetChild(2)), functionDefinitions)
 {
     this.globalMemory = globalMemory;
     localMemory[function.GetChild(1).Text] = paramValue;
 }
 /// <summary>
 /// Set up a local evaluator for a nested function call. The evaluator gets the definition
 ///  tree of the function; the set of all defined functions (to find locally called ones); a
 /// pointer to the global variable memory; and the value of the function parameter to be
 /// added to the local memory.
 /// </summary>
 /// <param name="function"></param>
 /// <param name="functionDefinitions"></param>
 /// <param name="globalMemory"></param>
 /// <param name="paramValue"></param>
 private FunctionalTreeParser(
     CommonTree function,
     IList<CommonTree> functionDefinitions,
     IDictionary<string, BigInteger> globalMemory,
     BigInteger paramValue)
     : this(// Expected tree for function: ^(FUNC ID ( INT | ID ) expr)
         new CommonTreeNodeStream(function.GetChild(2)), functionDefinitions)
 {
     //this.globalMemory = globalMemory;
     this.localMemory.Add(function.GetChild(1).Text, paramValue);
 }
Пример #4
0
        public void Test4Nodes()
        {
            // ^(101 ^(102 103) 104)
            CommonTree r0 = new CommonTree( new CommonToken( 101 ) );
            r0.AddChild( new CommonTree( new CommonToken( 102 ) ) );
            r0.GetChild( 0 ).AddChild( new CommonTree( new CommonToken( 103 ) ) );
            r0.AddChild( new CommonTree( new CommonToken( 104 ) ) );

            assertNull( r0.Parent );
            assertEquals( -1, r0.ChildIndex );
        }
Пример #5
0
        public void Test4Nodes()
        {
            // ^(101 ^(102 103) 104)
            ITree t = new CommonTree( new CommonToken( 101 ) );
            t.AddChild( new CommonTree( new CommonToken( 102 ) ) );
            t.GetChild( 0 ).AddChild( new CommonTree( new CommonToken( 103 ) ) );
            t.AddChild( new CommonTree( new CommonToken( 104 ) ) );

            ITreeNodeStream stream = newStream( t );
            string expecting = " 101 102 103 104";
            string found = ToNodesOnlyString( stream );
            Assert.AreEqual( expecting, found );

            expecting = " 101 2 102 2 103 3 104 3";
            found = ToTokenTypeString( stream );
            Assert.AreEqual( expecting, found );
        }
Пример #6
0
        private List<String> ToList(CommonTree tree, int childNum)
        {
            List<String> ids = new List<String>();

            // convert the tree to a List of Strings
            Console.WriteLine("1: " + childNum);
            if (tree.ChildCount > 0)
            {
                Console.WriteLine("2: " + childNum);
                for (int i = 0; i < tree.GetChild(childNum).ChildCount; i++)
                {
                    Console.WriteLine("3: " + childNum);
                    CommonTree child = (CommonTree)tree.GetChild(childNum).GetChild(i);
                    ids.Add(child.Text);
                    Console.WriteLine("add to List (" + childNum + "): " + child.Text);
                }
                Console.WriteLine("4: " + childNum);
            }
            return ids;
        }
Пример #7
0
 public void Visit(InsertOverwriteStatement statement, CommonTree tree)
 {
     Parent(tree).Children.Add(statement);
     SetLine(statement, tree);
     Visit(tree.GetChild(0));
     Visit(tree.GetChild(1));
 }
Пример #8
0
 internal KeyValuePair<string, StoreType> ParseArg(CommonTree node)
 {
   StoreType st = new StoreType();
   int i = 0;
   st.Name = node.GetChild(i).Text;
   st.VarKind = VarKindEnum.Argument;
   i++;
   if (Cmp(node.GetChild(i).Text, "data_type") == 0)
   {
     ParseDataType(st, (CommonTree)node.GetChild(i));
     i++;
   }
   if (i < node.ChildCount)
   {
     string s = node.GetChild(i).Text;
     if ((Cmp("in", s) == 0) || (Cmp("out", s) == 0) || (Cmp("inout", s) == 0))
     {
       st.ArgType = (ArgTypeEnum)Enum.Parse(typeof(ArgTypeEnum), s, true);
     }
   }
   return new KeyValuePair<string, StoreType>(st.Name, st);
 }
        private static string GetTypeText(CommonTree tree)
        {
            if (tree.Type == Java2Lexer.ARRAY_TYPE)
                return GetTypeText((CommonTree)tree.GetChild(0)) + "[]";

            // this covers primitiveType
            if (tree.ChildCount == 0)
                return tree.Text;

            if (tree.Type == Java2Lexer.DOT)
                return GetTypeText((CommonTree)tree.GetChild(0)) + "." + GetTypeText((CommonTree)tree.GetChild(1));

            // if we get here, we know the tree is ^(IDENTIFIER typeArguments)
            string name = tree.Text;
            IEnumerable<string> typeArguments = ((CommonTree)tree.GetChild(0)).Children.Select(GetTypeArgumentText);
            return string.Format("{0}<{1}>", name, string.Join(", ", typeArguments));
        }
Пример #10
0
 /// <summary>
 /// Parses begin/end block gathering info in all declared local variables.
 /// TODO: how to take care of session & globals? same as in emulation: by providing a watches facility.
 /// </summary>
 /// <param name="node"></param>
 /// <param name="vars"></param>
 private void ParseDeclares(CommonTree node, Dictionary<string, StoreType> vars)
 {
   if (( Cmp(node.Text, "declare") == 0 ) && 
       ( Cmp(node.GetChild(0).Text, "condition") != 0 ) &&
       ( Cmp( node.GetChild( 0 ).Text, "cursor") != 0 ))
   {
     // Register vars...
     StoreType[] stVars = ParseDeclare(node);
     StoreType st2;
     foreach (StoreType st in stVars)
     {
       // variables with same name, are hidden by already declared ones.
       if (!vars.TryGetValue(st.Name, out st2))
       {
         vars.Add(st.Name, st);
       }
     }        
   }
   else
   {
     if (node.Children == null) return;
     foreach (ITree ct in node.Children)
     {
       ParseDeclares((CommonTree)ct, vars);
     }
   }
 }
Пример #11
0
 /// <summary>
 /// For a given statement, instruments all triggers & functions that will be invoked
 /// at its execution.
 /// </summary>
 /// <param name="stmt"></param>
 private void PreinstrumentStatement(CommonTree stmt)
 {
   // Identify all current dependencies and instrument them:
   if ( (Cmp( stmt.Text, "begin_end" ) == 0) ||
     ( Cmp( stmt.Text, "loop" ) == 0 ))
   {
     // Nothing to preinstrument, body has already being instrumented.
     return;
   }
   if (Cmp(stmt.Text, "while") == 0)
   {
     stmt = ( CommonTree )stmt.GetChild(0);
   }
   else if (Cmp(stmt.Text, "repeat") == 0)
   {
     stmt = (CommonTree)stmt.GetChild(stmt.ChildCount - 1);
   }
   // TODO: if, etc.
   else if (Cmp(stmt.Text, "call") == 0)
   {
     // Get dependencies from args (like functions)
     RoutineInfo ri = GetRoutineInfo(((CommonTree)stmt).GetChild(0).Text);
     if (string.IsNullOrEmpty(ri.InstrumentedSourceCode))
       InstrumentRoutine(ri);
   }
   DoPreinstrumentStatement(stmt);
 }
Пример #12
0
        public void TestLT()
        {
            // ^(101 ^(102 103) 104)
            ITree t = new CommonTree( new CommonToken( 101 ) );
            t.AddChild( new CommonTree( new CommonToken( 102 ) ) );
            t.GetChild( 0 ).AddChild( new CommonTree( new CommonToken( 103 ) ) );
            t.AddChild( new CommonTree( new CommonToken( 104 ) ) );

            ITreeNodeStream stream = newStream( t );
            Assert.AreEqual( 101, ( (ITree)stream.LT( 1 ) ).Type );
            Assert.AreEqual( TokenTypes.Down, ( (ITree)stream.LT( 2 ) ).Type );
            Assert.AreEqual( 102, ( (ITree)stream.LT( 3 ) ).Type );
            Assert.AreEqual( TokenTypes.Down, ( (ITree)stream.LT( 4 ) ).Type );
            Assert.AreEqual( 103, ( (ITree)stream.LT( 5 ) ).Type );
            Assert.AreEqual( TokenTypes.Up, ( (ITree)stream.LT( 6 ) ).Type );
            Assert.AreEqual( 104, ( (ITree)stream.LT( 7 ) ).Type );
            Assert.AreEqual( TokenTypes.Up, ( (ITree)stream.LT( 8 ) ).Type );
            Assert.AreEqual( TokenTypes.EndOfFile, ( (ITree)stream.LT( 9 ) ).Type );
            // check way ahead
            Assert.AreEqual( TokenTypes.EndOfFile, ( (ITree)stream.LT( 100 ) ).Type );
        }
Пример #13
0
        public IAspectElement Visit(
            CommonTree root, int depth, IAspectElement element)
        {
            if (root.Token == null)
                return element;

            var token = root.Token.Text;
            switch (token) {
            case "ASPECT":
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                return element;

            case "ASPECT_BODY":
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                return element;

            case "ELEMENTS":
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                return element;

            case "ELEMENT":
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                return element;

            case "INTERTYPE_DECLARATION":
                element = new Intertype();
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                Intertypes.Add((Intertype)element);
                return element;

            case "POINTCUT_DECLARATION":
                element = new Pointcut();
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                Pointcuts.Add((Pointcut)element);
                return element;

            case "ADVICE_DECLARATION":
                element = new Advice();
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                Advices.Add((Advice)element);
                return element;

            case "TYPE":
                element.SetType(root.GetChild(0).Text);
                return element;

            case "TARGET_CLASS":
                element.SetTarget(root.GetChild(0).Text);
                return element;

            case "POINTCUT_NAME":
                element.SetName(root.GetChild(0).Text);
                return element;

            case "IDENTIFIER_WITH_CLASS_NAME":
                foreach (var child in root.Children) {
                    element.SetTarget(((CommonTree)child).Text);
                }
                return element;

            case "PARAMETERS":
                if (root.ChildCount > 0) {
                    foreach (var child in root.Children) {
                        element = Visit((CommonTree)child, depth + 1, element);
                    }
                }
                return element;

            case "PARAMETER":
                element = Visit((CommonTree)root.Children[0], depth + 1, element);
                element.SetParameter(((CommonTree)root.Children[1]).Text);
                return element;

            case "PARAMETER_TYPE":
                element.SetParameterType(root.GetChild(0).Text);
                return element;

            case "ARGUMENTS":
                WriteIndent(depth);
                Console.WriteLine("<" + token + ">");
                foreach (var child in root.Children) {
                    Visit((CommonTree)child, depth + 1, element);
                }
                WriteIndent(depth);
                Console.WriteLine("</ " + token + ">");
                return element;

            case "ARGUMENT":
                WriteIndent(depth);
                Console.WriteLine("<" + token + ">");
                foreach (var child in root.Children) {
                    Visit((CommonTree)child, depth + 1, element);
                }
                WriteIndent(depth);
                Console.WriteLine("</ " + token + ">");
                return element;

            case "POINTCUT_DECLARATOR":
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                return element;

            case "POINTCUT_TYPE":
                element.SetElementType(root.GetChild(0).Text);
                return element;

            case "ADVICE_BODY":
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                return element;

            case "ADVICE_TYPE":
                element.SetElementType(root.GetChild(0).Text);
                return element;

            case "ADVICE_TARGET":
                element.SetTarget(root.GetChild(0).Text);
                return element;

            case "CONTENTS":
                foreach (var child in root.Children) {
                    element.SetContents(((CommonTree)child).Text);
                }
                return element;

            case "LANGUAGE_DECLARATION":
                element.SetLanguageType(root.GetChild(0).Text);
                return element;

            case "LANGUAGE_DEPEND_BLOCK":
                foreach (var child in root.Children) {
                    element = Visit((CommonTree)child, depth + 1, element);
                }
                return element;

            default:
                return element;
            }
        }
Пример #14
0
 /// <summary>
 /// Children will enumerate children of node t.
 /// </summary>
 /// <param name="t">node for which children are to be identified.</param>
 /// <returns>returns one child at a time.</returns>
 public IEnumerable<CommonTree> Children(CommonTree t)
 {
     for (int i = 0; i < t.ChildCount; i++)
         yield return (CommonTree)t.GetChild(i);
 }
Пример #15
0
 public void Visit(VariableDeclarationStatement statement, CommonTree tree)
 {
     Parent(tree).Children.Add(statement);
     SetLine(statement, tree);
     statement.Variable = tree.GetChild(0).Text;
     Visit(tree.GetChild(1));
 }
Пример #16
0
 public void Visit(TakeAttributeStatement statement, CommonTree tree)
 {
     Parent(tree).Children.Add(statement);
     statement.Attriute = ParseLiteral(tree.GetChild(0).Text);
 }
Пример #17
0
        public void Visit(TableAlias alias, CommonTree tree)
        {
            Parent(tree).Children.Add(alias);
            SetLine(alias, tree);

            alias.Id = tree.GetChild(0).Text;
        }
Пример #18
0
        /// <summary>
        /// Parses an ARGB color from the MapCSS definition.
        /// </summary>
        /// <param name="colorTree"></param>
        /// <returns></returns>
        private static int ParseColor(CommonTree colorTree)
        {
            if (colorTree == null)
            {
                throw new ArgumentNullException("colorTree");
            }

            int valueInt;
            KnownColor namedColor;

            if (colorTree.Text == "VALUE_RGB")
            { // a pre-defined RGB value.
                string rString = colorTree.GetChild(0).Text;
                string gString = colorTree.GetChild(1).Text;
                string bString = colorTree.GetChild(2).Text;

                int r = int.Parse(rString);
                int g = int.Parse(gString);
                int b = int.Parse(bString);

                return SimpleColor.FromArgb(r, g, b).Value;
            }
            else if (int.TryParse(colorTree.Text, NumberStyles.Any, System.Globalization.CultureInfo.InvariantCulture, out valueInt))
            { // the color is defined as an integer? this cannot happen??
                return valueInt;
            }
#if!WINDOWS_PHONE
            else if (Enum.TryParse<KnownColor>(colorTree.Text, true, out namedColor))
#else
            else if (EnumHelper.TryParse<KnownColor>(colorTree.Text, true, out namedColor))
#endif
            { // the color was named.
                return SimpleColor.FromKnownColor(namedColor).Value;
            }
            else
            { // value could not be parsed.
                throw new MapCSSDomainParserException(colorTree,
                                                            string.Format("Color value cannot be parsed!"));
            }
        }
Пример #19
0
        public void TestList()
        {
            ITree root = new CommonTree( (IToken)null );

            ITree t = new CommonTree( new CommonToken( 101 ) );
            t.AddChild( new CommonTree( new CommonToken( 102 ) ) );
            t.GetChild( 0 ).AddChild( new CommonTree( new CommonToken( 103 ) ) );
            t.AddChild( new CommonTree( new CommonToken( 104 ) ) );

            ITree u = new CommonTree( new CommonToken( 105 ) );

            root.AddChild( t );
            root.AddChild( u );

            ITreeNodeStream stream = newStream( root );
            string expecting = " 101 102 103 104 105";
            string found = ToNodesOnlyString( stream );
            Assert.AreEqual( expecting, found );

            expecting = " 101 2 102 2 103 3 104 3 105";
            found = ToTokenTypeString( stream );
            Assert.AreEqual( expecting, found );
        }
Пример #20
0
        public void Visit(EachStatement eachStatement, CommonTree tree)
        {
            Parent(tree).Children.Add(eachStatement);
            SetLine(eachStatement, tree);

            eachStatement.IterationVariable = new VariableDeclarationStatement() { Variable = tree.GetChild(0).Text };
            SetLine(eachStatement.IterationVariable, tree.GetChild(0));

            var rowGetter = new TableVariableRowGetter() { Id = tree.GetChild(1).Text };
            SetLine(rowGetter, tree.GetChild(1));
            eachStatement.IterationVariable.Children.Add(rowGetter);

            eachStatement.TableReference = new TableVariableReference() { Id = tree.GetChild(1).Text };
            SetLine(eachStatement.TableReference, tree.GetChild(1));

            Visit(tree.GetChild(2));
        }
Пример #21
0
 public void Visit(TableMemberReference variable, CommonTree tree)
 {
     Parent(tree).Children.Add(variable);
     variable.RowReference = new TableVariableRowReference() { Id = tree.GetChild(0).Text, Parent = variable };
     SetLine(variable.RowReference, tree.GetChild(0));
     variable.Member = tree.GetChild(1).Text;
     SetLine(variable, tree.GetChild(1));
 }
Пример #22
0
 public void Visit(ThreadTableHint hint, CommonTree tree)
 {
     SetLine(hint, tree);
     Parent(tree).Children.Add(hint);
     hint.ThreadCount = int.Parse(tree.GetChild(0).Text);
 }
Пример #23
0
 /// <summary>
 /// Returns begin/end for a create routine block.
 /// </summary>
 /// <param name="t"></param>
 /// <returns></returns>
 private CommonTree GetBeginEnd(CommonTree t)
 {
   CommonTree beginEnd = null;
   int i = 0;
   while (i < t.ChildCount && Cmp(t.GetChild(i).Text, "begin_end") != 0)
     i++;
   if (i < t.ChildCount)
     beginEnd = (CommonTree)t.GetChild(i);
   return beginEnd;
 }
Пример #24
0
 private TeaseMedia GetImage(CommonTree picNode)
 {
     return (picNode != null) ? new TeaseMedia { Id = picNode.GetChild(0).Text.Trim('\'', '"') } : null;
 }
Пример #25
0
 /// <summary>
 /// Returns a description of the variable (or variables) declared within a single DECLARE statement.
 /// </summary>
 /// <param name="Tree"></param>
 /// <returns>Array with one or more variables.</returns>
 internal StoreType[] ParseDeclare( CommonTree Tree )
 {
   StoreType st = new StoreType();
   StoreType[] stVars = null;
   int idx = 0, i, idxDataType;
   while( ( idx < Tree.ChildCount ) && ( Cmp( Tree.GetChild( idx ).Text, "data_type") != 0) )
     idx++;
   if (idx >= Tree.ChildCount)
     throw new InvalidDataException("Argument node");
   stVars = new StoreType[ idx ];
   idxDataType = idx;
   ParseDataType(st, (CommonTree)Tree.GetChild(idx));
   while ((idx < Tree.ChildCount) && (Cmp(Tree.GetChild(idx).Text, "default") != 0))
     idx++;
   if (idx < Tree.ChildCount)
   {
     st.Value = Tree.GetChild(idx).GetChild(0).Text;
   }
   else
   {
     st.Value = DBNull.Value;
   }
   i = 0;
   while ((i < Tree.ChildCount) && (i < idxDataType))
   {
     stVars[ i ] = new StoreType();
     stVars[ i ].Name = Tree.GetChild(i).Text;
     stVars[ i ].Type = st.Type;
     stVars[ i ].Length = st.Length;
     stVars[ i ].Values = st.Values;
     stVars[ i ].Precision = st.Precision;
     stVars[ i ].Unsigned = st.Unsigned;
     stVars[ i ].Value = st.Value;
     i++;
   }
   return stVars;
 }
Пример #26
0
        private string GetPageId(CommonTree node)
        {
            if (node.Type == FlashTeaseScriptLexer.RANGE)
            {
                var fromNode = node.GetChild(0) as CommonTree;
                var toNode = node.GetChild(1) as CommonTree;
                if (fromNode != null && toNode != null)
                {
                    var fromText = String.Concat(fromNode.Children.Select(child => child.Text).ToArray());
                    var toText = String.Concat(toNode.Children.Select(child => child.Text).ToArray());

                    var prefix = node.GetFirstChildWithType(FlashTeaseScriptLexer.PREFIX) as CommonTree;

                    string prefixText = (prefix != null) ? prefix.GetChild(0).Text.Trim('\'', '"') : null;

                    return String.Format("{0}({1}..{2})", prefixText, fromText, toText);
                }
            }
            return String.Concat(node.Children.Select(child => child.Text).ToArray());
        }
Пример #27
0
 /// <summary>
 /// Parses a comma separated list of arguments.
 /// </summary>
 /// <param name="node"></param>
 /// <returns></returns>
 internal Dictionary<string, StoreType> ParseArgs(CommonTree node)
 {
   Dictionary<string, StoreType> args = new Dictionary<string, StoreType>();
   int i = 0;
   while (i < node.ChildCount && Cmp(node.GetChild(i).Text, "param") != 0)
     i++;
   while (i < node.ChildCount)
   {
     if (Cmp(node.GetChild(i).Text, "param") != 0) break;
     KeyValuePair<string, StoreType> arg = ParseArg((CommonTree)node.GetChild(i));
     args.Add(arg.Key, arg.Value);
     i++;
   }
   return args;
 }
Пример #28
0
        private string GetText(CommonTree textNode)
        {
            if (textNode == null)
            {
                return null;
            }
            string originalText = textNode.GetChild(0).Text.Trim('\'', '"');

            var result = new StringBuilder();

            if (!String.IsNullOrEmpty(originalText))
            {
                try
                {
                    var xmldoc = new XmlDocument();
                    xmldoc.LoadXml("<dummy>" + originalText + "</dummy>");
                    var pNodes = xmldoc.SelectNodes("//P");
                    if (pNodes != null && pNodes.Count > 0)
                    {
                        foreach (XmlElement element in pNodes)
                        {
                            result.AppendFormat("<p>{0}</p>", HttpUtility.HtmlEncode(element.InnerText));
                        }
                    }
                    else
                    {
                        result.Append(HttpUtility.HtmlEncode(xmldoc.InnerText));
                    }
                }
                catch (Exception)
                {
                    return HttpUtility.HtmlEncode(originalText);
                }
            }

            return (result.Length == 0) ? null : result.ToString();
        }
Пример #29
0
 private static string GetRoutineName(CommonTree t)
 {
   string name = null;
   if (Cmp(t.GetChild(1).Text, "definer") == 0)
     name = t.GetChild(3).Text;
   else
     name = t.GetChild(1).Text;
   return name;
 }
        private static string GetParameterType(CommonTree tree)
        {
            int index = 0;

            while (index < tree.ChildCount)
            {
                switch (tree.GetChild(index).Type)
                {
                case Java2Lexer.MONKEYS_AT:
                case Java2Lexer.FINAL:
                    index++;
                    continue;

                default:
                    break;
                }

                break;
            }

            string typeText = GetTypeText((CommonTree)tree.GetChild(index));

            if (tree.GetFirstChildWithType(Java2Lexer.ELLIPSIS) != null)
                typeText = typeText + "...";

            return typeText;
        }