Esempio n. 1
0
        public static VariableType GetNodeDestType(IAstNode node)
        {
            if (node is AstOperation operation)
            {
                // Load attribute basically just returns the attribute value.
                // Some built-in attributes may have different types, so we need
                // to return the type based on the attribute that is being read.
                if (operation.Inst == Instruction.LoadAttribute)
                {
                    return(GetOperandVarType((AstOperand)operation.GetSource(0)));
                }
                else if (operation is AstTextureOperation texOp &&
                         (texOp.Inst == Instruction.ImageLoad ||
                          texOp.Inst == Instruction.ImageStore))
                {
                    return(texOp.Format.GetComponentType());
                }

                return(GetDestVarType(operation.Inst));
            }
            else if (node is AstOperand operand)
            {
                return(GetOperandVarType(operand));
            }
            else
            {
                throw new ArgumentException($"Invalid node type \"{node?.GetType().Name ?? "null"}\".");
            }
        }
Esempio n. 2
0
        private void StartGraphNode(IAstNode node)
        {
            var graphNode = new Node( )
            {
                Id       = CreateNodeId(node),
                Label    = node.GetType( ).Name,
                Category = "TreeNode"
            };

            graphNode.Properties.Add("SourceInteval", node.Location.ToString( ));

            if (NodeStack.Count > 0)
            {
                var link = new Link( )
                {
                    Source = NodeStack.Peek( ).Id,
                    Target = graphNode.Id
                };

                Graph.Links.Add(link);
            }

            Graph.Nodes.Add(graphNode);
            NodeStack.Push(graphNode);
        }
        private Win.Controls.TreeViewItem ProduceNode(IAstNode node)
        {
            string header = node.GetType().Name;

            if (node is StaticStringNode)
            {
                header += "(" + ((StaticStringNode)node).Value + ")";
            }
            else if (node is NameNode)
            {
                header += "(" + ((NameNode)node).Value + ")";
            }
            else if (node is TypenameNode)
            {
                header += "(" + ((TypenameNode)node).Type.Name + ")";
            }
            else if (node is IExpressionNode)
            {
                header += "(" + ((IExpressionNode)node).Expression.Evaluate(new PolyToolkit.Evaluation.DefaultContext()) + ")";
            }
            return(new Win.Controls.TreeViewItem()
            {
                Header = header
            });
        }
Esempio n. 4
0
 public override void SetParentInChildNode(IAstNode node)
 {
     if (node.GetType() == typeof (ReservedTopLevel))
     {
         // SELECTなどの予約語をもつことからネスト構造のSQLをもつ
         HasQuery = true;
     }
     base.SetParentInChildNode(node);
 }
Esempio n. 5
0
 public override void SetParentInChildNode(IAstNode node)
 {
     if (node.GetType() == typeof(ReservedTopLevel))
     {
         // SELECTなどの予約語をもつことからネスト構造のSQLをもつ
         HasQuery = true;
     }
     base.SetParentInChildNode(node);
 }
Esempio n. 6
0
        public static string GetExpression(CodeGenContext context, IAstNode node)
        {
            if (node is AstOperation operation)
            {
                return(GetExpression(context, operation));
            }
            else if (node is AstOperand operand)
            {
                return(context.OperandManager.GetExpression(operand, context.Config, context.CbIndexable));
            }

            throw new ArgumentException($"Invalid node type \"{node?.GetType().Name ?? "null"}\".");
        }
Esempio n. 7
0
        private void WriteNode(IAstNode node)
        {
            Indent();

            string type = node.GetType().ToString();
            string name = type.Substring(type.LastIndexOf('.') + 1);

            _sb.Append(name);

            string innerType = node.ToString();

            innerType = innerType.Replace("\n", "\\n");
            innerType = innerType.Replace("\r", "\\r");

            int ms = innerType.IndexOf("Microsoft", StringComparison.Ordinal);

            if (ms >= 0)
            {
                innerType = innerType.Substring(type.LastIndexOf('.') + 1);
            }

            if (innerType != name)
            {
                _sb.Append("  [");
                _sb.Append(innerType);
                _sb.AppendLine("]");
            }
            else
            {
                _sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "  [{0}...{1})", node.Start, node.End));
            }

            _indent++;

            foreach (IAstNode child in node.Children)
            {
                WriteNode(child);
            }

            if (node is CommaSeparatedList)
            {
                var csl = node as CommaSeparatedList;
                if (csl.Count > 0 && csl[csl.Count - 1] is StubArgument)
                {
                    WriteNode(csl[csl.Count - 1]);
                }
            }

            _indent--;
        }
