File indexing completed on 2024-04-28 04:36:05

0001 /*
0002    (C) Copyright 2009 Jonathan Schmidt-Dominé <devel@the-user.org>
0003    Derived from the KDevelop-Java-Parser
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License version 2 as published by the Free Software Foundation.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017    Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "dumptree.h"
0021 #include "ccast.h"
0022 #include "kdev-pg-token-stream.h"
0023 
0024 #include <QString>
0025 
0026 #include <iostream>
0027 
0028 static char const * const names[] = {
0029   "AND_expression",
0030   "Abstract_declarator",
0031   "Additive_expression",
0032   "Argument_expression_list",
0033   "Asm_against_mangling",
0034   "Asm_specifier",
0035   "Assignment_expression",
0036   "Assignment_operator",
0037   "Cast_expression",
0038   "Compound_statement",
0039   "Conditional_expression",
0040   "Constant",
0041   "Constant_expression",
0042   "Ddeclaration",
0043   "Declaration",
0044   "Declaration_header",
0045   "Declaration_parameter",
0046   "Declaration_specifier",
0047   "Declarator",
0048   "Direct_abstract_declarator",
0049   "Direct_declarator",
0050   "Direct_declarator_rest",
0051   "Document",
0052   "Enum_specifier",
0053   "Enumerator",
0054   "Equality_expression",
0055   "Exclusive_OR_expression",
0056   "Execution_block",
0057   "Expression",
0058   "Expression_statement",
0059   "Ext_expression",
0060   "External_Block",
0061   "External_declaration",
0062   "Function_declaration",
0063   "Function_definition",
0064   "Inclusive_OR_expression",
0065   "Init_declarator",
0066   "Initializer",
0067   "Inline_asm",
0068   "Iteration_statement",
0069   "Jump_statement",
0070   "Labeled_statement",
0071   "Logical_AND_expression",
0072   "Logical_OR_expression",
0073   "Multiplicative_expression",
0074   "Named_parameter",
0075   "Parameter",
0076   "Parameter_declaration",
0077   "Parameter_type_list",
0078   "Pointer",
0079   "Postfix_expression",
0080   "Postfix_expression_rest",
0081   "Primary_expression",
0082   "Relational_expression",
0083   "Selection_statement",
0084   "Shift_expression",
0085   "Specifier_qualifier",
0086   "Statement",
0087   "Storage_class_specifier",
0088   "Struct_declaration",
0089   "Struct_declarator",
0090   "Struct_or_union_specifier",
0091   "Translation_unit",
0092   "Type_name",
0093   "Type_name_d",
0094   "Type_qualifier",
0095   "Type_specifier",
0096   "Typed_identifier",
0097   "Typedef_d",
0098   "Unary_expression",
0099   "Unary_operator",
0100   "Value_Declaration",
0101   "Variable_declaration",
0102   "Variable_or_function"
0103 };
0104 
0105 
0106 using namespace cc;
0107 
0108 DumpTree::DumpTree()
0109   : indent(0)
0110 {
0111 }
0112 
0113 void DumpTree::dump( AstNode * node )
0114 {
0115   visitNode(node);
0116 }
0117 
0118 void DumpTree::visitNode(AstNode *node)
0119 {
0120   QString nodeText;
0121   if (node)
0122   {
0123     std::cout << QString(indent * 2, ' ').toLatin1().constData() << names[node->kind - 1000]
0124              <<  "[" << node->startToken << "," << node->endToken << "]" << nodeText.toLatin1().constData() << std::endl;
0125   }
0126 
0127   ++indent;
0128   DefaultVisitor::visitNode(node);
0129   --indent;
0130 
0131   if (node)
0132   {
0133     std::cout << QString(indent * 2, ' ').toLatin1().constData() << names[node->kind - 1000] << std::endl;
0134   }
0135 }
0136 
0137 DumpTree::~DumpTree( )
0138 {
0139 }
0140