diff --git a/src/shared/cplusplus/ASTPatternBuilder.h b/src/shared/cplusplus/ASTPatternBuilder.h new file mode 100644 index 0000000000000000000000000000000000000000..8a85b72b1c6a048187c57b65349248b32ef66a1e --- /dev/null +++ b/src/shared/cplusplus/ASTPatternBuilder.h @@ -0,0 +1,904 @@ +/************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** Commercial Usage +** +** Licensees holding valid Qt Commercial licenses may use this file in +** accordance with the Qt Commercial License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Nokia. +** +** GNU Lesser General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** +**************************************************************************/ +#ifndef CPLUSPLUS_AST_PATTERN_BUILDER_H +#define CPLUSPLUS_AST_PATTERN_BUILDER_H + +#include "CPlusPlusForwardDeclarations.h" +#include "AST.h" +#include "MemoryPool.h" + +namespace CPlusPlus { + +class CPLUSPLUS_EXPORT ASTPatternBuilder +{ + MemoryPool pool; + MemoryPool::State state; + +public: + ASTPatternBuilder(): state(pool.state()) {} + + void reset() { pool.rewind(state); }; + + SimpleSpecifierAST *SimpleSpecifier() + { + SimpleSpecifierAST *__ast = new (&pool) SimpleSpecifierAST; + return __ast; + } + + AttributeSpecifierAST *AttributeSpecifier() + { + AttributeSpecifierAST *__ast = new (&pool) AttributeSpecifierAST; + return __ast; + } + + AttributeAST *Attribute() + { + AttributeAST *__ast = new (&pool) AttributeAST; + return __ast; + } + + TypeofSpecifierAST *TypeofSpecifier(ExpressionAST *expression = 0) + { + TypeofSpecifierAST *__ast = new (&pool) TypeofSpecifierAST; + __ast->expression = expression; + return __ast; + } + + DeclaratorAST *Declarator(CoreDeclaratorAST *core_declarator = 0, ExpressionAST *initializer = 0) + { + DeclaratorAST *__ast = new (&pool) DeclaratorAST; + __ast->core_declarator = core_declarator; + __ast->initializer = initializer; + return __ast; + } + + SimpleDeclarationAST *SimpleDeclaration() + { + SimpleDeclarationAST *__ast = new (&pool) SimpleDeclarationAST; + return __ast; + } + + EmptyDeclarationAST *EmptyDeclaration() + { + EmptyDeclarationAST *__ast = new (&pool) EmptyDeclarationAST; + return __ast; + } + + AccessDeclarationAST *AccessDeclaration() + { + AccessDeclarationAST *__ast = new (&pool) AccessDeclarationAST; + return __ast; + } + + AsmDefinitionAST *AsmDefinition() + { + AsmDefinitionAST *__ast = new (&pool) AsmDefinitionAST; + return __ast; + } + + BaseSpecifierAST *BaseSpecifier(NameAST *name = 0) + { + BaseSpecifierAST *__ast = new (&pool) BaseSpecifierAST; + __ast->name = name; + return __ast; + } + + CompoundLiteralAST *CompoundLiteral(ExpressionAST *type_id = 0, ExpressionAST *initializer = 0) + { + CompoundLiteralAST *__ast = new (&pool) CompoundLiteralAST; + __ast->type_id = type_id; + __ast->initializer = initializer; + return __ast; + } + + QtMethodAST *QtMethod(DeclaratorAST *declarator = 0) + { + QtMethodAST *__ast = new (&pool) QtMethodAST; + __ast->declarator = declarator; + return __ast; + } + + BinaryExpressionAST *BinaryExpression(ExpressionAST *left_expression = 0, ExpressionAST *right_expression = 0) + { + BinaryExpressionAST *__ast = new (&pool) BinaryExpressionAST; + __ast->left_expression = left_expression; + __ast->right_expression = right_expression; + return __ast; + } + + CastExpressionAST *CastExpression(ExpressionAST *type_id = 0, ExpressionAST *expression = 0) + { + CastExpressionAST *__ast = new (&pool) CastExpressionAST; + __ast->type_id = type_id; + __ast->expression = expression; + return __ast; + } + + ClassSpecifierAST *ClassSpecifier(NameAST *name = 0) + { + ClassSpecifierAST *__ast = new (&pool) ClassSpecifierAST; + __ast->name = name; + return __ast; + } + + CaseStatementAST *CaseStatement(ExpressionAST *expression = 0, StatementAST *statement = 0) + { + CaseStatementAST *__ast = new (&pool) CaseStatementAST; + __ast->expression = expression; + __ast->statement = statement; + return __ast; + } + + CompoundStatementAST *CompoundStatement() + { + CompoundStatementAST *__ast = new (&pool) CompoundStatementAST; + return __ast; + } + + ConditionAST *Condition(DeclaratorAST *declarator = 0) + { + ConditionAST *__ast = new (&pool) ConditionAST; + __ast->declarator = declarator; + return __ast; + } + + ConditionalExpressionAST *ConditionalExpression(ExpressionAST *condition = 0, ExpressionAST *left_expression = 0, ExpressionAST *right_expression = 0) + { + ConditionalExpressionAST *__ast = new (&pool) ConditionalExpressionAST; + __ast->condition = condition; + __ast->left_expression = left_expression; + __ast->right_expression = right_expression; + return __ast; + } + + CppCastExpressionAST *CppCastExpression(ExpressionAST *type_id = 0, ExpressionAST *expression = 0) + { + CppCastExpressionAST *__ast = new (&pool) CppCastExpressionAST; + __ast->type_id = type_id; + __ast->expression = expression; + return __ast; + } + + CtorInitializerAST *CtorInitializer() + { + CtorInitializerAST *__ast = new (&pool) CtorInitializerAST; + return __ast; + } + + DeclarationStatementAST *DeclarationStatement(DeclarationAST *declaration = 0) + { + DeclarationStatementAST *__ast = new (&pool) DeclarationStatementAST; + __ast->declaration = declaration; + return __ast; + } + + DeclaratorIdAST *DeclaratorId(NameAST *name = 0) + { + DeclaratorIdAST *__ast = new (&pool) DeclaratorIdAST; + __ast->name = name; + return __ast; + } + + NestedDeclaratorAST *NestedDeclarator(DeclaratorAST *declarator = 0) + { + NestedDeclaratorAST *__ast = new (&pool) NestedDeclaratorAST; + __ast->declarator = declarator; + return __ast; + } + + FunctionDeclaratorAST *FunctionDeclarator(ParameterDeclarationClauseAST *parameters = 0, ExceptionSpecificationAST *exception_specification = 0, ExpressionAST *as_cpp_initializer = 0) + { + FunctionDeclaratorAST *__ast = new (&pool) FunctionDeclaratorAST; + __ast->parameters = parameters; + __ast->exception_specification = exception_specification; + __ast->as_cpp_initializer = as_cpp_initializer; + return __ast; + } + + ArrayDeclaratorAST *ArrayDeclarator(ExpressionAST *expression = 0) + { + ArrayDeclaratorAST *__ast = new (&pool) ArrayDeclaratorAST; + __ast->expression = expression; + return __ast; + } + + DeleteExpressionAST *DeleteExpression(ExpressionAST *expression = 0) + { + DeleteExpressionAST *__ast = new (&pool) DeleteExpressionAST; + __ast->expression = expression; + return __ast; + } + + DoStatementAST *DoStatement(StatementAST *statement = 0, ExpressionAST *expression = 0) + { + DoStatementAST *__ast = new (&pool) DoStatementAST; + __ast->statement = statement; + __ast->expression = expression; + return __ast; + } + + NamedTypeSpecifierAST *NamedTypeSpecifier(NameAST *name = 0) + { + NamedTypeSpecifierAST *__ast = new (&pool) NamedTypeSpecifierAST; + __ast->name = name; + return __ast; + } + + ElaboratedTypeSpecifierAST *ElaboratedTypeSpecifier(NameAST *name = 0) + { + ElaboratedTypeSpecifierAST *__ast = new (&pool) ElaboratedTypeSpecifierAST; + __ast->name = name; + return __ast; + } + + EnumSpecifierAST *EnumSpecifier(NameAST *name = 0) + { + EnumSpecifierAST *__ast = new (&pool) EnumSpecifierAST; + __ast->name = name; + return __ast; + } + + EnumeratorAST *Enumerator(ExpressionAST *expression = 0) + { + EnumeratorAST *__ast = new (&pool) EnumeratorAST; + __ast->expression = expression; + return __ast; + } + + ExceptionDeclarationAST *ExceptionDeclaration(DeclaratorAST *declarator = 0) + { + ExceptionDeclarationAST *__ast = new (&pool) ExceptionDeclarationAST; + __ast->declarator = declarator; + return __ast; + } + + ExceptionSpecificationAST *ExceptionSpecification() + { + ExceptionSpecificationAST *__ast = new (&pool) ExceptionSpecificationAST; + return __ast; + } + + ExpressionOrDeclarationStatementAST *ExpressionOrDeclarationStatement(StatementAST *expression = 0, StatementAST *declaration = 0) + { + ExpressionOrDeclarationStatementAST *__ast = new (&pool) ExpressionOrDeclarationStatementAST; + __ast->expression = expression; + __ast->declaration = declaration; + return __ast; + } + + ExpressionStatementAST *ExpressionStatement(ExpressionAST *expression = 0) + { + ExpressionStatementAST *__ast = new (&pool) ExpressionStatementAST; + __ast->expression = expression; + return __ast; + } + + FunctionDefinitionAST *FunctionDefinition(DeclaratorAST *declarator = 0, CtorInitializerAST *ctor_initializer = 0, StatementAST *function_body = 0) + { + FunctionDefinitionAST *__ast = new (&pool) FunctionDefinitionAST; + __ast->declarator = declarator; + __ast->ctor_initializer = ctor_initializer; + __ast->function_body = function_body; + return __ast; + } + + ForeachStatementAST *ForeachStatement(DeclaratorAST *declarator = 0, ExpressionAST *initializer = 0, ExpressionAST *expression = 0, StatementAST *statement = 0) + { + ForeachStatementAST *__ast = new (&pool) ForeachStatementAST; + __ast->declarator = declarator; + __ast->initializer = initializer; + __ast->expression = expression; + __ast->statement = statement; + return __ast; + } + + ForStatementAST *ForStatement(StatementAST *initializer = 0, ExpressionAST *condition = 0, ExpressionAST *expression = 0, StatementAST *statement = 0) + { + ForStatementAST *__ast = new (&pool) ForStatementAST; + __ast->initializer = initializer; + __ast->condition = condition; + __ast->expression = expression; + __ast->statement = statement; + return __ast; + } + + IfStatementAST *IfStatement(ExpressionAST *condition = 0, StatementAST *statement = 0, StatementAST *else_statement = 0) + { + IfStatementAST *__ast = new (&pool) IfStatementAST; + __ast->condition = condition; + __ast->statement = statement; + __ast->else_statement = else_statement; + return __ast; + } + + ArrayInitializerAST *ArrayInitializer() + { + ArrayInitializerAST *__ast = new (&pool) ArrayInitializerAST; + return __ast; + } + + LabeledStatementAST *LabeledStatement(StatementAST *statement = 0) + { + LabeledStatementAST *__ast = new (&pool) LabeledStatementAST; + __ast->statement = statement; + return __ast; + } + + LinkageBodyAST *LinkageBody() + { + LinkageBodyAST *__ast = new (&pool) LinkageBodyAST; + return __ast; + } + + LinkageSpecificationAST *LinkageSpecification(DeclarationAST *declaration = 0) + { + LinkageSpecificationAST *__ast = new (&pool) LinkageSpecificationAST; + __ast->declaration = declaration; + return __ast; + } + + MemInitializerAST *MemInitializer(NameAST *name = 0) + { + MemInitializerAST *__ast = new (&pool) MemInitializerAST; + __ast->name = name; + return __ast; + } + + NestedNameSpecifierAST *NestedNameSpecifier(NameAST *class_or_namespace_name = 0) + { + NestedNameSpecifierAST *__ast = new (&pool) NestedNameSpecifierAST; + __ast->class_or_namespace_name = class_or_namespace_name; + return __ast; + } + + QualifiedNameAST *QualifiedName(NameAST *unqualified_name = 0) + { + QualifiedNameAST *__ast = new (&pool) QualifiedNameAST; + __ast->unqualified_name = unqualified_name; + return __ast; + } + + OperatorFunctionIdAST *OperatorFunctionId(OperatorAST *op = 0) + { + OperatorFunctionIdAST *__ast = new (&pool) OperatorFunctionIdAST; + __ast->op = op; + return __ast; + } + + ConversionFunctionIdAST *ConversionFunctionId() + { + ConversionFunctionIdAST *__ast = new (&pool) ConversionFunctionIdAST; + return __ast; + } + + SimpleNameAST *SimpleName() + { + SimpleNameAST *__ast = new (&pool) SimpleNameAST; + return __ast; + } + + DestructorNameAST *DestructorName() + { + DestructorNameAST *__ast = new (&pool) DestructorNameAST; + return __ast; + } + + TemplateIdAST *TemplateId() + { + TemplateIdAST *__ast = new (&pool) TemplateIdAST; + return __ast; + } + + NamespaceAST *Namespace(DeclarationAST *linkage_body = 0) + { + NamespaceAST *__ast = new (&pool) NamespaceAST; + __ast->linkage_body = linkage_body; + return __ast; + } + + NamespaceAliasDefinitionAST *NamespaceAliasDefinition(NameAST *name = 0) + { + NamespaceAliasDefinitionAST *__ast = new (&pool) NamespaceAliasDefinitionAST; + __ast->name = name; + return __ast; + } + + NewPlacementAST *NewPlacement() + { + NewPlacementAST *__ast = new (&pool) NewPlacementAST; + return __ast; + } + + NewArrayDeclaratorAST *NewArrayDeclarator(ExpressionAST *expression = 0) + { + NewArrayDeclaratorAST *__ast = new (&pool) NewArrayDeclaratorAST; + __ast->expression = expression; + return __ast; + } + + NewExpressionAST *NewExpression(NewPlacementAST *new_placement = 0, ExpressionAST *type_id = 0, NewTypeIdAST *new_type_id = 0, NewInitializerAST *new_initializer = 0) + { + NewExpressionAST *__ast = new (&pool) NewExpressionAST; + __ast->new_placement = new_placement; + __ast->type_id = type_id; + __ast->new_type_id = new_type_id; + __ast->new_initializer = new_initializer; + return __ast; + } + + NewInitializerAST *NewInitializer(ExpressionAST *expression = 0) + { + NewInitializerAST *__ast = new (&pool) NewInitializerAST; + __ast->expression = expression; + return __ast; + } + + NewTypeIdAST *NewTypeId() + { + NewTypeIdAST *__ast = new (&pool) NewTypeIdAST; + return __ast; + } + + OperatorAST *Operator() + { + OperatorAST *__ast = new (&pool) OperatorAST; + return __ast; + } + + ParameterDeclarationAST *ParameterDeclaration(DeclaratorAST *declarator = 0, ExpressionAST *expression = 0) + { + ParameterDeclarationAST *__ast = new (&pool) ParameterDeclarationAST; + __ast->declarator = declarator; + __ast->expression = expression; + return __ast; + } + + ParameterDeclarationClauseAST *ParameterDeclarationClause() + { + ParameterDeclarationClauseAST *__ast = new (&pool) ParameterDeclarationClauseAST; + return __ast; + } + + CallAST *Call() + { + CallAST *__ast = new (&pool) CallAST; + return __ast; + } + + ArrayAccessAST *ArrayAccess(ExpressionAST *expression = 0) + { + ArrayAccessAST *__ast = new (&pool) ArrayAccessAST; + __ast->expression = expression; + return __ast; + } + + PostIncrDecrAST *PostIncrDecr() + { + PostIncrDecrAST *__ast = new (&pool) PostIncrDecrAST; + return __ast; + } + + MemberAccessAST *MemberAccess(NameAST *member_name = 0) + { + MemberAccessAST *__ast = new (&pool) MemberAccessAST; + __ast->member_name = member_name; + return __ast; + } + + TypeidExpressionAST *TypeidExpression(ExpressionAST *expression = 0) + { + TypeidExpressionAST *__ast = new (&pool) TypeidExpressionAST; + __ast->expression = expression; + return __ast; + } + + TypenameCallExpressionAST *TypenameCallExpression(NameAST *name = 0) + { + TypenameCallExpressionAST *__ast = new (&pool) TypenameCallExpressionAST; + __ast->name = name; + return __ast; + } + + TypeConstructorCallAST *TypeConstructorCall() + { + TypeConstructorCallAST *__ast = new (&pool) TypeConstructorCallAST; + return __ast; + } + + PostfixExpressionAST *PostfixExpression(ExpressionAST *base_expression = 0) + { + PostfixExpressionAST *__ast = new (&pool) PostfixExpressionAST; + __ast->base_expression = base_expression; + return __ast; + } + + PointerToMemberAST *PointerToMember() + { + PointerToMemberAST *__ast = new (&pool) PointerToMemberAST; + return __ast; + } + + PointerAST *Pointer() + { + PointerAST *__ast = new (&pool) PointerAST; + return __ast; + } + + ReferenceAST *Reference() + { + ReferenceAST *__ast = new (&pool) ReferenceAST; + return __ast; + } + + BreakStatementAST *BreakStatement() + { + BreakStatementAST *__ast = new (&pool) BreakStatementAST; + return __ast; + } + + ContinueStatementAST *ContinueStatement() + { + ContinueStatementAST *__ast = new (&pool) ContinueStatementAST; + return __ast; + } + + GotoStatementAST *GotoStatement() + { + GotoStatementAST *__ast = new (&pool) GotoStatementAST; + return __ast; + } + + ReturnStatementAST *ReturnStatement(ExpressionAST *expression = 0) + { + ReturnStatementAST *__ast = new (&pool) ReturnStatementAST; + __ast->expression = expression; + return __ast; + } + + SizeofExpressionAST *SizeofExpression(ExpressionAST *expression = 0) + { + SizeofExpressionAST *__ast = new (&pool) SizeofExpressionAST; + __ast->expression = expression; + return __ast; + } + + NumericLiteralAST *NumericLiteral() + { + NumericLiteralAST *__ast = new (&pool) NumericLiteralAST; + return __ast; + } + + BoolLiteralAST *BoolLiteral() + { + BoolLiteralAST *__ast = new (&pool) BoolLiteralAST; + return __ast; + } + + ThisExpressionAST *ThisExpression() + { + ThisExpressionAST *__ast = new (&pool) ThisExpressionAST; + return __ast; + } + + NestedExpressionAST *NestedExpression(ExpressionAST *expression = 0) + { + NestedExpressionAST *__ast = new (&pool) NestedExpressionAST; + __ast->expression = expression; + return __ast; + } + + StringLiteralAST *StringLiteral(StringLiteralAST *next = 0) + { + StringLiteralAST *__ast = new (&pool) StringLiteralAST; + __ast->next = next; + return __ast; + } + + SwitchStatementAST *SwitchStatement(ExpressionAST *condition = 0, StatementAST *statement = 0) + { + SwitchStatementAST *__ast = new (&pool) SwitchStatementAST; + __ast->condition = condition; + __ast->statement = statement; + return __ast; + } + + TemplateDeclarationAST *TemplateDeclaration(DeclarationAST *declaration = 0) + { + TemplateDeclarationAST *__ast = new (&pool) TemplateDeclarationAST; + __ast->declaration = declaration; + return __ast; + } + + ThrowExpressionAST *ThrowExpression(ExpressionAST *expression = 0) + { + ThrowExpressionAST *__ast = new (&pool) ThrowExpressionAST; + __ast->expression = expression; + return __ast; + } + + TranslationUnitAST *TranslationUnit() + { + TranslationUnitAST *__ast = new (&pool) TranslationUnitAST; + return __ast; + } + + TryBlockStatementAST *TryBlockStatement(StatementAST *statement = 0) + { + TryBlockStatementAST *__ast = new (&pool) TryBlockStatementAST; + __ast->statement = statement; + return __ast; + } + + CatchClauseAST *CatchClause(ExceptionDeclarationAST *exception_declaration = 0, StatementAST *statement = 0) + { + CatchClauseAST *__ast = new (&pool) CatchClauseAST; + __ast->exception_declaration = exception_declaration; + __ast->statement = statement; + return __ast; + } + + TypeIdAST *TypeId(DeclaratorAST *declarator = 0) + { + TypeIdAST *__ast = new (&pool) TypeIdAST; + __ast->declarator = declarator; + return __ast; + } + + TypenameTypeParameterAST *TypenameTypeParameter(NameAST *name = 0, ExpressionAST *type_id = 0) + { + TypenameTypeParameterAST *__ast = new (&pool) TypenameTypeParameterAST; + __ast->name = name; + __ast->type_id = type_id; + return __ast; + } + + TemplateTypeParameterAST *TemplateTypeParameter(NameAST *name = 0, ExpressionAST *type_id = 0) + { + TemplateTypeParameterAST *__ast = new (&pool) TemplateTypeParameterAST; + __ast->name = name; + __ast->type_id = type_id; + return __ast; + } + + UnaryExpressionAST *UnaryExpression(ExpressionAST *expression = 0) + { + UnaryExpressionAST *__ast = new (&pool) UnaryExpressionAST; + __ast->expression = expression; + return __ast; + } + + UsingAST *Using(NameAST *name = 0) + { + UsingAST *__ast = new (&pool) UsingAST; + __ast->name = name; + return __ast; + } + + UsingDirectiveAST *UsingDirective(NameAST *name = 0) + { + UsingDirectiveAST *__ast = new (&pool) UsingDirectiveAST; + __ast->name = name; + return __ast; + } + + WhileStatementAST *WhileStatement(ExpressionAST *condition = 0, StatementAST *statement = 0) + { + WhileStatementAST *__ast = new (&pool) WhileStatementAST; + __ast->condition = condition; + __ast->statement = statement; + return __ast; + } + + ObjCClassForwardDeclarationAST *ObjCClassForwardDeclaration() + { + ObjCClassForwardDeclarationAST *__ast = new (&pool) ObjCClassForwardDeclarationAST; + return __ast; + } + + ObjCClassDeclarationAST *ObjCClassDeclaration(NameAST *class_name = 0, NameAST *category_name = 0, NameAST *superclass = 0, ObjCProtocolRefsAST *protocol_refs = 0, ObjCInstanceVariablesDeclarationAST *inst_vars_decl = 0) + { + ObjCClassDeclarationAST *__ast = new (&pool) ObjCClassDeclarationAST; + __ast->class_name = class_name; + __ast->category_name = category_name; + __ast->superclass = superclass; + __ast->protocol_refs = protocol_refs; + __ast->inst_vars_decl = inst_vars_decl; + return __ast; + } + + ObjCProtocolForwardDeclarationAST *ObjCProtocolForwardDeclaration() + { + ObjCProtocolForwardDeclarationAST *__ast = new (&pool) ObjCProtocolForwardDeclarationAST; + return __ast; + } + + ObjCProtocolDeclarationAST *ObjCProtocolDeclaration(NameAST *name = 0, ObjCProtocolRefsAST *protocol_refs = 0) + { + ObjCProtocolDeclarationAST *__ast = new (&pool) ObjCProtocolDeclarationAST; + __ast->name = name; + __ast->protocol_refs = protocol_refs; + return __ast; + } + + ObjCProtocolRefsAST *ObjCProtocolRefs() + { + ObjCProtocolRefsAST *__ast = new (&pool) ObjCProtocolRefsAST; + return __ast; + } + + ObjCMessageArgumentAST *ObjCMessageArgument(ExpressionAST *parameter_value_expression = 0) + { + ObjCMessageArgumentAST *__ast = new (&pool) ObjCMessageArgumentAST; + __ast->parameter_value_expression = parameter_value_expression; + return __ast; + } + + ObjCMessageExpressionAST *ObjCMessageExpression(ExpressionAST *receiver_expression = 0, ObjCSelectorAST *selector = 0) + { + ObjCMessageExpressionAST *__ast = new (&pool) ObjCMessageExpressionAST; + __ast->receiver_expression = receiver_expression; + __ast->selector = selector; + return __ast; + } + + ObjCProtocolExpressionAST *ObjCProtocolExpression() + { + ObjCProtocolExpressionAST *__ast = new (&pool) ObjCProtocolExpressionAST; + return __ast; + } + + ObjCTypeNameAST *ObjCTypeName(ExpressionAST *type_id = 0) + { + ObjCTypeNameAST *__ast = new (&pool) ObjCTypeNameAST; + __ast->type_id = type_id; + return __ast; + } + + ObjCEncodeExpressionAST *ObjCEncodeExpression(ObjCTypeNameAST *type_name = 0) + { + ObjCEncodeExpressionAST *__ast = new (&pool) ObjCEncodeExpressionAST; + __ast->type_name = type_name; + return __ast; + } + + ObjCSelectorWithoutArgumentsAST *ObjCSelectorWithoutArguments() + { + ObjCSelectorWithoutArgumentsAST *__ast = new (&pool) ObjCSelectorWithoutArgumentsAST; + return __ast; + } + + ObjCSelectorArgumentAST *ObjCSelectorArgument() + { + ObjCSelectorArgumentAST *__ast = new (&pool) ObjCSelectorArgumentAST; + return __ast; + } + + ObjCSelectorWithArgumentsAST *ObjCSelectorWithArguments() + { + ObjCSelectorWithArgumentsAST *__ast = new (&pool) ObjCSelectorWithArgumentsAST; + return __ast; + } + + ObjCSelectorExpressionAST *ObjCSelectorExpression(ObjCSelectorAST *selector = 0) + { + ObjCSelectorExpressionAST *__ast = new (&pool) ObjCSelectorExpressionAST; + __ast->selector = selector; + return __ast; + } + + ObjCInstanceVariablesDeclarationAST *ObjCInstanceVariablesDeclaration() + { + ObjCInstanceVariablesDeclarationAST *__ast = new (&pool) ObjCInstanceVariablesDeclarationAST; + return __ast; + } + + ObjCVisibilityDeclarationAST *ObjCVisibilityDeclaration() + { + ObjCVisibilityDeclarationAST *__ast = new (&pool) ObjCVisibilityDeclarationAST; + return __ast; + } + + ObjCPropertyAttributeAST *ObjCPropertyAttribute(ObjCSelectorAST *method_selector = 0) + { + ObjCPropertyAttributeAST *__ast = new (&pool) ObjCPropertyAttributeAST; + __ast->method_selector = method_selector; + return __ast; + } + + ObjCPropertyDeclarationAST *ObjCPropertyDeclaration(DeclarationAST *simple_declaration = 0) + { + ObjCPropertyDeclarationAST *__ast = new (&pool) ObjCPropertyDeclarationAST; + __ast->simple_declaration = simple_declaration; + return __ast; + } + + ObjCMessageArgumentDeclarationAST *ObjCMessageArgumentDeclaration(ObjCTypeNameAST *type_name = 0) + { + ObjCMessageArgumentDeclarationAST *__ast = new (&pool) ObjCMessageArgumentDeclarationAST; + __ast->type_name = type_name; + return __ast; + } + + ObjCMethodPrototypeAST *ObjCMethodPrototype(ObjCTypeNameAST *type_name = 0, ObjCSelectorAST *selector = 0) + { + ObjCMethodPrototypeAST *__ast = new (&pool) ObjCMethodPrototypeAST; + __ast->type_name = type_name; + __ast->selector = selector; + return __ast; + } + + ObjCMethodDeclarationAST *ObjCMethodDeclaration(ObjCMethodPrototypeAST *method_prototype = 0, StatementAST *function_body = 0) + { + ObjCMethodDeclarationAST *__ast = new (&pool) ObjCMethodDeclarationAST; + __ast->method_prototype = method_prototype; + __ast->function_body = function_body; + return __ast; + } + + ObjCSynthesizedPropertyAST *ObjCSynthesizedProperty() + { + ObjCSynthesizedPropertyAST *__ast = new (&pool) ObjCSynthesizedPropertyAST; + return __ast; + } + + ObjCSynthesizedPropertiesDeclarationAST *ObjCSynthesizedPropertiesDeclaration() + { + ObjCSynthesizedPropertiesDeclarationAST *__ast = new (&pool) ObjCSynthesizedPropertiesDeclarationAST; + return __ast; + } + + ObjCDynamicPropertiesDeclarationAST *ObjCDynamicPropertiesDeclaration() + { + ObjCDynamicPropertiesDeclarationAST *__ast = new (&pool) ObjCDynamicPropertiesDeclarationAST; + return __ast; + } + + ObjCFastEnumerationAST *ObjCFastEnumeration(DeclaratorAST *declarator = 0, ExpressionAST *initializer = 0, ExpressionAST *fast_enumeratable_expression = 0, StatementAST *body_statement = 0) + { + ObjCFastEnumerationAST *__ast = new (&pool) ObjCFastEnumerationAST; + __ast->declarator = declarator; + __ast->initializer = initializer; + __ast->fast_enumeratable_expression = fast_enumeratable_expression; + __ast->body_statement = body_statement; + return __ast; + } + + ObjCSynchronizedStatementAST *ObjCSynchronizedStatement(ExpressionAST *synchronized_object = 0, StatementAST *statement = 0) + { + ObjCSynchronizedStatementAST *__ast = new (&pool) ObjCSynchronizedStatementAST; + __ast->synchronized_object = synchronized_object; + __ast->statement = statement; + return __ast; + } + +}; + +} // end of namespace CPlusPlus + +#endif // CPLUSPLUS_AST_PATTERN_BUILDER_H diff --git a/src/shared/cplusplus/cplusplus.pri b/src/shared/cplusplus/cplusplus.pri index 8977a6fa4470ab908ee3c0e297d5be6af6e81a30..c55e9b7c3d93d116d271b9042cfc447225b80cdf 100644 --- a/src/shared/cplusplus/cplusplus.pri +++ b/src/shared/cplusplus/cplusplus.pri @@ -6,6 +6,7 @@ HEADERS += \ $$PWD/AST.h \ $$PWD/ASTVisitor.h \ $$PWD/ASTMatcher.h \ + $$PWD/ASTPatternBuilder.h \ $$PWD/ASTfwd.h \ $$PWD/Array.h \ $$PWD/CPlusPlusForwardDeclarations.h \ diff --git a/src/tools/cplusplus/Main.cpp b/src/tools/cplusplus/Main.cpp index 5491edc8d4695e048680c27d46002ec37667a70e..342c7751fd1c5771f9e2200ed8c5cc0affeeedf3 100644 --- a/src/tools/cplusplus/Main.cpp +++ b/src/tools/cplusplus/Main.cpp @@ -65,6 +65,7 @@ public: QList<QTextCursor> endOfPublicClassSpecifiers; }; +static Document::Ptr AST_h_document; static ASTNodes astNodes; static QTextCursor createCursor(TranslationUnit *unit, AST *ast, QTextDocument *document) @@ -612,15 +613,15 @@ QStringList generateAST_H(const Snapshot &snapshot, const QDir &cplusplusDir) QTextDocument document; document.setPlainText(source); - Document::Ptr doc = Document::create(fileName); + AST_h_document = Document::create(fileName); const QByteArray preprocessedCode = snapshot.preprocessedCode(source, fileName); - doc->setSource(preprocessedCode); - doc->check(); + AST_h_document->setSource(preprocessedCode); + AST_h_document->check(); - FindASTNodes process(doc, &document); - astNodes = process(doc->translationUnit()->ast()); + FindASTNodes process(AST_h_document, &document); + astNodes = process(AST_h_document->translationUnit()->ast()); - RemoveCastMethods removeCastMethods(doc, &document); + RemoveCastMethods removeCastMethods(AST_h_document, &document); QList<QTextCursor> baseCastMethodCursors = removeCastMethods(astNodes.base); QMap<ClassSpecifierAST *, QList<QTextCursor> > cursors; @@ -665,14 +666,14 @@ QStringList generateAST_H(const Snapshot &snapshot, const QDir &cplusplusDir) out << document.toPlainText(); } - Accept0CG cg(cplusplusDir, doc->control()); - cg(doc->translationUnit()->ast()); + Accept0CG cg(cplusplusDir, AST_h_document->control()); + cg(AST_h_document->translationUnit()->ast()); - Match0CG cg2(cplusplusDir, doc->control()); - cg2(doc->translationUnit()->ast()); + Match0CG cg2(cplusplusDir, AST_h_document->control()); + cg2(AST_h_document->translationUnit()->ast()); - MatcherCPPCG cg3(cplusplusDir, doc->control()); - cg3(doc->translationUnit()->ast()); + MatcherCPPCG cg3(cplusplusDir, AST_h_document->control()); + cg3(AST_h_document->translationUnit()->ast()); return astDerivedClasses; } @@ -757,6 +758,117 @@ void generateASTFwd_h(const Snapshot &snapshot, const QDir &cplusplusDir, const } } +void generateASTPatternBuilder_h(const QDir &cplusplusDir) +{ + QFileInfo fileInfo(cplusplusDir, QLatin1String("ASTPatternBuilder.h")); + QFile file(fileInfo.absoluteFilePath()); + if (! file.open(QFile::WriteOnly)) + return; + + Overview oo; + QTextStream out(&file); + + out + << copyrightHeader + << "#ifndef CPLUSPLUS_AST_PATTERN_BUILDER_H" << endl + << "#define CPLUSPLUS_AST_PATTERN_BUILDER_H" << endl + << endl + << "#include \"CPlusPlusForwardDeclarations.h\"" << endl + << "#include \"AST.h\"" << endl + << "#include \"MemoryPool.h\"" << endl + << endl + << "namespace CPlusPlus {" << endl + << endl + << "class CPLUSPLUS_EXPORT ASTPatternBuilder" << endl + << "{" << endl + << " MemoryPool pool;" << endl + << " MemoryPool::State state;" << endl + << endl + << "public:" << endl + << " ASTPatternBuilder(): state(pool.state()) {}" << endl + << endl + << " void reset() { pool.rewind(state); };" << endl + << endl; + + Control *control = AST_h_document->control(); + + foreach (ClassSpecifierAST *classNode, astNodes.deriveds) { + Class *klass = classNode->symbol; + + Identifier *match0_id = control->findOrInsertIdentifier("match0"); + Symbol *match0Method = klass->members()->lookat(match0_id); + for (; match0Method; match0Method = match0Method->next()) { + if (match0Method->identifier() != match0_id) + continue; + else break; + } + + if (! match0Method) + continue; + + const QString className = oo(klass->name()); + + if (! className.endsWith("AST")) + continue; + + const QString methodName = className.left(className.length() - 3); + + out + << " " << className << " *" << methodName << "("; + + QList<QPair<QString, QString> > args; + + bool first = true; + for (unsigned index = 0; index < klass->memberCount(); ++index) { + Declaration *member = klass->memberAt(index)->asDeclaration(); + if (! member) + continue; + + PointerType *ptrTy = member->type()->asPointerType(); + if (! ptrTy) + continue; + + const QString tyName = oo(ptrTy->elementType()); + if (tyName.endsWith("ListAST")) + continue; + else if (tyName.endsWith("AST")) { + if (! first) + out << ", "; + + const QString memberName = oo(member->name()); + + out << tyName << " *" << memberName << " = 0"; + args.append(qMakePair(tyName, memberName)); + first = false; + } + } + + out + << ")" << endl + << " {" << endl + << " " << className << " *__ast = new (&pool) " << className << ";" << endl; + + + QPair<QString, QString> p; + foreach (p, args) { + out + << " __ast->" << p.second << " = " << p.second << ";" << endl; + } + + out + << " return __ast;" << endl + << " }" << endl + << endl; + } + + out + << "};" << endl + << endl + << "} // end of namespace CPlusPlus" << endl + << endl + << "#endif // CPLUSPLUS_AST_PATTERN_BUILDER_H" << endl; +} + int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); @@ -774,4 +886,6 @@ int main(int argc, char *argv[]) QStringList astDerivedClasses = generateAST_H(snapshot, cplusplusDir); astDerivedClasses.sort(); generateASTFwd_h(snapshot, cplusplusDir, astDerivedClasses); + + generateASTPatternBuilder_h(cplusplusDir); } diff --git a/tests/manual/cplusplus/main.cpp b/tests/manual/cplusplus/main.cpp index 7c5cc07533da457cb88c35593adff20fadb38cd3..ef4af02ab1ca7204eb422765f43e031a9f2874b9 100644 --- a/tests/manual/cplusplus/main.cpp +++ b/tests/manual/cplusplus/main.cpp @@ -29,6 +29,7 @@ #include <AST.h> #include <ASTVisitor.h> +#include <ASTPatternBuilder.h> #include <ASTMatcher.h> #include <Control.h> #include <Scope.h> @@ -54,61 +55,6 @@ using namespace CPlusPlus; -class PatternBuilder -{ -public: - PatternBuilder() - : pool(new MemoryPool()) {} - - ~PatternBuilder() - { delete pool; } - - UnaryExpressionAST *CreateUnaryExpression(ExpressionAST *expr = 0) - { - UnaryExpressionAST *ast = new (pool) UnaryExpressionAST; - ast->expression = expr; - return ast; - } - - BinaryExpressionAST *CreateBinaryExpression(ExpressionAST *left = 0, ExpressionAST *right = 0) - { - BinaryExpressionAST *ast = new (pool) BinaryExpressionAST; - ast->left_expression = left; - ast->right_expression = right; - return ast; - } - - NumericLiteralAST *NumericLiteral() - { - NumericLiteralAST *ast = new (pool) NumericLiteralAST; - return ast; - } - - SimpleNameAST *SimpleName() - { - SimpleNameAST *ast = new (pool) SimpleNameAST; - return ast; - } - - IfStatementAST *IfStatement(ExpressionAST *cond = 0, StatementAST *iftrue = 0, StatementAST *iffalse = 0) - { - IfStatementAST *ast = new (pool) IfStatementAST; - ast->condition = cond; - ast->statement = iftrue; - ast->else_statement = iffalse; - return ast; - } - - CompoundStatementAST *CompoundStatement() - { - CompoundStatementAST *ast = new (pool) CompoundStatementAST; - return ast; - } - -private: - MemoryPool *pool; -}; - class ForEachNode: protected ASTVisitor { Document::Ptr doc; @@ -126,10 +72,10 @@ protected: virtual bool preVisit(AST *ast) { - PatternBuilder ir; - //IfStatementAST *pattern = ir.IfStatement(ir.SimpleName()); + ir.reset(); + IfStatementAST *pattern = ir.IfStatement(ir.SimpleName()); - CompoundStatementAST *pattern = ir.CompoundStatement(); + //CompoundStatementAST *pattern = ir.CompoundStatement(); if (ast->match(ast, pattern, &matcher)) translationUnit()->warning(ast->firstToken(), "matched"); @@ -137,6 +83,8 @@ protected: return true; } + + ASTPatternBuilder ir; ASTMatcher matcher; };