1
/***************************************************************************
2
* Copyright (C) 2005 by Alexander Dymo *
5
* Copyright (c) 2005 by Matt Rogers *
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. *
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. *
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
26
#include <qstringlist.h>
30
Abstract Syntax Tree (AST) class declarations.
38
* This is the base class. Objects of this type are not created by the parser.
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.
44
* Each AST node also knows how to write the information back into .pro file.
49
/**Type of AST node.*/
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.
59
/** Constructs AST with given node type.*/
60
AST(NodeType nodeType): m_nodeType(nodeType), m_depth(0) {}
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);
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.
74
virtual void writeBack(QString &buffer);
76
/** @return The type of the node.*/
77
virtual NodeType nodeType() const { return m_nodeType; }
79
/** Sets the depth of the node in AST.*/
80
void setDepth(int depth) { m_depth = depth; }
82
/** @return The depth of the node in AST.*/
83
int depth() const { return m_depth; }
85
/** @return The indentation string based on node depth.*/
86
virtual QString indentation();
88
//! \return true if this AST has children
89
bool hasChildren() const;
92
* Get the children of this ast
93
* \return the list of this ast's childre
95
QValueList<AST*> children() const;
101
QValueList<AST*> m_children;
111
* Represents complete projects, scopes and function scopes.
122
class ProjectAST: public AST
125
/**The kind of a project node.*/
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
135
/** Constructs a project node of given @p kind. */
136
ProjectAST(Kind kind = Project): AST(AST::ProjectAST), m_kind(kind) {}
138
virtual void writeBack(QString &buffer);
139
virtual void addChildAST(AST *node);
141
/** @return true if this node is a project.*/
142
bool isProject() const { return m_kind == Project; }
144
bool isRule() const { return m_kind == Rule; }
146
/** @return true if this node is an automake conditional */
147
bool isConditionalScope() const { return m_kind == ConditionalScope; }
149
/** @return true if this node is empty.*/
150
bool isEmpty() const { return m_kind == Empty; }
152
/**Scoped identifier (scope name or rule).*/
155
/**Function arguments. Empty for other kinds of projects.*/
158
/** The automake conditional has an else attached */
161
/**List of statements.*/
162
QValueList<AutoTools::AST*> statements;
171
* Assignment AST node.
172
* Represents assignments, for example:
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:
184
* then values will be stored as a two elements list:
190
class AssignmentAST: public AST
193
AssignmentAST(): AST(AST::AssignmentAST) {}
195
virtual void writeBack(QString &buffer);
197
/**Scoped name of the variable.*/
207
class AutomakeTargetAST : public AST
210
AutomakeTargetAST() : AST(AST::TargetAST) {}
212
virtual void writeBack( QString& buffer );
214
/// The name of the target
217
/// The dependencies for the target, if any
221
class ConditionAST : public AST
224
ConditionAST() : AST( AST::MakefileConditionalAST ) {}
226
virtual void writeBack( QString& buffer );
228
/// The keyword for the condition (if, else, endif)
231
/// The name of the condition
232
QString conditionName;
237
* Represents line feeds in files.
239
class NewLineAST: public AST
242
NewLineAST(): AST(AST::NewLineAST) {}
244
virtual void writeBack(QString &buffer);
251
* Represents comments.
253
class CommentAST: public AST
256
CommentAST(): AST(AST::CommentAST) {}
258
virtual void writeBack(QString &buffer);
269
// kate: indent-mode csands; space-indent off; tab-width 4; auto-insert-doxygen on;