comparison generator/parser/control.h @ 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 #ifndef CONTROL_H
45 #define CONTROL_H
46
47 #include "symbol.h"
48 #include "smallobject.h"
49
50 #include <QtCore/QHash>
51
52 struct Declarator;
53 struct Type;
54 class Lexer;
55 class Parser;
56
57 struct Context
58 {
59 Context *parent;
60
61 inline void bind(const NameSymbol *name, Type *type)
62 { symbol_table.insert(name, type); }
63
64 inline Type *resolve(const NameSymbol *name) const
65 {
66 if (Type *type = symbol_table.value(name))
67 return type;
68 else if (parent)
69 return parent->resolve(name);
70
71 return 0;
72 }
73
74 typedef QHash<const NameSymbol*, Type*> symbol_table_t;
75
76 symbol_table_t symbol_table;
77 };
78
79 class Control
80 {
81 public:
82 class ErrorMessage
83 {
84 public:
85 ErrorMessage ():
86 _M_line (0),
87 _M_column (0) {}
88
89 inline int line () const { return _M_line; }
90 inline void setLine (int line) { _M_line = line; }
91
92 inline int column () const { return _M_column; }
93 inline void setColumn (int column) { _M_column = column; }
94
95 inline QString fileName () const { return _M_fileName; }
96 inline void setFileName (const QString &fileName) { _M_fileName = fileName; }
97
98 inline QString message () const { return _M_message; }
99 inline void setMessage (const QString &message) { _M_message = message; }
100
101 private:
102 int _M_line;
103 int _M_column;
104 QString _M_fileName;
105 QString _M_message;
106 };
107
108 Control();
109 ~Control();
110
111 inline bool skipFunctionBody() const { return _M_skipFunctionBody; }
112 inline void setSkipFunctionBody(bool skip) { _M_skipFunctionBody = skip; }
113
114 Lexer *changeLexer(Lexer *lexer);
115 Parser *changeParser(Parser *parser);
116
117 Lexer *currentLexer() const { return _M_lexer; }
118 Parser *currentParser() const { return _M_parser; }
119
120 Context *current_context;
121
122 inline Context *currentContext() const
123 { return current_context; }
124
125 void pushContext();
126 void popContext();
127
128 Type *lookupType(const NameSymbol *name) const;
129 void declare(const NameSymbol *name, Type *type);
130
131 inline const NameSymbol *findOrInsertName(const char *data, size_t count)
132 { return name_table.findOrInsert(data, count); }
133
134 void declareTypedef(const NameSymbol *name, Declarator *d);
135 bool isTypedef(const NameSymbol *name) const;
136
137 void reportError (const ErrorMessage &errmsg);
138 QList<ErrorMessage> errorMessages () const;
139 void clearErrorMessages ();
140
141 private:
142 NameTable name_table;
143 QHash<const NameSymbol*, Declarator*> stl_typedef_table;
144 bool _M_skipFunctionBody;
145 Lexer *_M_lexer;
146 Parser *_M_parser;
147
148 QList<ErrorMessage> _M_error_messages;
149 };
150
151 #endif // CONTROL_H
152
153 // kate: space-indent on; indent-width 2; replace-tabs on;