Esempio n. 8
0
        public static bool ShouldAliasNameNode(IAstNode beforeNode)
        {
            // エイリアス定義の直前は必ずスペースかタブか改行
            if (!(beforeNode.GetType() == typeof(WhiteSpace)))
            {
                return(false);
            }

            // beforeはWhiteSpaceなので、beforeのbeforeを参照
            IAstNode node = beforeNode.BeforeNode;

            if (node.OriginalValue.ToUpper().Equals("AS") ||
                node.GetType() == typeof(TableOrColumnName) ||
                node.GetType() == typeof(Number) ||
                node.GetType() == typeof(QuateString)
                // ROWNUMなどの予約語の後にエイリアス定義が行われる場合
                || node.GetType() == typeof(ReservedWord) ||
                (node.GetType() == typeof(Bracket) && node.Value[0] == ')')
                )
            {
                return(true);
            }
            return(false);
        }
Esempio n. 9
0
        public static VariableType GetNodeDestType(CodeGenContext context, IAstNode node)
        {
            if (node is AstOperation operation)
            {
                // Load attribute basically just returns the attribute value.
                // Some built-in attributes may have different types, so we need
                // to return the type based on the attribute that is being read.
                if (operation.Inst == Instruction.LoadAttribute)
                {
                    return(GetOperandVarType((AstOperand)operation.GetSource(0)));
                }
                else if (operation.Inst == Instruction.Call)
                {
                    AstOperand funcId = (AstOperand)operation.GetSource(0);

                    Debug.Assert(funcId.Type == OperandType.Constant);

                    return(context.GetFunction(funcId.Value).ReturnType);
                }
                else if (operation is AstTextureOperation texOp &&
                         (texOp.Inst == Instruction.ImageLoad ||
                          texOp.Inst == Instruction.ImageStore))
                {
                    return(texOp.Format.GetComponentType());
                }

                return(GetDestVarType(operation.Inst));
            }
            else if (node is AstOperand operand)
            {
                if (operand.Type == OperandType.Argument)
                {
                    int argIndex = operand.Value;

                    return(context.CurrentFunction.GetArgumentType(argIndex));
                }

                return(GetOperandVarType(operand));
            }
            else
            {
                throw new ArgumentException($"Invalid node type \"{node?.GetType().Name ?? "null"}\".");
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Statementの子供を設定するとき、
        /// 子供の内容からStatementの構成情報を作成
        /// </summary>
        /// <param name="node"></param>
        public override void SetParentInChildNode(IAstNode node)
        {
            if (node.GetType() == typeof(Bracket))
            {
                HasNestStatement = true;
            }

            if (node.GetType() == typeof(StatementSeparator))
            {
                HasStatementSeparator   = true;
                StatementSeparatorValue = node.OriginalValue;
            }
            else if (node.GetType() == typeof(EvaluationString))
            {
                EvaluationValue = node.OriginalValue;
            }
            else if (   // =やLIKEなど評価等号が出現したあとは文字数をカウントしない
                !string.IsNullOrEmpty(EvaluationValue)
                // コメントやAS句はインデントを決定する文字列に利用しない
                || node.OriginalValue.Equals("AS") ||
                node.GetType() == typeof(AliasDefine) ||
                node.GetType() == typeof(WhiteSpace) ||
                node.GetType() == typeof(OneLineComment) ||
                node.GetType() == typeof(MultiLineComment)
                // Statementインデントをつける特殊な型のため文字数カウントを行わない
                || node.GetType() == typeof(StatementIndent))
            {
            }
            else
            {
                if (LeftIndentLength == 0 && node.OriginalValue.Length != 0)
                {
                    // Statementに必ずつくインデントを定義する
                    base.SetParentInChildNode(new StatementIndent(node));
                }
                LeftIndentLength += node.OriginalValue.Length;
            }
            base.SetParentInChildNode(node);
        }
Esempio n. 11
0
 private void SetParentOpenBracket(IAstNode node)
 {
     // Statementなど接続ノードはValueが空なのでBracket判定が必要
     if (node.GetType() == typeof(Bracket)
         && node.Value[0] == '(')
     {
         Bracket openNode = (Bracket)node;
         // 自分に対応するOpenかっこをみつけたら終了
         HasQuery = openNode.HasQuery;
         ParentNode = openNode.ParentNode;
         Level = openNode.ParentNode.Level;
         ParentNode.SetParentInChildNode(this);
     }
     else if (node.ParentNode != null) 
     {
         // みつかるまで、親を探す
         SetParentOpenBracket(node.ParentNode);
     }
     // なにもみつからなければ、親はからになる
 }
Esempio n. 12
0
 private void SetParentOpenBracket(IAstNode node)
 {
     // Statementなど接続ノードはValueが空なのでBracket判定が必要
     if (node.GetType() == typeof(Bracket) &&
         node.Value[0] == '(')
     {
         Bracket openNode = (Bracket)node;
         // 自分に対応するOpenかっこをみつけたら終了
         HasQuery   = openNode.HasQuery;
         ParentNode = openNode.ParentNode;
         Level      = openNode.ParentNode.Level;
         ParentNode.SetParentInChildNode(this);
     }
     else if (node.ParentNode != null)
     {
         // みつかるまで、親を探す
         SetParentOpenBracket(node.ParentNode);
     }
     // なにもみつからなければ、親はからになる
 }
Esempio n. 13
0
        private void WriteNode(IAstNode node) {
            Indent();

            string type = node.GetType().ToString();
            string name = type.Substring(type.LastIndexOf('.') + 1);

            _sb.Append(name);

            string innerType = node.ToString();

            innerType = innerType.Replace("\n", "\\n");
            innerType = innerType.Replace("\r", "\\r");

            int ms = innerType.IndexOf("Microsoft", StringComparison.Ordinal);
            if (ms >= 0) {
                innerType = innerType.Substring(type.LastIndexOf('.') + 1);
            }

            if (innerType != name) {
                _sb.Append("  [");
                _sb.Append(innerType);
                _sb.AppendLine("]");
            } else {
                _sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "  [{0}...{1})", node.Start, node.End));
            }

            _indent++;

            foreach (IAstNode child in node.Children) {
                WriteNode(child);
            }

            if (node is CommaSeparatedList) {
                var csl = node as CommaSeparatedList;
                if (csl.Count > 0 && csl[csl.Count - 1] is StubArgument) {
                    WriteNode(csl[csl.Count - 1]);
                }
            }

            _indent--;
        }
