use separate slot implementation for each module
[lqt.git] / cpptoxml / parser / control.h
blob01fbdeae950aa9eb0ad89bcc05ce681aec238240
1 /****************************************************************************
2 **
3 ** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
4 ** Copyright (C) 2002-2005 Roberto Raggi <roberto@kdevelop.org>
5 **
6 ** This file is part of the Qt Script Generator project on Trolltech Labs.
7 **
8 ** This file may be used under the terms of the GNU General Public
9 ** License version 2.0 as published by the Free Software Foundation
10 ** and appearing in the file LICENSE.GPL included in the packaging of
11 ** this file. Please review the following information to ensure GNU
12 ** General Public Licensing requirements will be met:
13 ** http://www.trolltech.com/products/qt/opensource.html
15 ** If you are unsure which license is appropriate for your use, please
16 ** review the following information:
17 ** http://www.trolltech.com/products/qt/licensing.html or contact the
18 ** sales department at sales@trolltech.com.
20 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
21 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 ****************************************************************************/
26 #ifndef CONTROL_H
27 #define CONTROL_H
29 #include "symbol.h"
30 #include "smallobject.h"
32 #include <QtCore/QHash>
34 struct Declarator;
35 struct Type;
36 class Lexer;
37 class Parser;
39 struct Context
41 Context *parent;
43 inline void bind(const NameSymbol *name, Type *type)
44 { symbol_table.insert(name, type); }
46 inline Type *resolve(const NameSymbol *name) const
48 if (Type *type = symbol_table.value(name))
49 return type;
50 else if (parent)
51 return parent->resolve(name);
53 return 0;
56 typedef QHash<const NameSymbol*, Type*> symbol_table_t;
58 symbol_table_t symbol_table;
61 class Control
63 public:
64 class ErrorMessage
66 public:
67 ErrorMessage ():
68 _M_line (0),
69 _M_column (0) {}
71 inline int line () const { return _M_line; }
72 inline void setLine (int line) { _M_line = line; }
74 inline int column () const { return _M_column; }
75 inline void setColumn (int column) { _M_column = column; }
77 inline QString fileName () const { return _M_fileName; }
78 inline void setFileName (const QString &fileName) { _M_fileName = fileName; }
80 inline QString message () const { return _M_message; }
81 inline void setMessage (const QString &message) { _M_message = message; }
83 private:
84 int _M_line;
85 int _M_column;
86 QString _M_fileName;
87 QString _M_message;
90 Control();
91 ~Control();
93 inline bool skipFunctionBody() const { return _M_skipFunctionBody; }
94 inline void setSkipFunctionBody(bool skip) { _M_skipFunctionBody = skip; }
96 Lexer *changeLexer(Lexer *lexer);
97 Parser *changeParser(Parser *parser);
99 Lexer *currentLexer() const { return _M_lexer; }
100 Parser *currentParser() const { return _M_parser; }
102 Context *current_context;
104 inline Context *currentContext() const
105 { return current_context; }
107 void pushContext();
108 void popContext();
110 Type *lookupType(const NameSymbol *name) const;
111 void declare(const NameSymbol *name, Type *type);
113 inline const NameSymbol *findOrInsertName(const char *data, size_t count)
114 { return name_table.findOrInsert(data, count); }
116 void declareTypedef(const NameSymbol *name, Declarator *d);
117 bool isTypedef(const NameSymbol *name) const;
119 void reportError (const ErrorMessage &errmsg);
120 QList<ErrorMessage> errorMessages () const;
121 void clearErrorMessages ();
123 private:
124 NameTable name_table;
125 QHash<const NameSymbol*, Declarator*> stl_typedef_table;
126 bool _M_skipFunctionBody;
127 Lexer *_M_lexer;
128 Parser *_M_parser;
130 QList<ErrorMessage> _M_error_messages;
133 #endif // CONTROL_H
135 // kate: space-indent on; indent-width 2; replace-tabs on;