~ubuntu-branches/debian/sid/kdevelop/sid

« back to all changes in this revision

Viewing changes to buildtools/lib/parsers/autotools/autotoolsast.h

  • Committer: Bazaar Package Importer
  • Author(s): Jeremy Lainé
  • Date: 2010-05-05 07:21:55 UTC
  • mfrom: (1.2.3 upstream) (5.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100505072155-h78lx19pu04sbhtn
Tags: 4:4.0.0-2
* Upload to unstable (Closes: #579947, #481832).
* Acknowledge obsolete NMU fixes (Closes: #562410, #546961).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 *   Copyright (C) 2005 by Alexander Dymo                                  *
3
 
 *   adymo@kdevelop.org                                                    *
4
 
 *                                                                         *
5
 
 *   Copyright (c) 2005 by Matt Rogers                                     *
6
 
 *   mattr@kde.org                                                         *
7
 
 *                                                                         *
8
 
 *   This program is free software; you can redistribute it and/or modify  *
9
 
 *   it under the terms of the GNU Library General Public License as       *
10
 
 *   published by the Free Software Foundation; either version 2 of the    *
11
 
 *   License, or (at your option) any later version.                       *
12
 
 *                                                                         *
13
 
 *   This program is distributed in the hope that it will be useful,       *
14
 
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
15
 
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
16
 
 *   GNU General Public License for more details.                          *
17
 
 *                                                                         *
18
 
 *   You should have received a copy of the GNU Library General Public     *
19
 
 *   License along with this program; if not, write to the                 *
20
 
 *   Free Software Foundation, Inc.,                                       *
21
 
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
22
 
 ***************************************************************************/
23
 
#ifndef AUTOTOOLSAST_H
24
 
#define AUTOTOOLSAST_H
25
 
 
26
 
#include <qstringlist.h>
27
 
 
28
 
/**
29
 
@file autotools.h
30
 
Abstract Syntax Tree (AST) class declarations.
31
 
*/
32
 
 
33
 
namespace AutoTools
34
 
{
35
 
 
36
 
/**
37
 
 * AST node.
38
 
 * This is the base class. Objects of this type are not created by the parser.
39
 
 *
40
 
 * Each AST node holds the list of its children which are always deleted in the
41
 
 * destructor. This way, it's possible call delete for only root AST node and
42
 
 * others will be deleted automatically.
43
 
 *
44
 
 * Each AST node also knows how to write the information back into .pro file.
45
 
 */
46
 
class AST
47
 
{
48
 
public:
49
 
        /**Type of AST node.*/
50
 
        enum NodeType {
51
 
                ProjectAST,                 ///< Project, scope or function scope.
52
 
                AssignmentAST,              ///< Variable assignment.
53
 
                TargetAST,                  ///< Automake target
54
 
                MakefileConditionalAST,     ///< Makefile.am conditional 
55
 
                NewLineAST,                 ///< Line feed.
56
 
                CommentAST                  ///< Comment.
57
 
        };
58
 
        
59
 
        /** Constructs AST with given node type.*/
60
 
        AST(NodeType nodeType): m_nodeType(nodeType), m_depth(0) {}
61
 
        virtual ~AST();
62
 
        
63
 
        /**
64
 
         * Adds child AST node to this node. Despite this function is virtual,
65
 
         * reimplementations should call it to make automatic destruction of
66
 
         * AST tree possible.*/
67
 
        virtual void addChildAST(AST *node);
68
 
        
69
 
        /** 
70
 
         * Writes information stored in the AST into the @p buffer.
71
 
         * This is a default implementation which iterates over child nodes
72
 
         * and calls writeBack for each child node.
73
 
         */
74
 
        virtual void writeBack(QString &buffer);
75
 
        
76
 
        /** @return The type of the node.*/
77
 
        virtual NodeType nodeType() const { return m_nodeType; }
78
 
        
79
 
        /** Sets the depth of the node in AST.*/
80
 
        void setDepth(int depth) { m_depth = depth; }
81
 
        
82
 
        /** @return The depth of the node in AST.*/
83
 
        int depth() const { return m_depth; }
84
 
        
85
 
        /** @return The indentation string based on node depth.*/
86
 
        virtual QString indentation();
87
 
        
88
 
        //! \return true if this AST has children
89
 
        bool hasChildren() const;
90
 
 
91
 
        /**
92
 
         * Get the children of this ast
93
 
         * \return the list of this ast's childre
94
 
         */
95
 
        QValueList<AST*> children() const;
96
 
 
97
 
 
98
 
        
99
 
protected:
100
 
        NodeType m_nodeType;
101
 
        QValueList<AST*> m_children;
102
 
        
103
 
private:
104
 
        int m_depth;
105
 
 
106
 
};
107
 
 
108
 
 
109
 
/**
110
 
 * Project AST node.
111
 
 * Represents complete projects, scopes and function scopes.
112
 
 * Examples:
113
 
 * @code
114
 
 * scopename{
115
 
 * var=value
116
 
 * }
117
 
 * function(args){
118
 
 * var=value
119
 
 * }
120
 
 * @endcode
121
 
 */
122
 
class ProjectAST: public AST
123
 
{
124
 
public:
125
 
        /**The kind of a project node.*/
126
 
        enum Kind
127
 
        {
128
 
                Project,            ///< Project
129
 
                Target,             ///< Custom Automake Target
130
 
                ConditionalScope,   ///< Automake Conditional
131
 
                Rule,               ///< Automake Rule
132
 
                Empty               ///< Project does not exist. the AST is empty
133
 
        };
134
 
        
135
 
        /** Constructs a project node of given @p kind. */
136
 
        ProjectAST(Kind kind = Project): AST(AST::ProjectAST), m_kind(kind) {}
137
 
        
138
 
        virtual void writeBack(QString &buffer);
139
 
        virtual void addChildAST(AST *node);
140
 
        
141
 
        /** @return true if this node is a project.*/
142
 
        bool isProject() const { return m_kind == Project; }
143
 
        
144
 
        bool isRule() const { return m_kind == Rule; }
145
 
        
146
 
        /** @return true if this node is an automake conditional */
147
 
        bool isConditionalScope() const { return m_kind == ConditionalScope; }
148
 
        
149
 
        /** @return true if this node is empty.*/
150
 
        bool isEmpty() const { return m_kind == Empty; }
151
 
        
152
 
        /**Scoped identifier (scope name or rule).*/
153
 
        QString scopedID;
154
 
        
155
 
        /**Function arguments. Empty for other kinds of projects.*/
156
 
        QString args;
157
 
        
158
 
        /** The automake conditional has an else attached */
159
 
        bool hasElse;
160
 
        
161
 
        /**List of statements.*/
162
 
        QValueList<AutoTools::AST*> statements;
163
 
        
164
 
private:
165
 
        Kind m_kind;
166
 
 
167
 
};
168
 
 
169
 
 
170
 
/**
171
 
 * Assignment AST node.
172
 
 * Represents assignments, for example:
173
 
 * \code
174
 
 * var=value
175
 
 * \endcode
176
 
 *
177
 
 * Values can be specified on several lines and
178
 
 * each line is stored as a string in the list of values.@n
179
 
 * For example, if we have in .pro:
180
 
 * \code
181
 
 * SOURCES=a.cpp \
182
 
 * b.cpp c.cpp
183
 
 * \endcode 
184
 
 * then values will be stored as a two elements list:
185
 
 * \code
186
 
 * a.cpp
187
 
 * b.cpp c.cpp
188
 
 * \endcode
189
 
 */
190
 
class AssignmentAST: public AST
191
 
{
192
 
public:
193
 
        AssignmentAST(): AST(AST::AssignmentAST) {}
194
 
 
195
 
        virtual void writeBack(QString &buffer);
196
 
        
197
 
        /**Scoped name of the variable.*/
198
 
        QString scopedID;
199
 
        
200
 
        /**Operator.*/
201
 
        QString op;
202
 
        
203
 
        /**List of values.*/
204
 
        QStringList values;
205
 
};
206
 
 
207
 
class AutomakeTargetAST : public AST
208
 
{
209
 
public:
210
 
        AutomakeTargetAST() : AST(AST::TargetAST) {}
211
 
        
212
 
        virtual void writeBack( QString& buffer );
213
 
        
214
 
        /// The name of the target
215
 
        QString target;
216
 
        
217
 
        /// The dependencies for the target, if any
218
 
        QStringList deps;
219
 
};
220
 
 
221
 
class ConditionAST : public AST
222
 
{
223
 
public:
224
 
        ConditionAST() : AST( AST::MakefileConditionalAST ) {}
225
 
        
226
 
        virtual void writeBack( QString& buffer );
227
 
        
228
 
        /// The keyword for the condition (if, else, endif)
229
 
        QString type;
230
 
                
231
 
        /// The name of the condition
232
 
        QString conditionName;
233
 
};
234
 
 
235
 
/**
236
 
 * New line AST node.
237
 
 * Represents line feeds in files.
238
 
 */
239
 
class NewLineAST: public AST
240
 
{
241
 
public:
242
 
        NewLineAST(): AST(AST::NewLineAST) {}
243
 
        
244
 
        virtual void writeBack(QString &buffer);
245
 
 
246
 
};
247
 
 
248
 
 
249
 
/**
250
 
 * Comment AST node.
251
 
 * Represents comments.
252
 
 */
253
 
class CommentAST: public AST
254
 
{
255
 
public:
256
 
        CommentAST(): AST(AST::CommentAST) {}
257
 
        
258
 
        virtual void writeBack(QString &buffer);
259
 
        
260
 
        /**Comment text.*/
261
 
        QString comment;
262
 
        
263
 
};
264
 
 
265
 
}
266
 
 
267
 
#endif
268
 
 
269
 
// kate: indent-mode csands; space-indent off; tab-width 4; auto-insert-doxygen on;