-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathastbuilder.h
More file actions
137 lines (118 loc) · 7.68 KB
/
Copy pathastbuilder.h
File metadata and controls
137 lines (118 loc) · 7.68 KB
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
/***************************************************************************
* This file is part of KDevelop *
* Copyright 2007 Andreas Pakulat <[email protected]> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Library General Public License as *
* published by the Free Software Foundation; either version 2 of the *
* License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef ASTBUILDER_H
#define ASTBUILDER_H
#include <QtCore/QStack>
#include "ast.h"
#include <kurl.h>
#include <QDomDocument>
#include "kdebug.h"
#include "QXmlStreamReader"
namespace PythonParser
{
class Parser;
class AstNode;
}
namespace Python
{
class Ast;
class CodeAst;
typedef QMap<QString, QString> stringDictionary;
class AstBuilder
{
public:
CodeAst* parse(KUrl filename);
private:
CodeAst* parseXmlAst(QString xml);
QString getXmlForFile(KUrl filename);
void parseXmlAstNode(QXmlStreamReader* xmlast, QXmlStreamReader::TokenType token);
bool parseAstNode(QString name, QString text, const QList<QXmlStreamAttribute>& attributes);
QList<Ast*> m_nodeStack;
// one map for regular ast nodes, and the others for primitive nodes of different types
QMap<int, Ast*> m_nodeMap;
QMap<int, ExpressionAst::Context> m_contextNodeMap;
QMap<int, Ast::BooleanOperationTypes> m_boolOpNodeMap;
QMap<int, Ast::ComparisonOperatorTypes> m_compOpNodeMap;
QMap<int, Ast::OperatorTypes> m_opNodeMap;
QMap<int, Ast::UnaryOperatorTypes> m_unaryOpNodeMap;
QStack<Ast*> m_astStack;
QMap<int, stringDictionary> m_attributeStore;
Ast* m_currentNode;
Ast::BooleanOperationTypes resolveBooleanOperator(const QString& identifier);
Ast::ComparisonOperatorTypes resolveComparisonOperator(const QString& identifier);
Ast::OperatorTypes resolveOperator(const QString& identifier);
Ast::UnaryOperatorTypes resolveUnaryOperator(const QString& identifier);
ExpressionAst::Context resolveContext(const QString& identifier);
QList<Ast::BooleanOperationTypes> resolveBooleanOperatorList(const QString& identifiers);
QList<Ast::ComparisonOperatorTypes> resolveComparisonOperatorList(const QString& identifiers);
QList<Ast::OperatorTypes> resolveOperatorList(const QString& identifiers);
QList<Ast::UnaryOperatorTypes> resolveUnaryOperatorList(const QString& identifiers);
QList<ExpressionAst::Context> resolveContextList(const QString& identifiers);
void populateAst();
template<typename T> QList<T*> resolveNodeList(const QString& commaSeperatedIdentifiers);
template<typename T> T* resolveNode(const QString& identifier);
Identifier* createIdentifier(const QString& name, Ast* range);
FunctionDefinitionAst* populateFunctionDefinitionAst(Ast* ast, const stringDictionary& currentAttributes);
AssignmentAst* populateAssignmentAst(Ast* ast, const stringDictionary& currentAttributes);
CodeAst* populateCodeAst(Ast* ast, const stringDictionary& currentAttributes);
ClassDefinitionAst* populateClassDefinitonAst(Ast* ast, const stringDictionary& currentAttributes);
NameAst* populateNameAst(Ast* ast, const stringDictionary& currentAttributes);
ReturnAst* populateReturnAst(Ast* ast, const stringDictionary& currentAttributes);
DeleteAst* populateDeleteAst(Ast* ast, const stringDictionary& currentAttributes);
ForAst* populateForAst(Ast* ast, const stringDictionary& currentAttributes);
WhileAst* populateWhileAst(Ast* ast, const stringDictionary& currentAttributes);
PrintAst* populatePrintAst(Ast* ast, const stringDictionary& currentAttributes);
IfAst* populateIfAst(Ast* ast, const stringDictionary& currentAttributes);
LambdaAst* populateLambdaAst(Ast* ast, const stringDictionary& currentAttributes);
BooleanOperationAst* populateBooleanOperationAst(Ast* ast, const stringDictionary& currentAttributes);
CallAst* populateCallAst(Ast* ast, const stringDictionary& currentAttributes);
DictAst* populateDictAst(Ast* ast, const stringDictionary& currentAttributes);
ListAst* populateListAst(Ast* ast, const stringDictionary& currentAttributes);
TupleAst* populateTupleAst(Ast* ast, const stringDictionary& currentAttributes);
AugmentedAssignmentAst* populateAugmentedAssignmentAst(Ast* ast, const stringDictionary& currentAttributes);
WithAst* populateWithAst(Ast* ast, const stringDictionary& currentAttributes);
RaiseAst* populateRaiseAst(Ast* ast, const stringDictionary& currentAttributes);
TryExceptAst* populateTryExceptAst(Ast* ast, const stringDictionary& currentAttributes);
TryFinallyAst* populateTryFinallyAst(Ast* ast, const stringDictionary& currentAttributes);
AssertionAst* populateAssertionAst(Ast* ast, const stringDictionary& currentAttributes);
ImportAst* populateImportAst(Ast* ast, const stringDictionary& currentAttributes);
ImportFromAst* populateImportFromAst(Ast* ast, const stringDictionary& currentAttributes);
ExecAst* populateExecAst(Ast* ast, const stringDictionary& currentAttributes);
GlobalAst* populateGlobalAst(Ast* ast, const stringDictionary& currentAttributes);
BinaryOperationAst* populateBinaryOperationAst(Ast* ast, const stringDictionary& currentAttributes);
AliasAst* populateAliasAst(Ast* ast, const stringDictionary& currentAttributes);
UnaryOperationAst* populateUnaryOperationAst(Ast* ast, const stringDictionary& currentAttributes);
IfExpressionAst* populateIfExpressionAst(Ast* ast, const stringDictionary& currentAttributes);
ListComprehensionAst* populateListComprehensionAst(Ast* ast, const stringDictionary& currentAttributes);
GeneratorExpressionAst* populateGeneratorExpressionAst(Ast* ast, const stringDictionary& currentAttributes);
ComprehensionAst* populateComprehensionAst(Ast* ast, const stringDictionary& currentAttributes);
CompareAst* populateCompareAst(Ast* ast, const stringDictionary& currentAttributes);
NumberAst* populateNumberAst(Ast* ast, const stringDictionary& currentAttributes);
StringAst* populateStringAst(Ast* ast, const stringDictionary& currentAttributes);
AttributeAst* populateAttributeAst(Ast* ast, const stringDictionary& currentAttributes);
SubscriptAst* populateSubscriptAst(Ast* ast, const stringDictionary& currentAttributes);
SliceAst* populateSliceAst(Ast* ast, const stringDictionary& currentAttributes);
KeywordAst* populateKeywordAst(Ast* ast, const stringDictionary& currentAttributes);
ArgumentsAst* populateArgumentsAst(Ast* ast, const stringDictionary& currentAttributes);
IndexAst* populateIndexAst(Ast* ast, const stringDictionary& currentAttributes);
ExceptionHandlerAst* populateExceptionHandlerAst(Ast* ast, const stringDictionary& currentAttributes);
};
}
#endif