See More

/*************************************************************************** * This file is part of KDevelop * * Copyright 2007 Andreas Pakulat * * * * 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 #include "ast.h" #include #include #include "kdebug.h" #include "QXmlStreamReader" namespace PythonParser { class Parser; class AstNode; } namespace Python { class Ast; class CodeAst; typedef QMap 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& attributes); QList m_nodeStack; // one map for regular ast nodes, and the others for primitive nodes of different types QMap m_nodeMap; QMap m_contextNodeMap; QMap m_boolOpNodeMap; QMap m_compOpNodeMap; QMap m_opNodeMap; QMap m_unaryOpNodeMap; QStack m_astStack; QMap 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<:booleanoperationtypes> resolveBooleanOperatorList(const QString& identifiers); QList<:comparisonoperatortypes> resolveComparisonOperatorList(const QString& identifiers); QList<:operatortypes> resolveOperatorList(const QString& identifiers); QList<:unaryoperatortypes> resolveUnaryOperatorList(const QString& identifiers); QList<:context> resolveContextList(const QString& identifiers); void populateAst(); template QList resolveNodeList(const QString& commaSeperatedIdentifiers); template 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