root/branches/dmdfe-2.0/dump.c

Revision 458, 2.9 kB (checked in by Gregor, 2 years ago)

MERGE: DMD 1.011

Line 
1 // Compiler implementation of the D programming language
2 // Copyright (c) 1999-2006 by Digital Mars
3 // All Rights Reserved
4 // written by Walter Bright
5 // http://www.digitalmars.com
6 // License for redistribution is by either the Artistic License
7 // in artistic.txt, or the GNU General Public License in gnu.txt.
8 // See the included readme.txt for details.
9
10 #include <stdio.h>
11 #include <ctype.h>
12 #include <assert.h>
13
14 #include "mars.h"
15 #include "mtype.h"
16 #include "declaration.h"
17 #include "expression.h"
18 #include "template.h"
19
20 static void indent(int indent)
21 {
22     int i;
23
24     for (i = 0; i < indent; i++)
25     printf(" ");
26 }
27
28 static char *type_print(Type *type)
29 {
30     return type ? type->toChars() : (char *) "null";
31 }
32
33 void dumpExpressions(int i, Expressions *exps)
34 {
35     for (size_t j = 0; j < exps->dim; j++)
36     {   Expression *e = (Expression *)exps->data[j];
37     indent(i);
38     printf("(\n");
39     e->dump(i + 2);
40     indent(i);
41     printf(")\n");
42     }
43 }
44
45 void Expression::dump(int i)
46 {
47     indent(i);
48     printf("%p %s type=%s\n", this, Token::toChars(op), type_print(type));
49 }
50
51 void IntegerExp::dump(int i)
52 {
53     indent(i);
54     printf("%p %jd type=%s\n", this, (intmax_t)value, type_print(type));
55 }
56
57 void IdentifierExp::dump(int i)
58 {
59     indent(i);
60     printf("%p ident '%s' type=%s\n", this, ident->toChars(), type_print(type));
61 }
62
63 void DsymbolExp::dump(int i)
64 {
65     indent(i);
66     printf("%p %s type=%s\n", this, s->toChars(), type_print(type));
67 }
68
69 void VarExp::dump(int i)
70 {
71     indent(i);
72     printf("%p %s var=%s type=%s\n", this, Token::toChars(op), var->toChars(), type_print(type));
73 }
74
75 void UnaExp::dump(int i)
76 {
77     indent(i);
78     printf("%p %s type=%s e1=%p\n", this, Token::toChars(op), type_print(type), e1);
79     if (e1)
80     e1->dump(i + 2);
81 }
82
83 void CallExp::dump(int i)
84 {
85     UnaExp::dump(i);
86     dumpExpressions(i, arguments);
87 }
88
89 void SliceExp::dump(int i)
90 {
91     indent(i);
92     printf("%p %s type=%s e1=%p\n", this, Token::toChars(op), type_print(type), e1);
93     if (e1)
94     e1->dump(i + 2);
95     if (lwr)
96     lwr->dump(i + 2);
97     if (upr)
98     upr->dump(i + 2);
99 }
100
101 void DotIdExp::dump(int i)
102 {
103     indent(i);
104     printf("%p %s type=%s ident=%s e1=%p\n", this, Token::toChars(op), type_print(type), ident->toChars(), e1);
105     if (e1)
106     e1->dump(i + 2);
107 }
108
109 void DotVarExp::dump(int i)
110 {
111     indent(i);
112     printf("%p %s type=%s var='%s' e1=%p\n", this, Token::toChars(op), type_print(type), var->toChars(), e1);
113     if (e1)
114     e1->dump(i + 2);
115 }
116
117 void DotTemplateInstanceExp::dump(int i)
118 {
119     indent(i);
120     printf("%p %s type=%s ti='%s' e1=%p\n", this, Token::toChars(op), type_print(type), ti->toChars(), e1);
121     if (e1)
122     e1->dump(i + 2);
123 }
124
125 void DelegateExp::dump(int i)
126 {
127     indent(i);
128     printf("%p %s func=%s type=%s e1=%p\n", this, Token::toChars(op), func->toChars(), type_print(type), e1);
129     if (e1)
130     e1->dump(i + 2);
131 }
132
133 void BinExp::dump(int i)
134 {
135     indent(i);
136     printf("%p %s type=%s e1=%p e2=%p\n", this, Token::toChars(op), type_print(type), e1, e2);
137     if (e1)
138     e1->dump(i + 2);
139     if (e2)
140     e2->dump(i + 2);
141 }
Note: See TracBrowser for help on using the browser.