Mercurial > projects > qtd
comparison generator/parser/control.cpp @ 1:e78566595089
initial import
author | mandel |
---|---|
date | Mon, 11 May 2009 16:01:50 +0000 |
parents | |
children | 09a0f1d048f2 |
comparison
equal
deleted
inserted
replaced
0:36fb74dc547d | 1:e78566595089 |
---|---|
1 /**************************************************************************** | |
2 ** | |
3 ** Copyright (C) 1992-2008 Nokia. All rights reserved. | |
4 ** Copyright (C) 2002-2005 Roberto Raggi <roberto@kdevelop.org> | |
5 ** | |
6 ** This file is part of Qt Jambi. | |
7 ** | |
8 ** * Commercial Usage | |
9 * Licensees holding valid Qt Commercial licenses may use this file in | |
10 * accordance with the Qt Commercial License Agreement provided with the | |
11 * Software or, alternatively, in accordance with the terms contained in | |
12 * a written agreement between you and Nokia. | |
13 * | |
14 * | |
15 * GNU General Public License Usage | |
16 * Alternatively, this file may be used under the terms of the GNU | |
17 * General Public License versions 2.0 or 3.0 as published by the Free | |
18 * Software Foundation and appearing in the file LICENSE.GPL included in | |
19 * the packaging of this file. Please review the following information | |
20 * to ensure GNU General Public Licensing requirements will be met: | |
21 * http://www.fsf.org/licensing/licenses/info/GPLv2.html and | |
22 * http://www.gnu.org/copyleft/gpl.html. In addition, as a special | |
23 * exception, Nokia gives you certain additional rights. These rights | |
24 * are described in the Nokia Qt GPL Exception version 1.2, included in | |
25 * the file GPL_EXCEPTION.txt in this package. | |
26 * | |
27 * Qt for Windows(R) Licensees | |
28 * As a special exception, Nokia, as the sole copyright holder for Qt | |
29 * Designer, grants users of the Qt/Eclipse Integration plug-in the | |
30 * right for the Qt/Eclipse Integration to link to functionality | |
31 * provided by Qt Designer and its related libraries. | |
32 * | |
33 * | |
34 * If you are unsure which license is appropriate for your use, please | |
35 * contact the sales department at qt-sales@nokia.com. | |
36 | |
37 ** | |
38 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | |
39 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | |
40 ** | |
41 ****************************************************************************/ | |
42 | |
43 | |
44 #include "control.h" | |
45 #include "lexer.h" | |
46 | |
47 Control::Control() | |
48 : current_context(0), | |
49 _M_skipFunctionBody(false), | |
50 _M_lexer(0), | |
51 _M_parser(0) | |
52 { | |
53 pushContext(); | |
54 | |
55 declareTypedef(findOrInsertName("__builtin_va_list", | |
56 strlen("__builtin_va_list")), 0); | |
57 } | |
58 | |
59 Control::~Control() | |
60 { | |
61 popContext(); | |
62 | |
63 Q_ASSERT(current_context == 0); | |
64 } | |
65 | |
66 Lexer *Control::changeLexer(Lexer *lexer) | |
67 { | |
68 Lexer *old = _M_lexer; | |
69 _M_lexer = lexer; | |
70 return old; | |
71 } | |
72 | |
73 Parser *Control::changeParser(Parser *parser) | |
74 { | |
75 Parser *old = _M_parser; | |
76 _M_parser = parser; | |
77 return old; | |
78 } | |
79 | |
80 Type *Control::lookupType(const NameSymbol *name) const | |
81 { | |
82 Q_ASSERT(current_context != 0); | |
83 | |
84 return current_context->resolve(name); | |
85 } | |
86 | |
87 void Control::declare(const NameSymbol *name, Type *type) | |
88 { | |
89 //printf("*** Declare:"); | |
90 //printSymbol(name); | |
91 //putchar('\n'); | |
92 Q_ASSERT(current_context != 0); | |
93 | |
94 current_context->bind(name, type); | |
95 } | |
96 | |
97 void Control::pushContext() | |
98 { | |
99 // printf("+Context\n"); | |
100 Context *new_context = new Context; | |
101 new_context->parent = current_context; | |
102 current_context = new_context; | |
103 } | |
104 | |
105 void Control::popContext() | |
106 { | |
107 // printf("-Context\n"); | |
108 Q_ASSERT(current_context != 0); | |
109 | |
110 Context *old_context = current_context; | |
111 current_context = current_context->parent; | |
112 | |
113 delete old_context; | |
114 } | |
115 | |
116 void Control::declareTypedef(const NameSymbol *name, Declarator *d) | |
117 { | |
118 // printf("declared typedef:"); | |
119 // printSymbol(name); | |
120 // printf("\n"); | |
121 stl_typedef_table.insert(name, d); | |
122 } | |
123 | |
124 bool Control::isTypedef(const NameSymbol *name) const | |
125 { | |
126 // printf("is typedef:"); | |
127 // printSymbol(name); | |
128 // printf("= %d\n", (stl_typedef_table.find(name) != stl_typedef_table.end())); | |
129 | |
130 return stl_typedef_table.contains(name); | |
131 } | |
132 | |
133 QList<Control::ErrorMessage> Control::errorMessages () const | |
134 { | |
135 return _M_error_messages; | |
136 } | |
137 | |
138 void Control::clearErrorMessages () | |
139 { | |
140 _M_error_messages.clear (); | |
141 } | |
142 | |
143 void Control::reportError (const ErrorMessage &errmsg) | |
144 { | |
145 _M_error_messages.append(errmsg); | |
146 } | |
147 | |
148 // kate: space-indent on; indent-width 2; replace-tabs on; |