Esempio n. 14
0
        public static VariableType GetNodeDestType(IAstNode node)
        {
            if (node is AstOperation operation)
            {
                return(GetDestVarType(operation.Inst));
            }
            else if (node is AstOperand operand)
            {
                if (operand.Type == OperandType.Attribute)
                {
                    if (_builtInAttributes.TryGetValue(operand.Value & ~3, out BuiltInAttribute builtInAttr))
                    {
                        return(builtInAttr.Type);
                    }
                }

                return(OperandInfo.GetVarType(operand));
            }
            else
            {
                throw new ArgumentException($"Invalid node type \"{node?.GetType().Name ?? "null"}\".");
            }
        }
Esempio n. 15
0
        public static bool ShouldAliasNameNode(IAstNode beforeNode)
        {
            // エイリアス定義の直前は必ずスペースかタブか改行
            if (!(beforeNode.GetType() == typeof(WhiteSpace)))
            {
                return false;
            }

            // beforeはWhiteSpaceなので、beforeのbeforeを参照
            IAstNode node = beforeNode.BeforeNode;
            if (node.OriginalValue.ToUpper().Equals("AS")
                || node.GetType() == typeof(TableOrColumnName)
                || node.GetType() == typeof(Number)
                || node.GetType() == typeof(QuateString)
                // ROWNUMなどの予約語の後にエイリアス定義が行われる場合
                || node.GetType() == typeof(ReservedWord)
                || (node.GetType() == typeof(Bracket) && node.Value[0]==')')
                )
            {
                return true;
            }
            return false;
        } 
Esempio n. 16
0
 /// <summary>
 /// Statementの子供を設定するとき、
 /// 子供の内容からStatementの構成情報を作成
 /// </summary>
 /// <param name="node"></param>
 public override void SetParentInChildNode(IAstNode node)
 {
     if (node.GetType() == typeof (Bracket))
     {
         HasNestStatement = true;
     }
     
     if (node.GetType() == typeof (StatementSeparator))
     {
         HasStatementSeparator = true;
         StatementSeparatorValue = node.OriginalValue;
     }
     else if (node.GetType() == typeof (EvaluationString))
     {
         EvaluationValue = node.OriginalValue;
     }
     else if (   // =やLIKEなど評価等号が出現したあとは文字数をカウントしない
                 !string.IsNullOrEmpty(EvaluationValue)
                 // コメントやAS句はインデントを決定する文字列に利用しない
              || node.OriginalValue.Equals("AS")
              || node.GetType() == typeof (AliasDefine)
              || node.GetType() == typeof (WhiteSpace)
              || node.GetType() == typeof (OneLineComment)
              || node.GetType() == typeof (MultiLineComment)
                 // Statementインデントをつける特殊な型のため文字数カウントを行わない
              || node.GetType() == typeof (StatementIndent))
     {
     }
     else
     {
         if (LeftIndentLength == 0 && node.OriginalValue.Length != 0)
         {
             // Statementに必ずつくインデントを定義する
             base.SetParentInChildNode(new StatementIndent(node));
         }
         LeftIndentLength += node.OriginalValue.Length;
     }
     base.SetParentInChildNode(node);
 }
Esempio n. 17
0
 private static string CreateNodeId(IAstNode node)
 {
     return($"{node.GetType( ).GUID}-{node.GetHashCode( )}");
 }
Esempio n. 18
0
 private static void ShowResults(IAstNode node)
 {
     Console.WriteLine("Parsed {0}", node.GetType( ).Name);
 }