File: dumptree.cpp

package info (click to toggle)
kdevelop-pg-qt 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,284 kB
  • sloc: cpp: 22,743; lex: 928; ansic: 716; yacc: 615; ruby: 68; sh: 14; lisp: 10; fortran: 6; makefile: 2
file content (128 lines) | stat: -rw-r--r-- 2,685 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
    SPDX-FileCopyrightText: 2009 Jonathan Schmidt-Dominé <devel@the-user.org>
    Derived from the KDevelop-Java-Parser

    SPDX-License-Identifier: LGPL-2.0-only
*/

#include "dumptree.h"
#include "ccast.h"
#include "kdev-pg-token-stream.h"

#include <QString>

#include <iostream>

static char const * const names[] = {
  "AND_expression",
  "Abstract_declarator",
  "Additive_expression",
  "Argument_expression_list",
  "Asm_against_mangling",
  "Asm_specifier",
  "Assignment_expression",
  "Assignment_operator",
  "Cast_expression",
  "Compound_statement",
  "Conditional_expression",
  "Constant",
  "Constant_expression",
  "Ddeclaration",
  "Declaration",
  "Declaration_header",
  "Declaration_parameter",
  "Declaration_specifier",
  "Declarator",
  "Direct_abstract_declarator",
  "Direct_declarator",
  "Direct_declarator_rest",
  "Document",
  "Enum_specifier",
  "Enumerator",
  "Equality_expression",
  "Exclusive_OR_expression",
  "Execution_block",
  "Expression",
  "Expression_statement",
  "Ext_expression",
  "External_Block",
  "External_declaration",
  "Function_declaration",
  "Function_definition",
  "Inclusive_OR_expression",
  "Init_declarator",
  "Initializer",
  "Inline_asm",
  "Iteration_statement",
  "Jump_statement",
  "Labeled_statement",
  "Logical_AND_expression",
  "Logical_OR_expression",
  "Multiplicative_expression",
  "Named_parameter",
  "Parameter",
  "Parameter_declaration",
  "Parameter_type_list",
  "Pointer",
  "Postfix_expression",
  "Postfix_expression_rest",
  "Primary_expression",
  "Relational_expression",
  "Selection_statement",
  "Shift_expression",
  "Specifier_qualifier",
  "Statement",
  "Storage_class_specifier",
  "Struct_declaration",
  "Struct_declarator",
  "Struct_or_union_specifier",
  "Translation_unit",
  "Type_name",
  "Type_name_d",
  "Type_qualifier",
  "Type_specifier",
  "Typed_identifier",
  "Typedef_d",
  "Unary_expression",
  "Unary_operator",
  "Value_Declaration",
  "Variable_declaration",
  "Variable_or_function"
};


using namespace cc;

DumpTree::DumpTree()
  : indent(0)
{
}

void DumpTree::dump( AstNode * node )
{
  visitNode(node);
}

void DumpTree::visitNode(AstNode *node)
{
  QString nodeText;
  if (node)
  {
    std::cout << QString(indent * 2, QLatin1Char(' ')).toLatin1().constData() << names[node->kind - 1000]
             <<  "[" << node->startToken << "," << node->endToken << "]" << nodeText.toLatin1().constData() << std::endl;
  }

  ++indent;
  DefaultVisitor::visitNode(node);
  --indent;

  if (node)
  {
    std::cout << QString(indent * 2, QLatin1Char(' ')).toLatin1().constData() << names[node->kind - 1000] << std::endl;
  }
}

DumpTree::~DumpTree( )
{
}