summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/codeimport/nativeimportbase.h
blob: 34fac3289fac2e752e7928b59800f158fc8053f3 (plain)
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *  copyright (C) 2005-2007                                                *
 *  Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                   *
 ***************************************************************************/

#ifndef NATIVEIMPORTBASE_H
#define NATIVEIMPORTBASE_H

#include <tqstring.h>
#include <tqstringlist.h>
#include "classimport.h"
#include "../umlnamespace.h"

class UMLPackage;
class UMLClassifier;

/**
 * Intermediate base class for native Umbrello implementations of
 * programming language import
 *
 * The default call sequence is as follows (RealizedLanguageImport
 * is used as a placeholder name for the concrete language importer.)
 *   NativeImportBase                      RealizedLanguageImport
 * --> importFiles()
 *       parseFile()
 *         -----------------------------------> initVars()
 *         scan()
 *           preprocess() (may be reimplemented)
 *           ---------------------------------> fillSource()
 *         -----------------------------------> parseStmt()
 * This sequence may be changed by overriding default implementations
 * of virtual methods in NativeImportBase.
 *
 * @short Base class for native implementations of language import
 * @author Oliver Kellogg <okellogg@users.sourceforge.net>
 * Bugs and comments to uml-devel@lists.sf.net or http://bugs.trinitydesktop.org
 */
class NativeImportBase : public ClassImport {
public:
    /**
     * Constructor
     * @param singleLineCommentIntro  "//" for IDL and Java, "--" for Ada
     */
    NativeImportBase(const TQString &singleLineCommentIntro);
    virtual ~NativeImportBase();

protected:
    /**
     * Implement abstract operation from ClassImport.
     */
    void initialize();

    /**
     * Set the delimiter strings for a multi line comment.
     *
     * @param intro  In languages with a C style multiline comment
     *               this is slash-star.
     * @param end    In languages with a C style multiline comment
     *               this is star-slash.
     */
    void setMultiLineComment(const TQString &intro, const TQString &end);
    /**
     * Set the delimiter strings for an alternative form of
     * multi line comment. See setMultiLineComment().
     */
    void setMultiLineAltComment(const TQString &intro, const TQString &end);

    /**
     * Import a single file.
     * The default implementation should be feasible for languages that
     * don't depend on an external preprocessor.
     *
     * @param filename  The file to import.
     */
    virtual void parseFile(const TQString& filename);

    /**
     * Initialize auxiliary variables.
     * This is called by the default implementation of parseFile()
     * after scanning (before parsing the TQStringList m_source.)
     * The default implementation is empty.
     */
    virtual void initVars();

    /**
     * Scan a single line.
     * parseFile() calls this for each line read from the input file.
     * This in turn calls other methods such as preprocess() and fillSource().
     *
     * @param line  The line to scan.
     */
    void scan(TQString line);

    /**
     * Preprocess a line.
     * May modify the given line to remove items consumed by the
     * preprocessing such as comments or preprocessor directives.
     * The default implementation handles multi-line comments.
     *
     * @param line  The line to preprocess.
     * @return      True if the line was completely consumed,
     *              false if there are still items left in the line
     *              for further analysis.
     */
    virtual bool preprocess(TQString& line);

    /**
     * Split the line so that a string is returned as a single element of the list.
     * When not in a string then split at white space.
     * The default implementation is suitable for C style strings and char constants.
     */
    virtual TQStringList split(const TQString& line);

    /**
     * Analyze the given word and fill `m_source'.
     * A "word" is a whitespace delimited item from the input line.
     * To be provided by the specific importer class.
     */
    virtual void fillSource(const TQString& word) = 0;

    /**
     * Parse the statement which starts at m_source[m_srcIndex]
     * leaving m_srcIndex pointing to the end of the recognized
     * statement.
     * To be provided by the concrete importer.
     *
     * @return   True if the statement was recognized.
     */
    virtual bool parseStmt() = 0;

    /**
     * Advance m_srcIndex until m_source[m_srcIndex] contains the lexeme
     * given by `until'.
     */
    void skipStmt(TQString until = ";");

    /**
     * Advance m_srcIndex to the index of the corresponding closing character
     * of the given opening.  Nested opening/closing pairs are respected.
     * Valid openers are:    '{'  '['  '('  '<'
     *
     * @return  True for success, false for misuse (invalid opener) or
     *          if no matching closing character is found in m_source.
     */
    bool skipToClosing(TQChar opener);

    /**
     * Advance m_srcIndex until m_source[m_srcIndex] contains a non-comment.
     * Comments encountered during advancement are accumulated in `m_comment'.
     * If m_srcIndex hits the end of m_source then TQString() is returned.
     */
    TQString advance();

    /**
     * How to start a single line comment in this programming language.
     */
    TQString m_singleLineCommentIntro;

    /**
     * The scanned lexemes.
     */
    TQStringList m_source;
    /**
     * Used for indexing m_source.
     */
    uint m_srcIndex;

    /**
     * Stack of scopes for use by the specific importer.
     */
    UMLPackage *m_scope[32];
    /**
     * Indexes m_scope. Index 0 is reserved for global scope.
     */
    uint m_scopeIndex;

    /**
     * The class currently being processed.
     */
    UMLClassifier *m_klass;
    /**
     * The current access (public/protected/private)
     */
    Uml::Visibility m_currentAccess;
    /**
     * Intermediate accumulator for comment text.
     */
    TQString m_comment;
    /**
     * True if we are currently in a multi-line comment.
     * Only applies to languages with multi-line comments.
     */
    bool m_inComment;
    /**
     * Accumulator for abstractness
     */
    bool m_isAbstract;

    /**
     * List of parsed files. Contains file names without paths.
     * Before actually parsing a given file, NativeImportBase checks
     * whether the name is already present in this list in order to
     * avoid parsing the same file multiple times.
     */
    TQStringList m_parsedFiles;

    /**
     * Multi line comment delimiters
     */
    TQString m_multiLineCommentIntro;
    TQString m_multiLineCommentEnd;
    /**
     * Some languages support an alternative set of multi line
     * comment delimiters.
     */
    TQString m_multiLineAltCommentIntro;
    TQString m_multiLineAltCommentEnd;
};

#endif