Fixes: move all files in shared/* to src/shared/*

This commit is contained in:
hjk
2009-01-26 16:19:24 +01:00
parent c85ba53365
commit fe0533de2a
203 changed files with 15 additions and 16 deletions

3985
src/shared/cplusplus/AST.cpp Normal file

File diff suppressed because it is too large Load Diff

1989
src/shared/cplusplus/AST.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,105 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "ASTVisitor.h"
#include "AST.h"
#include "TranslationUnit.h"
#include "Control.h"
CPLUSPLUS_BEGIN_NAMESPACE
ASTVisitor::ASTVisitor(Control *control)
: _control(control)
{ }
ASTVisitor::~ASTVisitor()
{ }
void ASTVisitor::accept(AST *ast)
{ AST::accept(ast, this); }
Control *ASTVisitor::control() const
{ return _control; }
TranslationUnit *ASTVisitor::translationUnit() const
{ return _control->translationUnit(); }
int ASTVisitor::tokenKind(unsigned index) const
{ return translationUnit()->tokenKind(index); }
const char *ASTVisitor::spell(unsigned index) const
{
if (! index)
return 0;
return translationUnit()->tokenAt(index).spell();
}
Identifier *ASTVisitor::identifier(unsigned index) const
{ return translationUnit()->identifier(index); }
Literal *ASTVisitor::literal(unsigned index) const
{ return translationUnit()->literal(index); }
NumericLiteral *ASTVisitor::numericLiteral(unsigned index) const
{ return translationUnit()->numericLiteral(index); }
StringLiteral *ASTVisitor::stringLiteral(unsigned index) const
{ return translationUnit()->stringLiteral(index); }
void ASTVisitor::getTokenPosition(unsigned index,
unsigned *line,
unsigned *column,
StringLiteral **fileName) const
{ translationUnit()->getTokenPosition(index, line, column, fileName); }
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,200 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_ASTVISITOR_H
#define CPLUSPLUS_ASTVISITOR_H
#include "CPlusPlusForwardDeclarations.h"
#include "ASTfwd.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT ASTVisitor
{
ASTVisitor(const ASTVisitor &other);
void operator =(const ASTVisitor &other);
public:
ASTVisitor(Control *control);
virtual ~ASTVisitor();
Control *control() const;
TranslationUnit *translationUnit() const;
int tokenKind(unsigned index) const;
const char *spell(unsigned index) const;
Identifier *identifier(unsigned index) const;
Literal *literal(unsigned index) const;
NumericLiteral *numericLiteral(unsigned index) const;
StringLiteral *stringLiteral(unsigned index) const;
void getTokenPosition(unsigned index,
unsigned *line,
unsigned *column = 0,
StringLiteral **fileName = 0) const;
void accept(AST *ast);
virtual bool preVisit(AST *) { return true; }
virtual void postVisit(AST *) {}
virtual bool visit(AccessDeclarationAST *) { return true; }
virtual bool visit(ArrayAccessAST *) { return true; }
virtual bool visit(ArrayDeclaratorAST *) { return true; }
virtual bool visit(ArrayInitializerAST *) { return true; }
virtual bool visit(AsmDefinitionAST *) { return true; }
virtual bool visit(AttributeSpecifierAST *) { return true; }
virtual bool visit(AttributeAST *) { return true; }
virtual bool visit(BaseSpecifierAST *) { return true; }
virtual bool visit(BinaryExpressionAST *) { return true; }
virtual bool visit(BoolLiteralAST *) { return true; }
virtual bool visit(BreakStatementAST *) { return true; }
virtual bool visit(CallAST *) { return true; }
virtual bool visit(CaseStatementAST *) { return true; }
virtual bool visit(CastExpressionAST *) { return true; }
virtual bool visit(CatchClauseAST *) { return true; }
virtual bool visit(ClassSpecifierAST *) { return true; }
virtual bool visit(CompoundLiteralAST *) { return true; }
virtual bool visit(CompoundStatementAST *) { return true; }
virtual bool visit(ConditionAST *) { return true; }
virtual bool visit(ConditionalExpressionAST *) { return true; }
virtual bool visit(ContinueStatementAST *) { return true; }
virtual bool visit(ConversionFunctionIdAST *) { return true; }
virtual bool visit(CppCastExpressionAST *) { return true; }
virtual bool visit(CtorInitializerAST *) { return true; }
virtual bool visit(DeclaratorAST *) { return true; }
virtual bool visit(DeclarationStatementAST *) { return true; }
virtual bool visit(DeclaratorIdAST *) { return true; }
virtual bool visit(DeclaratorListAST *) { return true; }
virtual bool visit(DeleteExpressionAST *) { return true; }
virtual bool visit(DestructorNameAST *) { return true; }
virtual bool visit(DoStatementAST *) { return true; }
virtual bool visit(ElaboratedTypeSpecifierAST *) { return true; }
virtual bool visit(EmptyDeclarationAST *) { return true; }
virtual bool visit(EnumSpecifierAST *) { return true; }
virtual bool visit(EnumeratorAST *) { return true; }
virtual bool visit(ExceptionDeclarationAST *) { return true; }
virtual bool visit(ExceptionSpecificationAST *) { return true; }
virtual bool visit(ExpressionListAST *) { return true; }
virtual bool visit(ExpressionOrDeclarationStatementAST *) { return true; }
virtual bool visit(ExpressionStatementAST *) { return true; }
virtual bool visit(ForStatementAST *) { return true; }
virtual bool visit(FunctionDeclaratorAST *) { return true; }
virtual bool visit(FunctionDefinitionAST *) { return true; }
virtual bool visit(GotoStatementAST *) { return true; }
virtual bool visit(IfStatementAST *) { return true; }
virtual bool visit(LabeledStatementAST *) { return true; }
virtual bool visit(LinkageBodyAST *) { return true; }
virtual bool visit(LinkageSpecificationAST *) { return true; }
virtual bool visit(MemInitializerAST *) { return true; }
virtual bool visit(MemberAccessAST *) { return true; }
virtual bool visit(NamedTypeSpecifierAST *) { return true; }
virtual bool visit(NamespaceAST *) { return true; }
virtual bool visit(NamespaceAliasDefinitionAST *) { return true; }
virtual bool visit(NestedDeclaratorAST *) { return true; }
virtual bool visit(NestedExpressionAST *) { return true; }
virtual bool visit(NestedNameSpecifierAST *) { return true; }
virtual bool visit(NewDeclaratorAST *) { return true; }
virtual bool visit(NewExpressionAST *) { return true; }
virtual bool visit(NewInitializerAST *) { return true; }
virtual bool visit(NewTypeIdAST *) { return true; }
virtual bool visit(NumericLiteralAST *) { return true; }
virtual bool visit(OperatorAST *) { return true; }
virtual bool visit(OperatorFunctionIdAST *) { return true; }
virtual bool visit(ParameterDeclarationAST *) { return true; }
virtual bool visit(ParameterDeclarationClauseAST *) { return true; }
virtual bool visit(PointerAST *) { return true; }
virtual bool visit(PointerToMemberAST *) { return true; }
virtual bool visit(PostIncrDecrAST *) { return true; }
virtual bool visit(PostfixExpressionAST *) { return true; }
virtual bool visit(QualifiedNameAST *) { return true; }
virtual bool visit(ReferenceAST *) { return true; }
virtual bool visit(ReturnStatementAST *) { return true; }
virtual bool visit(SimpleDeclarationAST *) { return true; }
virtual bool visit(SimpleNameAST *) { return true; }
virtual bool visit(SimpleSpecifierAST *) { return true; }
virtual bool visit(SizeofExpressionAST *) { return true; }
virtual bool visit(StringLiteralAST *) { return true; }
virtual bool visit(SwitchStatementAST *) { return true; }
virtual bool visit(TemplateArgumentListAST *) { return true; }
virtual bool visit(TemplateDeclarationAST *) { return true; }
virtual bool visit(TemplateIdAST *) { return true; }
virtual bool visit(TemplateTypeParameterAST *) { return true; }
virtual bool visit(ThisExpressionAST *) { return true; }
virtual bool visit(ThrowExpressionAST *) { return true; }
virtual bool visit(TranslationUnitAST *) { return true; }
virtual bool visit(TryBlockStatementAST *) { return true; }
virtual bool visit(TypeConstructorCallAST *) { return true; }
virtual bool visit(TypeIdAST *) { return true; }
virtual bool visit(TypeidExpressionAST *) { return true; }
virtual bool visit(TypeofSpecifierAST *) { return true; }
virtual bool visit(TypenameCallExpressionAST *) { return true; }
virtual bool visit(TypenameTypeParameterAST *) { return true; }
virtual bool visit(UnaryExpressionAST *) { return true; }
virtual bool visit(UsingAST *) { return true; }
virtual bool visit(UsingDirectiveAST *) { return true; }
virtual bool visit(WhileStatementAST *) { return true; }
virtual bool visit(QtMethodAST *) { return true; }
// ObjC++
virtual bool visit(IdentifierListAST *) { return true; }
virtual bool visit(ObjCClassDeclarationAST *) { return true; }
private:
Control *_control;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_ASTVISITOR_H

View File

@@ -0,0 +1,178 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_ASTFWD_H
#define CPLUSPLUS_ASTFWD_H
#include <CPlusPlusForwardDeclarations.h>
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class AST;
class ASTVisitor;
class AccessDeclarationAST;
class ArrayAccessAST;
class ArrayDeclaratorAST;
class ArrayInitializerAST;
class AsmDefinitionAST;
class AttributeAST;
class AttributeSpecifierAST;
class BaseSpecifierAST;
class BinaryExpressionAST;
class BoolLiteralAST;
class BreakStatementAST;
class CallAST;
class CaseStatementAST;
class CastExpressionAST;
class CatchClauseAST;
class ClassSpecifierAST;
class CompoundLiteralAST;
class CompoundStatementAST;
class ConditionAST;
class ConditionalExpressionAST;
class ContinueStatementAST;
class ConversionFunctionIdAST;
class CoreDeclaratorAST;
class CppCastExpressionAST;
class CtorInitializerAST;
class DeclarationAST;
class DeclarationStatementAST;
class DeclaratorAST;
class DeclaratorIdAST;
class DeclaratorListAST;
class DeleteExpressionAST;
class DestructorNameAST;
class DoStatementAST;
class ElaboratedTypeSpecifierAST;
class EmptyDeclarationAST;
class EnumSpecifierAST;
class EnumeratorAST;
class ExceptionDeclarationAST;
class ExceptionSpecificationAST;
class ExpressionAST;
class ExpressionListAST;
class ExpressionOrDeclarationStatementAST;
class ExpressionStatementAST;
class ForStatementAST;
class FunctionDeclaratorAST;
class FunctionDefinitionAST;
class GotoStatementAST;
class IfStatementAST;
class LabeledStatementAST;
class LinkageBodyAST;
class LinkageSpecificationAST;
class MemInitializerAST;
class MemberAccessAST;
class NameAST;
class NamedTypeSpecifierAST;
class NamespaceAST;
class NamespaceAliasDefinitionAST;
class NestedDeclaratorAST;
class NestedExpressionAST;
class NestedNameSpecifierAST;
class NewDeclaratorAST;
class NewExpressionAST;
class NewInitializerAST;
class NewTypeIdAST;
class NumericLiteralAST;
class OperatorAST;
class OperatorFunctionIdAST;
class ParameterDeclarationAST;
class ParameterDeclarationClauseAST;
class PointerAST;
class PointerToMemberAST;
class PostIncrDecrAST;
class PostfixAST;
class PostfixDeclaratorAST;
class PostfixExpressionAST;
class PtrOperatorAST;
class QualifiedNameAST;
class ReferenceAST;
class ReturnStatementAST;
class SimpleDeclarationAST;
class SimpleNameAST;
class SimpleSpecifierAST;
class SizeofExpressionAST;
class SpecifierAST;
class StatementAST;
class StringLiteralAST;
class SwitchStatementAST;
class TemplateArgumentListAST;
class TemplateDeclarationAST;
class TemplateIdAST;
class TemplateTypeParameterAST;
class ThisExpressionAST;
class ThrowExpressionAST;
class TranslationUnitAST;
class TryBlockStatementAST;
class TypeConstructorCallAST;
class TypeIdAST;
class TypeidExpressionAST;
class TypenameCallExpressionAST;
class TypenameTypeParameterAST;
class TypeofSpecifierAST;
class UnaryExpressionAST;
class UsingAST;
class UsingDirectiveAST;
class WhileStatementAST;
class QtMethodAST;
// ObjC++
class IdentifierListAST;
class ObjCClassDeclarationAST;
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_ASTFWD_H

View File

@@ -0,0 +1,34 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "Array.h"

View File

@@ -0,0 +1,135 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_ARRAY_H
#define CPLUSPLUS_ARRAY_H
#include "CPlusPlusForwardDeclarations.h"
#include <new>
#include <cstdlib>
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
template <typename _Tp, int SEGMENT_SHIFT = 4>
class Array
{
Array(const Array &other);
void operator =(const Array &other);
public:
Array()
: _segments(0),
_allocatedSegments(0),
_segmentCount(-1),
_allocatedElements(0),
_count(-1)
{ }
~Array()
{
if (_segments) {
for (int index = 0; index <= _segmentCount; ++index) {
delete[] (_segments[index] + (index << SEGMENT_SHIFT));
}
free(_segments);
}
}
inline unsigned size() const
{ return _count + 1; }
inline unsigned count() const
{ return _count + 1; }
inline const _Tp &at(unsigned index) const
{ return _segments[index >> SEGMENT_SHIFT][index]; }
inline const _Tp &operator[](unsigned index) const
{ return _segments[index >> SEGMENT_SHIFT][index]; }
inline _Tp &operator[](unsigned index)
{ return _segments[index >> SEGMENT_SHIFT][index]; }
void push_back(const _Tp &value)
{
if (++_count == _allocatedElements) {
if (++_segmentCount == _allocatedSegments) {
_allocatedSegments += 4;
_segments = (_Tp **) realloc(_segments, _allocatedSegments * sizeof(_Tp *));
}
_Tp *segment = new _Tp[SEGMENT_SIZE];
_segments[_segmentCount] = segment - (_segmentCount << SEGMENT_SHIFT);
_allocatedElements += SEGMENT_SIZE;
}
_segments[_count >> SEGMENT_SHIFT][_count] = value;
}
private:
enum {
SEGMENT_SIZE = 1 << SEGMENT_SHIFT
};
_Tp **_segments;
int _allocatedSegments;
int _segmentCount;
int _allocatedElements;
int _count;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_ARRAY_H

View File

@@ -0,0 +1,140 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_CPLUSPLUSFORWARDDECLARATIONS_H
#define CPLUSPLUS_CPLUSPLUSFORWARDDECLARATIONS_H
#ifdef HAVE_QT
# include <QtCore/qglobal.h>
# define CPLUSPLUS_BEGIN_HEADER
# define CPLUSPLUS_END_HEADER
# if defined(CPLUSPLUS_BUILD_LIB)
# define CPLUSPLUS_EXPORT Q_DECL_EXPORT
# else
# define CPLUSPLUS_EXPORT Q_DECL_IMPORT
# endif
#else
# define CPLUSPLUS_BEGIN_HEADER
# define CPLUSPLUS_END_HEADER
# define CPLUSPLUS_EXPORT
#endif
#ifdef CPLUSPLUS_WITH_NAMESPACE
# define CPLUSPLUS_BEGIN_NAMESPACE namespace CPlusPlus {
# define CPLUSPLUS_END_NAMESPACE } // end of namespace CPlusPLus
# define CPLUSPLUS_USE_NAMESPACE using namespace CPlusPlus;
#else
# define CPLUSPLUS_BEGIN_NAMESPACE
# define CPLUSPLUS_END_NAMESPACE
# define CPLUSPLUS_USE_NAMESPACE ;
#endif
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class TranslationUnit;
class Semantic;
class Control;
class MemoryPool;
class DiagnosticClient;
class Identifier;
class Literal;
class StringLiteral;
class NumericLiteral;
class Scope;
// names
class NameVisitor;
class Name;
class NameId;
class TemplateNameId;
class DestructorNameId;
class OperatorNameId;
class ConversionNameId;
class QualifiedNameId;
// types
class FullySpecifiedType;
class TypeVisitor;
class Type;
class VoidType;
class IntegerType;
class FloatType;
class PointerToMemberType;
class PointerType;
class ReferenceType;
class ArrayType;
class NamedType;
// symbols
class SymbolVisitor;
class Symbol;
class ScopedSymbol;
class UsingNamespaceDirective;
class UsingDeclaration;
class Declaration;
class Argument;
class Function;
class Namespace;
class BaseClass;
class Block;
class Class;
class Enum;
class Use;
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_CPLUSPLUSFORWARDDECLARATIONS_H

View File

@@ -0,0 +1,374 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "CheckDeclaration.h"
#include "Semantic.h"
#include "AST.h"
#include "TranslationUnit.h"
#include "Scope.h"
#include "Names.h"
#include "CoreTypes.h"
#include "Symbols.h"
#include "Control.h"
#include <cassert>
CPLUSPLUS_BEGIN_NAMESPACE
CheckDeclaration::CheckDeclaration(Semantic *semantic)
: SemanticCheck(semantic),
_declaration(0),
_scope(0),
_templateParameters(0),
_checkAnonymousArguments(false)
{ }
CheckDeclaration::~CheckDeclaration()
{ }
void CheckDeclaration::check(DeclarationAST *declaration,
Scope *scope, Scope *templateParameters)
{
Scope *previousScope = switchScope(scope);
Scope *previousTemplateParameters = switchTemplateParameters(templateParameters);
DeclarationAST *previousDeclaration = switchDeclaration(declaration);
accept(declaration);
(void) switchDeclaration(previousDeclaration);
(void) switchTemplateParameters(previousTemplateParameters);
(void) switchScope(previousScope);
}
DeclarationAST *CheckDeclaration::switchDeclaration(DeclarationAST *declaration)
{
DeclarationAST *previousDeclaration = _declaration;
_declaration = declaration;
return previousDeclaration;
}
Scope *CheckDeclaration::switchScope(Scope *scope)
{
Scope *previousScope = _scope;
_scope = scope;
return previousScope;
}
Scope *CheckDeclaration::switchTemplateParameters(Scope *templateParameters)
{
Scope *previousTemplateParameters = _templateParameters;
_templateParameters = templateParameters;
return previousTemplateParameters;
}
void CheckDeclaration::checkFunctionArguments(Function *fun)
{
if (! _checkAnonymousArguments)
return;
if (_scope->isClassScope() && fun->isPublic()) {
for (unsigned argc = 0; argc < fun->argumentCount(); ++argc) {
Argument *arg = fun->argumentAt(argc)->asArgument();
assert(arg != 0);
if (! arg->name()) {
translationUnit()->warning(arg->sourceLocation(),
"anonymous argument");
}
}
}
}
bool CheckDeclaration::visit(SimpleDeclarationAST *ast)
{
FullySpecifiedType ty = semantic()->check(ast->decl_specifier_seq, _scope);
FullySpecifiedType qualTy = ty.qualifiedType();
if (_templateParameters) {
if (Class *klass = ty->asClass()) {
klass->setTemplateParameters(_templateParameters);
}
}
for (DeclaratorListAST *it = ast->declarators; it; it = it->next) {
Name *name = 0;
FullySpecifiedType declTy = semantic()->check(it->declarator, qualTy,
_scope, &name);
if (Function *fun = declTy->asFunction()) {
fun->setScope(_scope);
fun->setName(name);
fun->setMethodKey(semantic()->currentMethodKey());
fun->setVisibility(semantic()->currentVisibility());
} else if (semantic()->currentMethodKey() != Function::NormalMethod) {
translationUnit()->warning(ast->firstToken(),
"expected a function declaration");
}
unsigned location = 0;
if (it->declarator)
location = it->declarator->firstToken();
else
location = ast->firstToken();
Declaration *symbol = control()->newDeclaration(location, name);
symbol->setType(control()->integerType(IntegerType::Int));
symbol->setType(declTy);
if (_templateParameters && it == ast->declarators && ! ty->asClass())
symbol->setTemplateParameters(_templateParameters);
symbol->setVisibility(semantic()->currentVisibility());
if (ty.isFriend())
symbol->setStorage(Symbol::Friend);
else if (ty.isRegister())
symbol->setStorage(Symbol::Register);
else if (ty.isStatic())
symbol->setStorage(Symbol::Static);
else if (ty.isExtern())
symbol->setStorage(Symbol::Extern);
else if (ty.isMutable())
symbol->setStorage(Symbol::Mutable);
else if (ty.isTypedef())
symbol->setStorage(Symbol::Typedef);
_scope->enterSymbol(symbol);
}
return false;
}
bool CheckDeclaration::visit(EmptyDeclarationAST *)
{
return false;
}
bool CheckDeclaration::visit(AccessDeclarationAST *ast)
{
int accessSpecifier = tokenKind(ast->access_specifier_token);
int visibility = semantic()->visibilityForAccessSpecifier(accessSpecifier);
semantic()->switchVisibility(visibility);
if (ast->slots_token)
semantic()->switchMethodKey(Function::SlotMethod);
else if (accessSpecifier == T_SIGNALS)
semantic()->switchMethodKey(Function::SignalMethod);
else
semantic()->switchMethodKey(Function::NormalMethod);
return false;
}
bool CheckDeclaration::visit(AsmDefinitionAST *)
{
return false;
}
bool CheckDeclaration::visit(ExceptionDeclarationAST *)
{
return false;
}
bool CheckDeclaration::visit(FunctionDefinitionAST *ast)
{
FullySpecifiedType ty = semantic()->check(ast->decl_specifier_seq, _scope);
FullySpecifiedType qualTy = ty.qualifiedType();
Name *name = 0;
FullySpecifiedType funTy = semantic()->check(ast->declarator, qualTy,
_scope, &name);
Function *fun = funTy->asFunction();
if (! fun) {
translationUnit()->error(ast->firstToken(),
"expected a function prototype");
return false;
}
fun->setName(name);
fun->setTemplateParameters(_templateParameters);
fun->setVisibility(semantic()->currentVisibility());
fun->setMethodKey(semantic()->currentMethodKey());
checkFunctionArguments(fun);
_scope->enterSymbol(fun);
if (ast->ctor_initializer) {
bool looksLikeCtor = false;
if (ty.isValid() || ! fun->identity())
looksLikeCtor = false;
else if (fun->identity()->isNameId() || fun->identity()->isTemplateNameId())
looksLikeCtor = true;
if (! looksLikeCtor) {
translationUnit()->error(ast->ctor_initializer->firstToken(),
"only constructors take base initializers");
}
}
const int previousVisibility = semantic()->switchVisibility(Symbol::Public);
const int previousMethodKey = semantic()->switchMethodKey(Function::NormalMethod);
semantic()->check(ast->function_body, fun->members());
semantic()->switchMethodKey(previousMethodKey);
semantic()->switchVisibility(previousVisibility);
if (ast->next && ast->next->asEmptyDeclaration()) {
translationUnit()->warning(ast->next->firstToken(),
"unnecessary semicolon after function block");
}
return false;
}
bool CheckDeclaration::visit(LinkageBodyAST *ast)
{
for (DeclarationAST *decl = ast->declarations; decl; decl = decl->next) {
semantic()->check(decl, _scope);
}
return false;
}
bool CheckDeclaration::visit(LinkageSpecificationAST *ast)
{
for (DeclarationAST *decl = ast->declaration; decl; decl = decl->next) {
semantic()->check(decl, _scope);
}
return false;
}
bool CheckDeclaration::visit(NamespaceAST *ast)
{
Identifier *id = identifier(ast->identifier_token);
Name *namespaceName = control()->nameId(id);
Namespace *ns = control()->newNamespace(ast->firstToken(), namespaceName);
_scope->enterSymbol(ns);
semantic()->check(ast->linkage_body, ns->members()); // ### we'll do the merge later.
if (ast->next && ast->next->asEmptyDeclaration()) {
translationUnit()->warning(ast->next->firstToken(),
"unnecessary semicolon after namespace");
}
return false;
}
bool CheckDeclaration::visit(NamespaceAliasDefinitionAST *)
{
return false;
}
bool CheckDeclaration::visit(ParameterDeclarationAST *ast)
{
Name *argName = 0;
FullySpecifiedType ty = semantic()->check(ast->type_specifier, _scope);
FullySpecifiedType argTy = semantic()->check(ast->declarator, ty.qualifiedType(),
_scope, &argName);
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
Argument *arg = control()->newArgument(ast->firstToken(), argName);
if (ast->expression)
arg->setInitializer(true);
arg->setType(argTy);
_scope->enterSymbol(arg);
return false;
}
bool CheckDeclaration::visit(TemplateDeclarationAST *ast)
{
/*
Template *templ = control()->newTemplate(ast->firstToken());
for (DeclarationAST *param = ast->template_parameters; param;
param = param->next) {
semantic()->check(param, templ->members());
}
*/
Scope *previousScope = switchScope(new Scope(_scope->owner()));
for (DeclarationAST *param = ast->template_parameters; param;
param = param->next) {
semantic()->check(param, _scope);
}
Scope *templateParameters = switchScope(previousScope);
semantic()->check(ast->declaration, _scope, templateParameters);
return false;
}
bool CheckDeclaration::visit(TypenameTypeParameterAST *ast)
{
Name *name = semantic()->check(ast->name, _scope);
Argument *arg = control()->newArgument(ast->firstToken(), name); // ### new template type
_scope->enterSymbol(arg);
return false;
}
bool CheckDeclaration::visit(TemplateTypeParameterAST *ast)
{
Name *name = semantic()->check(ast->name, _scope);
Argument *arg = control()->newArgument(ast->firstToken(), name); // ### new template type
_scope->enterSymbol(arg);
return false;
}
bool CheckDeclaration::visit(UsingAST *ast)
{
Name *name = semantic()->check(ast->name, _scope);
UsingDeclaration *u = control()->newUsingDeclaration(ast->firstToken(), name);
_scope->enterSymbol(u);
return false;
}
bool CheckDeclaration::visit(UsingDirectiveAST *ast)
{
Name *name = semantic()->check(ast->name, _scope);
UsingNamespaceDirective *u = control()->newUsingNamespaceDirective(ast->firstToken(), name);
_scope->enterSymbol(u);
return false;
}
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,106 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_CHECKDECLARATION_H
#define CPLUSPLUS_CHECKDECLARATION_H
#include "CPlusPlusForwardDeclarations.h"
#include "SemanticCheck.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT CheckDeclaration: public SemanticCheck
{
public:
CheckDeclaration(Semantic *semantic);
virtual ~CheckDeclaration();
void check(DeclarationAST *declaration, Scope *scope, Scope *templateParameters);
protected:
DeclarationAST *switchDeclaration(DeclarationAST *declaration);
Scope *switchScope(Scope *scope);
Scope *switchTemplateParameters(Scope *templateParameters);
void checkFunctionArguments(Function *fun);
using ASTVisitor::visit;
virtual bool visit(SimpleDeclarationAST *ast);
virtual bool visit(EmptyDeclarationAST *ast);
virtual bool visit(AccessDeclarationAST *ast);
virtual bool visit(AsmDefinitionAST *ast);
virtual bool visit(ExceptionDeclarationAST *ast);
virtual bool visit(FunctionDefinitionAST *ast);
virtual bool visit(LinkageBodyAST *ast);
virtual bool visit(LinkageSpecificationAST *ast);
virtual bool visit(NamespaceAST *ast);
virtual bool visit(NamespaceAliasDefinitionAST *ast);
virtual bool visit(ParameterDeclarationAST *ast);
virtual bool visit(TemplateDeclarationAST *ast);
virtual bool visit(TypenameTypeParameterAST *ast);
virtual bool visit(TemplateTypeParameterAST *ast);
virtual bool visit(UsingAST *ast);
virtual bool visit(UsingDirectiveAST *ast);
private:
DeclarationAST *_declaration;
Scope *_scope;
Scope *_templateParameters;
bool _checkAnonymousArguments: 1;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_CHECKDECLARATION_H

View File

@@ -0,0 +1,258 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "CheckDeclarator.h"
#include "Semantic.h"
#include "AST.h"
#include "Control.h"
#include "TranslationUnit.h"
#include "Literals.h"
#include "CoreTypes.h"
#include "Symbols.h"
CPLUSPLUS_BEGIN_NAMESPACE
CheckDeclarator::CheckDeclarator(Semantic *semantic)
: SemanticCheck(semantic),
_declarator(0),
_scope(0),
_name(0)
{ }
CheckDeclarator::~CheckDeclarator()
{ }
FullySpecifiedType CheckDeclarator::check(DeclaratorAST *declarator,
FullySpecifiedType type,
Scope *scope,
Name **name)
{
FullySpecifiedType previousType = switchFullySpecifiedType(type);
Scope *previousScope = switchScope(scope);
DeclaratorAST *previousDeclarator = switchDeclarator(declarator);
Name **previousName = switchName(name);
accept(declarator);
(void) switchName(previousName);
(void) switchDeclarator(previousDeclarator);
(void) switchScope(previousScope);
return switchFullySpecifiedType(previousType);
}
FullySpecifiedType CheckDeclarator::check(PtrOperatorAST *ptrOperators,
FullySpecifiedType type,
Scope *scope)
{
FullySpecifiedType previousType = switchFullySpecifiedType(type);
Scope *previousScope = switchScope(scope);
accept(ptrOperators);
(void) switchScope(previousScope);
return switchFullySpecifiedType(previousType);
}
DeclaratorAST *CheckDeclarator::switchDeclarator(DeclaratorAST *declarator)
{
DeclaratorAST *previousDeclarator = _declarator;
_declarator = declarator;
return previousDeclarator;
}
FullySpecifiedType CheckDeclarator::switchFullySpecifiedType(FullySpecifiedType type)
{
FullySpecifiedType previousType = _fullySpecifiedType;
_fullySpecifiedType = type;
return previousType;
}
Scope *CheckDeclarator::switchScope(Scope *scope)
{
Scope *previousScope = _scope;
_scope = scope;
return previousScope;
}
Name **CheckDeclarator::switchName(Name **name)
{
Name **previousName = _name;
_name = name;
return previousName;
}
bool CheckDeclarator::visit(DeclaratorAST *ast)
{
accept(ast->ptr_operators);
accept(ast->postfix_declarators);
accept(ast->core_declarator);
// ### check the initializer
// FullySpecifiedType exprTy = semantic()->check(ast->initializer, _scope);
if (ast->initializer && _fullySpecifiedType->isFunction()) {
_fullySpecifiedType->asFunction()->setPureVirtual(true);
}
return false;
}
bool CheckDeclarator::visit(DeclaratorIdAST *ast)
{
Name *name = semantic()->check(ast->name, _scope);
if (_name)
*_name = name;
return false;
}
bool CheckDeclarator::visit(NestedDeclaratorAST *ast)
{
accept(ast->declarator);
return false;
}
bool CheckDeclarator::visit(FunctionDeclaratorAST *ast)
{
Function *fun = control()->newFunction(ast->firstToken());
fun->setReturnType(_fullySpecifiedType);
if (ast->parameters) {
DeclarationAST *parameter_declarations = ast->parameters->parameter_declarations;
for (DeclarationAST *decl = parameter_declarations; decl; decl = decl->next) {
semantic()->check(decl, fun->arguments());
}
if (ast->parameters->dot_dot_dot_token)
fun->setVariadic(true);
}
// check the arguments
bool hasDefaultArguments = false;
for (unsigned i = 0; i < fun->argumentCount(); ++i) {
Argument *arg = fun->argumentAt(i)->asArgument();
if (hasDefaultArguments && ! arg->hasInitializer()) {
translationUnit()->error(ast->firstToken(),
"default argument missing for parameter at position %d", i + 1);
} else if (! hasDefaultArguments) {
hasDefaultArguments = arg->hasInitializer();
}
}
FullySpecifiedType funTy(fun);
_fullySpecifiedType = funTy;
for (SpecifierAST *it = ast->cv_qualifier_seq; it; it = it->next) {
SimpleSpecifierAST *cv = static_cast<SimpleSpecifierAST *>(it);
int k = tokenKind(cv->specifier_token);
if (k == T_CONST)
fun->setConst(true);
else if (k == T_VOLATILE)
fun->setVolatile(true);
}
accept(ast->next);
return false;
}
bool CheckDeclarator::visit(ArrayDeclaratorAST *ast)
{
ArrayType *ty = control()->arrayType(_fullySpecifiedType); // ### set the dimension
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
FullySpecifiedType arrTy(ty);
_fullySpecifiedType = ty;
accept(ast->next);
return false;
}
bool CheckDeclarator::visit(PointerToMemberAST *ast)
{
Name *memberName = semantic()->check(ast->nested_name_specifier, _scope);
PointerToMemberType *ptrTy = control()->pointerToMemberType(memberName, _fullySpecifiedType);
FullySpecifiedType ty(ptrTy);
_fullySpecifiedType = ty;
applyCvQualifiers(ast->cv_qualifier_seq);
accept(ast->next);
return false;
}
bool CheckDeclarator::visit(PointerAST *ast)
{
PointerType *ptrTy = control()->pointerType(_fullySpecifiedType);
FullySpecifiedType ty(ptrTy);
_fullySpecifiedType = ty;
applyCvQualifiers(ast->cv_qualifier_seq);
accept(ast->next);
return false;
}
bool CheckDeclarator::visit(ReferenceAST *ast)
{
ReferenceType *refTy = control()->referenceType(_fullySpecifiedType);
FullySpecifiedType ty(refTy);
_fullySpecifiedType = ty;
accept(ast->next);
return false;
}
void CheckDeclarator::applyCvQualifiers(SpecifierAST *cv)
{
for (; cv; cv = cv->next) {
SimpleSpecifierAST *spec = static_cast<SimpleSpecifierAST *>(cv);
switch (translationUnit()->tokenKind(spec->specifier_token)) {
case T_VOLATILE:
_fullySpecifiedType.setVolatile(true);
break;
case T_CONST:
_fullySpecifiedType.setConst(true);
break;
default:
break;
} // switch
}
}
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,110 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_CHECKDECLARATOR_H
#define CPLUSPLUS_CHECKDECLARATOR_H
#include "CPlusPlusForwardDeclarations.h"
#include "SemanticCheck.h"
#include "FullySpecifiedType.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT CheckDeclarator: public SemanticCheck
{
public:
CheckDeclarator(Semantic *semantic);
virtual ~CheckDeclarator();
FullySpecifiedType check(DeclaratorAST *declarator,
FullySpecifiedType type,
Scope *scope,
Name **name);
FullySpecifiedType check(PtrOperatorAST *ptrOperators,
FullySpecifiedType type,
Scope *scope);
protected:
DeclaratorAST *switchDeclarator(DeclaratorAST *declarator);
FullySpecifiedType switchFullySpecifiedType(FullySpecifiedType type);
Scope *switchScope(Scope *scope);
Name **switchName(Name **name);
using ASTVisitor::visit;
virtual bool visit(DeclaratorAST *ast);
// ptr operators
virtual bool visit(PointerToMemberAST *ast);
virtual bool visit(PointerAST *ast);
virtual bool visit(ReferenceAST *ast);
// core declarators
virtual bool visit(DeclaratorIdAST *ast);
virtual bool visit(NestedDeclaratorAST *ast);
// postfix declarators
virtual bool visit(FunctionDeclaratorAST *ast);
virtual bool visit(ArrayDeclaratorAST *ast);
void applyCvQualifiers(SpecifierAST *cv);
private:
DeclaratorAST *_declarator;
Scope *_scope;
Name **_name;
FullySpecifiedType _fullySpecifiedType;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_CHECKDECLARATOR_H

View File

@@ -0,0 +1,369 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "CheckExpression.h"
#include "Semantic.h"
#include "TranslationUnit.h"
#include "AST.h"
#include "Scope.h"
#include "Literals.h"
#include "CoreTypes.h"
#include "Symbols.h"
#include "Control.h"
CPLUSPLUS_BEGIN_NAMESPACE
CheckExpression::CheckExpression(Semantic *semantic)
: SemanticCheck(semantic),
_expression(0),
_scope(0),
_checkOldStyleCasts(false)
{ }
CheckExpression::~CheckExpression()
{ }
FullySpecifiedType CheckExpression::check(ExpressionAST *expression, Scope *scope)
{
FullySpecifiedType previousType = switchFullySpecifiedType(FullySpecifiedType());
Scope *previousScope = switchScope(scope);
ExpressionAST *previousExpression = switchExpression(expression);
accept(expression);
(void) switchExpression(previousExpression);
(void) switchScope(previousScope);
return switchFullySpecifiedType(previousType);
}
ExpressionAST *CheckExpression::switchExpression(ExpressionAST *expression)
{
ExpressionAST *previousExpression = _expression;
_expression = expression;
return previousExpression;
}
FullySpecifiedType CheckExpression::switchFullySpecifiedType(FullySpecifiedType type)
{
FullySpecifiedType previousType = _fullySpecifiedType;
_fullySpecifiedType = type;
return previousType;
}
Scope *CheckExpression::switchScope(Scope *scope)
{
Scope *previousScope = _scope;
_scope = scope;
return previousScope;
}
bool CheckExpression::visit(ExpressionListAST *ast)
{
for (ExpressionListAST *it = ast; it; it = it->next) {
FullySpecifiedType exprTy = semantic()->check(it->expression, _scope);
}
return false;
}
bool CheckExpression::visit(BinaryExpressionAST *ast)
{
FullySpecifiedType leftExprTy = semantic()->check(ast->left_expression, _scope);
FullySpecifiedType rightExprTy = semantic()->check(ast->right_expression, _scope);
return false;
}
bool CheckExpression::visit(CastExpressionAST *ast)
{
FullySpecifiedType castTy = semantic()->check(ast->type_id, _scope);
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
if (_checkOldStyleCasts && ! castTy->isVoidType())
translationUnit()->warning(ast->firstToken(),
"ugly old style cast");
return false;
}
bool CheckExpression::visit(ConditionAST *ast)
{
FullySpecifiedType typeSpecTy = semantic()->check(ast->type_specifier, _scope);
Name *name = 0;
FullySpecifiedType declTy = semantic()->check(ast->declarator, typeSpecTy.qualifiedType(),
_scope, &name);
Declaration *decl = control()->newDeclaration(ast->declarator->firstToken(), name);
decl->setType(declTy);
_scope->enterSymbol(decl);
return false;
}
bool CheckExpression::visit(ConditionalExpressionAST *ast)
{
FullySpecifiedType condTy = semantic()->check(ast->condition, _scope);
FullySpecifiedType leftExprTy = semantic()->check(ast->left_expression, _scope);
FullySpecifiedType rightExprTy = semantic()->check(ast->right_expression, _scope);
return false;
}
bool CheckExpression::visit(CppCastExpressionAST *ast)
{
FullySpecifiedType typeIdTy = semantic()->check(ast->type_id, _scope);
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
return false;
}
bool CheckExpression::visit(DeleteExpressionAST *ast)
{
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
return false;
}
bool CheckExpression::visit(ArrayInitializerAST *ast)
{
for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
FullySpecifiedType exprTy = semantic()->check(it->expression, _scope);
}
return false;
}
bool CheckExpression::visit(QualifiedNameAST *ast)
{
Name *name = semantic()->check(ast, _scope);
_scope->addUse(ast->firstToken(), name);
return false;
}
bool CheckExpression::visit(OperatorFunctionIdAST *ast)
{
Name *name = semantic()->check(ast, _scope);
_scope->addUse(ast->firstToken(), name);
return false;
}
bool CheckExpression::visit(ConversionFunctionIdAST *ast)
{
Name *name = semantic()->check(ast, _scope);
_scope->addUse(ast->firstToken(), name);
return false;
}
bool CheckExpression::visit(SimpleNameAST *ast)
{
Name *name = semantic()->check(ast, _scope);
_scope->addUse(ast->firstToken(), name);
return false;
}
bool CheckExpression::visit(DestructorNameAST *ast)
{
Name *name = semantic()->check(ast, _scope);
_scope->addUse(ast->firstToken(), name);
return false;
}
bool CheckExpression::visit(TemplateIdAST *ast)
{
Name *name = semantic()->check(ast, _scope);
_scope->addUse(ast->firstToken(), name);
return false;
}
bool CheckExpression::visit(NewExpressionAST *ast)
{
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
FullySpecifiedType typeIdTy = semantic()->check(ast->type_id, _scope);
// ### process new-typeid
// ### process new-initializer
return false;
}
bool CheckExpression::visit(TypeidExpressionAST *ast)
{
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
return false;
}
bool CheckExpression::visit(TypenameCallExpressionAST *ast)
{
if (Name *name = semantic()->check(ast->name, _scope)) {
_scope->addUse(ast->name->firstToken(), name);
}
for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
FullySpecifiedType exprTy = semantic()->check(it->expression, _scope);
}
return false;
}
bool CheckExpression::visit(TypeConstructorCallAST *ast)
{
FullySpecifiedType typeSpecTy = semantic()->check(ast->type_specifier, _scope);
for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
FullySpecifiedType exprTy = semantic()->check(it->expression, _scope);
}
return false;
}
bool CheckExpression::visit(PostfixExpressionAST *ast)
{
FullySpecifiedType exprTy = semantic()->check(ast->base_expression, _scope);
for (PostfixAST *fx = ast->postfix_expressions; fx; fx = fx->next) {
accept(fx); // ### not exactly.
}
return false;
}
bool CheckExpression::visit(SizeofExpressionAST *ast)
{
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
return false;
}
bool CheckExpression::visit(NumericLiteralAST *)
{
_fullySpecifiedType.setType(control()->integerType(IntegerType::Int));
return false;
}
bool CheckExpression::visit(BoolLiteralAST *)
{
_fullySpecifiedType.setType(control()->integerType(IntegerType::Bool));
return false;
}
bool CheckExpression::visit(StringLiteralAST *)
{
IntegerType *charTy = control()->integerType(IntegerType::Char);
_fullySpecifiedType.setType(control()->pointerType(charTy));
return false;
}
bool CheckExpression::visit(ThisExpressionAST *)
{
return false;
}
bool CheckExpression::visit(NestedExpressionAST *ast)
{
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
return false;
}
bool CheckExpression::visit(ThrowExpressionAST *ast)
{
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
return false;
}
bool CheckExpression::visit(TypeIdAST *ast)
{
FullySpecifiedType typeSpecTy = semantic()->check(ast->type_specifier, _scope);
FullySpecifiedType declTy = semantic()->check(ast->declarator, typeSpecTy.qualifiedType(),
_scope);
_fullySpecifiedType = declTy;
return false;
}
bool CheckExpression::visit(UnaryExpressionAST *ast)
{
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
return false;
}
bool CheckExpression::visit(QtMethodAST *ast)
{
Name *name = 0;
Scope dummy;
FullySpecifiedType methTy = semantic()->check(ast->declarator, FullySpecifiedType(),
&dummy, &name);
Function *fty = methTy->asFunction();
if (! fty)
translationUnit()->warning(ast->firstToken(), "expected a function declarator");
else {
for (unsigned i = 0; i < fty->argumentCount(); ++i) {
Symbol *arg = fty->argumentAt(i);
if (arg->name())
translationUnit()->warning(arg->sourceLocation(),
"argument should be anonymous");
}
}
return false;
}
bool CheckExpression::visit(CompoundLiteralAST *ast)
{
/*FullySpecifiedType exprTy = */ semantic()->check(ast->type_id, _scope);
/*FullySpecifiedType initTy = */ semantic()->check(ast->initializer, _scope);
return false;
}
bool CheckExpression::visit(CallAST *ast)
{
for (ExpressionListAST *it = ast->expression_list; it; it = it->next) {
FullySpecifiedType exprTy = semantic()->check(it->expression, _scope);
}
return false;
}
bool CheckExpression::visit(ArrayAccessAST *ast)
{
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
return false;
}
bool CheckExpression::visit(PostIncrDecrAST *)
{
return false;
}
bool CheckExpression::visit(MemberAccessAST *ast)
{
if (Name *name = semantic()->check(ast->member_name, _scope))
_scope->addUse(ast->member_name->firstToken(), name);
return false;
}
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,127 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_CHECKEXPRESSION_H
#define CPLUSPLUS_CHECKEXPRESSION_H
#include "CPlusPlusForwardDeclarations.h"
#include "SemanticCheck.h"
#include "FullySpecifiedType.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT CheckExpression: public SemanticCheck
{
public:
CheckExpression(Semantic *semantic);
virtual ~CheckExpression();
FullySpecifiedType check(ExpressionAST *expression, Scope *scope);
protected:
ExpressionAST *switchExpression(ExpressionAST *expression);
FullySpecifiedType switchFullySpecifiedType(FullySpecifiedType type);
Scope *switchScope(Scope *scope);
using ASTVisitor::visit;
virtual bool visit(ExpressionListAST *ast);
virtual bool visit(BinaryExpressionAST *ast);
virtual bool visit(CastExpressionAST *ast);
virtual bool visit(ConditionAST *ast);
virtual bool visit(ConditionalExpressionAST *ast);
virtual bool visit(CppCastExpressionAST *ast);
virtual bool visit(DeleteExpressionAST *ast);
virtual bool visit(ArrayInitializerAST *ast);
virtual bool visit(NewExpressionAST *ast);
virtual bool visit(TypeidExpressionAST *ast);
virtual bool visit(TypenameCallExpressionAST *ast);
virtual bool visit(TypeConstructorCallAST *ast);
virtual bool visit(PostfixExpressionAST *ast);
virtual bool visit(SizeofExpressionAST *ast);
virtual bool visit(NumericLiteralAST *ast);
virtual bool visit(BoolLiteralAST *ast);
virtual bool visit(ThisExpressionAST *ast);
virtual bool visit(NestedExpressionAST *ast);
virtual bool visit(StringLiteralAST *ast);
virtual bool visit(ThrowExpressionAST *ast);
virtual bool visit(TypeIdAST *ast);
virtual bool visit(UnaryExpressionAST *ast);
virtual bool visit(QtMethodAST *ast);
virtual bool visit(CompoundLiteralAST *ast);
//names
virtual bool visit(QualifiedNameAST *ast);
virtual bool visit(OperatorFunctionIdAST *ast);
virtual bool visit(ConversionFunctionIdAST *ast);
virtual bool visit(SimpleNameAST *ast);
virtual bool visit(DestructorNameAST *ast);
virtual bool visit(TemplateIdAST *ast);
// postfix expressions
virtual bool visit(CallAST *ast);
virtual bool visit(ArrayAccessAST *ast);
virtual bool visit(PostIncrDecrAST *ast);
virtual bool visit(MemberAccessAST *ast);
private:
ExpressionAST *_expression;
FullySpecifiedType _fullySpecifiedType;
Scope *_scope;
bool _checkOldStyleCasts: 1;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_CHECKEXPRESSION_H

View File

@@ -0,0 +1,348 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "CheckName.h"
#include "Semantic.h"
#include "AST.h"
#include "Control.h"
#include "TranslationUnit.h"
#include "Literals.h"
#include "Names.h"
#include "CoreTypes.h"
#include "Symbols.h"
#include <cassert>
CPLUSPLUS_BEGIN_NAMESPACE
CheckName::CheckName(Semantic *semantic)
: SemanticCheck(semantic),
_name(0),
_scope(0)
{ }
CheckName::~CheckName()
{ }
Name *CheckName::check(NameAST *name, Scope *scope)
{
Name *previousName = switchName(0);
Scope *previousScope = switchScope(scope);
accept(name);
(void) switchScope(previousScope);
return switchName(previousName);
}
Name *CheckName::check(NestedNameSpecifierAST *nested_name_specifier, Scope *scope)
{
Name *previousName = switchName(0);
Scope *previousScope = switchScope(scope);
std::vector<Name *> names;
for (NestedNameSpecifierAST *it = nested_name_specifier;
it; it = it->next) {
names.push_back(semantic()->check(it->class_or_namespace_name, _scope));
}
_name = control()->qualifiedNameId(&names[0], names.size());
(void) switchScope(previousScope);
return switchName(previousName);
}
Name *CheckName::switchName(Name *name)
{
Name *previousName = _name;
_name = name;
return previousName;
}
Scope *CheckName::switchScope(Scope *scope)
{
Scope *previousScope = _scope;
_scope = scope;
return previousScope;
}
bool CheckName::visit(QualifiedNameAST *ast)
{
std::vector<Name *> names;
for (NestedNameSpecifierAST *it = ast->nested_name_specifier;
it; it = it->next) {
names.push_back(semantic()->check(it->class_or_namespace_name, _scope));
}
names.push_back(semantic()->check(ast->unqualified_name, _scope));
_name = control()->qualifiedNameId(&names[0], names.size(),
ast->global_scope_token != 0);
return false;
}
bool CheckName::visit(OperatorFunctionIdAST *ast)
{
assert(ast->op != 0);
OperatorNameId::Kind kind = OperatorNameId::InvalidOp;
switch (tokenKind(ast->op->op_token)) {
case T_NEW:
if (ast->op->open_token)
kind = OperatorNameId::NewArrayOp;
else
kind = OperatorNameId::NewOp;
break;
case T_DELETE:
if (ast->op->open_token)
kind = OperatorNameId::DeleteArrayOp;
else
kind = OperatorNameId::DeleteOp;
break;
case T_PLUS:
kind = OperatorNameId::PlusOp;
break;
case T_MINUS:
kind = OperatorNameId::MinusOp;
break;
case T_STAR:
kind = OperatorNameId::StarOp;
break;
case T_SLASH:
kind = OperatorNameId::SlashOp;
break;
case T_PERCENT:
kind = OperatorNameId::PercentOp;
break;
case T_CARET:
kind = OperatorNameId::CaretOp;
break;
case T_AMPER:
kind = OperatorNameId::AmpOp;
break;
case T_PIPE:
kind = OperatorNameId::PipeOp;
break;
case T_TILDE:
kind = OperatorNameId::TildeOp;
break;
case T_EXCLAIM:
kind = OperatorNameId::ExclaimOp;
break;
case T_EQUAL:
kind = OperatorNameId::EqualOp;
break;
case T_LESS:
kind = OperatorNameId::LessOp;
break;
case T_GREATER:
kind = OperatorNameId::GreaterOp;
break;
case T_PLUS_EQUAL:
kind = OperatorNameId::PlusEqualOp;
break;
case T_MINUS_EQUAL:
kind = OperatorNameId::MinusEqualOp;
break;
case T_STAR_EQUAL:
kind = OperatorNameId::StarEqualOp;
break;
case T_SLASH_EQUAL:
kind = OperatorNameId::SlashEqualOp;
break;
case T_PERCENT_EQUAL:
kind = OperatorNameId::PercentEqualOp;
break;
case T_CARET_EQUAL:
kind = OperatorNameId::CaretEqualOp;
break;
case T_AMPER_EQUAL:
kind = OperatorNameId::AmpEqualOp;
break;
case T_PIPE_EQUAL:
kind = OperatorNameId::PipeEqualOp;
break;
case T_LESS_LESS:
kind = OperatorNameId::LessLessOp;
break;
case T_GREATER_GREATER:
kind = OperatorNameId::GreaterGreaterOp;
break;
case T_LESS_LESS_EQUAL:
kind = OperatorNameId::LessLessEqualOp;
break;
case T_GREATER_GREATER_EQUAL:
kind = OperatorNameId::GreaterGreaterEqualOp;
break;
case T_EQUAL_EQUAL:
kind = OperatorNameId::EqualEqualOp;
break;
case T_EXCLAIM_EQUAL:
kind = OperatorNameId::ExclaimEqualOp;
break;
case T_LESS_EQUAL:
kind = OperatorNameId::LessEqualOp;
break;
case T_GREATER_EQUAL:
kind = OperatorNameId::GreaterEqualOp;
break;
case T_AMPER_AMPER:
kind = OperatorNameId::AmpAmpOp;
break;
case T_PIPE_PIPE:
kind = OperatorNameId::PipePipeOp;
break;
case T_PLUS_PLUS:
kind = OperatorNameId::PlusPlusOp;
break;
case T_MINUS_MINUS:
kind = OperatorNameId::MinusMinusOp;
break;
case T_COMMA:
kind = OperatorNameId::CommaOp;
break;
case T_ARROW_STAR:
kind = OperatorNameId::ArrowStarOp;
break;
case T_ARROW:
kind = OperatorNameId::ArrowOp;
break;
case T_LPAREN:
kind = OperatorNameId::FunctionCallOp;
break;
case T_LBRACKET:
kind = OperatorNameId::ArrayAccessOp;
break;
default:
kind = OperatorNameId::InvalidOp;
} // switch
_name = control()->operatorNameId(kind);
return false;
}
bool CheckName::visit(ConversionFunctionIdAST *ast)
{
FullySpecifiedType ty = semantic()->check(ast->type_specifier, _scope);
ty = semantic()->check(ast->ptr_operators, ty, _scope);
_name = control()->conversionNameId(ty);
return false;
}
bool CheckName::visit(SimpleNameAST *ast)
{
Identifier *id = identifier(ast->identifier_token);
_name = control()->nameId(id);
return false;
}
bool CheckName::visit(DestructorNameAST *ast)
{
Identifier *id = identifier(ast->identifier_token);
_name = control()->destructorNameId(id);
return false;
}
bool CheckName::visit(TemplateIdAST *ast)
{
Identifier *id = identifier(ast->identifier_token);
std::vector<FullySpecifiedType> templateArguments;
for (TemplateArgumentListAST *it = ast->template_arguments; it;
it = it->next) {
ExpressionAST *arg = it->template_argument;
FullySpecifiedType exprTy = semantic()->check(arg, _scope);
templateArguments.push_back(exprTy);
}
if (templateArguments.empty())
_name = control()->templateNameId(id);
else
_name = control()->templateNameId(id, &templateArguments[0],
templateArguments.size());
return false;
}
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,92 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_CHECKNAME_H
#define CPLUSPLUS_CHECKNAME_H
#include "CPlusPlusForwardDeclarations.h"
#include "SemanticCheck.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT CheckName: public SemanticCheck
{
public:
CheckName(Semantic *semantic);
virtual ~CheckName();
Name *check(NameAST *name, Scope *scope);
Name *check(NestedNameSpecifierAST *name, Scope *scope);
protected:
Name *switchName(Name *name);
Scope *switchScope(Scope *scope);
using ASTVisitor::visit;
virtual bool visit(QualifiedNameAST *ast);
virtual bool visit(OperatorFunctionIdAST *ast);
virtual bool visit(ConversionFunctionIdAST *ast);
virtual bool visit(SimpleNameAST *ast);
virtual bool visit(DestructorNameAST *ast);
virtual bool visit(TemplateIdAST *ast);
private:
Name *_name;
Scope *_scope;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_CHECKNAME_H

View File

@@ -0,0 +1,392 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "CheckSpecifier.h"
#include "Semantic.h"
#include "AST.h"
#include "Token.h"
#include "TranslationUnit.h"
#include "Literals.h"
#include "Names.h"
#include "CoreTypes.h"
#include "Symbols.h"
#include "Control.h"
#include "Scope.h"
CPLUSPLUS_BEGIN_NAMESPACE
CheckSpecifier::CheckSpecifier(Semantic *semantic)
: SemanticCheck(semantic),
_specifier(0),
_scope(0)
{ }
CheckSpecifier::~CheckSpecifier()
{ }
FullySpecifiedType CheckSpecifier::check(SpecifierAST *specifier, Scope *scope)
{
FullySpecifiedType previousType = switchFullySpecifiedType(FullySpecifiedType());
Scope *previousScope = switchScope(scope);
SpecifierAST *previousSpecifier = switchSpecifier(specifier);
accept(specifier);
(void) switchSpecifier(previousSpecifier);
(void) switchScope(previousScope);
return switchFullySpecifiedType(previousType);
}
SpecifierAST *CheckSpecifier::switchSpecifier(SpecifierAST *specifier)
{
SpecifierAST *previousSpecifier = _specifier;
_specifier = specifier;
return previousSpecifier;
}
FullySpecifiedType CheckSpecifier::switchFullySpecifiedType(FullySpecifiedType type)
{
FullySpecifiedType previousType = _fullySpecifiedType;
_fullySpecifiedType = type;
return previousType;
}
Scope *CheckSpecifier::switchScope(Scope *scope)
{
Scope *previousScope = _scope;
_scope = scope;
return previousScope;
}
bool CheckSpecifier::visit(SimpleSpecifierAST *ast)
{
switch (tokenKind(ast->specifier_token)) {
case T_CONST:
if (_fullySpecifiedType.isConst())
translationUnit()->error(ast->specifier_token,
"duplicate `%s'", spell(ast->specifier_token));
_fullySpecifiedType.setConst(true);
break;
case T_VOLATILE:
if (_fullySpecifiedType.isVolatile())
translationUnit()->error(ast->specifier_token,
"duplicate `%s'", spell(ast->specifier_token));
_fullySpecifiedType.setVolatile(true);
break;
case T_FRIEND:
if (_fullySpecifiedType.isFriend())
translationUnit()->error(ast->specifier_token,
"duplicate `%s'", spell(ast->specifier_token));
_fullySpecifiedType.setFriend(true);
break;
case T_REGISTER:
if (_fullySpecifiedType.isRegister())
translationUnit()->error(ast->specifier_token,
"duplicate `%s'", spell(ast->specifier_token));
_fullySpecifiedType.setRegister(true);
break;
case T_STATIC:
if (_fullySpecifiedType.isStatic())
translationUnit()->error(ast->specifier_token,
"duplicate `%s'", spell(ast->specifier_token));
_fullySpecifiedType.setStatic(true);
break;
case T_EXTERN:
if (_fullySpecifiedType.isExtern())
translationUnit()->error(ast->specifier_token,
"duplicate `%s'", spell(ast->specifier_token));
_fullySpecifiedType.setExtern(true);
break;
case T_MUTABLE:
if (_fullySpecifiedType.isMutable())
translationUnit()->error(ast->specifier_token,
"duplicate `%s'", spell(ast->specifier_token));
_fullySpecifiedType.setMutable(true);
break;
case T_TYPEDEF:
if (_fullySpecifiedType.isTypedef())
translationUnit()->error(ast->specifier_token,
"duplicate `%s'", spell(ast->specifier_token));
_fullySpecifiedType.setTypedef(true);
break;
case T_INLINE:
if (_fullySpecifiedType.isInline())
translationUnit()->error(ast->specifier_token,
"duplicate `%s'", spell(ast->specifier_token));
_fullySpecifiedType.setInline(true);
break;
case T_VIRTUAL:
if (_fullySpecifiedType.isVirtual())
translationUnit()->error(ast->specifier_token,
"duplicate `%s'", spell(ast->specifier_token));
_fullySpecifiedType.setVirtual(true);
break;
case T_EXPLICIT:
if (_fullySpecifiedType.isExplicit())
translationUnit()->error(ast->specifier_token,
"duplicate `%s'", spell(ast->specifier_token));
_fullySpecifiedType.setExplicit(true);
break;
case T_SIGNED:
if (_fullySpecifiedType.isSigned())
translationUnit()->error(ast->specifier_token,
"duplicate `%s'", spell(ast->specifier_token));
_fullySpecifiedType.setSigned(true);
break;
case T_UNSIGNED:
if (_fullySpecifiedType.isUnsigned())
translationUnit()->error(ast->specifier_token,
"duplicate `%s'", spell(ast->specifier_token));
_fullySpecifiedType.setUnsigned(true);
break;
case T_CHAR:
if (_fullySpecifiedType.type())
translationUnit()->error(ast->specifier_token,
"duplicate data type in declaration");
_fullySpecifiedType.setType(control()->integerType(IntegerType::Char));
break;
case T_WCHAR_T:
if (_fullySpecifiedType.type())
translationUnit()->error(ast->specifier_token,
"duplicate data type in declaration");
_fullySpecifiedType.setType(control()->integerType(IntegerType::WideChar));
break;
case T_BOOL:
if (_fullySpecifiedType.type())
translationUnit()->error(ast->specifier_token,
"duplicate data type in declaration");
_fullySpecifiedType.setType(control()->integerType(IntegerType::Bool));
break;
case T_SHORT:
if (Type *tp = _fullySpecifiedType.type()) {
IntegerType *intType = control()->integerType(IntegerType::Int);
if (tp != intType)
translationUnit()->error(ast->specifier_token,
"duplicate data type in declaration");
}
_fullySpecifiedType.setType(control()->integerType(IntegerType::Short));
break;
case T_INT:
if (Type *tp = _fullySpecifiedType.type()) {
IntegerType *shortType = control()->integerType(IntegerType::Short);
IntegerType *longType = control()->integerType(IntegerType::Long);
IntegerType *longLongType = control()->integerType(IntegerType::LongLong);
if (tp == shortType || tp == longType || tp == longLongType)
break;
translationUnit()->error(ast->specifier_token,
"duplicate data type in declaration");
}
_fullySpecifiedType.setType(control()->integerType(IntegerType::Int));
break;
case T_LONG:
if (Type *tp = _fullySpecifiedType.type()) {
IntegerType *intType = control()->integerType(IntegerType::Int);
IntegerType *longType = control()->integerType(IntegerType::Long);
FloatType *doubleType = control()->floatType(FloatType::Double);
if (tp == longType) {
_fullySpecifiedType.setType(control()->integerType(IntegerType::LongLong));
break;
} else if (tp == doubleType) {
_fullySpecifiedType.setType(control()->floatType(FloatType::LongDouble));
break;
} else if (tp != intType) {
translationUnit()->error(ast->specifier_token,
"duplicate data type in declaration");
}
}
_fullySpecifiedType.setType(control()->integerType(IntegerType::Long));
break;
case T_FLOAT:
if (_fullySpecifiedType.type())
translationUnit()->error(ast->specifier_token,
"duplicate data type in declaration");
_fullySpecifiedType.setType(control()->floatType(FloatType::Float));
break;
case T_DOUBLE:
if (Type *tp = _fullySpecifiedType.type()) {
IntegerType *longType = control()->integerType(IntegerType::Long);
if (tp == longType) {
_fullySpecifiedType.setType(control()->floatType(FloatType::LongDouble));
break;
}
translationUnit()->error(ast->specifier_token,
"duplicate data type in declaration");
}
_fullySpecifiedType.setType(control()->floatType(FloatType::Double));
break;
case T_VOID:
if (_fullySpecifiedType.type())
translationUnit()->error(ast->specifier_token,
"duplicate data type in declaration");
_fullySpecifiedType.setType(control()->voidType());
break;
default:
break;
} // switch
accept(ast->next);
return false;
}
bool CheckSpecifier::visit(ClassSpecifierAST *ast)
{
Name *className = semantic()->check(ast->name, _scope);
Class *klass = control()->newClass(ast->firstToken(), className);
unsigned classKey = tokenKind(ast->classkey_token);
if (classKey == T_CLASS)
klass->setClassKey(Class::ClassKey);
else if (classKey == T_STRUCT)
klass->setClassKey(Class::StructKey);
else if (classKey == T_UNION)
klass->setClassKey(Class::UnionKey);
klass->setVisibility(semantic()->currentVisibility());
_scope->enterSymbol(klass);
_fullySpecifiedType.setType(klass);
for (BaseSpecifierAST *base = ast->base_clause; base; base = base->next) {
Name *baseClassName = semantic()->check(base->name, _scope);
BaseClass *baseClass = control()->newBaseClass(ast->firstToken(), baseClassName);
if (base->token_virtual)
baseClass->setVirtual(true);
if (base->token_access_specifier) {
int accessSpecifier = tokenKind(base->token_access_specifier);
int visibility = semantic()->visibilityForAccessSpecifier(accessSpecifier);
baseClass->setVisibility(visibility);
}
klass->addBaseClass(baseClass);
}
int visibility = semantic()->visibilityForClassKey(classKey);
int previousVisibility = semantic()->switchVisibility(visibility);
int previousMethodKey = semantic()->switchMethodKey(Function::NormalMethod);
for (DeclarationAST *member = ast->member_specifiers;
member; member = member->next) {
semantic()->check(member, klass->members());
}
(void) semantic()->switchMethodKey(previousMethodKey);
(void) semantic()->switchVisibility(previousVisibility);
accept(ast->next);
return false;
}
bool CheckSpecifier::visit(NamedTypeSpecifierAST *ast)
{
Name *name = semantic()->check(ast->name, _scope);
_fullySpecifiedType.setType(control()->namedType(name));
accept(ast->next);
return false;
}
bool CheckSpecifier::visit(ElaboratedTypeSpecifierAST *ast)
{
Name *name = semantic()->check(ast->name, _scope);
_fullySpecifiedType.setType(control()->namedType(name));
accept(ast->next);
return false;
}
bool CheckSpecifier::visit(EnumSpecifierAST *ast)
{
Name *name = semantic()->check(ast->name, _scope);
Enum *e = control()->newEnum(ast->firstToken(), name);
e->setVisibility(semantic()->currentVisibility());
_scope->enterSymbol(e);
_fullySpecifiedType.setType(e);
for (EnumeratorAST *enumerator = ast->enumerators; enumerator;
enumerator = enumerator->next) {
Identifier *id = identifier(enumerator->identifier_token);
if (! id)
continue;
NameId *enumeratorName = control()->nameId(id);
Declaration *decl = control()->newDeclaration(enumerator->firstToken(),
enumeratorName);
e->addMember(decl);
}
accept(ast->next);
return false;
}
bool CheckSpecifier::visit(TypeofSpecifierAST *ast)
{
semantic()->check(ast->expression, _scope);
accept(ast->next);
return false;
}
bool CheckSpecifier::visit(AttributeSpecifierAST *)
{
return false;
}
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,95 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_CHECKSPECIFIER_H
#define CPLUSPLUS_CHECKSPECIFIER_H
#include "CPlusPlusForwardDeclarations.h"
#include "SemanticCheck.h"
#include "FullySpecifiedType.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT CheckSpecifier: public SemanticCheck
{
public:
CheckSpecifier(Semantic *semantic);
virtual ~CheckSpecifier();
FullySpecifiedType check(SpecifierAST *specifier, Scope *scope);
protected:
SpecifierAST *switchSpecifier(SpecifierAST *specifier);
FullySpecifiedType switchFullySpecifiedType(FullySpecifiedType type);
Scope *switchScope(Scope *scope);
using ASTVisitor::visit;
virtual bool visit(SimpleSpecifierAST *ast);
virtual bool visit(ClassSpecifierAST *ast);
virtual bool visit(NamedTypeSpecifierAST *ast);
virtual bool visit(ElaboratedTypeSpecifierAST *ast);
virtual bool visit(EnumSpecifierAST *ast);
virtual bool visit(TypeofSpecifierAST *ast);
virtual bool visit(AttributeSpecifierAST *ast);
private:
SpecifierAST *_specifier;
FullySpecifiedType _fullySpecifiedType;
Scope *_scope;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_CHECKSPECIFIER_H

View File

@@ -0,0 +1,239 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "CheckStatement.h"
#include "Semantic.h"
#include "AST.h"
#include "TranslationUnit.h"
#include "Scope.h"
#include "CoreTypes.h"
#include "Control.h"
#include "Symbols.h"
CPLUSPLUS_BEGIN_NAMESPACE
CheckStatement::CheckStatement(Semantic *semantic)
: SemanticCheck(semantic),
_statement(0),
_scope(0)
{ }
CheckStatement::~CheckStatement()
{ }
void CheckStatement::check(StatementAST *statement, Scope *scope)
{
Scope *previousScope = switchScope(scope);
StatementAST *previousStatement = switchStatement(statement);
accept(statement);
(void) switchStatement(previousStatement);
(void) switchScope(previousScope);
}
StatementAST *CheckStatement::switchStatement(StatementAST *statement)
{
StatementAST *previousStatement = _statement;
_statement = statement;
return previousStatement;
}
Scope *CheckStatement::switchScope(Scope *scope)
{
Scope *previousScope = _scope;
_scope = scope;
return previousScope;
}
bool CheckStatement::visit(CaseStatementAST *ast)
{
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
semantic()->check(ast->statement, _scope);
return false;
}
bool CheckStatement::visit(CompoundStatementAST *ast)
{
Block *block = control()->newBlock(ast->lbrace_token);
_scope->enterSymbol(block);
Scope *previousScope = switchScope(block->members());
for (StatementAST *it = ast->statements; it; it = it->next) {
semantic()->check(it, _scope);
}
(void) switchScope(previousScope);
return false;
}
bool CheckStatement::visit(DeclarationStatementAST *ast)
{
semantic()->check(ast->declaration, _scope);
return false;
}
bool CheckStatement::visit(DoStatementAST *ast)
{
semantic()->check(ast->statement, _scope);
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
return false;
}
bool CheckStatement::visit(ExpressionOrDeclarationStatementAST *ast)
{
// translationUnit()->warning(ast->firstToken(),
// "ambiguous expression or declaration statement");
if (ast->declaration)
semantic()->check(ast->declaration, _scope);
else
semantic()->check(ast->expression, _scope);
return false;
}
bool CheckStatement::visit(ExpressionStatementAST *ast)
{
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
return false;
}
bool CheckStatement::visit(ForStatementAST *ast)
{
Block *block = control()->newBlock(ast->for_token);
_scope->enterSymbol(block);
Scope *previousScope = switchScope(block->members());
semantic()->check(ast->initializer, _scope);
FullySpecifiedType condTy = semantic()->check(ast->condition, _scope);
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
semantic()->check(ast->statement, _scope);
(void) switchScope(previousScope);
return false;
}
bool CheckStatement::visit(IfStatementAST *ast)
{
Block *block = control()->newBlock(ast->if_token);
_scope->enterSymbol(block);
Scope *previousScope = switchScope(block->members());
FullySpecifiedType exprTy = semantic()->check(ast->condition, _scope);
semantic()->check(ast->statement, _scope);
semantic()->check(ast->else_statement, _scope);
(void) switchScope(previousScope);
return false;
}
bool CheckStatement::visit(LabeledStatementAST *ast)
{
semantic()->check(ast->statement, _scope);
return false;
}
bool CheckStatement::visit(BreakStatementAST *)
{
return false;
}
bool CheckStatement::visit(ContinueStatementAST *)
{
return false;
}
bool CheckStatement::visit(GotoStatementAST *)
{
return false;
}
bool CheckStatement::visit(ReturnStatementAST *ast)
{
FullySpecifiedType exprTy = semantic()->check(ast->expression, _scope);
return false;
}
bool CheckStatement::visit(SwitchStatementAST *ast)
{
Block *block = control()->newBlock(ast->switch_token);
_scope->enterSymbol(block);
Scope *previousScope = switchScope(block->members());
FullySpecifiedType condTy = semantic()->check(ast->condition, _scope);
semantic()->check(ast->statement, _scope);
(void) switchScope(previousScope);
return false;
}
bool CheckStatement::visit(TryBlockStatementAST *ast)
{
semantic()->check(ast->statement, _scope);
for (CatchClauseAST *c = ast->catch_clause_seq; c; c = c->next) {
semantic()->check(c, _scope);
}
return false;
}
bool CheckStatement::visit(CatchClauseAST *ast)
{
Block *block = control()->newBlock(ast->catch_token);
_scope->enterSymbol(block);
Scope *previousScope = switchScope(block->members());
semantic()->check(ast->exception_declaration, _scope);
semantic()->check(ast->statement, _scope);
(void) switchScope(previousScope);
return false;
}
bool CheckStatement::visit(WhileStatementAST *ast)
{
Block *block = control()->newBlock(ast->while_token);
_scope->enterSymbol(block);
Scope *previousScope = switchScope(block->members());
FullySpecifiedType condTy = semantic()->check(ast->condition, _scope);
semantic()->check(ast->statement, _scope);
(void) switchScope(previousScope);
return false;
}
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,102 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_CHECKSTATEMENT_H
#define CPLUSPLUS_CHECKSTATEMENT_H
#include "CPlusPlusForwardDeclarations.h"
#include "SemanticCheck.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT CheckStatement: public SemanticCheck
{
public:
CheckStatement(Semantic *semantic);
virtual ~CheckStatement();
void check(StatementAST *statement, Scope *scope);
protected:
StatementAST *switchStatement(StatementAST *statement);
Scope *switchScope(Scope *scope);
using ASTVisitor::visit;
virtual bool visit(CaseStatementAST *ast);
virtual bool visit(CompoundStatementAST *ast);
virtual bool visit(DeclarationStatementAST *ast);
virtual bool visit(DoStatementAST *ast);
virtual bool visit(ExpressionOrDeclarationStatementAST *ast);
virtual bool visit(ExpressionStatementAST *ast);
virtual bool visit(ForStatementAST *ast);
virtual bool visit(IfStatementAST *ast);
virtual bool visit(LabeledStatementAST *ast);
virtual bool visit(BreakStatementAST *ast);
virtual bool visit(ContinueStatementAST *ast);
virtual bool visit(GotoStatementAST *ast);
virtual bool visit(ReturnStatementAST *ast);
virtual bool visit(SwitchStatementAST *ast);
virtual bool visit(TryBlockStatementAST *ast);
virtual bool visit(CatchClauseAST *ast);
virtual bool visit(WhileStatementAST *ast);
private:
StatementAST *_statement;
Scope *_scope;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_CHECKSTATEMENT_H

View File

@@ -0,0 +1,636 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "Control.h"
#include "MemoryPool.h"
#include "Literals.h"
#include "LiteralTable.h"
#include "TranslationUnit.h"
#include "CoreTypes.h"
#include "Symbols.h"
#include "Names.h"
#include "Array.h"
#include <map> // ### replace me with LiteralTable
#include <string>
CPLUSPLUS_BEGIN_NAMESPACE
template <typename _Iterator>
static void delete_map_entries(_Iterator first, _Iterator last)
{
for (; first != last; ++first)
delete first->second;
}
template <typename _Map>
static void delete_map_entries(const _Map &m)
{ delete_map_entries(m.begin(), m.end()); }
template <typename _Iterator>
static void delete_array_entries(_Iterator first, _Iterator last)
{
for (; first != last; ++first)
delete *first;
}
template <typename _Array>
static void delete_array_entries(const _Array &a)
{ delete_array_entries(a.begin(), a.end()); }
class Control::Data
{
public:
Data(Control *control)
: control(control),
translationUnit(0),
diagnosticClient(0)
{ }
~Data()
{
// names
delete_map_entries(nameIds);
delete_map_entries(destructorNameIds);
delete_map_entries(operatorNameIds);
delete_map_entries(conversionNameIds);
delete_map_entries(qualifiedNameIds);
delete_map_entries(templateNameIds);
// types
delete_map_entries(integerTypes);
delete_map_entries(floatTypes);
delete_map_entries(pointerToMemberTypes);
delete_map_entries(pointerTypes);
delete_map_entries(referenceTypes);
delete_map_entries(arrayTypes);
delete_map_entries(namedTypes);
// symbols
delete_array_entries(declarations);
delete_array_entries(arguments);
delete_array_entries(functions);
delete_array_entries(baseClasses);
delete_array_entries(blocks);
delete_array_entries(classes);
delete_array_entries(namespaces);
delete_array_entries(usingNamespaceDirectives);
delete_array_entries(enums);
delete_array_entries(usingDeclarations);
}
NameId *findOrInsertNameId(Identifier *id)
{
if (! id)
return 0;
std::map<Identifier *, NameId *>::iterator it = nameIds.lower_bound(id);
if (it == nameIds.end() || it->first != id)
it = nameIds.insert(it, std::make_pair(id, new NameId(id)));
return it->second;
}
TemplateNameId *findOrInsertTemplateNameId(Identifier *id,
const std::vector<FullySpecifiedType> &templateArguments)
{
if (! id)
return 0;
const TemplateNameIdKey key(id, templateArguments);
std::map<TemplateNameIdKey, TemplateNameId *>::iterator it =
templateNameIds.lower_bound(key);
if (it == templateNameIds.end() || it->first != key) {
const FullySpecifiedType *args = 0;
if (templateArguments.size())
args = &templateArguments[0];
TemplateNameId *templ = new TemplateNameId(id, args,
templateArguments.size());
it = templateNameIds.insert(it, std::make_pair(key, templ));
}
return it->second;
}
DestructorNameId *findOrInsertDestructorNameId(Identifier *id)
{
if (! id)
return 0;
std::map<Identifier *, DestructorNameId *>::iterator it = destructorNameIds.lower_bound(id);
if (it == destructorNameIds.end() || it->first != id)
it = destructorNameIds.insert(it, std::make_pair(id, new DestructorNameId(id)));
return it->second;
}
OperatorNameId *findOrInsertOperatorNameId(int kind)
{
const int key(kind);
std::map<int, OperatorNameId *>::iterator it = operatorNameIds.lower_bound(key);
if (it == operatorNameIds.end() || it->first != key)
it = operatorNameIds.insert(it, std::make_pair(key, new OperatorNameId(kind)));
return it->second;
}
ConversionNameId *findOrInsertConversionNameId(FullySpecifiedType type)
{
std::map<FullySpecifiedType, ConversionNameId *>::iterator it =
conversionNameIds.lower_bound(type);
if (it == conversionNameIds.end() || it->first != type)
it = conversionNameIds.insert(it, std::make_pair(type, new ConversionNameId(type)));
return it->second;
}
QualifiedNameId *findOrInsertQualifiedNameId(const std::vector<Name *> &names, bool isGlobal)
{
const QualifiedNameIdKey key(names, isGlobal);
std::map<QualifiedNameIdKey, QualifiedNameId *>::iterator it =
qualifiedNameIds.lower_bound(key);
if (it == qualifiedNameIds.end() || it->first != key) {
QualifiedNameId *name = new QualifiedNameId(&names[0], names.size(), isGlobal);
it = qualifiedNameIds.insert(it, std::make_pair(key, name));
}
return it->second;
}
IntegerType *findOrInsertIntegerType(int kind)
{
const int key = int(kind);
std::map<int, IntegerType *>::iterator it = integerTypes.lower_bound(key);
if (it == integerTypes.end() || it->first != key)
it = integerTypes.insert(it, std::make_pair(key, new IntegerType(kind)));
return it->second;
}
FloatType *findOrInsertFloatType(int kind)
{
const int key = int(kind);
std::map<int, FloatType *>::iterator it = floatTypes.lower_bound(key);
if (it == floatTypes.end() || it->first != key)
it = floatTypes.insert(it, std::make_pair(key, new FloatType(kind)));
return it->second;
}
PointerToMemberType *findOrInsertPointerToMemberType(Name *memberName, FullySpecifiedType elementType)
{
const PointerToMemberTypeKey key(memberName, elementType);
std::map<PointerToMemberTypeKey, PointerToMemberType *>::iterator it =
pointerToMemberTypes.lower_bound(key);
if (it == pointerToMemberTypes.end() || it->first != key)
it = pointerToMemberTypes.insert(it, std::make_pair(key, new PointerToMemberType(memberName, elementType)));
return it->second;
}
PointerType *findOrInsertPointerType(FullySpecifiedType elementType)
{
std::map<FullySpecifiedType, PointerType *>::iterator it =
pointerTypes.lower_bound(elementType);
if (it == pointerTypes.end() || it->first != elementType)
it = pointerTypes.insert(it, std::make_pair(elementType, new PointerType(elementType)));
return it->second;
}
ReferenceType *findOrInsertReferenceType(FullySpecifiedType elementType)
{
std::map<FullySpecifiedType, ReferenceType *>::iterator it =
referenceTypes.lower_bound(elementType);
if (it == referenceTypes.end() || it->first != elementType)
it = referenceTypes.insert(it, std::make_pair(elementType, new ReferenceType(elementType)));
return it->second;
}
ArrayType *findOrInsertArrayType(FullySpecifiedType elementType, size_t size)
{
const ArrayKey key(elementType, size);
std::map<ArrayKey, ArrayType *>::iterator it =
arrayTypes.lower_bound(key);
if (it == arrayTypes.end() || it->first != key)
it = arrayTypes.insert(it, std::make_pair(key, new ArrayType(elementType, size)));
return it->second;
}
NamedType *findOrInsertNamedType(Name *name)
{
std::map<Name *, NamedType *>::iterator it = namedTypes.lower_bound(name);
if (it == namedTypes.end() || it->first != name)
it = namedTypes.insert(it, std::make_pair(name, new NamedType(name)));
return it->second;
}
Declaration *newDeclaration(unsigned sourceLocation, Name *name)
{
Declaration *declaration = new Declaration(translationUnit,
sourceLocation, name);
declarations.push_back(declaration);
return declaration;
}
Argument *newArgument(unsigned sourceLocation, Name *name)
{
Argument *argument = new Argument(translationUnit,
sourceLocation, name);
arguments.push_back(argument);
return argument;
}
Function *newFunction(unsigned sourceLocation, Name *name)
{
Function *function = new Function(translationUnit,
sourceLocation, name);
functions.push_back(function);
return function;
}
BaseClass *newBaseClass(unsigned sourceLocation, Name *name)
{
BaseClass *baseClass = new BaseClass(translationUnit,
sourceLocation, name);
baseClasses.push_back(baseClass);
return baseClass;
}
Block *newBlock(unsigned sourceLocation)
{
Block *block = new Block(translationUnit, sourceLocation);
blocks.push_back(block);
return block;
}
Class *newClass(unsigned sourceLocation, Name *name)
{
Class *klass = new Class(translationUnit,
sourceLocation, name);
classes.push_back(klass);
return klass;
}
Namespace *newNamespace(unsigned sourceLocation, Name *name)
{
Namespace *ns = new Namespace(translationUnit,
sourceLocation, name);
namespaces.push_back(ns);
return ns;
}
UsingNamespaceDirective *newUsingNamespaceDirective(unsigned sourceLocation, Name *name)
{
UsingNamespaceDirective *u = new UsingNamespaceDirective(translationUnit,
sourceLocation, name);
usingNamespaceDirectives.push_back(u);
return u;
}
Enum *newEnum(unsigned sourceLocation, Name *name)
{
Enum *e = new Enum(translationUnit,
sourceLocation, name);
enums.push_back(e);
return e;
}
UsingDeclaration *newUsingDeclaration(unsigned sourceLocation, Name *name)
{
UsingDeclaration *u = new UsingDeclaration(translationUnit,
sourceLocation, name);
usingDeclarations.push_back(u);
return u;
}
struct TemplateNameIdKey {
Identifier *id;
std::vector<FullySpecifiedType> templateArguments;
TemplateNameIdKey(Identifier *id, const std::vector<FullySpecifiedType> &templateArguments)
: id(id), templateArguments(templateArguments)
{ }
bool operator == (const TemplateNameIdKey &other) const
{ return id == other.id && templateArguments == other.templateArguments; }
bool operator != (const TemplateNameIdKey &other) const
{ return ! operator==(other); }
bool operator < (const TemplateNameIdKey &other) const
{
if (id == other.id)
return std::lexicographical_compare(templateArguments.begin(),
templateArguments.end(),
other.templateArguments.begin(),
other.templateArguments.end());
return id < other.id;
}
};
struct QualifiedNameIdKey {
std::vector<Name *> names;
bool isGlobal;
QualifiedNameIdKey(const std::vector<Name *> &names, bool isGlobal) :
names(names), isGlobal(isGlobal)
{ }
bool operator == (const QualifiedNameIdKey &other) const
{ return isGlobal == other.isGlobal && names == other.names; }
bool operator != (const QualifiedNameIdKey &other) const
{ return ! operator==(other); }
bool operator < (const QualifiedNameIdKey &other) const
{
if (isGlobal == other.isGlobal)
return std::lexicographical_compare(names.begin(), names.end(),
other.names.begin(), other.names.end());
return isGlobal < other.isGlobal;
}
};
struct ArrayKey {
FullySpecifiedType type;
size_t size;
ArrayKey() :
size(0)
{ }
ArrayKey(FullySpecifiedType type, size_t size) :
type(type), size(size)
{ }
bool operator == (const ArrayKey &other) const
{ return type == other.type && size == other.size; }
bool operator != (const ArrayKey &other) const
{ return ! operator==(other); }
bool operator < (const ArrayKey &other) const
{
if (type == other.type)
return size < other.size;
return type < other.type;
}
};
struct PointerToMemberTypeKey {
Name *memberName;
FullySpecifiedType type;
PointerToMemberTypeKey()
: memberName(0)
{ }
PointerToMemberTypeKey(Name *memberName, FullySpecifiedType type)
: memberName(memberName), type(type)
{ }
bool operator == (const PointerToMemberTypeKey &other) const
{ return memberName == other.memberName && type == other.type; }
bool operator != (const PointerToMemberTypeKey &other) const
{ return ! operator==(other); }
bool operator < (const PointerToMemberTypeKey &other) const
{
if (memberName == other.memberName)
return type < other.type;
return memberName < other.memberName;
}
};
Control *control;
TranslationUnit *translationUnit;
DiagnosticClient *diagnosticClient;
LiteralTable<Identifier> identifiers;
LiteralTable<StringLiteral> stringLiterals;
LiteralTable<NumericLiteral> numericLiterals;
LiteralTable<StringLiteral> fileNames;
// ### replace std::map with lookup tables. ASAP!
// names
std::map<Identifier *, NameId *> nameIds;
std::map<Identifier *, DestructorNameId *> destructorNameIds;
std::map<int, OperatorNameId *> operatorNameIds;
std::map<FullySpecifiedType, ConversionNameId *> conversionNameIds;
std::map<TemplateNameIdKey, TemplateNameId *> templateNameIds;
std::map<QualifiedNameIdKey, QualifiedNameId *> qualifiedNameIds;
// types
VoidType voidType;
std::map<int, IntegerType *> integerTypes;
std::map<int, FloatType *> floatTypes;
std::map<PointerToMemberTypeKey, PointerToMemberType *> pointerToMemberTypes;
std::map<FullySpecifiedType, PointerType *> pointerTypes;
std::map<FullySpecifiedType, ReferenceType *> referenceTypes;
std::map<ArrayKey, ArrayType *> arrayTypes;
std::map<Name *, NamedType *> namedTypes;
// symbols
std::vector<Declaration *> declarations;
std::vector<Argument *> arguments;
std::vector<Function *> functions;
std::vector<BaseClass *> baseClasses;
std::vector<Block *> blocks;
std::vector<Class *> classes;
std::vector<Namespace *> namespaces;
std::vector<UsingNamespaceDirective *> usingNamespaceDirectives;
std::vector<Enum *> enums;
std::vector<UsingDeclaration *> usingDeclarations;
};
Control::Control()
{ d = new Data(this); }
Control::~Control()
{ delete d; }
TranslationUnit *Control::translationUnit() const
{ return d->translationUnit; }
TranslationUnit *Control::switchTranslationUnit(TranslationUnit *unit)
{
TranslationUnit *previousTranslationUnit = d->translationUnit;
d->translationUnit = unit;
return previousTranslationUnit;
}
DiagnosticClient *Control::diagnosticClient() const
{ return d->diagnosticClient; }
void Control::setDiagnosticClient(DiagnosticClient *diagnosticClient)
{ d->diagnosticClient = diagnosticClient; }
Identifier *Control::findOrInsertIdentifier(const char *chars, unsigned size)
{ return d->identifiers.findOrInsertLiteral(chars, size); }
Identifier *Control::findOrInsertIdentifier(const char *chars)
{
unsigned length = std::char_traits<char>::length(chars);
return findOrInsertIdentifier(chars, length);
}
Control::IdentifierIterator Control::firstIdentifier() const
{ return d->identifiers.begin(); }
Control::IdentifierIterator Control::lastIdentifier() const
{ return d->identifiers.end(); }
StringLiteral *Control::findOrInsertStringLiteral(const char *chars, unsigned size)
{ return d->stringLiterals.findOrInsertLiteral(chars, size); }
StringLiteral *Control::findOrInsertStringLiteral(const char *chars)
{
unsigned length = std::char_traits<char>::length(chars);
return findOrInsertStringLiteral(chars, length);
}
NumericLiteral *Control::findOrInsertNumericLiteral(const char *chars, unsigned size)
{ return d->numericLiterals.findOrInsertLiteral(chars, size); }
NumericLiteral *Control::findOrInsertNumericLiteral(const char *chars)
{
unsigned length = std::char_traits<char>::length(chars);
return findOrInsertNumericLiteral(chars, length);
}
unsigned Control::fileNameCount() const
{ return d->fileNames.size(); }
StringLiteral *Control::fileNameAt(unsigned index) const
{ return d->fileNames.at(index); }
StringLiteral *Control::findOrInsertFileName(const char *chars, unsigned size)
{ return d->fileNames.findOrInsertLiteral(chars, size); }
StringLiteral *Control::findOrInsertFileName(const char *chars)
{
unsigned length = std::char_traits<char>::length(chars);
return findOrInsertFileName(chars, length);
}
NameId *Control::nameId(Identifier *id)
{ return d->findOrInsertNameId(id); }
TemplateNameId *Control::templateNameId(Identifier *id,
FullySpecifiedType *const args,
unsigned argv)
{
std::vector<FullySpecifiedType> templateArguments(args, args + argv);
return d->findOrInsertTemplateNameId(id, templateArguments);
}
DestructorNameId *Control::destructorNameId(Identifier *id)
{ return d->findOrInsertDestructorNameId(id); }
OperatorNameId *Control::operatorNameId(int kind)
{ return d->findOrInsertOperatorNameId(kind); }
ConversionNameId *Control::conversionNameId(FullySpecifiedType type)
{ return d->findOrInsertConversionNameId(type); }
QualifiedNameId *Control::qualifiedNameId(Name *const *names,
unsigned nameCount,
bool isGlobal)
{
std::vector<Name *> classOrNamespaceNames(names, names + nameCount);
return d->findOrInsertQualifiedNameId(classOrNamespaceNames, isGlobal);
}
VoidType *Control::voidType()
{ return &d->voidType; }
IntegerType *Control::integerType(int kind)
{ return d->findOrInsertIntegerType(kind); }
FloatType *Control::floatType(int kind)
{ return d->findOrInsertFloatType(kind); }
PointerToMemberType *Control::pointerToMemberType(Name *memberName, FullySpecifiedType elementType)
{ return d->findOrInsertPointerToMemberType(memberName, elementType); }
PointerType *Control::pointerType(FullySpecifiedType elementType)
{ return d->findOrInsertPointerType(elementType); }
ReferenceType *Control::referenceType(FullySpecifiedType elementType)
{ return d->findOrInsertReferenceType(elementType); }
ArrayType *Control::arrayType(FullySpecifiedType elementType, size_t size)
{ return d->findOrInsertArrayType(elementType, size); }
NamedType *Control::namedType(Name *name)
{ return d->findOrInsertNamedType(name); }
Argument *Control::newArgument(unsigned sourceLocation, Name *name)
{ return d->newArgument(sourceLocation, name); }
Function *Control::newFunction(unsigned sourceLocation, Name *name)
{ return d->newFunction(sourceLocation, name); }
Namespace *Control::newNamespace(unsigned sourceLocation, Name *name)
{ return d->newNamespace(sourceLocation, name); }
BaseClass *Control::newBaseClass(unsigned sourceLocation, Name *name)
{ return d->newBaseClass(sourceLocation, name); }
Class *Control::newClass(unsigned sourceLocation, Name *name)
{ return d->newClass(sourceLocation, name); }
Enum *Control::newEnum(unsigned sourceLocation, Name *name)
{ return d->newEnum(sourceLocation, name); }
Block *Control::newBlock(unsigned sourceLocation)
{ return d->newBlock(sourceLocation); }
Declaration *Control::newDeclaration(unsigned sourceLocation, Name *name)
{ return d->newDeclaration(sourceLocation, name); }
UsingNamespaceDirective *Control::newUsingNamespaceDirective(unsigned sourceLocation,
Name *name)
{ return d->newUsingNamespaceDirective(sourceLocation, name); }
UsingDeclaration *Control::newUsingDeclaration(unsigned sourceLocation, Name *name)
{ return d->newUsingDeclaration(sourceLocation, name); }
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,180 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_CONTROL_H
#define CPLUSPLUS_CONTROL_H
#include "CPlusPlusForwardDeclarations.h"
#include <cstddef>
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT Control
{
public:
Control();
~Control();
TranslationUnit *translationUnit() const;
TranslationUnit *switchTranslationUnit(TranslationUnit *unit);
DiagnosticClient *diagnosticClient() const;
void setDiagnosticClient(DiagnosticClient *diagnosticClient);
/// Returns the canonical name id.
NameId *nameId(Identifier *id);
/// Returns the canonical template name id.
TemplateNameId *templateNameId(Identifier *id,
FullySpecifiedType *const args = 0,
unsigned argc = 0);
/// Returns the canonical destructor name id.
DestructorNameId *destructorNameId(Identifier *id);
/// Returns the canonical operator name id.
OperatorNameId *operatorNameId(int operatorId);
/// Returns the canonical conversion name id.
ConversionNameId *conversionNameId(FullySpecifiedType type);
/// Returns the canonical qualified name id.
QualifiedNameId *qualifiedNameId(Name *const *names,
unsigned nameCount,
bool isGlobal = false);
/// Returns a Type object of type VoidType.
VoidType *voidType();
/// Returns a Type object of type IntegerType.
IntegerType *integerType(int integerId);
/// Returns a Type object of type FloatType.
FloatType *floatType(int floatId);
/// Returns a Type object of type PointertoMemberType.
PointerToMemberType *pointerToMemberType(Name *memberName,
FullySpecifiedType elementType);
/// Returns a Type object of type PointerType.
PointerType *pointerType(FullySpecifiedType elementType);
/// Returns a Type object of type ReferenceType.
ReferenceType *referenceType(FullySpecifiedType elementType);
/// Retruns a Type object of type ArrayType.
ArrayType *arrayType(FullySpecifiedType elementType, size_t size = 0);
/// Returns a Type object of type NamedType.
NamedType *namedType(Name *name);
/// Creates a new Declaration symbol.
Declaration *newDeclaration(unsigned sourceLocation, Name *name = 0);
/// Creates a new Argument symbol.
Argument *newArgument(unsigned sourceLocation, Name *name = 0);
/// Creates a new Function symbol.
Function *newFunction(unsigned sourceLocation, Name *name = 0);
/// Creates a new Namespace symbol.
Namespace *newNamespace(unsigned sourceLocation, Name *name = 0);
/// Creates a new BaseClass symbol.
BaseClass *newBaseClass(unsigned sourceLocation, Name *name = 0);
/// Creates a new Class symbol.
Class *newClass(unsigned sourceLocation, Name *name = 0);
/// Creates a new Enum symbol.
Enum *newEnum(unsigned sourceLocation, Name *name = 0);
/// Creates a new Block symbol.
Block *newBlock(unsigned sourceLocation);
/// Creates a new UsingNamespaceDirective symbol.
UsingNamespaceDirective *newUsingNamespaceDirective(unsigned sourceLocation, Name *name = 0);
/// Creates a new UsingDeclaration symbol.
UsingDeclaration *newUsingDeclaration(unsigned sourceLocation, Name *name = 0);
Identifier *findOrInsertIdentifier(const char *chars, unsigned size);
Identifier *findOrInsertIdentifier(const char *chars);
typedef const Identifier *const *IdentifierIterator;
IdentifierIterator firstIdentifier() const;
IdentifierIterator lastIdentifier() const;
StringLiteral *findOrInsertStringLiteral(const char *chars, unsigned size);
StringLiteral *findOrInsertStringLiteral(const char *chars);
NumericLiteral *findOrInsertNumericLiteral(const char *chars, unsigned size);
NumericLiteral *findOrInsertNumericLiteral(const char *chars);
StringLiteral *findOrInsertFileName(const char *chars, unsigned size);
StringLiteral *findOrInsertFileName(const char *chars);
unsigned fileNameCount() const;
StringLiteral *fileNameAt(unsigned index) const;
private:
class Data;
friend class Data;
Data *d;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_CONTROL_H

View File

@@ -0,0 +1,237 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "CoreTypes.h"
#include "TypeVisitor.h"
#include "Names.h"
#include <algorithm>
CPLUSPLUS_BEGIN_NAMESPACE
bool VoidType::isEqualTo(const Type *other) const
{
const VoidType *o = other->asVoidType();
return o != 0;
}
void VoidType::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }
PointerToMemberType::PointerToMemberType(Name *memberName, FullySpecifiedType elementType)
: _memberName(memberName),
_elementType(elementType)
{ }
PointerToMemberType::~PointerToMemberType()
{ }
Name *PointerToMemberType::memberName() const
{ return _memberName; }
FullySpecifiedType PointerToMemberType::elementType() const
{ return _elementType; }
bool PointerToMemberType::isEqualTo(const Type *other) const
{
const PointerToMemberType *o = other->asPointerToMemberType();
if (! o)
return false;
else if (! _memberName->isEqualTo(o->_memberName))
return false;
return _elementType.isEqualTo(o->_elementType);
}
void PointerToMemberType::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }
PointerType::PointerType(FullySpecifiedType elementType)
: _elementType(elementType)
{ }
PointerType::~PointerType()
{ }
bool PointerType::isEqualTo(const Type *other) const
{
const PointerType *o = other->asPointerType();
if (! o)
return false;
return _elementType.isEqualTo(o->_elementType);
}
void PointerType::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }
FullySpecifiedType PointerType::elementType() const
{ return _elementType; }
ReferenceType::ReferenceType(FullySpecifiedType elementType)
: _elementType(elementType)
{ }
ReferenceType::~ReferenceType()
{ }
bool ReferenceType::isEqualTo(const Type *other) const
{
const ReferenceType *o = other->asReferenceType();
if (! o)
return false;
return _elementType.isEqualTo(o->_elementType);
}
void ReferenceType::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }
FullySpecifiedType ReferenceType::elementType() const
{ return _elementType; }
IntegerType::IntegerType(int kind)
: _kind(kind)
{ }
IntegerType::~IntegerType()
{ }
bool IntegerType::isEqualTo(const Type *other) const
{
const IntegerType *o = other->asIntegerType();
if (! o)
return false;
return _kind == o->_kind;
}
void IntegerType::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }
int IntegerType::kind() const
{ return _kind; }
FloatType::FloatType(int kind)
: _kind(kind)
{ }
FloatType::~FloatType()
{ }
void FloatType::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }
int FloatType::kind() const
{ return _kind; }
bool FloatType::isEqualTo(const Type *other) const
{
const FloatType *o = other->asFloatType();
if (! o)
return false;
return _kind == o->_kind;
}
ArrayType::ArrayType(FullySpecifiedType elementType, size_t size)
: _elementType(elementType), _size(size)
{ }
ArrayType::~ArrayType()
{ }
bool ArrayType::isEqualTo(const Type *other) const
{
const ArrayType *o = other->asArrayType();
if (! o)
return false;
else if (_size != o->_size)
return false;
return _elementType.isEqualTo(o->_elementType);
}
void ArrayType::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }
FullySpecifiedType ArrayType::elementType() const
{ return _elementType; }
size_t ArrayType::size() const
{ return _size; }
NamedType::NamedType(Name *name)
: _name(name)
{ }
NamedType::~NamedType()
{ }
Name *NamedType::name() const
{ return _name; }
bool NamedType::isEqualTo(const Type *other) const
{
const NamedType *o = other->asNamedType();
if (! o)
return false;
Name *name = _name;
if (QualifiedNameId *q = name->asQualifiedNameId())
name = q->unqualifiedNameId();
Name *otherName = o->name();
if (QualifiedNameId *q = otherName->asQualifiedNameId())
otherName = q->unqualifiedNameId();
return name->isEqualTo(otherName);
}
void NamedType::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,217 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_CORETYPES_H
#define CPLUSPLUS_CORETYPES_H
#include "CPlusPlusForwardDeclarations.h"
#include "Type.h"
#include "FullySpecifiedType.h"
#include <cstddef>
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT VoidType: public Type
{
public:
virtual bool isEqualTo(const Type *other) const;
protected:
virtual void accept0(TypeVisitor *visitor);
};
class CPLUSPLUS_EXPORT IntegerType: public Type
{
public:
enum Kind {
Char,
WideChar,
Bool,
Short,
Int,
Long,
LongLong
};
public:
IntegerType(int kind);
virtual ~IntegerType();
int kind() const;
virtual bool isEqualTo(const Type *other) const;
protected:
virtual void accept0(TypeVisitor *visitor);
private:
int _kind;
};
class CPLUSPLUS_EXPORT FloatType: public Type
{
public:
enum Kind {
Float,
Double,
LongDouble
};
public:
FloatType(int kind);
virtual ~FloatType();
int kind() const;
virtual bool isEqualTo(const Type *other) const;
protected:
virtual void accept0(TypeVisitor *visitor);
private:
int _kind;
};
class CPLUSPLUS_EXPORT PointerType: public Type
{
public:
PointerType(FullySpecifiedType elementType);
virtual ~PointerType();
FullySpecifiedType elementType() const;
virtual bool isEqualTo(const Type *other) const;
protected:
virtual void accept0(TypeVisitor *visitor);
private:
FullySpecifiedType _elementType;
};
class CPLUSPLUS_EXPORT PointerToMemberType: public Type
{
public:
PointerToMemberType(Name *memberName, FullySpecifiedType elementType);
virtual ~PointerToMemberType();
Name *memberName() const;
FullySpecifiedType elementType() const;
virtual bool isEqualTo(const Type *other) const;
protected:
virtual void accept0(TypeVisitor *visitor);
private:
Name *_memberName;
FullySpecifiedType _elementType;
};
class CPLUSPLUS_EXPORT ReferenceType: public Type
{
public:
ReferenceType(FullySpecifiedType elementType);
virtual ~ReferenceType();
FullySpecifiedType elementType() const;
virtual bool isEqualTo(const Type *other) const;
protected:
virtual void accept0(TypeVisitor *visitor);
private:
FullySpecifiedType _elementType;
};
class CPLUSPLUS_EXPORT ArrayType: public Type
{
public:
ArrayType(FullySpecifiedType elementType, size_t size);
virtual ~ArrayType();
FullySpecifiedType elementType() const;
size_t size() const;
virtual bool isEqualTo(const Type *other) const;
protected:
virtual void accept0(TypeVisitor *visitor);
private:
FullySpecifiedType _elementType;
size_t _size;
};
class CPLUSPLUS_EXPORT NamedType: public Type
{
public:
NamedType(Name *name);
virtual ~NamedType();
Name *name() const;
virtual bool isEqualTo(const Type *other) const;
protected:
virtual void accept0(TypeVisitor *visitor);
private:
Name *_name;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_CORETYPES_H

View File

@@ -0,0 +1,63 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "DiagnosticClient.h"
CPLUSPLUS_BEGIN_NAMESPACE
DiagnosticClient::DiagnosticClient()
{ }
DiagnosticClient::~DiagnosticClient()
{ }
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,86 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_DIAGNOSTICCLIENT_H
#define CPLUSPLUS_DIAGNOSTICCLIENT_H
#include "CPlusPlusForwardDeclarations.h"
#include <cstdarg>
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT DiagnosticClient
{
DiagnosticClient(const DiagnosticClient &other);
void operator =(const DiagnosticClient &other);
public:
enum Level {
Warning,
Error,
Fatal
};
DiagnosticClient();
virtual ~DiagnosticClient();
virtual void report(int level,
StringLiteral *fileName,
unsigned line, unsigned column,
const char *format, va_list ap) = 0;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_DIAGNOSTICCLIENT_H

View File

@@ -0,0 +1,204 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "FullySpecifiedType.h"
#include "Type.h"
CPLUSPLUS_BEGIN_NAMESPACE
FullySpecifiedType::FullySpecifiedType(Type *type) :
_type(type), _flags(0)
{ }
FullySpecifiedType::~FullySpecifiedType()
{ }
bool FullySpecifiedType::isValid() const
{ return _type != 0; }
Type *FullySpecifiedType::type() const
{ return _type; }
void FullySpecifiedType::setType(Type *type)
{ _type = type; }
FullySpecifiedType FullySpecifiedType::qualifiedType() const
{
FullySpecifiedType ty = *this;
ty.setFriend(false);
ty.setRegister(false);
ty.setStatic(false);
ty.setExtern(false);
ty.setMutable(false);
ty.setTypedef(false);
return ty;
}
bool FullySpecifiedType::isConst() const
{ return _isConst; }
void FullySpecifiedType::setConst(bool isConst)
{ _isConst = isConst; }
bool FullySpecifiedType::isVolatile() const
{ return _isVolatile; }
void FullySpecifiedType::setVolatile(bool isVolatile)
{ _isVolatile = isVolatile; }
bool FullySpecifiedType::isSigned() const
{ return _isSigned; }
void FullySpecifiedType::setSigned(bool isSigned)
{ _isSigned = isSigned; }
bool FullySpecifiedType::isUnsigned() const
{ return _isUnsigned; }
void FullySpecifiedType::setUnsigned(bool isUnsigned)
{ _isUnsigned = isUnsigned; }
bool FullySpecifiedType::isFriend() const
{ return _isFriend; }
void FullySpecifiedType::setFriend(bool isFriend)
{ _isFriend = isFriend; }
bool FullySpecifiedType::isRegister() const
{ return _isRegister; }
void FullySpecifiedType::setRegister(bool isRegister)
{ _isRegister = isRegister; }
bool FullySpecifiedType::isStatic() const
{ return _isStatic; }
void FullySpecifiedType::setStatic(bool isStatic)
{ _isStatic = isStatic; }
bool FullySpecifiedType::isExtern() const
{ return _isExtern; }
void FullySpecifiedType::setExtern(bool isExtern)
{ _isExtern = isExtern; }
bool FullySpecifiedType::isMutable() const
{ return _isMutable; }
void FullySpecifiedType::setMutable(bool isMutable)
{ _isMutable = isMutable; }
bool FullySpecifiedType::isTypedef() const
{ return _isTypedef; }
void FullySpecifiedType::setTypedef(bool isTypedef)
{ _isTypedef = isTypedef; }
bool FullySpecifiedType::isInline() const
{ return _isInline; }
void FullySpecifiedType::setInline(bool isInline)
{ _isInline = isInline; }
bool FullySpecifiedType::isVirtual() const
{ return _isVirtual; }
void FullySpecifiedType::setVirtual(bool isVirtual)
{ _isVirtual = isVirtual; }
bool FullySpecifiedType::isExplicit() const
{ return _isExplicit; }
void FullySpecifiedType::setExplicit(bool isExplicit)
{ _isExplicit = isExplicit; }
bool FullySpecifiedType::isEqualTo(const FullySpecifiedType &other) const
{
if (_flags != other._flags)
return false;
if (_type == other._type)
return true;
else if (! _type)
return false;
else
return _type->isEqualTo(other._type);
}
Type &FullySpecifiedType::operator*()
{ return *_type; }
FullySpecifiedType::operator bool() const
{ return _type != 0; }
const Type &FullySpecifiedType::operator*() const
{ return *_type; }
Type *FullySpecifiedType::operator->()
{ return _type; }
const Type *FullySpecifiedType::operator->() const
{ return _type; }
bool FullySpecifiedType::operator == (const FullySpecifiedType &other) const
{ return _type == other._type && _flags == other._flags; }
bool FullySpecifiedType::operator != (const FullySpecifiedType &other) const
{ return ! operator ==(other); }
bool FullySpecifiedType::operator < (const FullySpecifiedType &other) const
{
if (_type == other._type)
return _flags < other._flags;
return _type < other._type;
}
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,158 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_FULLYSPECIFIEDTYPE_H
#define CPLUSPLUS_FULLYSPECIFIEDTYPE_H
#include "CPlusPlusForwardDeclarations.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT FullySpecifiedType
{
public:
FullySpecifiedType(Type *type = 0);
~FullySpecifiedType();
bool isValid() const;
operator bool() const;
Type *type() const;
void setType(Type *type);
FullySpecifiedType qualifiedType() const;
bool isConst() const;
void setConst(bool isConst);
bool isVolatile() const;
void setVolatile(bool isVolatile);
bool isSigned() const;
void setSigned(bool isSigned);
bool isUnsigned() const;
void setUnsigned(bool isUnsigned);
bool isFriend() const;
void setFriend(bool isFriend);
bool isRegister() const;
void setRegister(bool isRegister);
bool isStatic() const;
void setStatic(bool isStatic);
bool isExtern() const;
void setExtern(bool isExtern);
bool isMutable() const;
void setMutable(bool isMutable);
bool isTypedef() const;
void setTypedef(bool isTypedef);
bool isInline() const;
void setInline(bool isInline);
bool isVirtual() const;
void setVirtual(bool isVirtual);
bool isExplicit() const;
void setExplicit(bool isExplicit);
bool isEqualTo(const FullySpecifiedType &other) const;
Type &operator*();
const Type &operator*() const;
Type *operator->();
const Type *operator->() const;
bool operator == (const FullySpecifiedType &other) const;
bool operator != (const FullySpecifiedType &other) const;
bool operator < (const FullySpecifiedType &other) const;
private:
Type *_type;
union {
unsigned _flags;
struct {
// cv qualifiers
unsigned _isConst: 1;
unsigned _isVolatile: 1;
// sign
unsigned _isSigned: 1;
unsigned _isUnsigned: 1;
// storage class specifiers
unsigned _isFriend: 1;
unsigned _isRegister: 1;
unsigned _isStatic: 1;
unsigned _isExtern: 1;
unsigned _isMutable: 1;
unsigned _isTypedef: 1;
// function specifiers
unsigned _isInline: 1;
unsigned _isVirtual: 1;
unsigned _isExplicit: 1;
};
};
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_FULLYSPECIFIEDTYPE_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,86 @@
#include "Lexer.h"
#include "Token.h"
%token-prefix=T_
%toupper
%no-enums
%namespace=Lexer
%%
__asm
__asm__
__attribute
__attribute__
__const
__const__
__inline
__inline__
__typeof
__typeof__
__volatile
__volatile__
asm
auto
bool
break
case
catch
char
class
const
const_cast
continue
default
delete
do
double
dynamic_cast
else
enum
explicit
export
extern
false
float
for
friend
goto
if
inline
int
long
mutable
namespace
new
operator
private
protected
public
register
reinterpret_cast
return
short
signed
sizeof
static
static_cast
struct
switch
template
this
throw
true
try
typedef
typeid
typename
typeof
union
unsigned
using
virtual
void
volatile
wchar_t
while

View File

@@ -0,0 +1,680 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "Lexer.h"
#include "Control.h"
#include "TranslationUnit.h"
#include <cctype>
#include <cassert>
CPLUSPLUS_BEGIN_NAMESPACE
Lexer::Lexer(TranslationUnit *unit)
: _translationUnit(unit),
_state(Lexer::DefaultState),
_flags(0),
_currentLine(1)
{
_scanKeywords = true;
setSource(_translationUnit->firstSourceChar(),
_translationUnit->lastSourceChar());
}
Lexer::Lexer(const char *firstChar, const char *lastChar)
: _translationUnit(0),
_state(Lexer::DefaultState),
_flags(0),
_currentLine(1)
{
_scanKeywords = true;
setSource(firstChar, lastChar);
}
Lexer::~Lexer()
{ }
TranslationUnit *Lexer::translationUnit() const
{ return _translationUnit; }
Control *Lexer::control() const
{
if (_translationUnit)
return _translationUnit->control();
return 0;
}
void Lexer::setSource(const char *firstChar, const char *lastChar)
{
_firstChar = firstChar;
_lastChar = lastChar;
_currentChar = _firstChar - 1;
_tokenStart = _currentChar;
_yychar = '\n';
}
void Lexer::setStartWithNewline(bool enabled)
{
if (enabled)
_yychar = '\n';
else
_yychar = ' ';
}
int Lexer::state() const
{ return _state; }
void Lexer::setState(int state)
{ _state = state; }
bool Lexer::qtMocRunEnabled() const
{ return _qtMocRunEnabled; }
void Lexer::setQtMocRunEnabled(bool onoff)
{ _qtMocRunEnabled = onoff; }
bool Lexer::objCEnabled() const
{ return _objCEnabled; }
void Lexer::setObjCEnabled(bool onoff)
{ _objCEnabled = onoff; }
bool Lexer::isIncremental() const
{ return _isIncremental; }
void Lexer::setIncremental(bool isIncremental)
{ _isIncremental = isIncremental; }
bool Lexer::scanCommentTokens() const
{ return _scanCommentTokens; }
void Lexer::setScanCommentTokens(bool onoff)
{ _scanCommentTokens = onoff; }
bool Lexer::scanKeywords() const
{ return _scanKeywords; }
void Lexer::setScanKeywords(bool onoff)
{ _scanKeywords = onoff; }
void Lexer::setScanAngleStringLiteralTokens(bool onoff)
{ _scanAngleStringLiteralTokens = onoff; }
void Lexer::pushLineStartOffset()
{
++_currentLine;
if (_translationUnit)
_translationUnit->pushLineOffset(_currentChar - _firstChar);
}
unsigned Lexer::tokenOffset() const
{ return _tokenStart - _firstChar; }
unsigned Lexer::tokenLength() const
{ return _currentChar - _tokenStart; }
const char *Lexer::tokenBegin() const
{ return _tokenStart; }
const char *Lexer::tokenEnd() const
{ return _currentChar; }
unsigned Lexer::currentLine() const
{ return _currentLine; }
void Lexer::scan(Token *tok)
{
tok->reset();
scan_helper(tok);
tok->length = _currentChar - _tokenStart;
}
void Lexer::scan_helper(Token *tok)
{
_Lagain:
while (_yychar && std::isspace(_yychar)) {
if (_yychar == '\n')
tok->newline = true;
else
tok->whitespace = true;
yyinp();
}
if (! _translationUnit)
tok->lineno = _currentLine;
_tokenStart = _currentChar;
tok->offset = _currentChar - _firstChar;
if (_state == MultiLineCommentState) {
if (! _yychar) {
tok->kind = T_EOF_SYMBOL;
return;
}
while (_yychar) {
if (_yychar != '*')
yyinp();
else {
yyinp();
if (_yychar == '/') {
yyinp();
_state = DefaultState;
break;
}
}
}
if (! _scanCommentTokens)
goto _Lagain;
tok->kind = T_COMMENT;
return; // done
}
if (! _yychar) {
tok->kind = T_EOF_SYMBOL;
return;
}
unsigned char ch = _yychar;
yyinp();
switch (ch) {
case '\\':
while (_yychar != '\n' && std::isspace(_yychar))
yyinp();
// ### assert(! _yychar || _yychar == '\n');
if (_yychar == '\n') {
tok->joined = true;
tok->newline = false;
yyinp();
}
goto _Lagain;
case '"': case '\'': {
const char quote = ch;
tok->kind = quote == '"'
? T_STRING_LITERAL
: T_CHAR_LITERAL;
const char *yytext = _currentChar;
while (_yychar && _yychar != quote) {
if (_yychar != '\\')
yyinp();
else {
yyinp(); // skip `\\'
if (_yychar)
yyinp();
}
}
// assert(_yychar == quote);
int yylen = _currentChar - yytext;
if (_yychar == quote)
yyinp();
if (control())
tok->string = control()->findOrInsertStringLiteral(yytext, yylen);
} break;
case '{':
tok->kind = T_LBRACE;
break;
case '}':
tok->kind = T_RBRACE;
break;
case '[':
tok->kind = T_LBRACKET;
break;
case ']':
tok->kind = T_RBRACKET;
break;
case '#':
if (_yychar == '#') {
tok->kind = T_POUND_POUND;
yyinp();
} else {
tok->kind = T_POUND;
}
break;
case '(':
tok->kind = T_LPAREN;
break;
case ')':
tok->kind = T_RPAREN;
break;
case ';':
tok->kind = T_SEMICOLON;
break;
case ':':
if (_yychar == ':') {
yyinp();
tok->kind = T_COLON_COLON;
} else {
tok->kind = T_COLON;
}
break;
case '.':
if (_yychar == '*') {
yyinp();
tok->kind = T_DOT_STAR;
} else if (_yychar == '.') {
yyinp();
// ### assert(_yychar);
if (_yychar == '.') {
yyinp();
tok->kind = T_DOT_DOT_DOT;
} else {
tok->kind = T_ERROR;
}
} else if (std::isdigit(_yychar)) {
const char *yytext = _currentChar - 2;
do {
if (_yychar == 'e' || _yychar == 'E') {
yyinp();
if (_yychar == '-' || _yychar == '+') {
yyinp();
// ### assert(std::isdigit(_yychar));
}
} else if (std::isalnum(_yychar) || _yychar == '.') {
yyinp();
} else {
break;
}
} while (_yychar);
int yylen = _currentChar - yytext;
tok->kind = T_INT_LITERAL;
if (control())
tok->number = control()->findOrInsertNumericLiteral(yytext, yylen);
} else {
tok->kind = T_DOT;
}
break;
case '?':
tok->kind = T_QUESTION;
break;
case '+':
if (_yychar == '+') {
yyinp();
tok->kind = T_PLUS_PLUS;
} else if (_yychar == '=') {
yyinp();
tok->kind = T_PLUS_EQUAL;
} else {
tok->kind = T_PLUS;
}
break;
case '-':
if (_yychar == '-') {
yyinp();
tok->kind = T_MINUS_MINUS;
} else if (_yychar == '=') {
yyinp();
tok->kind = T_MINUS_EQUAL;
} else if (_yychar == '>') {
yyinp();
if (_yychar == '*') {
yyinp();
tok->kind = T_ARROW_STAR;
} else {
tok->kind = T_ARROW;
}
} else {
tok->kind = T_MINUS;
}
break;
case '*':
if (_yychar == '=') {
yyinp();
tok->kind = T_STAR_EQUAL;
} else {
tok->kind = T_STAR;
}
break;
case '/':
if (_yychar == '/') {
do {
yyinp();
} while (_yychar && _yychar != '\n');
if (! _scanCommentTokens)
goto _Lagain;
tok->kind = T_COMMENT;
} else if (_yychar == '*') {
yyinp();
while (_yychar) {
if (_yychar != '*') {
yyinp();
} else {
yyinp();
if (_yychar == '/')
break;
}
}
if (_yychar)
yyinp();
else
_state = MultiLineCommentState;
if (! _scanCommentTokens)
goto _Lagain;
tok->kind = T_COMMENT;
} else if (_yychar == '=') {
yyinp();
tok->kind = T_SLASH_EQUAL;
} else {
tok->kind = T_SLASH;
}
break;
case '%':
if (_yychar == '=') {
yyinp();
tok->kind = T_PERCENT_EQUAL;
} else {
tok->kind = T_PERCENT;
}
break;
case '^':
if (_yychar == '=') {
yyinp();
tok->kind = T_CARET_EQUAL;
} else {
tok->kind = T_CARET;
}
break;
case '&':
if (_yychar == '&') {
yyinp();
tok->kind = T_AMPER_AMPER;
} else if (_yychar == '=') {
yyinp();
tok->kind = T_AMPER_EQUAL;
} else {
tok->kind = T_AMPER;
}
break;
case '|':
if (_yychar == '|') {
yyinp();
tok->kind = T_PIPE_PIPE;
} else if (_yychar == '=') {
yyinp();
tok->kind = T_PIPE_EQUAL;
} else {
tok->kind = T_PIPE;
}
break;
case '~':
if (_yychar == '=') {
yyinp();
tok->kind = T_TILDE_EQUAL;
} else {
tok->kind = T_TILDE;
}
break;
case '!':
if (_yychar == '=') {
yyinp();
tok->kind = T_EXCLAIM_EQUAL;
} else {
tok->kind = T_EXCLAIM;
}
break;
case '=':
if (_yychar == '=') {
yyinp();
tok->kind = T_EQUAL_EQUAL;
} else {
tok->kind = T_EQUAL;
}
break;
case '<':
if (_scanAngleStringLiteralTokens) {
const char *yytext = _currentChar;
while (_yychar && _yychar != '>')
yyinp();
int yylen = _currentChar - yytext;
// ### assert(_yychar == '>');
if (_yychar == '>')
yyinp();
if (control())
tok->string = control()->findOrInsertStringLiteral(yytext, yylen);
tok->kind = T_ANGLE_STRING_LITERAL;
} else if (_yychar == '<') {
yyinp();
if (_yychar == '=') {
yyinp();
tok->kind = T_LESS_LESS_EQUAL;
} else
tok->kind = T_LESS_LESS;
} else if (_yychar == '=') {
yyinp();
tok->kind = T_LESS_EQUAL;
} else {
tok->kind = T_LESS;
}
break;
case '>':
if (_yychar == '>') {
yyinp();
if (_yychar == '=') {
yyinp();
tok->kind = T_GREATER_GREATER_EQUAL;
} else
tok->kind = T_LESS_LESS;
tok->kind = T_GREATER_GREATER;
} else if (_yychar == '=') {
yyinp();
tok->kind = T_GREATER_EQUAL;
} else {
tok->kind = T_GREATER;
}
break;
case ',':
tok->kind = T_COMMA;
break;
default: {
if (_objCEnabled) {
if (ch == '@' && _yychar >= 'a' && _yychar <= 'z') {
const char *yytext = _currentChar;
do {
yyinp();
if (! isalnum(_yychar))
break;
} while (_yychar);
const int yylen = _currentChar - yytext;
tok->kind = classifyObjCAtKeyword(yytext, yylen);
break;
} else if (ch == '@' && _yychar == '"') {
// objc @string literals
ch = _yychar;
yyinp();
tok->kind = T_AT_STRING_LITERAL;
const char *yytext = _currentChar;
while (_yychar && _yychar != '"') {
if (_yychar != '\\')
yyinp();
else {
yyinp(); // skip `\\'
if (_yychar)
yyinp();
}
}
// assert(_yychar == '"');
int yylen = _currentChar - yytext;
if (_yychar == '"')
yyinp();
if (control())
tok->string = control()->findOrInsertStringLiteral(yytext, yylen);
break;
}
}
if (ch == 'L' && (_yychar == '"' || _yychar == '\'')) {
// wide char/string literals
ch = _yychar;
yyinp();
const char quote = ch;
tok->kind = quote == '"'
? T_WIDE_STRING_LITERAL
: T_WIDE_CHAR_LITERAL;
const char *yytext = _currentChar;
while (_yychar && _yychar != quote) {
if (_yychar != '\\')
yyinp();
else {
yyinp(); // skip `\\'
if (_yychar)
yyinp();
}
}
// assert(_yychar == quote);
int yylen = _currentChar - yytext;
if (_yychar == quote)
yyinp();
if (control())
tok->string = control()->findOrInsertStringLiteral(yytext, yylen);
} else if (std::isalpha(ch) || ch == '_') {
const char *yytext = _currentChar - 1;
while (std::isalnum(_yychar) || _yychar == '_')
yyinp();
int yylen = _currentChar - yytext;
if (_scanKeywords)
tok->kind = classify(yytext, yylen, _qtMocRunEnabled);
else
tok->kind = T_IDENTIFIER;
if (tok->kind == T_IDENTIFIER) {
tok->kind = classifyOperator(yytext, yylen);
if (control())
tok->identifier = control()->findOrInsertIdentifier(yytext, yylen);
}
break;
} else if (std::isdigit(ch)) {
const char *yytext = _currentChar - 1;
while (_yychar) {
if (_yychar == 'e' || _yychar == 'E') {
yyinp();
if (_yychar == '-' || _yychar == '+') {
yyinp();
// ### assert(std::isdigit(_yychar));
}
} else if (std::isalnum(_yychar) || _yychar == '.') {
yyinp();
} else {
break;
}
}
int yylen = _currentChar - yytext;
tok->kind = T_INT_LITERAL;
if (control())
tok->number = control()->findOrInsertNumericLiteral(yytext, yylen);
break;
} else {
tok->kind = T_ERROR;
break;
}
} // default
} // switch
}
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,159 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_LEXER_H
#define CPLUSPLUS_LEXER_H
#include "CPlusPlusForwardDeclarations.h"
#include "Token.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT Lexer
{
Lexer(const Lexer &other);
void operator =(const Lexer &other);
public:
enum State {
DefaultState,
MultiLineCommentState
};
Lexer(TranslationUnit *unit);
Lexer(const char *firstChar, const char *lastChar);
~Lexer();
Control *control() const;
TranslationUnit *translationUnit() const;
bool qtMocRunEnabled() const;
void setQtMocRunEnabled(bool onoff);
bool objCEnabled() const;
void setObjCEnabled(bool onoff);
void scan(Token *tok);
inline void operator()(Token *tok)
{ scan(tok); }
unsigned tokenOffset() const;
unsigned tokenLength() const;
const char *tokenBegin() const;
const char *tokenEnd() const;
unsigned currentLine() const;
bool scanCommentTokens() const;
void setScanCommentTokens(bool onoff);
bool scanKeywords() const;
void setScanKeywords(bool onoff);
bool scanAngleStringLiteralTokens() const;
void setScanAngleStringLiteralTokens(bool onoff);
void setStartWithNewline(bool enabled);
int state() const;
void setState(int state);
bool isIncremental() const;
void setIncremental(bool isIncremental);
private:
void scan_helper(Token *tok);
void setSource(const char *firstChar, const char *lastChar);
static int classify(const char *string, int length, bool q);
static int classifyObjCAtKeyword(const char *s, int n);
static int classifyOperator(const char *string, int length);
inline void yyinp()
{
if (++_currentChar == _lastChar)
_yychar = 0;
else {
_yychar = *_currentChar;
if (_yychar == '\n')
pushLineStartOffset();
}
}
void pushLineStartOffset();
private:
TranslationUnit *_translationUnit;
const char *_firstChar;
const char *_currentChar;
const char *_lastChar;
const char *_tokenStart;
unsigned char _yychar;
int _state;
union {
unsigned _flags;
struct {
unsigned _isIncremental: 1;
unsigned _scanCommentTokens: 1;
unsigned _scanKeywords: 1;
unsigned _scanAngleStringLiteralTokens: 1;
unsigned _qtMocRunEnabled: 1;
unsigned _objCEnabled: 1;
};
};
unsigned _currentLine;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_LEXER_H

View File

@@ -0,0 +1,34 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "LiteralTable.h"

View File

@@ -0,0 +1,181 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_LITERALTABLE_H
#define CPLUSPLUS_LITERALTABLE_H
#include "CPlusPlusForwardDeclarations.h"
#include <cstring>
#include <cstdlib>
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
template <typename _Literal>
class LiteralTable
{
LiteralTable(const LiteralTable &other);
void operator =(const LiteralTable &other);
public:
typedef _Literal **iterator;
public:
LiteralTable()
: _literals(0),
_allocatedLiterals(0),
_literalCount(-1),
_buckets(0),
_allocatedBuckets(0)
{ }
~LiteralTable()
{
if (_literals) {
_Literal **lastLiteral = _literals + _literalCount + 1;
for (_Literal **it = _literals; it != lastLiteral; ++it)
delete *it;
free(_literals);
}
if (_buckets)
free(_buckets);
}
bool empty() const
{ return _literalCount == -1; }
unsigned size() const
{ return _literalCount + 1; }
_Literal *at(unsigned index) const
{ return _literals[index]; }
iterator begin() const
{ return _literals; }
iterator end() const
{ return _literals + _literalCount + 1; }
_Literal *findOrInsertLiteral(const char *chars, unsigned size)
{
if (_buckets) {
unsigned h = _Literal::hashCode(chars, size);
_Literal *literal = _buckets[h % _allocatedBuckets];
for (; literal; literal = static_cast<_Literal *>(literal->_next)) {
if (literal->size() == size && ! strncmp(literal->chars(), chars, size))
return literal;
}
}
_Literal *literal = new _Literal(chars, size);
if (++_literalCount == _allocatedLiterals) {
_allocatedLiterals <<= 1;
if (! _allocatedLiterals)
_allocatedLiterals = 256;
_literals = (_Literal **) realloc(_literals, sizeof(_Literal *) * _allocatedLiterals);
}
_literals[_literalCount] = literal;
if (! _buckets || _literalCount >= _allocatedBuckets * .6)
rehash();
else {
unsigned h = literal->hashCode() % _allocatedBuckets;
literal->_next = _buckets[h];
_buckets[h] = literal;
}
return literal;
}
protected:
void rehash()
{
if (_buckets)
free(_buckets);
_allocatedBuckets <<= 1;
if (! _allocatedBuckets)
_allocatedBuckets = 256;
_buckets = (_Literal **) calloc(_allocatedBuckets, sizeof(_Literal *));
_Literal **lastLiteral = _literals + (_literalCount + 1);
for (_Literal **it = _literals; it != lastLiteral; ++it) {
_Literal *literal = *it;
unsigned h = literal->hashCode() % _allocatedBuckets;
literal->_next = _buckets[h];
_buckets[h] = literal;
}
}
protected:
MemoryPool *_pool;
_Literal **_literals;
int _allocatedLiterals;
int _literalCount;
_Literal **_buckets;
int _allocatedBuckets;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_LITERALTABLE_H

View File

@@ -0,0 +1,138 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "Literals.h"
#include <cstring>
#include <algorithm>
#include <iostream>
CPLUSPLUS_BEGIN_NAMESPACE
////////////////////////////////////////////////////////////////////////////////
Literal::Literal(const char *chars, unsigned size)
: _index(0), _next(0)
{
_chars = new char[size + 1];
strncpy(_chars, chars, size);
_chars[size] = '\0';
_size = size;
_hashCode = hashCode(_chars, _size);
}
Literal::~Literal()
{ delete[] _chars; }
Literal::iterator Literal::begin() const
{ return _chars; }
Literal::iterator Literal::end() const
{ return _chars + _size; }
const char *Literal::chars() const
{ return _chars; }
char Literal::at(unsigned index) const
{ return _chars[index]; }
unsigned Literal::size() const
{ return _size; }
unsigned Literal::hashCode() const
{ return _hashCode; }
unsigned Literal::hashCode(const char *chars, unsigned size)
{
unsigned h = 0;
for (unsigned i = 0; i < size; ++i)
h = (h >> 5) - h + chars[i];
return h;
}
////////////////////////////////////////////////////////////////////////////////
StringLiteral::StringLiteral(const char *chars, unsigned size)
: Literal(chars, size)
{ }
StringLiteral::~StringLiteral()
{ }
////////////////////////////////////////////////////////////////////////////////
NumericLiteral::NumericLiteral(const char *chars, unsigned size)
: Literal(chars, size)
{ }
NumericLiteral::~NumericLiteral()
{ }
////////////////////////////////////////////////////////////////////////////////
Identifier::Identifier(const char *chars, unsigned size)
: Literal(chars, size)
{ }
Identifier::~Identifier()
{ }
bool Identifier::isEqualTo(const Identifier *other) const
{
if (this == other)
return true;
else if (hashCode() != other->hashCode())
return false;
else if (size() != other->size())
return false;
return ! strcmp(chars(), other->chars());
}
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,122 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_LITERALS_H
#define CPLUSPLUS_LITERALS_H
#include "CPlusPlusForwardDeclarations.h"
#include "Token.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT Literal
{
Literal(const Literal &other);
void operator =(const Literal &other);
public:
typedef const char *iterator;
typedef iterator const_iterator;
public:
Literal(const char *chars, unsigned size);
virtual ~Literal();
iterator begin() const;
iterator end() const;
char at(unsigned index) const;
const char *chars() const;
unsigned size() const;
unsigned hashCode() const;
static unsigned hashCode(const char *chars, unsigned size);
private:
char *_chars;
unsigned _size;
unsigned _hashCode;
public:
// ### private
unsigned _index;
Literal *_next;
};
class CPLUSPLUS_EXPORT StringLiteral: public Literal
{
public:
StringLiteral(const char *chars, unsigned size);
virtual ~StringLiteral();
};
class CPLUSPLUS_EXPORT NumericLiteral: public Literal
{
public:
NumericLiteral(const char *chars, unsigned size);
virtual ~NumericLiteral();
};
class CPLUSPLUS_EXPORT Identifier: public Literal
{
public:
Identifier(const char *chars, unsigned size);
virtual ~Identifier();
bool isEqualTo(const Identifier *other) const;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_LITERALS_H

View File

@@ -0,0 +1,130 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "MemoryPool.h"
#include <cstdlib>
#include <cstring>
#include <cassert>
CPLUSPLUS_BEGIN_NAMESPACE
MemoryPool::MemoryPool()
: _initializeAllocatedMemory(true),
_blocks(0),
_allocatedBlocks(0),
_blockCount(-1),
ptr(0),
end(0)
{ }
MemoryPool::~MemoryPool()
{
if (_blockCount != -1) {
for (int i = 0; i < _blockCount + 1; ++i) {
free(_blocks[i]);
}
}
if (_blocks)
free(_blocks);
}
bool MemoryPool::initializeAllocatedMemory() const
{ return _initializeAllocatedMemory; }
void MemoryPool::setInitializeAllocatedMemory(bool initializeAllocatedMemory)
{ _initializeAllocatedMemory = initializeAllocatedMemory; }
void *MemoryPool::allocate_helper(size_t size)
{
assert(size < BLOCK_SIZE);
if (++_blockCount == _allocatedBlocks) {
if (! _allocatedBlocks)
_allocatedBlocks = 8;
else
_allocatedBlocks *= 2;
_blocks = (char **) realloc(_blocks, sizeof(char *) * _allocatedBlocks);
}
char *&block = _blocks[_blockCount];
if (_initializeAllocatedMemory)
block = (char *) calloc(1, BLOCK_SIZE);
else
block = (char *) malloc(BLOCK_SIZE);
ptr = block;
end = ptr + BLOCK_SIZE;
void *addr = ptr;
ptr += size;
return addr;
}
Managed::Managed()
{ }
Managed::~Managed()
{ }
void *Managed::operator new(size_t size, MemoryPool *pool)
{ return pool->allocate(size); }
void Managed::operator delete(void *)
{ }
void Managed::operator delete(void *, MemoryPool *)
{ }
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,120 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_MEMORYPOOL_H
#define CPLUSPLUS_MEMORYPOOL_H
#include "CPlusPlusForwardDeclarations.h"
#include <cstddef>
#include <new>
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT MemoryPool
{
MemoryPool(const MemoryPool &other);
void operator =(const MemoryPool &other);
public:
MemoryPool();
~MemoryPool();
bool initializeAllocatedMemory() const;
void setInitializeAllocatedMemory(bool initializeAllocatedMemory);
inline void *allocate(size_t size)
{
size = (size + 7) & ~7;
if (ptr && (ptr + size < end)) {
void *addr = ptr;
ptr += size;
return addr;
}
return allocate_helper(size);
}
private:
void *allocate_helper(size_t size);
private:
bool _initializeAllocatedMemory;
char **_blocks;
int _allocatedBlocks;
int _blockCount;
char *ptr, *end;
enum
{
BLOCK_SIZE = 8 * 1024,
DEFAULT_BLOCK_COUNT = 8
};
};
class CPLUSPLUS_EXPORT Managed
{
Managed(const Managed &other);
void operator = (const Managed &other);
public:
Managed();
virtual ~Managed();
void *operator new(size_t size, MemoryPool *pool);
void operator delete(void *);
void operator delete(void *, MemoryPool *);
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_MEMORYPOOL_H

View File

@@ -0,0 +1,133 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "Name.h"
#include "Names.h"
#include "NameVisitor.h"
CPLUSPLUS_BEGIN_NAMESPACE
Name::Name()
{ }
Name::~Name()
{ }
bool Name::isNameId() const
{ return dynamic_cast<const NameId *>(this) != 0; }
bool Name::isTemplateNameId() const
{ return dynamic_cast<const TemplateNameId *>(this) != 0; }
bool Name::isDestructorNameId() const
{ return dynamic_cast<const DestructorNameId *>(this) != 0; }
bool Name::isOperatorNameId() const
{ return dynamic_cast<const OperatorNameId *>(this) != 0; }
bool Name::isConversionNameId() const
{ return dynamic_cast<const ConversionNameId *>(this) != 0; }
bool Name::isQualifiedNameId() const
{ return dynamic_cast<const QualifiedNameId *>(this) != 0; }
const NameId *Name::asNameId() const
{ return dynamic_cast<const NameId *>(this); }
const TemplateNameId *Name::asTemplateNameId() const
{ return dynamic_cast<const TemplateNameId *>(this); }
const DestructorNameId *Name::asDestructorNameId() const
{ return dynamic_cast<const DestructorNameId *>(this); }
const OperatorNameId *Name::asOperatorNameId() const
{ return dynamic_cast<const OperatorNameId *>(this); }
const ConversionNameId *Name::asConversionNameId() const
{ return dynamic_cast<const ConversionNameId *>(this); }
const QualifiedNameId *Name::asQualifiedNameId() const
{ return dynamic_cast<const QualifiedNameId *>(this); }
NameId *Name::asNameId()
{ return dynamic_cast<NameId *>(this); }
TemplateNameId *Name::asTemplateNameId()
{ return dynamic_cast<TemplateNameId *>(this); }
DestructorNameId *Name::asDestructorNameId()
{ return dynamic_cast<DestructorNameId *>(this); }
OperatorNameId *Name::asOperatorNameId()
{ return dynamic_cast<OperatorNameId *>(this); }
ConversionNameId *Name::asConversionNameId()
{ return dynamic_cast<ConversionNameId *>(this); }
QualifiedNameId *Name::asQualifiedNameId()
{ return dynamic_cast<QualifiedNameId *>(this); }
void Name::accept(NameVisitor *visitor)
{
if (visitor->preVisit(this))
accept0(visitor);
visitor->postVisit(this);
}
void Name::accept(Name *name, NameVisitor *visitor)
{
if (! name)
return;
name->accept(visitor);
}
CPLUSPLUS_END_NAMESPACE

103
src/shared/cplusplus/Name.h Normal file
View File

@@ -0,0 +1,103 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_NAME_H
#define CPLUSPLUS_NAME_H
#include "CPlusPlusForwardDeclarations.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT Name
{
Name(const Name &other);
void operator =(const Name &other);
public:
Name();
virtual ~Name();
bool isNameId() const;
bool isTemplateNameId() const;
bool isDestructorNameId() const;
bool isOperatorNameId() const;
bool isConversionNameId() const;
bool isQualifiedNameId() const;
const NameId *asNameId() const;
const TemplateNameId *asTemplateNameId() const;
const DestructorNameId *asDestructorNameId() const;
const OperatorNameId *asOperatorNameId() const;
const ConversionNameId *asConversionNameId() const;
const QualifiedNameId *asQualifiedNameId() const;
NameId *asNameId();
TemplateNameId *asTemplateNameId();
DestructorNameId *asDestructorNameId();
OperatorNameId *asOperatorNameId();
ConversionNameId *asConversionNameId();
QualifiedNameId *asQualifiedNameId();
virtual bool isEqualTo(const Name *other) const = 0;
void accept(NameVisitor *visitor);
static void accept(Name *name, NameVisitor *visitor);
protected:
virtual void accept0(NameVisitor *visitor) = 0;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_NAME_H

View File

@@ -0,0 +1,67 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "NameVisitor.h"
#include "Names.h"
CPLUSPLUS_BEGIN_NAMESPACE
NameVisitor::NameVisitor()
{ }
NameVisitor::~NameVisitor()
{ }
void NameVisitor::accept(Name *name)
{ Name::accept(name, this); }
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,86 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_NAMEVISITOR_H
#define CPLUSPLUS_NAMEVISITOR_H
#include "CPlusPlusForwardDeclarations.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT NameVisitor
{
NameVisitor(const NameVisitor &other);
void operator =(const NameVisitor &other);
public:
NameVisitor();
virtual ~NameVisitor();
void accept(Name *name);
virtual bool preVisit(Name *) { return true; }
virtual void postVisit(Name *) {}
virtual void visit(NameId *) {}
virtual void visit(TemplateNameId *) {}
virtual void visit(DestructorNameId *) {}
virtual void visit(OperatorNameId *) {}
virtual void visit(ConversionNameId *) {}
virtual void visit(QualifiedNameId *) {}
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_NAMEVISITOR_H

View File

@@ -0,0 +1,262 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "Names.h"
#include "NameVisitor.h"
#include "Literals.h"
#include <cstring>
#include <algorithm>
CPLUSPLUS_BEGIN_NAMESPACE
QualifiedNameId::QualifiedNameId(Name *const names[],
unsigned nameCount,
bool isGlobal)
: _names(0),
_nameCount(nameCount),
_isGlobal(isGlobal)
{
if (_nameCount) {
_names = new Name *[_nameCount];
std::copy(&names[0], &names[nameCount], _names);
}
}
QualifiedNameId::~QualifiedNameId()
{ delete[] _names; }
void QualifiedNameId::accept0(NameVisitor *visitor)
{ visitor->visit(this); }
unsigned QualifiedNameId::nameCount() const
{ return _nameCount; }
Name *QualifiedNameId::nameAt(unsigned index) const
{ return _names[index]; }
Name *const *QualifiedNameId::names() const
{ return _names; }
bool QualifiedNameId::isGlobal() const
{ return _isGlobal; }
Name *QualifiedNameId::unqualifiedNameId() const
{
if (! _nameCount)
return 0;
return _names[_nameCount - 1];
}
bool QualifiedNameId::isEqualTo(const Name *other) const
{
const QualifiedNameId *q = other->asQualifiedNameId();
if (! q)
return false;
else if (isGlobal() != q->isGlobal())
return false;
else {
const unsigned count = nameCount();
if (count != q->nameCount())
return false;
for (unsigned i = 0; i < count; ++i) {
Name *l = nameAt(i);
Name *r = q->nameAt(i);
if (! l->isEqualTo(r))
return false;
}
}
return true;
}
NameId::NameId(Identifier *identifier)
: _identifier(identifier)
{ }
NameId::~NameId()
{ }
void NameId::accept0(NameVisitor *visitor)
{ visitor->visit(this); }
Identifier *NameId::identifier() const
{ return _identifier; }
bool NameId::isEqualTo(const Name *other) const
{
const NameId *nameId = other->asNameId();
if (! nameId)
return false;
Identifier *l = identifier();
Identifier *r = nameId->identifier();
return l->isEqualTo(r);
}
DestructorNameId::DestructorNameId(Identifier *identifier)
: _identifier(identifier)
{ }
DestructorNameId::~DestructorNameId()
{ }
void DestructorNameId::accept0(NameVisitor *visitor)
{ visitor->visit(this); }
Identifier *DestructorNameId::identifier() const
{ return _identifier; }
bool DestructorNameId::isEqualTo(const Name *other) const
{
const DestructorNameId *d = other->asDestructorNameId();
if (! d)
return false;
Identifier *l = identifier();
Identifier *r = d->identifier();
return l->isEqualTo(r);
}
TemplateNameId::TemplateNameId(Identifier *identifier,
const FullySpecifiedType templateArguments[],
unsigned templateArgumentCount)
: _identifier(identifier),
_templateArguments(0),
_templateArgumentCount(templateArgumentCount)
{
if (_templateArgumentCount) {
_templateArguments = new FullySpecifiedType[_templateArgumentCount];
std::copy(&templateArguments[0], &templateArguments[_templateArgumentCount],
_templateArguments);
}
}
TemplateNameId::~TemplateNameId()
{ delete[] _templateArguments; }
void TemplateNameId::accept0(NameVisitor *visitor)
{ visitor->visit(this); }
Identifier *TemplateNameId::identifier() const
{ return _identifier; }
unsigned TemplateNameId::templateArgumentCount() const
{ return _templateArgumentCount; }
const FullySpecifiedType &TemplateNameId::templateArgumentAt(unsigned index) const
{ return _templateArguments[index]; }
const FullySpecifiedType *TemplateNameId::templateArguments() const
{ return _templateArguments; }
bool TemplateNameId::isEqualTo(const Name *other) const
{
const TemplateNameId *t = other->asTemplateNameId();
if (! t)
return false;
Identifier *l = identifier();
Identifier *r = t->identifier();
if (! l->isEqualTo(r))
return false;
if (_templateArgumentCount != t->_templateArgumentCount)
return false;
for (unsigned i = 0; i < _templateArgumentCount; ++i) {
const FullySpecifiedType &l = _templateArguments[i];
const FullySpecifiedType &r = t->_templateArguments[i];
if (! l.isEqualTo(r))
return false;
}
return true;
}
OperatorNameId::OperatorNameId(int kind)
: _kind(kind)
{ }
OperatorNameId::~OperatorNameId()
{ }
void OperatorNameId::accept0(NameVisitor *visitor)
{ visitor->visit(this); }
int OperatorNameId::kind() const
{ return _kind; }
bool OperatorNameId::isEqualTo(const Name *other) const
{
const OperatorNameId *o = other->asOperatorNameId();
if (! o)
return false;
return _kind == o->kind();
}
ConversionNameId::ConversionNameId(FullySpecifiedType type)
: _type(type)
{ }
ConversionNameId::~ConversionNameId()
{ }
void ConversionNameId::accept0(NameVisitor *visitor)
{ visitor->visit(this); }
FullySpecifiedType ConversionNameId::type() const
{ return _type; }
bool ConversionNameId::isEqualTo(const Name *other) const
{
const ConversionNameId *c = other->asConversionNameId();
if (! c)
return false;
return _type.isEqualTo(c->type());
}
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,241 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_NAMES_H
#define CPLUSPLUS_NAMES_H
#include "CPlusPlusForwardDeclarations.h"
#include "Name.h"
#include "FullySpecifiedType.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT QualifiedNameId: public Name
{
public:
QualifiedNameId(Name *const names[],
unsigned nameCount,
bool isGlobal = false);
virtual ~QualifiedNameId();
unsigned nameCount() const;
Name *nameAt(unsigned index) const;
Name *const *names() const;
Name *unqualifiedNameId() const;
bool isGlobal() const;
virtual bool isEqualTo(const Name *other) const;
protected:
virtual void accept0(NameVisitor *visitor);
private:
Name **_names;
unsigned _nameCount;
bool _isGlobal;
};
class CPLUSPLUS_EXPORT NameId: public Name
{
public:
NameId(Identifier *identifier);
virtual ~NameId();
Identifier *identifier() const;
virtual bool isEqualTo(const Name *other) const;
protected:
virtual void accept0(NameVisitor *visitor);
private:
Identifier *_identifier;
};
class CPLUSPLUS_EXPORT DestructorNameId: public Name
{
public:
DestructorNameId(Identifier *identifier);
virtual ~DestructorNameId();
Identifier *identifier() const;
virtual bool isEqualTo(const Name *other) const;
protected:
virtual void accept0(NameVisitor *visitor);
private:
Identifier *_identifier;
};
class CPLUSPLUS_EXPORT TemplateNameId: public Name
{
public:
TemplateNameId(Identifier *identifier,
const FullySpecifiedType templateArguments[],
unsigned templateArgumentCount);
virtual ~TemplateNameId();
Identifier *identifier() const;
// ### find a better name
unsigned templateArgumentCount() const;
const FullySpecifiedType &templateArgumentAt(unsigned index) const;
const FullySpecifiedType *templateArguments() const;
virtual bool isEqualTo(const Name *other) const;
protected:
virtual void accept0(NameVisitor *visitor);
private:
Identifier *_identifier;
FullySpecifiedType *_templateArguments;
unsigned _templateArgumentCount;
};
class CPLUSPLUS_EXPORT OperatorNameId: public Name
{
public:
/*
new delete new[] delete[]
+ - * / % ^ & | ~
! = < > += -= *= /= %=
^= &= |= << >> >>= <<= == !=
<= >= && || ++ -- , ->* ->
() []
*/
enum Kind {
InvalidOp,
NewOp,
DeleteOp,
NewArrayOp,
DeleteArrayOp,
PlusOp,
MinusOp,
StarOp,
SlashOp,
PercentOp,
CaretOp,
AmpOp,
PipeOp,
TildeOp,
ExclaimOp,
EqualOp,
LessOp,
GreaterOp,
PlusEqualOp,
MinusEqualOp,
StarEqualOp,
SlashEqualOp,
PercentEqualOp,
CaretEqualOp,
AmpEqualOp,
PipeEqualOp,
LessLessOp,
GreaterGreaterOp,
LessLessEqualOp,
GreaterGreaterEqualOp,
EqualEqualOp,
ExclaimEqualOp,
LessEqualOp,
GreaterEqualOp,
AmpAmpOp,
PipePipeOp,
PlusPlusOp,
MinusMinusOp,
CommaOp,
ArrowStarOp,
ArrowOp,
FunctionCallOp,
ArrayAccessOp
};
public:
OperatorNameId(int kind);
virtual ~OperatorNameId();
int kind() const;
virtual bool isEqualTo(const Name *other) const;
protected:
virtual void accept0(NameVisitor *visitor);
private:
int _kind;
};
class CPLUSPLUS_EXPORT ConversionNameId: public Name
{
public:
ConversionNameId(FullySpecifiedType type);
virtual ~ConversionNameId();
FullySpecifiedType type() const;
virtual bool isEqualTo(const Name *other) const;
protected:
virtual void accept0(NameVisitor *visitor);
private:
FullySpecifiedType _type;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_NAMES_H

View File

@@ -0,0 +1,464 @@
#include "Lexer.h"
#include "Token.h"
CPLUSPLUS_BEGIN_NAMESPACE
static inline int classify3(const char *s) {
if (s[0] == 'e') {
if (s[1] == 'n') {
if (s[2] == 'd') {
return T_AT_END;
}
}
}
else if (s[0] == 't') {
if (s[1] == 'r') {
if (s[2] == 'y') {
return T_AT_TRY;
}
}
}
return T_ERROR;
}
static inline int classify4(const char *s) {
if (s[0] == 'd') {
if (s[1] == 'e') {
if (s[2] == 'f') {
if (s[3] == 's') {
return T_AT_DEFS;
}
}
}
}
return T_ERROR;
}
static inline int classify5(const char *s) {
if (s[0] == 'c') {
if (s[1] == 'a') {
if (s[2] == 't') {
if (s[3] == 'c') {
if (s[4] == 'h') {
return T_AT_CATCH;
}
}
}
}
else if (s[1] == 'l') {
if (s[2] == 'a') {
if (s[3] == 's') {
if (s[4] == 's') {
return T_AT_CLASS;
}
}
}
}
}
else if (s[0] == 't') {
if (s[1] == 'h') {
if (s[2] == 'r') {
if (s[3] == 'o') {
if (s[4] == 'w') {
return T_AT_THROW;
}
}
}
}
}
return T_ERROR;
}
static inline int classify6(const char *s) {
if (s[0] == 'e') {
if (s[1] == 'n') {
if (s[2] == 'c') {
if (s[3] == 'o') {
if (s[4] == 'd') {
if (s[5] == 'e') {
return T_AT_ENCODE;
}
}
}
}
}
}
else if (s[0] == 'p') {
if (s[1] == 'u') {
if (s[2] == 'b') {
if (s[3] == 'l') {
if (s[4] == 'i') {
if (s[5] == 'c') {
return T_AT_PUBLIC;
}
}
}
}
}
}
return T_ERROR;
}
static inline int classify7(const char *s) {
if (s[0] == 'd') {
if (s[1] == 'y') {
if (s[2] == 'n') {
if (s[3] == 'a') {
if (s[4] == 'm') {
if (s[5] == 'i') {
if (s[6] == 'c') {
return T_AT_DYNAMIC;
}
}
}
}
}
}
}
else if (s[0] == 'f') {
if (s[1] == 'i') {
if (s[2] == 'n') {
if (s[3] == 'a') {
if (s[4] == 'l') {
if (s[5] == 'l') {
if (s[6] == 'y') {
return T_AT_FINALLY;
}
}
}
}
}
}
}
else if (s[0] == 'p') {
if (s[1] == 'a') {
if (s[2] == 'c') {
if (s[3] == 'k') {
if (s[4] == 'a') {
if (s[5] == 'g') {
if (s[6] == 'e') {
return T_AT_PACKAGE;
}
}
}
}
}
}
else if (s[1] == 'r') {
if (s[2] == 'i') {
if (s[3] == 'v') {
if (s[4] == 'a') {
if (s[5] == 't') {
if (s[6] == 'e') {
return T_AT_PRIVATE;
}
}
}
}
}
}
}
return T_ERROR;
}
static inline int classify8(const char *s) {
if (s[0] == 'o') {
if (s[1] == 'p') {
if (s[2] == 't') {
if (s[3] == 'i') {
if (s[4] == 'o') {
if (s[5] == 'n') {
if (s[6] == 'a') {
if (s[7] == 'l') {
return T_AT_OPTIONAL;
}
}
}
}
}
}
}
}
else if (s[0] == 'p') {
if (s[1] == 'r') {
if (s[2] == 'o') {
if (s[3] == 'p') {
if (s[4] == 'e') {
if (s[5] == 'r') {
if (s[6] == 't') {
if (s[7] == 'y') {
return T_AT_PROPERTY;
}
}
}
}
}
else if (s[3] == 't') {
if (s[4] == 'o') {
if (s[5] == 'c') {
if (s[6] == 'o') {
if (s[7] == 'l') {
return T_AT_PROTOCOL;
}
}
}
}
}
}
}
}
else if (s[0] == 'r') {
if (s[1] == 'e') {
if (s[2] == 'q') {
if (s[3] == 'u') {
if (s[4] == 'i') {
if (s[5] == 'r') {
if (s[6] == 'e') {
if (s[7] == 'd') {
return T_AT_REQUIRED;
}
}
}
}
}
}
}
}
else if (s[0] == 's') {
if (s[1] == 'e') {
if (s[2] == 'l') {
if (s[3] == 'e') {
if (s[4] == 'c') {
if (s[5] == 't') {
if (s[6] == 'o') {
if (s[7] == 'r') {
return T_AT_SELECTOR;
}
}
}
}
}
}
}
}
return T_ERROR;
}
static inline int classify9(const char *s) {
if (s[0] == 'i') {
if (s[1] == 'n') {
if (s[2] == 't') {
if (s[3] == 'e') {
if (s[4] == 'r') {
if (s[5] == 'f') {
if (s[6] == 'a') {
if (s[7] == 'c') {
if (s[8] == 'e') {
return T_AT_INTERFACE;
}
}
}
}
}
}
}
}
}
else if (s[0] == 'p') {
if (s[1] == 'r') {
if (s[2] == 'o') {
if (s[3] == 't') {
if (s[4] == 'e') {
if (s[5] == 'c') {
if (s[6] == 't') {
if (s[7] == 'e') {
if (s[8] == 'd') {
return T_AT_PROTECTED;
}
}
}
}
}
}
}
}
}
return T_ERROR;
}
static inline int classify10(const char *s) {
if (s[0] == 's') {
if (s[1] == 'y') {
if (s[2] == 'n') {
if (s[3] == 't') {
if (s[4] == 'h') {
if (s[5] == 'e') {
if (s[6] == 's') {
if (s[7] == 'i') {
if (s[8] == 'z') {
if (s[9] == 'e') {
return T_AT_SYNTHESIZE;
}
}
}
}
}
}
}
}
}
}
return T_ERROR;
}
static inline int classify11(const char *s) {
if (s[0] == 'n') {
if (s[1] == 'o') {
if (s[2] == 't') {
if (s[3] == '_') {
if (s[4] == 'k') {
if (s[5] == 'e') {
if (s[6] == 'y') {
if (s[7] == 'w') {
if (s[8] == 'o') {
if (s[9] == 'r') {
if (s[10] == 'd') {
return T_AT_NOT_KEYWORD;
}
}
}
}
}
}
}
}
}
}
}
return T_ERROR;
}
static inline int classify12(const char *s) {
if (s[0] == 's') {
if (s[1] == 'y') {
if (s[2] == 'n') {
if (s[3] == 'c') {
if (s[4] == 'h') {
if (s[5] == 'r') {
if (s[6] == 'o') {
if (s[7] == 'n') {
if (s[8] == 'i') {
if (s[9] == 'z') {
if (s[10] == 'e') {
if (s[11] == 'd') {
return T_AT_SYNCHRONIZED;
}
}
}
}
}
}
}
}
}
}
}
}
return T_ERROR;
}
static inline int classify14(const char *s) {
if (s[0] == 'i') {
if (s[1] == 'm') {
if (s[2] == 'p') {
if (s[3] == 'l') {
if (s[4] == 'e') {
if (s[5] == 'm') {
if (s[6] == 'e') {
if (s[7] == 'n') {
if (s[8] == 't') {
if (s[9] == 'a') {
if (s[10] == 't') {
if (s[11] == 'i') {
if (s[12] == 'o') {
if (s[13] == 'n') {
return T_AT_IMPLEMENTATION;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return T_ERROR;
}
static inline int classify19(const char *s) {
if (s[0] == 'c') {
if (s[1] == 'o') {
if (s[2] == 'm') {
if (s[3] == 'p') {
if (s[4] == 'a') {
if (s[5] == 't') {
if (s[6] == 'i') {
if (s[7] == 'b') {
if (s[8] == 'i') {
if (s[9] == 'l') {
if (s[10] == 'i') {
if (s[11] == 't') {
if (s[12] == 'y') {
if (s[13] == '_') {
if (s[14] == 'a') {
if (s[15] == 'l') {
if (s[16] == 'i') {
if (s[17] == 'a') {
if (s[18] == 's') {
return T_AT_COMPATIBILITY_ALIAS;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return T_ERROR;
}
int Lexer::classifyObjCAtKeyword(const char *s, int n) {
switch (n) {
case 3: return classify3(s);
case 4: return classify4(s);
case 5: return classify5(s);
case 6: return classify6(s);
case 7: return classify7(s);
case 8: return classify8(s);
case 9: return classify9(s);
case 10: return classify10(s);
case 11: return classify11(s);
case 12: return classify12(s);
case 14: return classify14(s);
case 19: return classify19(s);
default: return T_ERROR;
} // switch
}
CPLUSPLUS_END_NAMESPACE

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,292 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_PARSER_H
#define CPLUSPLUS_PARSER_H
#include "CPlusPlusForwardDeclarations.h"
#include "ASTfwd.h"
#include "Token.h"
#include "TranslationUnit.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT Parser
{
public:
Parser(TranslationUnit *translationUnit);
~Parser();
bool qtMocRunEnabled() const;
void setQtMocRunEnabled(bool onoff);
bool objCEnabled() const;
void setObjCEnabled(bool onoff);
bool parseTranslationUnit(TranslationUnitAST *&node);
public:
bool parseAccessSpecifier(SpecifierAST *&node);
bool parseExpressionList(ExpressionListAST *&node);
bool parseAbstractCoreDeclarator(DeclaratorAST *&node);
bool parseAbstractDeclarator(DeclaratorAST *&node);
bool parseEmptyDeclaration(DeclarationAST *&node);
bool parseAccessDeclaration(DeclarationAST *&node);
bool parseAdditiveExpression(ExpressionAST *&node);
bool parseAndExpression(ExpressionAST *&node);
bool parseAsmDefinition(DeclarationAST *&node);
bool parseAssignmentExpression(ExpressionAST *&node);
bool parseBaseClause(BaseSpecifierAST *&node);
bool parseBaseSpecifier(BaseSpecifierAST *&node);
bool parseBlockDeclaration(DeclarationAST *&node);
bool parseCppCastExpression(ExpressionAST *&node);
bool parseCastExpression(ExpressionAST *&node);
bool parseClassSpecifier(SpecifierAST *&node);
bool parseCommaExpression(ExpressionAST *&node);
bool parseCompoundStatement(StatementAST *&node);
bool parseBreakStatement(StatementAST *&node);
bool parseContinueStatement(StatementAST *&node);
bool parseGotoStatement(StatementAST *&node);
bool parseReturnStatement(StatementAST *&node);
bool parseCondition(ExpressionAST *&node);
bool parseConditionalExpression(ExpressionAST *&node);
bool parseConstantExpression(ExpressionAST *&node);
bool parseCtorInitializer(CtorInitializerAST *&node);
bool parseCvQualifiers(SpecifierAST *&node);
bool parseDeclaratorOrAbstractDeclarator(DeclaratorAST *&node);
bool parseDeclaration(DeclarationAST *&node);
bool parseSimpleDeclaration(DeclarationAST *&node, bool acceptStructDeclarator = false);
bool parseDeclarationStatement(StatementAST *&node);
bool parseCoreDeclarator(DeclaratorAST *&node);
bool parseDeclarator(DeclaratorAST *&node);
bool parseDeleteExpression(ExpressionAST *&node);
bool parseDoStatement(StatementAST *&node);
bool parseElaboratedTypeSpecifier(SpecifierAST *&node);
bool parseEnumSpecifier(SpecifierAST *&node);
bool parseEnumerator(EnumeratorAST *&node);
bool parseEqualityExpression(ExpressionAST *&node);
bool parseExceptionDeclaration(ExceptionDeclarationAST *&node);
bool parseExceptionSpecification(ExceptionSpecificationAST *&node);
bool parseExclusiveOrExpression(ExpressionAST *&node);
bool parseExpression(ExpressionAST *&node);
bool parseExpressionOrDeclarationStatement(StatementAST *&node);
bool parseExpressionStatement(StatementAST *&node);
bool parseForInitStatement(StatementAST *&node);
bool parseForStatement(StatementAST *&node);
bool parseFunctionBody(StatementAST *&node);
bool parseIfStatement(StatementAST *&node);
bool parseInclusiveOrExpression(ExpressionAST *&node);
bool parseInitDeclarator(DeclaratorAST *&node, bool acceptStructDeclarator);
bool parseInitializerList(ExpressionListAST *&node);
bool parseInitializer(ExpressionAST *&node);
bool parseInitializerClause(ExpressionAST *&node);
bool parseLabeledStatement(StatementAST *&node);
bool parseLinkageBody(DeclarationAST *&node);
bool parseLinkageSpecification(DeclarationAST *&node);
bool parseLogicalAndExpression(ExpressionAST *&node);
bool parseLogicalOrExpression(ExpressionAST *&node);
bool parseMemInitializer(MemInitializerAST *&node);
bool parseMemInitializerList(MemInitializerAST *&node);
bool parseMemberSpecification(DeclarationAST *&node);
bool parseMultiplicativeExpression(ExpressionAST *&node);
bool parseTemplateId(NameAST *&node);
bool parseClassOrNamespaceName(NameAST *&node);
bool parseNameId(NameAST *&node);
bool parseName(NameAST *&node, bool acceptTemplateId = true);
bool parseNestedNameSpecifier(NestedNameSpecifierAST *&node, bool acceptTemplateId);
bool parseNestedNameSpecifierOpt(NestedNameSpecifierAST *&name, bool acceptTemplateId);
bool parseNamespace(DeclarationAST *&node);
bool parseNamespaceAliasDefinition(DeclarationAST *&node);
bool parseNewDeclarator(NewDeclaratorAST *&node);
bool parseNewExpression(ExpressionAST *&node);
bool parseNewInitializer(NewInitializerAST *&node);
bool parseNewTypeId(NewTypeIdAST *&node);
bool parseOperator(OperatorAST *&node);
bool parseConversionFunctionId(NameAST *&node);
bool parseOperatorFunctionId(NameAST *&node);
bool parseParameterDeclaration(DeclarationAST *&node);
bool parseParameterDeclarationClause(ParameterDeclarationClauseAST *&node);
bool parseParameterDeclarationList(DeclarationAST *&node);
bool parsePmExpression(ExpressionAST *&node);
bool parseTypeidExpression(ExpressionAST *&node);
bool parseTypenameCallExpression(ExpressionAST *&node);
bool parseCorePostfixExpression(ExpressionAST *&node);
bool parsePostfixExpression(ExpressionAST *&node);
bool parsePostfixExpressionInternal(ExpressionAST *&node);
bool parsePrimaryExpression(ExpressionAST *&node);
bool parseNestedExpression(ExpressionAST *&node);
bool parsePtrOperator(PtrOperatorAST *&node);
bool parseRelationalExpression(ExpressionAST *&node);
bool parseShiftExpression(ExpressionAST *&node);
bool parseStatement(StatementAST *&node);
bool parseThisExpression(ExpressionAST *&node);
bool parseBoolLiteral(ExpressionAST *&node);
bool parseNumericLiteral(ExpressionAST *&node);
bool parseStringLiteral(ExpressionAST *&node);
bool parseSwitchStatement(StatementAST *&node);
bool parseTemplateArgument(ExpressionAST *&node);
bool parseTemplateArgumentList(TemplateArgumentListAST *&node);
bool parseTemplateDeclaration(DeclarationAST *&node);
bool parseTemplateParameter(DeclarationAST *&node);
bool parseTemplateParameterList(DeclarationAST *&node);
bool parseThrowExpression(ExpressionAST *&node);
bool parseTryBlockStatement(StatementAST *&node);
bool parseCatchClause(CatchClauseAST *&node);
bool parseTypeId(ExpressionAST *&node);
bool parseTypeIdList(ExpressionListAST *&node);
bool parseTypenameTypeParameter(DeclarationAST *&node);
bool parseTemplateTypeParameter(DeclarationAST *&node);
bool parseTypeParameter(DeclarationAST *&node);
bool parseBuiltinTypeSpecifier(SpecifierAST *&node);
bool parseAttributeSpecifier(SpecifierAST *&node);
bool parseAttributeList(AttributeAST *&node);
bool parseSimpleTypeSpecifier(SpecifierAST *&node)
{ return parseDeclSpecifierSeq(node, true, true); }
bool parseTypeSpecifier(SpecifierAST *&node)
{ return parseDeclSpecifierSeq(node, true); }
bool parseDeclSpecifierSeq(SpecifierAST *&node,
bool onlyTypeSpecifiers = false,
bool simplified = false);
bool parseUnaryExpression(ExpressionAST *&node);
bool parseUnqualifiedName(NameAST *&node, bool acceptTemplateId = true);
bool parseUsing(DeclarationAST *&node);
bool parseUsingDirective(DeclarationAST *&node);
bool parseWhileStatement(StatementAST *&node);
// Qt MOC run
bool parseQtMethod(ExpressionAST *&node);
// ObjC++
bool parseObjCClassDeclaration(DeclarationAST *&node);
bool parseObjCInterface(DeclarationAST *&node,
SpecifierAST *attributes = 0);
bool parseObjCProtocol(DeclarationAST *&node,
SpecifierAST *attributes = 0);
bool parseObjCProtocolRefs();
bool parseObjClassInstanceVariables();
bool parseObjCInterfaceMemberDeclaration();
bool parseObjCInstanceVariableDeclaration(DeclarationAST *&node);
bool parseObjCPropertyDeclaration(DeclarationAST *&node,
SpecifierAST *attributes = 0);
bool parseObjCImplementation(DeclarationAST *&node);
bool parseObjCMethodPrototype();
bool parseObjCPropertyAttribute();
bool parseObjCTypeName();
bool parseObjCSelector();
bool parseObjCKeywordDeclaration();
bool parseObjCTypeQualifiers();
bool parseObjCEnd(DeclarationAST *&node);
bool lookAtObjCSelector() const;
bool skipUntil(int token);
bool skipUntilDeclaration();
bool skipUntilStatement();
bool skip(int l, int r);
bool lookAtCVQualifier() const;
bool lookAtFunctionSpecifier() const;
bool lookAtStorageClassSpecifier() const;
bool lookAtBuiltinTypeSpecifier() const;
bool lookAtClassKey() const;
bool lookAtAssignmentOperator() const;
void match(int kind, unsigned *token);
bool maybeFunctionCall(SimpleDeclarationAST *simpleDecl) const;
bool maybeSimpleExpression(SimpleDeclarationAST *simpleDecl) const;
private:
bool switchTemplateArguments(bool templateArguments);
bool blockErrors(bool block);
inline const Token &tok(int i = 1) const
{ return _translationUnit->tokenAt(_tokenIndex + i - 1); }
inline int LA(int n = 1) const
{ return _translationUnit->tokenKind(_tokenIndex + n - 1); }
inline int consumeToken()
{ return _tokenIndex++; }
inline unsigned cursor() const
{ return _tokenIndex; }
inline void rewind(unsigned cursor)
{ _tokenIndex = cursor; }
private:
TranslationUnit *_translationUnit;
Control *_control;
MemoryPool *_pool;
unsigned _tokenIndex;
bool _templateArguments: 1;
bool _qtMocRunEnabled: 1;
bool _objCEnabled: 1;
bool _inFunctionBody: 1;
bool _inObjCImplementationContext: 1;
private:
Parser(const Parser& source);
void operator =(const Parser& source);
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_PARSER_H

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,163 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef CPLUSPLUS_PRETTYPRINTER_H
#define CPLUSPLUS_PRETTYPRINTER_H
#include "CPlusPlusForwardDeclarations.h"
#include "ASTVisitor.h"
#include <iosfwd>
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class PrettyPrinter: protected ASTVisitor
{
public:
PrettyPrinter(Control *control, std::ostream &out);
void operator()(AST *ast);
protected:
virtual bool visit(AccessDeclarationAST *ast);
virtual bool visit(ArrayAccessAST *ast);
virtual bool visit(ArrayDeclaratorAST *ast);
virtual bool visit(ArrayInitializerAST *ast);
virtual bool visit(AsmDefinitionAST *ast);
virtual bool visit(AttributeSpecifierAST *ast);
virtual bool visit(AttributeAST *ast);
virtual bool visit(BaseSpecifierAST *ast);
virtual bool visit(BinaryExpressionAST *ast);
virtual bool visit(BoolLiteralAST *ast);
virtual bool visit(BreakStatementAST *ast);
virtual bool visit(CallAST *ast);
virtual bool visit(CaseStatementAST *ast);
virtual bool visit(CastExpressionAST *ast);
virtual bool visit(CatchClauseAST *ast);
virtual bool visit(ClassSpecifierAST *ast);
virtual bool visit(CompoundLiteralAST *ast);
virtual bool visit(CompoundStatementAST *ast);
virtual bool visit(ConditionAST *ast);
virtual bool visit(ConditionalExpressionAST *ast);
virtual bool visit(ContinueStatementAST *ast);
virtual bool visit(ConversionFunctionIdAST *ast);
virtual bool visit(CppCastExpressionAST *ast);
virtual bool visit(CtorInitializerAST *ast);
virtual bool visit(DeclaratorAST *ast);
virtual bool visit(DeclarationStatementAST *ast);
virtual bool visit(DeclaratorIdAST *ast);
virtual bool visit(DeclaratorListAST *ast);
virtual bool visit(DeleteExpressionAST *ast);
virtual bool visit(DestructorNameAST *ast);
virtual bool visit(DoStatementAST *ast);
virtual bool visit(ElaboratedTypeSpecifierAST *ast);
virtual bool visit(EmptyDeclarationAST *ast);
virtual bool visit(EnumSpecifierAST *ast);
virtual bool visit(EnumeratorAST *ast);
virtual bool visit(ExceptionDeclarationAST *ast);
virtual bool visit(ExceptionSpecificationAST *ast);
virtual bool visit(ExpressionListAST *ast);
virtual bool visit(ExpressionOrDeclarationStatementAST *ast);
virtual bool visit(ExpressionStatementAST *ast);
virtual bool visit(ForStatementAST *ast);
virtual bool visit(FunctionDeclaratorAST *ast);
virtual bool visit(FunctionDefinitionAST *ast);
virtual bool visit(GotoStatementAST *ast);
virtual bool visit(IfStatementAST *ast);
virtual bool visit(LabeledStatementAST *ast);
virtual bool visit(LinkageBodyAST *ast);
virtual bool visit(LinkageSpecificationAST *ast);
virtual bool visit(MemInitializerAST *ast);
virtual bool visit(MemberAccessAST *ast);
virtual bool visit(NamedTypeSpecifierAST *ast);
virtual bool visit(NamespaceAST *ast);
virtual bool visit(NamespaceAliasDefinitionAST *ast);
virtual bool visit(NestedDeclaratorAST *ast);
virtual bool visit(NestedExpressionAST *ast);
virtual bool visit(NestedNameSpecifierAST *ast);
virtual bool visit(NewDeclaratorAST *ast);
virtual bool visit(NewExpressionAST *ast);
virtual bool visit(NewInitializerAST *ast);
virtual bool visit(NewTypeIdAST *ast);
virtual bool visit(NumericLiteralAST *ast);
virtual bool visit(OperatorAST *ast);
virtual bool visit(OperatorFunctionIdAST *ast);
virtual bool visit(ParameterDeclarationAST *ast);
virtual bool visit(ParameterDeclarationClauseAST *ast);
virtual bool visit(PointerAST *ast);
virtual bool visit(PointerToMemberAST *ast);
virtual bool visit(PostIncrDecrAST *ast);
virtual bool visit(PostfixExpressionAST *ast);
virtual bool visit(QualifiedNameAST *ast);
virtual bool visit(ReferenceAST *ast);
virtual bool visit(ReturnStatementAST *ast);
virtual bool visit(SimpleDeclarationAST *ast);
virtual bool visit(SimpleNameAST *ast);
virtual bool visit(SimpleSpecifierAST *ast);
virtual bool visit(SizeofExpressionAST *ast);
virtual bool visit(StringLiteralAST *ast);
virtual bool visit(SwitchStatementAST *ast);
virtual bool visit(TemplateArgumentListAST *ast);
virtual bool visit(TemplateDeclarationAST *ast);
virtual bool visit(TemplateIdAST *ast);
virtual bool visit(TemplateTypeParameterAST *ast);
virtual bool visit(ThisExpressionAST *ast);
virtual bool visit(ThrowExpressionAST *ast);
virtual bool visit(TranslationUnitAST *ast);
virtual bool visit(TryBlockStatementAST *ast);
virtual bool visit(TypeConstructorCallAST *ast);
virtual bool visit(TypeIdAST *ast);
virtual bool visit(TypeidExpressionAST *ast);
virtual bool visit(TypeofSpecifierAST *ast);
virtual bool visit(TypenameCallExpressionAST *ast);
virtual bool visit(TypenameTypeParameterAST *ast);
virtual bool visit(UnaryExpressionAST *ast);
virtual bool visit(UsingAST *ast);
virtual bool visit(UsingDirectiveAST *ast);
virtual bool visit(WhileStatementAST *ast);
virtual bool visit(QtMethodAST *ast);
void indent();
void deindent();
void newline();
private:
std::ostream &out;
unsigned depth;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_PRETTYPRINTER_H

View File

@@ -0,0 +1,310 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "Scope.h"
#include "Symbols.h"
#include "Names.h"
#include "Literals.h"
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <iostream>
CPLUSPLUS_BEGIN_NAMESPACE
Scope::Scope(ScopedSymbol *owner)
: _owner(owner),
_symbols(0),
_allocatedSymbols(0),
_symbolCount(-1),
_hash(0),
_hashSize(0),
_uses(0),
_allocatedUses(0),
_useCount(-1)
{ }
Scope::~Scope()
{
if (_symbols)
free(_symbols);
if (_hash)
free(_hash);
if (_uses)
free(_uses);
}
ScopedSymbol *Scope::owner() const
{ return _owner; }
void Scope::setOwner(ScopedSymbol *owner)
{ _owner = owner; }
Scope *Scope::enclosingScope() const
{
if (! _owner)
return 0;
return _owner->scope();
}
Scope *Scope::enclosingNamespaceScope() const
{
Scope *scope = enclosingScope();
for (; scope; scope = scope->enclosingScope()) {
if (scope->owner()->isNamespace())
break;
}
return scope;
}
Scope *Scope::enclosingClassScope() const
{
Scope *scope = enclosingScope();
for (; scope; scope = scope->enclosingScope()) {
if (scope->owner()->isClass())
break;
}
return scope;
}
Scope *Scope::enclosingEnumScope() const
{
Scope *scope = enclosingScope();
for (; scope; scope = scope->enclosingScope()) {
if (scope->owner()->isEnum())
break;
}
return scope;
}
Scope *Scope::enclosingFunctionScope() const
{
Scope *scope = enclosingScope();
for (; scope; scope = scope->enclosingScope()) {
if (scope->owner()->isFunction())
break;
}
return scope;
}
Scope *Scope::enclosingBlockScope() const
{
Scope *scope = enclosingScope();
for (; scope; scope = scope->enclosingScope()) {
if (scope->owner()->isBlock())
break;
}
return scope;
}
bool Scope::isNamespaceScope() const
{ return dynamic_cast<const Namespace *>(_owner) != 0; }
bool Scope::isClassScope() const
{ return dynamic_cast<const Class *>(_owner) != 0; }
bool Scope::isEnumScope() const
{ return dynamic_cast<const Enum *>(_owner) != 0; }
bool Scope::isBlockScope() const
{ return dynamic_cast<const Block *>(_owner) != 0; }
bool Scope::isPrototypeScope() const
{
if (const Function *f = dynamic_cast<const Function *>(_owner))
return f->arguments() == this;
return false;
}
bool Scope::isFunctionScope() const
{
if (const Function *f = dynamic_cast<const Function *>(_owner))
return f->arguments() != this;
return false;
}
void Scope::enterSymbol(Symbol *symbol)
{
if (++_symbolCount == _allocatedSymbols) {
_allocatedSymbols <<= 1;
if (! _allocatedSymbols)
_allocatedSymbols = DefaultInitialSize;
_symbols = reinterpret_cast<Symbol **>(realloc(_symbols, sizeof(Symbol *) * _allocatedSymbols));
}
assert(! symbol->_scope || symbol->scope() == this);
symbol->_index = _symbolCount;
symbol->_scope = this;
_symbols[_symbolCount] = symbol;
if (_symbolCount >= _hashSize * 0.6)
rehash();
else {
const unsigned h = hashValue(symbol);
symbol->_next = _hash[h];
_hash[h] = symbol;
}
}
Symbol *Scope::lookat(Identifier *id) const
{
if (! _hash)
return 0;
const unsigned h = id->hashCode() % _hashSize;
Symbol *symbol = _hash[h];
for (; symbol; symbol = symbol->_next) {
Name *identity = symbol->identity();
if (NameId *nameId = identity->asNameId()) {
if (nameId->identifier()->isEqualTo(id))
break;
} else if (TemplateNameId *t = identity->asTemplateNameId()) {
if (t->identifier()->isEqualTo(id))
break;
} else if (DestructorNameId *d = identity->asDestructorNameId()) {
if (d->identifier()->isEqualTo(id))
break;
} else if (identity->isQualifiedNameId()) {
assert(0);
}
}
return symbol;
}
Symbol *Scope::lookat(int operatorId) const
{
if (! _hash)
return 0;
const unsigned h = operatorId % _hashSize;
Symbol *symbol = _hash[h];
for (; symbol; symbol = symbol->_next) {
Name *identity = symbol->identity();
if (OperatorNameId *op = identity->asOperatorNameId()) {
if (op->kind() == operatorId)
break;
}
}
return symbol;
}
void Scope::rehash()
{
_hashSize <<= 1;
if (! _hashSize)
_hashSize = DefaultInitialSize;
_hash = reinterpret_cast<Symbol **>(realloc(_hash, sizeof(Symbol *) * _hashSize));
memset(_hash, 0, sizeof(Symbol *) * _hashSize);
for (int index = 0; index < _symbolCount + 1; ++index) {
Symbol *symbol = _symbols[index];
const unsigned h = hashValue(symbol);
symbol->_next = _hash[h];
_hash[h] = symbol;
}
}
unsigned Scope::hashValue(Symbol *symbol) const
{
if (! symbol)
return 0;
return symbol->hashCode() % _hashSize;
}
bool Scope::isEmpty() const
{ return _symbolCount == -1; }
unsigned Scope::symbolCount() const
{ return _symbolCount + 1; }
Symbol *Scope::symbolAt(unsigned index) const
{
if (! _symbols)
return 0;
return _symbols[index];
}
Scope::iterator Scope::firstSymbol() const
{ return _symbols; }
Scope::iterator Scope::lastSymbol() const
{ return _symbols + _symbolCount + 1; }
unsigned Scope::useCount() const
{ return _useCount + 1; }
Use *Scope::useAt(unsigned index) const
{ return &_uses[index]; }
void Scope::addUse(unsigned sourceOffset, Name *name)
{
#ifdef CPLUSPLUS_WITH_USES
if (++_useCount == _allocatedUses) {
_allocatedUses += 4;
_uses = reinterpret_cast<Use *>(realloc(_uses, _allocatedUses * sizeof(Use)));
}
Symbol *lastVisibleSymbol;
if (_symbolCount == -1)
lastVisibleSymbol = owner();
else
lastVisibleSymbol = _symbols[_symbolCount];
_uses[_useCount].init(sourceOffset, name, lastVisibleSymbol);
#endif
}
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,198 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_SCOPE_H
#define CPLUSPLUS_SCOPE_H
#include "CPlusPlusForwardDeclarations.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT Use
{
public:
inline Name *name() const
{ return _name; }
inline unsigned sourceOffset() const
{ return _sourceOffset; }
inline Symbol *lastVisibleSymbol() const
{ return _lastVisibleSymbol; }
private:
void init(unsigned sourceOffset, Name *name, Symbol *lastVisibleSymbol)
{
_sourceOffset = sourceOffset;
_name = name;
_lastVisibleSymbol = lastVisibleSymbol;
}
unsigned _sourceOffset;
Name *_name;
Symbol *_lastVisibleSymbol;
friend class Scope;
};
class CPLUSPLUS_EXPORT Scope
{
Scope(const Scope &other);
void operator =(const Scope &other);
public:
typedef Symbol **iterator;
public:
/// Constructs an empty Scope.
Scope(ScopedSymbol *owner = 0);
/// Destroy this scope.
~Scope();
/// Returns this scope's owner Symbol.
ScopedSymbol *owner() const;
/// Sets this scope's owner Symbol.
void setOwner(ScopedSymbol *owner); // ### remove me
/// Returns the enclosing scope.
Scope *enclosingScope() const;
/// Returns the eclosing namespace scope.
Scope *enclosingNamespaceScope() const;
/// Returns the enclosing class scope.
Scope *enclosingClassScope() const;
/// Returns the enclosing enum scope.
Scope *enclosingEnumScope() const;
/// Rerturns the enclosing function scope.
Scope *enclosingFunctionScope() const;
/// Rerturns the enclosing Block scope.
Scope *enclosingBlockScope() const;
/// Returns true if this scope's owner is a Namespace Symbol.
bool isNamespaceScope() const;
/// Returns true if this scope's owner is a Class Symbol.
bool isClassScope() const;
/// Returns true if this scope's owner is an Enum Symbol.
bool isEnumScope() const;
/// Returns true if this scope's owner is a Block Symbol.
bool isBlockScope() const;
/// Returns true if this scope's owner is a Function Symbol.
bool isFunctionScope() const;
/// Returns true if this scope's owner is a Prototype Symbol.
bool isPrototypeScope() const;
/// Adds a Symbol to this Scope.
void enterSymbol(Symbol *symbol);
/// Returns true if this Scope is empty; otherwise returns false.
bool isEmpty() const;
/// Returns the number of symbols is in the scope.
unsigned symbolCount() const;
/// Returns the Symbol at the given position.
Symbol *symbolAt(unsigned index) const;
/// Returns the first Symbol in the scope.
iterator firstSymbol() const;
/// Returns the last Symbol in the scope.
iterator lastSymbol() const;
Symbol *lookat(Identifier *id) const;
Symbol *lookat(int operatorId) const;
unsigned useCount() const;
Use *useAt(unsigned index) const;
void addUse(unsigned sourceOffset, Name *name);
private:
/// Returns the hash value for the given Symbol.
unsigned hashValue(Symbol *symbol) const;
/// Updates the hash table.
void rehash();
private:
enum { DefaultInitialSize = 11 };
ScopedSymbol *_owner;
Symbol **_symbols;
int _allocatedSymbols;
int _symbolCount;
Symbol **_hash;
int _hashSize;
Use *_uses;
int _allocatedUses;
int _useCount;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_SCOPE_H

View File

@@ -0,0 +1,198 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "Semantic.h"
#include "TranslationUnit.h"
#include "Control.h"
#include "Scope.h"
#include "Symbols.h"
#include "Token.h"
#include "CheckSpecifier.h"
#include "CheckDeclaration.h"
#include "CheckDeclarator.h"
#include "CheckStatement.h"
#include "CheckExpression.h"
#include "CheckName.h"
CPLUSPLUS_BEGIN_NAMESPACE
class Semantic::Data
{
public:
Data(Semantic *semantic, Control *control)
: semantic(semantic),
control(control),
visibility(Symbol::Public),
methodKey(Function::NormalMethod),
checkSpecifier(0),
checkDeclaration(0),
checkDeclarator(0),
checkExpression(0),
checkStatement(0),
checkName(0)
{ }
~Data()
{
delete checkSpecifier;
delete checkDeclaration;
delete checkDeclarator;
delete checkExpression;
delete checkStatement;
delete checkName;
}
Semantic *semantic;
Control *control;
int visibility;
int methodKey;
CheckSpecifier *checkSpecifier;
CheckDeclaration *checkDeclaration;
CheckDeclarator *checkDeclarator;
CheckExpression *checkExpression;
CheckStatement *checkStatement;
CheckName *checkName;
};
Semantic::Semantic(Control *control)
{
d = new Data(this, control);
d->checkSpecifier = new CheckSpecifier(this);
d->checkDeclaration = new CheckDeclaration(this);
d->checkDeclarator = new CheckDeclarator(this);
d->checkExpression = new CheckExpression(this);
d->checkStatement = new CheckStatement(this);
d->checkName = new CheckName(this);
}
Semantic::~Semantic()
{ delete d; }
Control *Semantic::control() const
{ return d->control; }
FullySpecifiedType Semantic::check(SpecifierAST *specifier, Scope *scope)
{ return d->checkSpecifier->check(specifier, scope); }
void Semantic::check(DeclarationAST *declaration, Scope *scope, Scope *templateParameters)
{ d->checkDeclaration->check(declaration, scope, templateParameters); }
FullySpecifiedType Semantic::check(DeclaratorAST *declarator, FullySpecifiedType type,
Scope *scope, Name **name)
{ return d->checkDeclarator->check(declarator, type, scope, name); }
FullySpecifiedType Semantic::check(PtrOperatorAST *ptrOperators, FullySpecifiedType type,
Scope *scope)
{ return d->checkDeclarator->check(ptrOperators, type, scope); }
FullySpecifiedType Semantic::check(ExpressionAST *expression, Scope *scope)
{ return d->checkExpression->check(expression, scope); }
void Semantic::check(StatementAST *statement, Scope *scope)
{ d->checkStatement->check(statement, scope); }
Name *Semantic::check(NameAST *name, Scope *scope)
{ return d->checkName->check(name, scope); }
Name *Semantic::check(NestedNameSpecifierAST *name, Scope *scope)
{ return d->checkName->check(name, scope); }
int Semantic::currentVisibility() const
{ return d->visibility; }
int Semantic::switchVisibility(int visibility)
{
int previousVisibility = d->visibility;
d->visibility = visibility;
return previousVisibility;
}
int Semantic::currentMethodKey() const
{ return d->methodKey; }
int Semantic::switchMethodKey(int methodKey)
{
int previousMethodKey = d->methodKey;
d->methodKey = methodKey;
return previousMethodKey;
}
int Semantic::visibilityForAccessSpecifier(int tokenKind) const
{
switch (tokenKind) {
case T_PUBLIC:
return Symbol::Public;
case T_PROTECTED:
return Symbol::Protected;
case T_PRIVATE:
return Symbol::Private;
case T_SIGNALS:
return Symbol::Protected;
default:
return Symbol::Public;
}
}
int Semantic::visibilityForClassKey(int tokenKind) const
{
switch (tokenKind) {
case T_CLASS:
return Symbol::Private;
case T_STRUCT:
case T_UNION:
return Symbol::Public;
default:
return Symbol::Public;
}
}
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,109 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_SEMANTIC_H
#define CPLUSPLUS_SEMANTIC_H
#include "CPlusPlusForwardDeclarations.h"
#include "ASTfwd.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT Semantic
{
Semantic(const Semantic &other);
void operator =(const Semantic &other);
public:
Semantic(Control *control);
virtual ~Semantic();
Control *control() const;
FullySpecifiedType check(SpecifierAST *specifier, Scope *scope);
FullySpecifiedType check(DeclaratorAST *declarator, FullySpecifiedType type,
Scope *scope, Name **name = 0); // ### ugly
FullySpecifiedType check(PtrOperatorAST *ptrOperators, FullySpecifiedType type,
Scope *scope);
FullySpecifiedType check(ExpressionAST *expression, Scope *scope);
void check(DeclarationAST *declaration, Scope *scope, Scope *templateParameters = 0);
void check(StatementAST *statement, Scope *scope);
Name *check(NameAST *name, Scope *scope);
Name *check(NestedNameSpecifierAST *name, Scope *scope);
int currentVisibility() const;
int switchVisibility(int visibility);
int currentMethodKey() const;
int switchMethodKey(int methodKey);
int visibilityForClassKey(int tokenKind) const;
int visibilityForAccessSpecifier(int tokenKind) const;
private:
class Data;
friend class Data;
Data *d;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_SEMANTIC_H

View File

@@ -0,0 +1,72 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "SemanticCheck.h"
#include "Semantic.h"
CPLUSPLUS_BEGIN_NAMESPACE
SemanticCheck::SemanticCheck(Semantic *semantic)
: ASTVisitor(semantic->control()),
_semantic(semantic)
{ }
SemanticCheck::~SemanticCheck()
{ }
Semantic *SemanticCheck::semantic() const
{ return _semantic; }
Control *SemanticCheck::control() const
{ return _semantic->control(); }
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,78 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_SEMANTICCHECK_H
#define CPLUSPLUS_SEMANTICCHECK_H
#include "CPlusPlusForwardDeclarations.h"
#include "ASTVisitor.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT SemanticCheck: public ASTVisitor
{
public:
SemanticCheck(Semantic *semantic);
virtual ~SemanticCheck();
Control *control() const;
Semantic *semantic() const;
private:
Semantic *_semantic;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_SEMANTICCHECK_H

View File

@@ -0,0 +1,421 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "Symbol.h"
#include "Symbols.h"
#include "Control.h"
#include "Names.h"
#include "TranslationUnit.h"
#include "Literals.h"
#include "MemoryPool.h"
#include "SymbolVisitor.h"
#include "NameVisitor.h"
#include <cstddef>
#include <cassert>
CPLUSPLUS_BEGIN_NAMESPACE
class Symbol::HashCode: protected NameVisitor
{
public:
HashCode()
: _value(0)
{ }
virtual ~HashCode()
{ }
unsigned operator()(Name *name)
{
unsigned previousValue = switchValue(0);
accept(name);
return switchValue(previousValue);
}
protected:
unsigned switchValue(unsigned value)
{
unsigned previousValue = _value;
_value = value;
return previousValue;
}
virtual void visit(NameId *name)
{ _value = name->identifier()->hashCode(); }
virtual void visit(TemplateNameId *name)
{ _value = name->identifier()->hashCode(); }
virtual void visit(DestructorNameId *name)
{ _value = name->identifier()->hashCode(); }
virtual void visit(OperatorNameId *name)
{ _value = unsigned(name->kind()); }
virtual void visit(ConversionNameId *)
{ _value = 0; } // ### TODO: implement me
virtual void visit(QualifiedNameId *name)
{ _value = operator()(name->unqualifiedNameId()); }
private:
unsigned _value;
};
class Symbol::IdentityForName: protected NameVisitor
{
public:
IdentityForName()
: _identity(0)
{ }
virtual ~IdentityForName()
{ }
Name *operator()(Name *name)
{
Name *previousIdentity = switchIdentity(0);
accept(name);
return switchIdentity(previousIdentity);
}
protected:
Name *switchIdentity(Name *identity)
{
Name *previousIdentity = _identity;
_identity = identity;
return previousIdentity;
}
virtual void visit(NameId *name)
{ _identity = name; }
virtual void visit(TemplateNameId *name)
{ _identity = name; }
virtual void visit(DestructorNameId *name)
{ _identity = name; }
virtual void visit(OperatorNameId *name)
{ _identity = name; }
virtual void visit(ConversionNameId *name)
{ _identity = name; }
virtual void visit(QualifiedNameId *name)
{ _identity = name->unqualifiedNameId(); }
private:
Name *_identity;
};
Symbol::Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name)
: _control(translationUnit->control()),
_sourceLocation(sourceLocation),
_sourceOffset(0),
_name(0),
_hashCode(0),
_storage(Symbol::NoStorage),
_visibility(Symbol::Public),
_scope(0),
_index(0),
_next(0)
{
if (sourceLocation)
_sourceOffset = translationUnit->tokenAt(sourceLocation).offset;
setName(name);
}
Symbol::~Symbol()
{ }
Control *Symbol::control() const
{ return _control; }
TranslationUnit *Symbol::translationUnit() const
{ return _control->translationUnit(); }
void Symbol::visitSymbol(SymbolVisitor *visitor)
{
if (visitor->preVisit(this))
visitSymbol0(visitor);
visitor->postVisit(this);
}
void Symbol::visitSymbol(Symbol *symbol, SymbolVisitor *visitor)
{
if (! symbol)
return;
symbol->visitSymbol(visitor);
}
unsigned Symbol::sourceLocation() const
{ return _sourceLocation; }
unsigned Symbol::sourceOffset() const
{ return _sourceOffset; }
unsigned Symbol::line() const
{
unsigned line = 0, column = 0;
StringLiteral *fileId = 0;
translationUnit()->getPosition(_sourceOffset, &line, &column, &fileId);
return line;
}
unsigned Symbol::column() const
{
#ifdef CPLUSPLUS_WITH_COLUMNS
unsigned line = 0, column = 0;
StringLiteral *fileId = 0;
translationUnit()->getPosition(_sourceOffset, &line, &column, &fileId);
return column;
#else
return 0;
#endif
}
StringLiteral *Symbol::fileId() const
{
unsigned line = 0, column = 0;
StringLiteral *fileId = 0;
translationUnit()->getPosition(_sourceOffset, &line, &column, &fileId);
return fileId;
}
const char *Symbol::fileName() const
{ return fileId()->chars(); }
unsigned Symbol::fileNameLength() const
{ return fileId()->size(); }
Name *Symbol::identity() const
{
IdentityForName id;
return id(_name);
}
Name *Symbol::name() const
{ return _name; }
void Symbol::setName(Name *name)
{
_name = name;
if (! _name)
_hashCode = 0;
else {
IdentityForName identityForName;
HashCode hh;
_hashCode = hh(identityForName(_name));
}
}
Scope *Symbol::scope() const
{ return _scope; }
void Symbol::setScope(Scope *scope)
{
assert(! _scope);
_scope = scope;
}
unsigned Symbol::index() const
{ return _index; }
Symbol *Symbol::next() const
{ return _next; }
unsigned Symbol::hashCode() const
{ return _hashCode; }
int Symbol::storage() const
{ return _storage; }
void Symbol::setStorage(int storage)
{ _storage = storage; }
int Symbol::visibility() const
{ return _visibility; }
void Symbol::setVisibility(int visibility)
{ _visibility = visibility; }
bool Symbol::isFriend() const
{ return _storage == Friend; }
bool Symbol::isRegister() const
{ return _storage == Register; }
bool Symbol::isStatic() const
{ return _storage == Static; }
bool Symbol::isExtern() const
{ return _storage == Extern; }
bool Symbol::isMutable() const
{ return _storage == Mutable; }
bool Symbol::isTypedef() const
{ return _storage == Typedef; }
bool Symbol::isPublic() const
{ return _visibility == Public; }
bool Symbol::isProtected() const
{ return _visibility == Protected; }
bool Symbol::isPrivate() const
{ return _visibility == Private; }
bool Symbol::isScopedSymbol() const
{ return dynamic_cast<const ScopedSymbol *>(this) != 0; }
bool Symbol::isEnum() const
{ return dynamic_cast<const Enum *>(this) != 0; }
bool Symbol::isFunction() const
{ return dynamic_cast<const Function *>(this) != 0; }
bool Symbol::isNamespace() const
{ return dynamic_cast<const Namespace *>(this) != 0; }
bool Symbol::isClass() const
{ return dynamic_cast<const Class *>(this) != 0; }
bool Symbol::isBlock() const
{ return dynamic_cast<const Block *>(this) != 0; }
bool Symbol::isUsingNamespaceDirective() const
{ return dynamic_cast<const UsingNamespaceDirective *>(this) != 0; }
bool Symbol::isUsingDeclaration() const
{ return dynamic_cast<const UsingDeclaration *>(this) != 0; }
bool Symbol::isDeclaration() const
{ return dynamic_cast<const Declaration *>(this) != 0; }
bool Symbol::isArgument() const
{ return dynamic_cast<const Argument *>(this) != 0; }
bool Symbol::isBaseClass() const
{ return dynamic_cast<const BaseClass *>(this) != 0; }
const ScopedSymbol *Symbol::asScopedSymbol() const
{ return dynamic_cast<const ScopedSymbol *>(this); }
const Enum *Symbol::asEnum() const
{ return dynamic_cast<const Enum *>(this); }
const Function *Symbol::asFunction() const
{ return dynamic_cast<const Function *>(this); }
const Namespace *Symbol::asNamespace() const
{ return dynamic_cast<const Namespace *>(this); }
const Class *Symbol::asClass() const
{ return dynamic_cast<const Class *>(this); }
const Block *Symbol::asBlock() const
{ return dynamic_cast<const Block *>(this); }
const UsingNamespaceDirective *Symbol::asUsingNamespaceDirective() const
{ return dynamic_cast<const UsingNamespaceDirective *>(this); }
const UsingDeclaration *Symbol::asUsingDeclaration() const
{ return dynamic_cast<const UsingDeclaration *>(this); }
const Declaration *Symbol::asDeclaration() const
{ return dynamic_cast<const Declaration *>(this); }
const Argument *Symbol::asArgument() const
{ return dynamic_cast<const Argument *>(this); }
const BaseClass *Symbol::asBaseClass() const
{ return dynamic_cast<const BaseClass *>(this); }
ScopedSymbol *Symbol::asScopedSymbol()
{ return dynamic_cast<ScopedSymbol *>(this); }
Enum *Symbol::asEnum()
{ return dynamic_cast<Enum *>(this); }
Function *Symbol::asFunction()
{ return dynamic_cast<Function *>(this); }
Namespace *Symbol::asNamespace()
{ return dynamic_cast<Namespace *>(this); }
Class *Symbol::asClass()
{ return dynamic_cast<Class *>(this); }
Block *Symbol::asBlock()
{ return dynamic_cast<Block *>(this); }
UsingNamespaceDirective *Symbol::asUsingNamespaceDirective()
{ return dynamic_cast<UsingNamespaceDirective *>(this); }
UsingDeclaration *Symbol::asUsingDeclaration()
{ return dynamic_cast<UsingDeclaration *>(this); }
Declaration *Symbol::asDeclaration()
{ return dynamic_cast<Declaration *>(this); }
Argument *Symbol::asArgument()
{ return dynamic_cast<Argument *>(this); }
BaseClass *Symbol::asBaseClass()
{ return dynamic_cast<BaseClass *>(this); }
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,266 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_SYMBOL_H
#define CPLUSPLUS_SYMBOL_H
#include "CPlusPlusForwardDeclarations.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT Symbol
{
Symbol(const Symbol &other);
void operator =(const Symbol &other);
public:
/// Storage class specifier
enum Storage {
NoStorage = 0,
Friend,
Register,
Static,
Extern,
Mutable,
Typedef
};
/// Access specifier.
enum Visibility {
Public,
Protected,
Private
};
public:
/// Constructs a Symbol with the given source location, name and translation unit.
Symbol(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name);
/// Destroy this Symbol.
virtual ~Symbol();
/// Returns this Symbol's Control object.
Control *control() const;
/// Returns this Symbol's source location.
unsigned sourceLocation() const;
/// Returns this Symbol's source offset.
unsigned sourceOffset() const;
/// Returns this Symbol's line number.
unsigned line() const;
/// Returns this Symbol's column number.
unsigned column() const;
/// Returns this Symbol's file name.
StringLiteral *fileId() const;
/// Returns this Symbol's file name.
const char *fileName() const;
/// Returns this Symbol's file name length.
unsigned fileNameLength() const;
/// Returns this Symbol's name.
Name *name() const;
/// Sets this Symbol's name.
void setName(Name *name); // ### dangerous
/// Returns this Symbol's storage class specifier.
int storage() const;
/// Sets this Symbol's storage class specifier.
void setStorage(int storage);
/// Returns this Symbol's visibility.
int visibility() const;
/// Sets this Symbol's visibility.
void setVisibility(int visibility);
/// Returns this Symbol's scope.
Scope *scope() const;
/// Returns the next chained Symbol.
Symbol *next() const;
/// Returns true if this Symbol has friend storage specifier.
bool isFriend() const;
/// Returns true if this Symbol has register storage specifier.
bool isRegister() const;
/// Returns true if this Symbol has static storage specifier.
bool isStatic() const;
/// Returns true if this Symbol has extern storage specifier.
bool isExtern() const;
/// Returns true if this Symbol has mutable storage specifier.
bool isMutable() const;
/// Returns true if this Symbol has typedef storage specifier.
bool isTypedef() const;
/// Returns true if this Symbol's visibility is public.
bool isPublic() const;
/// Returns true if this Symbol's visibility is protected.
bool isProtected() const;
/// Returns true if this Symbol's visibility is private.
bool isPrivate() const;
/// Returns true if this Symbol is a ScopedSymbol.
bool isScopedSymbol() const;
/// Returns true if this Symbol is an Enum.
bool isEnum() const;
/// Returns true if this Symbol is an Function.
bool isFunction() const;
/// Returns true if this Symbol is a Namespace.
bool isNamespace() const;
/// Returns true if this Symbol is a Class.
bool isClass() const;
/// Returns true if this Symbol is a Block.
bool isBlock() const;
/// Returns true if this Symbol is a UsingNamespaceDirective.
bool isUsingNamespaceDirective() const;
/// Returns true if this Symbol is a UsingDeclaration.
bool isUsingDeclaration() const;
/// Returns true if this Symbol is a Declaration.
bool isDeclaration() const;
/// Returns true if this Symbol is an Argument.
bool isArgument() const;
/// Returns true if this Symbol is a BaseClass.
bool isBaseClass() const;
const ScopedSymbol *asScopedSymbol() const;
const Enum *asEnum() const;
const Function *asFunction() const;
const Namespace *asNamespace() const;
const Class *asClass() const;
const Block *asBlock() const;
const UsingNamespaceDirective *asUsingNamespaceDirective() const;
const UsingDeclaration *asUsingDeclaration() const;
const Declaration *asDeclaration() const;
const Argument *asArgument() const;
const BaseClass *asBaseClass() const;
ScopedSymbol *asScopedSymbol();
Enum *asEnum();
Function *asFunction();
Namespace *asNamespace();
Class *asClass();
Block *asBlock();
UsingNamespaceDirective *asUsingNamespaceDirective();
UsingDeclaration *asUsingDeclaration();
Declaration *asDeclaration();
Argument *asArgument();
BaseClass *asBaseClass();
/// Returns this Symbol's type.
virtual FullySpecifiedType type() const = 0;
/// Returns this Symbol's hash value.
unsigned hashCode() const;
/// Returns this Symbol's index.
unsigned index() const;
Name *identity() const;
void setScope(Scope *scope); // ### make me private
void visitSymbol(SymbolVisitor *visitor);
static void visitSymbol(Symbol *symbol, SymbolVisitor *visitor);
protected:
virtual void visitSymbol0(SymbolVisitor *visitor) = 0;
TranslationUnit *translationUnit() const;
private:
Control *_control;
unsigned _sourceLocation;
unsigned _sourceOffset;
Name *_name;
unsigned _hashCode;
int _storage;
int _visibility;
Scope *_scope;
unsigned _index;
Symbol *_next;
class IdentityForName;
class HashCode;
friend class Scope;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_SYMBOL_H

View File

@@ -0,0 +1,66 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "SymbolVisitor.h"
#include "Symbol.h"
CPLUSPLUS_USE_NAMESPACE
SymbolVisitor::SymbolVisitor()
{ }
SymbolVisitor::~SymbolVisitor()
{ }
void SymbolVisitor::accept(Symbol *symbol)
{ Symbol::visitSymbol(symbol, this); }

View File

@@ -0,0 +1,90 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef SYMBOLVISITOR_H
#define SYMBOLVISITOR_H
#include "CPlusPlusForwardDeclarations.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT SymbolVisitor
{
SymbolVisitor(const SymbolVisitor &other);
void operator =(const SymbolVisitor &other);
public:
SymbolVisitor();
virtual ~SymbolVisitor();
void accept(Symbol *symbol);
virtual bool preVisit(Symbol *) { return true; }
virtual void postVisit(Symbol *) {}
virtual bool visit(UsingNamespaceDirective *) { return true; }
virtual bool visit(UsingDeclaration *) { return true; }
virtual bool visit(Declaration *) { return true; }
virtual bool visit(Argument *) { return true; }
virtual bool visit(BaseClass *) { return true; }
virtual bool visit(Enum *) { return true; }
virtual bool visit(Function *) { return true; }
virtual bool visit(Namespace *) { return true; }
virtual bool visit(Class *) { return true; }
virtual bool visit(Block *) { return true; }
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // SYMBOLVISITOR_H

View File

@@ -0,0 +1,484 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "Symbols.h"
#include "Names.h"
#include "TypeVisitor.h"
#include "SymbolVisitor.h"
#include "Scope.h"
#include <cstdlib>
CPLUSPLUS_BEGIN_NAMESPACE
UsingNamespaceDirective::UsingNamespaceDirective(TranslationUnit *translationUnit,
unsigned sourceLocation, Name *name)
: Symbol(translationUnit, sourceLocation, name)
{ }
UsingNamespaceDirective::~UsingNamespaceDirective()
{ }
FullySpecifiedType UsingNamespaceDirective::type() const
{ return FullySpecifiedType(); }
void UsingNamespaceDirective::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }
UsingDeclaration::UsingDeclaration(TranslationUnit *translationUnit,
unsigned sourceLocation, Name *name)
: Symbol(translationUnit, sourceLocation, name)
{ }
UsingDeclaration::~UsingDeclaration()
{ }
FullySpecifiedType UsingDeclaration::type() const
{ return FullySpecifiedType(); }
void UsingDeclaration::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }
Declaration::Declaration(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name)
: Symbol(translationUnit, sourceLocation, name),
_templateParameters(0)
{ }
Declaration::~Declaration()
{ delete _templateParameters; }
unsigned Declaration::templateParameterCount() const
{
if (! _templateParameters)
return 0;
return _templateParameters->symbolCount();
}
Symbol *Declaration::templateParameterAt(unsigned index) const
{ return _templateParameters->symbolAt(index); }
Scope *Declaration::templateParameters() const
{ return _templateParameters; }
void Declaration::setTemplateParameters(Scope *templateParameters)
{ _templateParameters = templateParameters; }
void Declaration::setType(FullySpecifiedType type)
{ _type = type; }
FullySpecifiedType Declaration::type() const
{ return _type; }
void Declaration::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }
Argument::Argument(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name)
: Symbol(translationUnit, sourceLocation, name),
_initializer(false)
{ }
Argument::~Argument()
{ }
bool Argument::hasInitializer() const
{ return _initializer; }
void Argument::setInitializer(bool hasInitializer)
{ _initializer = hasInitializer; }
void Argument::setType(FullySpecifiedType type)
{ _type = type; }
FullySpecifiedType Argument::type() const
{ return _type; }
void Argument::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }
Function::Function(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name)
: ScopedSymbol(translationUnit, sourceLocation, name),
_templateParameters(0),
_flags(0)
{ _arguments = new Scope(this); }
Function::~Function()
{
delete _templateParameters;
delete _arguments;
}
bool Function::isNormal() const
{ return _methodKey == NormalMethod; }
bool Function::isSignal() const
{ return _methodKey == SignalMethod; }
bool Function::isSlot() const
{ return _methodKey == SlotMethod; }
int Function::methodKey() const
{ return _methodKey; }
void Function::setMethodKey(int key)
{ _methodKey = key; }
unsigned Function::templateParameterCount() const
{
if (! _templateParameters)
return 0;
return _templateParameters->symbolCount();
}
Symbol *Function::templateParameterAt(unsigned index) const
{ return _templateParameters->symbolAt(index); }
Scope *Function::templateParameters() const
{ return _templateParameters; }
void Function::setTemplateParameters(Scope *templateParameters)
{ _templateParameters = templateParameters; }
bool Function::isEqualTo(const Type *other) const
{
const Function *o = other->asFunction();
if (! o)
return false;
Name *l = identity();
Name *r = o->identity();
if (l == r || (l && l->isEqualTo(r))) {
if (_arguments->symbolCount() != o->_arguments->symbolCount())
return false;
else if (! _returnType.isEqualTo(o->_returnType))
return false;
for (unsigned i = 0; i < _arguments->symbolCount(); ++i) {
Symbol *l = _arguments->symbolAt(i);
Symbol *r = o->_arguments->symbolAt(i);
if (! l->type().isEqualTo(r->type()))
return false;
}
return true;
}
return false;
}
void Function::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }
FullySpecifiedType Function::type() const
{ return FullySpecifiedType(const_cast<Function *>(this)); }
FullySpecifiedType Function::returnType() const
{ return _returnType; }
void Function::setReturnType(FullySpecifiedType returnType)
{ _returnType = returnType; }
unsigned Function::argumentCount() const
{
if (! _arguments)
return 0;
return _arguments->symbolCount();
}
Symbol *Function::argumentAt(unsigned index) const
{ return _arguments->symbolAt(index); }
Scope *Function::arguments() const
{ return _arguments; }
bool Function::isVariadic() const
{ return _isVariadic; }
void Function::setVariadic(bool isVariadic)
{ _isVariadic = isVariadic; }
bool Function::isConst() const
{ return _isConst; }
void Function::setConst(bool isConst)
{ _isConst = isConst; }
bool Function::isVolatile() const
{ return _isVolatile; }
void Function::setVolatile(bool isVolatile)
{ _isVolatile = isVolatile; }
bool Function::isPureVirtual() const
{ return _isPureVirtual; }
void Function::setPureVirtual(bool isPureVirtual)
{ _isPureVirtual = isPureVirtual; }
void Function::visitSymbol0(SymbolVisitor *visitor)
{
if (visitor->visit(this)) {
for (unsigned i = 0; i < _arguments->symbolCount(); ++i) {
visitSymbol(_arguments->symbolAt(i), visitor);
}
for (unsigned i = 0; i < memberCount(); ++i) {
visitSymbol(memberAt(i), visitor);
}
}
}
ScopedSymbol::ScopedSymbol(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name)
: Symbol(translationUnit, sourceLocation, name)
{ _members = new Scope(this); }
ScopedSymbol::~ScopedSymbol()
{ delete _members; }
unsigned ScopedSymbol::memberCount() const
{
if (! _members)
return 0;
return _members->symbolCount();
}
Symbol *ScopedSymbol::memberAt(unsigned index) const
{
if (! _members)
return 0;
return _members->symbolAt(index);
}
Scope *ScopedSymbol::members() const
{ return _members; }
void ScopedSymbol::addMember(Symbol *member)
{ _members->enterSymbol(member); }
Block::Block(TranslationUnit *translationUnit, unsigned sourceLocation)
: ScopedSymbol(translationUnit, sourceLocation, /*name = */ 0)
{ }
Block::~Block()
{ }
FullySpecifiedType Block::type() const
{ return FullySpecifiedType(); }
void Block::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }
Enum::Enum(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name)
: ScopedSymbol(translationUnit, sourceLocation, name)
{ }
Enum::~Enum()
{ }
FullySpecifiedType Enum::type() const
{ return FullySpecifiedType(const_cast<Enum *>(this)); }
bool Enum::isEqualTo(const Type *other) const
{
const Enum *o = other->asEnum();
if (! o)
return false;
Name *l = identity();
Name *r = o->identity();
if (l == r)
return true;
else if (! l)
return false;
return l->isEqualTo(r);
}
void Enum::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }
void Enum::visitSymbol0(SymbolVisitor *visitor)
{
if (visitor->visit(this)) {
for (unsigned i = 0; i < memberCount(); ++i) {
visitSymbol(memberAt(i), visitor);
}
}
}
Namespace::Namespace(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name)
: ScopedSymbol(translationUnit, sourceLocation, name)
{ }
Namespace::~Namespace()
{ }
bool Namespace::isEqualTo(const Type *other) const
{
const Namespace *o = other->asNamespace();
if (! o)
return false;
Name *l = identity();
Name *r = o->identity();
if (l == r || (l && l->isEqualTo(r)))
return true;
return false;
}
void Namespace::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }
void Namespace::visitSymbol0(SymbolVisitor *visitor)
{
if (visitor->visit(this)) {
for (unsigned i = 0; i < memberCount(); ++i) {
visitSymbol(memberAt(i), visitor);
}
}
}
FullySpecifiedType Namespace::type() const
{ return FullySpecifiedType(const_cast<Namespace *>(this)); }
BaseClass::BaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name)
: Symbol(translationUnit, sourceLocation, name),
_isVirtual(false)
{ }
BaseClass::~BaseClass()
{ }
FullySpecifiedType BaseClass::type() const
{ return FullySpecifiedType(); }
bool BaseClass::isVirtual() const
{ return _isVirtual; }
void BaseClass::setVirtual(bool isVirtual)
{ _isVirtual = isVirtual; }
void BaseClass::visitSymbol0(SymbolVisitor *visitor)
{ visitor->visit(this); }
Class::Class(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name)
: ScopedSymbol(translationUnit, sourceLocation, name),
_key(ClassKey),
_templateParameters(0)
{ }
Class::~Class()
{ delete _templateParameters; }
bool Class::isClass() const
{ return _key == ClassKey; }
bool Class::isStruct() const
{ return _key == StructKey; }
bool Class::isUnion() const
{ return _key == UnionKey; }
Class::Key Class::classKey() const
{ return _key; }
void Class::setClassKey(Key key)
{ _key = key; }
unsigned Class::templateParameterCount() const
{
if (! _templateParameters)
return 0;
return _templateParameters->symbolCount();
}
Symbol *Class::templateParameterAt(unsigned index) const
{ return _templateParameters->symbolAt(index); }
Scope *Class::templateParameters() const
{ return _templateParameters; }
void Class::setTemplateParameters(Scope *templateParameters)
{ _templateParameters = templateParameters; }
void Class::accept0(TypeVisitor *visitor)
{ visitor->visit(this); }
unsigned Class::baseClassCount() const
{ return _baseClasses.count(); }
BaseClass *Class::baseClassAt(unsigned index) const
{ return _baseClasses.at(index); }
void Class::addBaseClass(BaseClass *baseClass)
{ _baseClasses.push_back(baseClass); }
FullySpecifiedType Class::type() const
{ return FullySpecifiedType(const_cast<Class *>(this)); }
bool Class::isEqualTo(const Type *other) const
{
const Class *o = other->asClass();
if (! o)
return false;
Name *l = identity();
Name *r = o->identity();
if (l == r || (l && l->isEqualTo(r)))
return true;
else
return false;
}
void Class::visitSymbol0(SymbolVisitor *visitor)
{
if (visitor->visit(this)) {
for (unsigned i = 0; i < _baseClasses.size(); ++i) {
visitSymbol(_baseClasses.at(i), visitor);
}
for (unsigned i = 0; i < memberCount(); ++i) {
visitSymbol(memberAt(i), visitor);
}
}
}
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,338 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_SYMBOLS_H
#define CPLUSPLUS_SYMBOLS_H
#include "CPlusPlusForwardDeclarations.h"
#include "Symbol.h"
#include "Type.h"
#include "FullySpecifiedType.h"
#include "Array.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT UsingNamespaceDirective: public Symbol
{
public:
UsingNamespaceDirective(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name);
virtual ~UsingNamespaceDirective();
// Symbol's interface
virtual FullySpecifiedType type() const;
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
};
class CPLUSPLUS_EXPORT UsingDeclaration: public Symbol
{
public:
UsingDeclaration(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name);
virtual ~UsingDeclaration();
// Symbol's interface
virtual FullySpecifiedType type() const;
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
};
class CPLUSPLUS_EXPORT Declaration: public Symbol
{
public:
Declaration(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name);
virtual ~Declaration();
unsigned templateParameterCount() const;
Symbol *templateParameterAt(unsigned index) const;
Scope *templateParameters() const;
void setTemplateParameters(Scope *templateParameters);
void setType(FullySpecifiedType type);
// Symbol's interface
virtual FullySpecifiedType type() const;
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
private:
FullySpecifiedType _type;
Scope *_templateParameters;
};
class CPLUSPLUS_EXPORT Argument: public Symbol
{
public:
Argument(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name);
virtual ~Argument();
void setType(FullySpecifiedType type);
bool hasInitializer() const;
void setInitializer(bool hasInitializer);
// Symbol's interface
virtual FullySpecifiedType type() const;
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
private:
FullySpecifiedType _type;
bool _initializer: 1;
};
class CPLUSPLUS_EXPORT ScopedSymbol: public Symbol
{
public:
ScopedSymbol(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name);
virtual ~ScopedSymbol();
unsigned memberCount() const;
Symbol *memberAt(unsigned index) const;
Scope *members() const;
void addMember(Symbol *member);
private:
Scope *_members;
};
class CPLUSPLUS_EXPORT Block: public ScopedSymbol
{
public:
Block(TranslationUnit *translationUnit, unsigned sourceLocation);
virtual ~Block();
// Symbol's interface
virtual FullySpecifiedType type() const;
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
};
class CPLUSPLUS_EXPORT Enum: public ScopedSymbol, public Type
{
public:
Enum(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name);
virtual ~Enum();
// Symbol's interface
virtual FullySpecifiedType type() const;
// Type's interface
virtual bool isEqualTo(const Type *other) const;
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
virtual void accept0(TypeVisitor *visitor);
};
class CPLUSPLUS_EXPORT Function: public ScopedSymbol, public Type
{
public:
enum MethodKey {
NormalMethod,
SlotMethod,
SignalMethod
};
public:
Function(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name);
virtual ~Function();
bool isNormal() const;
bool isSignal() const;
bool isSlot() const;
int methodKey() const;
void setMethodKey(int key);
unsigned templateParameterCount() const;
Symbol *templateParameterAt(unsigned index) const;
Scope *templateParameters() const;
void setTemplateParameters(Scope *templateParameters);
FullySpecifiedType returnType() const;
void setReturnType(FullySpecifiedType returnType);
unsigned argumentCount() const;
Symbol *argumentAt(unsigned index) const;
Scope *arguments() const;
bool isVariadic() const;
void setVariadic(bool isVariadic);
bool isConst() const;
void setConst(bool isConst);
bool isVolatile() const;
void setVolatile(bool isVolatile);
bool isPureVirtual() const;
void setPureVirtual(bool isPureVirtual);
// Symbol's interface
virtual FullySpecifiedType type() const;
// Type's interface
virtual bool isEqualTo(const Type *other) const;
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
virtual void accept0(TypeVisitor *visitor);
private:
Name *_name;
Scope *_templateParameters;
FullySpecifiedType _returnType;
union {
unsigned _flags;
struct {
unsigned _isVariadic: 1;
unsigned _isPureVirtual: 1;
unsigned _isConst: 1;
unsigned _isVolatile: 1;
unsigned _methodKey: 3;
};
};
Scope *_arguments;
};
class CPLUSPLUS_EXPORT Namespace: public ScopedSymbol, public Type
{
public:
Namespace(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name);
virtual ~Namespace();
// Symbol's interface
virtual FullySpecifiedType type() const;
// Type's interface
virtual bool isEqualTo(const Type *other) const;
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
virtual void accept0(TypeVisitor *visitor);
};
class CPLUSPLUS_EXPORT BaseClass: public Symbol
{
public:
BaseClass(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name);
virtual ~BaseClass();
bool isVirtual() const;
void setVirtual(bool isVirtual);
// Symbol's interface
virtual FullySpecifiedType type() const;
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
private:
bool _isVirtual;
};
class CPLUSPLUS_EXPORT Class: public ScopedSymbol, public Type
{
public:
Class(TranslationUnit *translationUnit, unsigned sourceLocation, Name *name);
virtual ~Class();
enum Key {
ClassKey,
StructKey,
UnionKey
};
bool isClass() const;
bool isStruct() const;
bool isUnion() const;
Key classKey() const;
void setClassKey(Key key);
unsigned templateParameterCount() const;
Symbol *templateParameterAt(unsigned index) const;
Scope *templateParameters() const;
void setTemplateParameters(Scope *templateParameters);
unsigned baseClassCount() const;
BaseClass *baseClassAt(unsigned index) const;
void addBaseClass(BaseClass *baseClass);
// Symbol's interface
virtual FullySpecifiedType type() const;
// Type's interface
virtual bool isEqualTo(const Type *other) const;
protected:
virtual void visitSymbol0(SymbolVisitor *visitor);
virtual void accept0(TypeVisitor *visitor);
private:
Key _key;
Scope *_templateParameters;
Array<BaseClass *> _baseClasses;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_SYMBOLS_H

View File

@@ -0,0 +1,140 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "Token.h"
#include "Literals.h"
CPLUSPLUS_BEGIN_NAMESPACE
static const char *token_names[] = {
(""), ("<error>"),
("<comment>"),
("<identifier>"), ("<int literal>"), ("<float literal>"), ("<char literal>"),
("<wide char literal>"), ("<string literal>"), ("<wide char literal>"),
("<@string literal>"), ("<angle string literal>"),
("&"), ("&&"), ("&="), ("->"), ("->*"), ("^"), ("^="), (":"), ("::"),
(","), ("/"), ("/="), ("."), ("..."), (".*"), ("="), ("=="), ("!"),
("!="), (">"), (">="), (">>"), (">>="), ("{"), ("["), ("<"), ("<="),
("<<"), ("<<="), ("("), ("-"), ("-="), ("--"), ("%"), ("%="), ("|"),
("|="), ("||"), ("+"), ("+="), ("++"), ("#"), ("##"), ("?"), ("}"),
("]"), (")"), (";"), ("*"), ("*="), ("~"), ("~="),
("asm"), ("auto"), ("bool"), ("break"), ("case"), ("catch"), ("char"),
("class"), ("const"), ("const_cast"), ("continue"), ("default"),
("delete"), ("do"), ("double"), ("dynamic_cast"), ("else"), ("enum"),
("explicit"), ("export"), ("extern"), ("false"), ("float"), ("for"),
("friend"), ("goto"), ("if"), ("inline"), ("int"), ("long"),
("mutable"), ("namespace"), ("new"), ("operator"), ("private"),
("protected"), ("public"), ("register"), ("reinterpret_cast"),
("return"), ("short"), ("signed"), ("sizeof"), ("static"),
("static_cast"), ("struct"), ("switch"), ("template"), ("this"),
("throw"), ("true"), ("try"), ("typedef"), ("typeid"), ("typename"),
("union"), ("unsigned"), ("using"), ("virtual"), ("void"),
("volatile"), ("wchar_t"), ("while"),
// gnu
("__attribute__"), ("__typeof__"),
// objc @keywords
("@catch"), ("@class"), ("@compatibility_alias"), ("@defs"), ("@dynamic"),
("@encode"), ("@end"), ("@finally"), ("@implementation"), ("@interface"),
("@not_keyword"), ("@optional"), ("@package"), ("@private"), ("@property"),
("@protected"), ("@protocol"), ("@public"), ("@required"), ("@selector"),
("@synchronized"), ("@synthesize"), ("@throw"), ("@try"),
("SIGNAL"), ("SLOT"), ("Q_SIGNALS"), ("Q_SLOTS")
};
Token::Token() :
flags(0), offset(0), ptr(0)
{
}
Token::~Token()
{
}
void Token::reset()
{
flags = 0;
offset = 0;
ptr = 0;
}
const char *Token::name(int kind)
{ return token_names[kind]; }
const char *Token::spell() const
{
switch (kind) {
case T_IDENTIFIER:
return identifier->chars();
case T_INT_LITERAL:
case T_FLOAT_LITERAL:
case T_CHAR_LITERAL:
case T_STRING_LITERAL:
case T_AT_STRING_LITERAL:
case T_ANGLE_STRING_LITERAL:
case T_WIDE_CHAR_LITERAL:
case T_WIDE_STRING_LITERAL:
return literal->chars();
default:
return token_names[kind];
} // switch
}
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,336 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_TOKEN_H
#define CPLUSPLUS_TOKEN_H
#include "CPlusPlusForwardDeclarations.h"
#include <cstddef>
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
enum Kind {
T_EOF_SYMBOL = 0,
T_ERROR,
T_COMMENT,
T_IDENTIFIER,
T_FIRST_LITERAL,
T_INT_LITERAL = T_FIRST_LITERAL,
T_FLOAT_LITERAL,
T_CHAR_LITERAL,
T_WIDE_CHAR_LITERAL,
T_STRING_LITERAL,
T_WIDE_STRING_LITERAL,
T_AT_STRING_LITERAL,
T_ANGLE_STRING_LITERAL,
T_LAST_LITERAL = T_ANGLE_STRING_LITERAL,
T_FIRST_OPERATOR,
T_AMPER = T_FIRST_OPERATOR,
T_AMPER_AMPER,
T_AMPER_EQUAL,
T_ARROW,
T_ARROW_STAR,
T_CARET,
T_CARET_EQUAL,
T_COLON,
T_COLON_COLON,
T_COMMA,
T_SLASH,
T_SLASH_EQUAL,
T_DOT,
T_DOT_DOT_DOT,
T_DOT_STAR,
T_EQUAL,
T_EQUAL_EQUAL,
T_EXCLAIM,
T_EXCLAIM_EQUAL,
T_GREATER,
T_GREATER_EQUAL,
T_GREATER_GREATER,
T_GREATER_GREATER_EQUAL,
T_LBRACE,
T_LBRACKET,
T_LESS,
T_LESS_EQUAL,
T_LESS_LESS,
T_LESS_LESS_EQUAL,
T_LPAREN,
T_MINUS,
T_MINUS_EQUAL,
T_MINUS_MINUS,
T_PERCENT,
T_PERCENT_EQUAL,
T_PIPE,
T_PIPE_EQUAL,
T_PIPE_PIPE,
T_PLUS,
T_PLUS_EQUAL,
T_PLUS_PLUS,
T_POUND,
T_POUND_POUND,
T_QUESTION,
T_RBRACE,
T_RBRACKET,
T_RPAREN,
T_SEMICOLON,
T_STAR,
T_STAR_EQUAL,
T_TILDE,
T_TILDE_EQUAL,
T_LAST_OPERATOR = T_TILDE_EQUAL,
T_FIRST_KEYWORD,
T_ASM = T_FIRST_KEYWORD,
T_AUTO,
T_BOOL,
T_BREAK,
T_CASE,
T_CATCH,
T_CHAR,
T_CLASS,
T_CONST,
T_CONST_CAST,
T_CONTINUE,
T_DEFAULT,
T_DELETE,
T_DO,
T_DOUBLE,
T_DYNAMIC_CAST,
T_ELSE,
T_ENUM,
T_EXPLICIT,
T_EXPORT,
T_EXTERN,
T_FALSE,
T_FLOAT,
T_FOR,
T_FRIEND,
T_GOTO,
T_IF,
T_INLINE,
T_INT,
T_LONG,
T_MUTABLE,
T_NAMESPACE,
T_NEW,
T_OPERATOR,
T_PRIVATE,
T_PROTECTED,
T_PUBLIC,
T_REGISTER,
T_REINTERPRET_CAST,
T_RETURN,
T_SHORT,
T_SIGNED,
T_SIZEOF,
T_STATIC,
T_STATIC_CAST,
T_STRUCT,
T_SWITCH,
T_TEMPLATE,
T_THIS,
T_THROW,
T_TRUE,
T_TRY,
T_TYPEDEF,
T_TYPEID,
T_TYPENAME,
T_UNION,
T_UNSIGNED,
T_USING,
T_VIRTUAL,
T_VOID,
T_VOLATILE,
T_WCHAR_T,
T_WHILE,
T___ATTRIBUTE__,
T___TYPEOF__,
// obj c++ @ keywords
T_FIRST_OBJC_AT_KEYWORD,
T_AT_CATCH = T_FIRST_OBJC_AT_KEYWORD,
T_AT_CLASS,
T_AT_COMPATIBILITY_ALIAS,
T_AT_DEFS,
T_AT_DYNAMIC,
T_AT_ENCODE,
T_AT_END,
T_AT_FINALLY,
T_AT_IMPLEMENTATION,
T_AT_INTERFACE,
T_AT_NOT_KEYWORD,
T_AT_OPTIONAL,
T_AT_PACKAGE,
T_AT_PRIVATE,
T_AT_PROPERTY,
T_AT_PROTECTED,
T_AT_PROTOCOL,
T_AT_PUBLIC,
T_AT_REQUIRED,
T_AT_SELECTOR,
T_AT_SYNCHRONIZED,
T_AT_SYNTHESIZE,
T_AT_THROW,
T_AT_TRY,
T_LAST_OBJC_AT_KEYWORD,
T_FIRST_QT_KEYWORD = T_LAST_OBJC_AT_KEYWORD,
// Qt keywords
T_SIGNAL = T_FIRST_QT_KEYWORD,
T_SLOT,
T_SIGNALS,
T_SLOTS,
T_LAST_KEYWORD = T_SLOTS,
// aliases
T_OR = T_PIPE_PIPE,
T_AND = T_AMPER_AMPER,
T_NOT = T_EXCLAIM,
T_XOR = T_CARET,
T_BITOR = T_PIPE,
T_COMPL = T_TILDE,
T_OR_EQ = T_PIPE_EQUAL,
T_AND_EQ = T_AMPER_EQUAL,
T_BITAND = T_AMPER,
T_NOT_EQ = T_EXCLAIM_EQUAL,
T_XOR_EQ = T_CARET_EQUAL,
T___ASM = T_ASM,
T___ASM__ = T_ASM,
T_TYPEOF = T___TYPEOF__,
T___TYPEOF = T___TYPEOF__,
T___INLINE = T_INLINE,
T___INLINE__ = T_INLINE,
T___CONST = T_CONST,
T___CONST__ = T_CONST,
T___VOLATILE = T_VOLATILE,
T___VOLATILE__ = T_VOLATILE,
T___ATTRIBUTE = T___ATTRIBUTE__
};
class CPLUSPLUS_EXPORT Token
{
public:
Token();
~Token();
inline bool is(unsigned k) const { return kind == k; }
inline bool isNot(unsigned k) const { return kind != k; }
const char *spell() const;
void reset();
inline unsigned begin() const
{ return offset; }
inline unsigned end() const
{ return offset + length; }
inline bool isLiteral() const
{ return kind >= T_FIRST_LITERAL && kind <= T_LAST_LITERAL; }
inline bool isOperator() const
{ return kind >= T_FIRST_OPERATOR && kind <= T_LAST_OPERATOR; }
inline bool isKeyword() const
{ return kind >= T_FIRST_KEYWORD && kind < T_FIRST_QT_KEYWORD; }
inline bool isObjCAtKeyword() const
{ return kind >= T_FIRST_OBJC_AT_KEYWORD && kind < T_LAST_OBJC_AT_KEYWORD; }
static const char *name(int kind);
public:
union {
unsigned flags;
struct {
unsigned kind : 8;
unsigned newline : 1;
unsigned whitespace : 1;
unsigned joined : 1;
unsigned expanded : 1;
unsigned pad : 4;
unsigned length : 16;
};
};
unsigned offset;
union {
void *ptr;
Literal *literal;
NumericLiteral *number;
StringLiteral *string;
Identifier *identifier;
unsigned close_brace;
unsigned lineno;
};
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_TOKEN_H

View File

@@ -0,0 +1,474 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "TranslationUnit.h"
#include "Control.h"
#include "Parser.h"
#include "Lexer.h"
#include "MemoryPool.h"
#include "AST.h"
#include "Literals.h"
#include "DiagnosticClient.h"
#include <stack>
#include <cstdlib>
#include <cstdarg>
#include <algorithm>
CPLUSPLUS_BEGIN_NAMESPACE
TranslationUnit::TranslationUnit(Control *control, StringLiteral *fileId)
: _control(control),
_fileId(fileId),
_firstSourceChar(0),
_lastSourceChar(0),
_pool(0),
_ast(0),
_flags(0)
{
_tokens = new Array<Token, 8>();
_previousTranslationUnit = control->switchTranslationUnit(this);
_pool = new MemoryPool();
}
TranslationUnit::~TranslationUnit()
{
(void) _control->switchTranslationUnit(_previousTranslationUnit);
delete _tokens;
delete _pool;
}
bool TranslationUnit::qtMocRunEnabled() const
{ return _qtMocRunEnabled; }
void TranslationUnit::setQtMocRunEnabled(bool onoff)
{ _qtMocRunEnabled = onoff; }
bool TranslationUnit::objCEnabled() const
{ return _objCEnabled; }
void TranslationUnit::setObjCEnabled(bool onoff)
{ _objCEnabled = onoff; }
Control *TranslationUnit::control() const
{ return _control; }
StringLiteral *TranslationUnit::fileId() const
{ return _fileId; }
const char *TranslationUnit::fileName() const
{ return _fileId->chars(); }
unsigned TranslationUnit::fileNameLength() const
{ return _fileId->size(); }
const char *TranslationUnit::firstSourceChar() const
{ return _firstSourceChar; }
const char *TranslationUnit::lastSourceChar() const
{ return _lastSourceChar; }
unsigned TranslationUnit::sourceLength() const
{ return _lastSourceChar - _firstSourceChar; }
void TranslationUnit::setSource(const char *source, unsigned size)
{
_firstSourceChar = source;
_lastSourceChar = source + size;
}
unsigned TranslationUnit::tokenCount() const
{ return _tokens->size(); }
const Token &TranslationUnit::tokenAt(unsigned index) const
{ return _tokens->at(index); }
int TranslationUnit::tokenKind(unsigned index) const
{ return _tokens->at(index).kind; }
Identifier *TranslationUnit::identifier(unsigned index) const
{ return _tokens->at(index).identifier; }
Literal *TranslationUnit::literal(unsigned index) const
{ return _tokens->at(index).literal; }
StringLiteral *TranslationUnit::stringLiteral(unsigned index) const
{ return _tokens->at(index).string; }
NumericLiteral *TranslationUnit::numericLiteral(unsigned index) const
{ return _tokens->at(index).number; }
unsigned TranslationUnit::matchingBrace(unsigned index) const
{ return _tokens->at(index).close_brace; }
MemoryPool *TranslationUnit::memoryPool() const
{ return _pool; }
AST *TranslationUnit::ast() const
{ return _ast; }
bool TranslationUnit::isTokenized() const
{ return _tokenized; }
bool TranslationUnit::isParsed() const
{ return _parsed; }
void TranslationUnit::tokenize()
{
if (isTokenized())
return;
_tokenized = true;
Lexer lex(this);
lex.setQtMocRunEnabled(_qtMocRunEnabled);
lex.setObjCEnabled(_objCEnabled);
std::stack<unsigned> braces;
_tokens->push_back(Token()); // the first token needs to be invalid!
pushLineOffset(0);
pushPreprocessorLine(0, 1, fileId());
Identifier *lineId = control()->findOrInsertIdentifier("line");
Token tk;
do {
lex(&tk);
_Lrecognize:
if (tk.is(T_POUND)) {
unsigned offset = tk.offset;
lex(&tk);
if (! tk.newline && tk.is(T_IDENTIFIER) && tk.identifier == lineId)
lex(&tk);
if (! tk.newline && tk.is(T_INT_LITERAL)) {
unsigned line = (unsigned) strtoul(tk.spell(), 0, 0);
lex(&tk);
if (! tk.newline && tk.is(T_STRING_LITERAL)) {
StringLiteral *fileName = control()->findOrInsertFileName(tk.string->chars(),
tk.string->size());
pushPreprocessorLine(offset, line, fileName);
lex(&tk);
}
}
while (tk.isNot(T_EOF_SYMBOL) && ! tk.newline)
lex(&tk);
goto _Lrecognize;
} else if (tk.kind == T_LBRACE) {
braces.push(_tokens->size());
} else if (tk.kind == T_RBRACE && ! braces.empty()) {
const unsigned open_brace_index = braces.top();
braces.pop();
(*_tokens)[open_brace_index].close_brace = _tokens->size();
}
_tokens->push_back(tk);
} while (tk.kind);
for (; ! braces.empty(); braces.pop()) {
unsigned open_brace_index = braces.top();
(*_tokens)[open_brace_index].close_brace = _tokens->size();
}
}
bool TranslationUnit::skipFunctionBody() const
{ return _skipFunctionBody; }
void TranslationUnit::setSkipFunctionBody(bool skipFunctionBody)
{ _skipFunctionBody = skipFunctionBody; }
bool TranslationUnit::parse(ParseMode mode)
{
if (isParsed())
return false;
if (! isTokenized())
tokenize();
Parser parser(this);
parser.setQtMocRunEnabled(_qtMocRunEnabled);
parser.setObjCEnabled(_objCEnabled);
bool parsed = false;
switch (mode) {
case ParseTranlationUnit: {
TranslationUnitAST *node = 0;
parsed = parser.parseTranslationUnit(node);
_ast = node;
} break;
case ParseDeclaration: {
DeclarationAST *node = 0;
parsed = parser.parseDeclaration(node);
_ast = node;
} break;
case ParseExpression: {
ExpressionAST *node = 0;
parsed = parser.parseExpression(node);
_ast = node;
} break;
case ParseStatement: {
StatementAST *node = 0;
parsed = parser.parseStatement(node);
_ast = node;
} break;
default:
break;
} // switch
return parsed;
}
void TranslationUnit::pushLineOffset(unsigned offset)
{ _lineOffsets.push_back(offset); }
void TranslationUnit::pushPreprocessorLine(unsigned offset,
unsigned line,
StringLiteral *fileName)
{ _ppLines.push_back(PPLine(offset, line, fileName)); }
unsigned TranslationUnit::findLineNumber(unsigned offset) const
{
std::vector<unsigned>::const_iterator it =
std::lower_bound(_lineOffsets.begin(), _lineOffsets.end(), offset);
if (it != _lineOffsets.begin())
--it;
return it - _lineOffsets.begin();
}
TranslationUnit::PPLine TranslationUnit::findPreprocessorLine(unsigned offset) const
{
std::vector<PPLine>::const_iterator it =
std::lower_bound(_ppLines.begin(), _ppLines.end(), PPLine(offset));
if (it != _ppLines.begin())
--it;
return *it;
}
unsigned TranslationUnit::findColumnNumber(unsigned offset, unsigned lineNumber) const
{
if (! offset)
return 0;
return offset - _lineOffsets[lineNumber];
}
void TranslationUnit::getTokenPosition(unsigned index,
unsigned *line,
unsigned *column,
StringLiteral **fileName) const
{ return getPosition(tokenAt(index).offset, line, column, fileName); }
void TranslationUnit::getPosition(unsigned tokenOffset,
unsigned *line,
unsigned *column,
StringLiteral **fileName) const
{
unsigned lineNumber = findLineNumber(tokenOffset);
unsigned columnNumber = findColumnNumber(tokenOffset, lineNumber);
const PPLine ppLine = findPreprocessorLine(tokenOffset);
lineNumber -= findLineNumber(ppLine.offset) + 1;
lineNumber += ppLine.line;
if (line)
*line = lineNumber;
if (column)
*column = columnNumber;
if (fileName)
*fileName = ppLine.fileName;
}
bool TranslationUnit::blockErrors(bool block)
{
bool previous = _blockErrors;
_blockErrors = block;
return previous;
}
void TranslationUnit::warning(unsigned index, const char *format, ...)
{
if (_blockErrors)
return;
index = std::min(index, tokenCount() - 1);
unsigned line = 0, column = 0;
StringLiteral *fileName = 0;
getTokenPosition(index, &line, &column, &fileName);
if (DiagnosticClient *client = control()->diagnosticClient()) {
va_list args;
va_start(args, format);
client->report(DiagnosticClient::Warning, fileName, line, column,
format, args);
va_end(args);
} else {
fprintf(stderr, "%s:%d: ", fileName->chars(), line);
fprintf(stderr, "warning: ");
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
fputc('\n', stderr);
showErrorLine(index, column, stderr);
}
}
void TranslationUnit::error(unsigned index, const char *format, ...)
{
if (_blockErrors)
return;
index = std::min(index, tokenCount() - 1);
unsigned line = 0, column = 0;
StringLiteral *fileName = 0;
getTokenPosition(index, &line, &column, &fileName);
if (DiagnosticClient *client = control()->diagnosticClient()) {
va_list args;
va_start(args, format);
client->report(DiagnosticClient::Error, fileName, line, column,
format, args);
va_end(args);
} else {
fprintf(stderr, "%s:%d: ", fileName->chars(), line);
fprintf(stderr, "error: ");
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
fputc('\n', stderr);
showErrorLine(index, column, stderr);
}
}
void TranslationUnit::fatal(unsigned index, const char *format, ...)
{
if (_blockErrors)
return;
index = std::min(index, tokenCount() - 1);
unsigned line = 0, column = 0;
StringLiteral *fileName = 0;
getTokenPosition(index, &line, &column, &fileName);
if (DiagnosticClient *client = control()->diagnosticClient()) {
va_list args;
va_start(args, format);
client->report(DiagnosticClient::Fatal, fileName, line, column,
format, args);
va_end(args);
} else {
fprintf(stderr, "%s:%d: ", fileName->chars(), line);
fprintf(stderr, "fatal: ");
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
fputc('\n', stderr);
showErrorLine(index, column, stderr);
}
exit(EXIT_FAILURE);
}
void TranslationUnit::showErrorLine(unsigned index, unsigned column, FILE *out)
{
unsigned lineOffset = _lineOffsets[findLineNumber(_tokens->at(index).offset)];
for (const char *cp = _firstSourceChar + lineOffset + 1; *cp && *cp != '\n'; ++cp) {
fputc(*cp, out);
}
fputc('\n', out);
const char *end = _firstSourceChar + lineOffset + 1 + column - 1;
for (const char *cp = _firstSourceChar + lineOffset + 1; cp != end; ++cp) {
if (*cp != '\t')
fputc(' ', out);
else
fputc('\t', out);
}
fputc('^', out);
fputc('\n', out);
}
void TranslationUnit::resetAST()
{
delete _pool;
_pool = 0;
}
void TranslationUnit::release()
{
resetAST();
delete _tokens;
_tokens = 0;
}
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,201 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_TRANSLATIONUNIT_H
#define CPLUSPLUS_TRANSLATIONUNIT_H
#include "CPlusPlusForwardDeclarations.h"
#include "ASTfwd.h"
#include "Token.h"
#include "Array.h"
#include <cstdio>
#include <vector> // ### remove me
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT TranslationUnit
{
TranslationUnit(const TranslationUnit &other);
void operator =(const TranslationUnit &other);
public:
TranslationUnit(Control *control, StringLiteral *fileId);
~TranslationUnit();
Control *control() const;
StringLiteral *fileId() const;
const char *fileName() const;
unsigned fileNameLength() const;
const char *firstSourceChar() const;
const char *lastSourceChar() const;
unsigned sourceLength() const;
void setSource(const char *source, unsigned size);
unsigned tokenCount() const;
const Token &tokenAt(unsigned index) const;
int tokenKind(unsigned index) const;
unsigned matchingBrace(unsigned index) const;
Identifier *identifier(unsigned index) const;
Literal *literal(unsigned index) const;
StringLiteral *stringLiteral(unsigned index) const;
NumericLiteral *numericLiteral(unsigned index) const;
MemoryPool *memoryPool() const;
AST *ast() const;
bool blockErrors(bool block);
bool qtMocRunEnabled() const;
void setQtMocRunEnabled(bool onoff);
bool objCEnabled() const;
void setObjCEnabled(bool onoff);
void warning(unsigned index, const char *fmt, ...);
void error(unsigned index, const char *fmt, ...);
void fatal(unsigned index, const char *fmt, ...);
bool isTokenized() const;
void tokenize();
bool skipFunctionBody() const;
void setSkipFunctionBody(bool skipFunctionBody);
bool isParsed() const;
enum ParseMode {
ParseTranlationUnit,
ParseDeclaration,
ParseExpression,
ParseStatement
};
bool parse(ParseMode mode = ParseTranlationUnit);
void resetAST();
void release();
void getPosition(unsigned offset,
unsigned *line,
unsigned *column = 0,
StringLiteral **fileName = 0) const;
void getTokenPosition(unsigned index,
unsigned *line,
unsigned *column = 0,
StringLiteral **fileName = 0) const;
void pushLineOffset(unsigned offset);
void pushPreprocessorLine(unsigned offset,
unsigned line,
StringLiteral *fileName);
public:
struct PPLine {
unsigned offset;
unsigned line;
StringLiteral *fileName;
PPLine(unsigned offset = 0,
unsigned line = 0,
StringLiteral *fileName = 0)
: offset(offset), line(line), fileName(fileName)
{ }
bool operator == (const PPLine &other) const
{ return offset == other.offset; }
bool operator != (const PPLine &other) const
{ return offset != other.offset; }
bool operator < (const PPLine &other) const
{ return offset < other.offset; }
};
private:
unsigned findLineNumber(unsigned offset) const;
unsigned findColumnNumber(unsigned offset, unsigned lineNumber) const;
PPLine findPreprocessorLine(unsigned offset) const;
void showErrorLine(unsigned index, unsigned column, FILE *out);
Control *_control;
StringLiteral *_fileId;
const char *_firstSourceChar;
const char *_lastSourceChar;
Array<Token, 8> *_tokens;
std::vector<unsigned> _lineOffsets;
std::vector<PPLine> _ppLines;
MemoryPool *_pool;
AST *_ast;
TranslationUnit *_previousTranslationUnit;
union {
unsigned _flags;
struct {
unsigned _tokenized: 1;
unsigned _parsed: 1;
unsigned _blockErrors: 1;
unsigned _skipFunctionBody: 1;
unsigned _qtMocRunEnabled: 1;
unsigned _objCEnabled: 1;
};
};
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_TRANSLATIONUNIT_H

View File

@@ -0,0 +1,198 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "Type.h"
#include "TypeVisitor.h"
#include "CoreTypes.h"
#include "Symbols.h"
CPLUSPLUS_BEGIN_NAMESPACE
Type::Type()
{ }
Type::~Type()
{ }
bool Type::isVoidType() const
{ return dynamic_cast<const VoidType *>(this) != 0; }
bool Type::isIntegerType() const
{ return dynamic_cast<const IntegerType *>(this) != 0; }
bool Type::isFloatType() const
{ return dynamic_cast<const FloatType *>(this) != 0; }
bool Type::isPointerType() const
{ return dynamic_cast<const PointerType *>(this) != 0; }
bool Type::isPointerToMemberType() const
{ return dynamic_cast<const PointerToMemberType *>(this) != 0; }
bool Type::isReferenceType() const
{ return dynamic_cast<const ReferenceType *>(this) != 0; }
bool Type::isArrayType() const
{ return dynamic_cast<const ArrayType *>(this) != 0; }
bool Type::isNamedType() const
{ return dynamic_cast<const NamedType *>(this) != 0; }
bool Type::isFunction() const
{ return dynamic_cast<const Function *>(this) != 0; }
bool Type::isNamespace() const
{ return dynamic_cast<const Namespace *>(this) != 0; }
bool Type::isClass() const
{ return dynamic_cast<const Class *>(this) != 0; }
bool Type::isEnum() const
{ return dynamic_cast<const Enum *>(this) != 0; }
bool Type::isScopedSymbol() const
{ return dynamic_cast<const ScopedSymbol *>(this) != 0; }
const VoidType *Type::asVoidType() const
{ return dynamic_cast<const VoidType *>(this); }
const IntegerType *Type::asIntegerType() const
{ return dynamic_cast<const IntegerType *>(this); }
const FloatType *Type::asFloatType() const
{ return dynamic_cast<const FloatType *>(this); }
const PointerType *Type::asPointerType() const
{ return dynamic_cast<const PointerType *>(this); }
const PointerToMemberType *Type::asPointerToMemberType() const
{ return dynamic_cast<const PointerToMemberType *>(this); }
const ReferenceType *Type::asReferenceType() const
{ return dynamic_cast<const ReferenceType *>(this); }
const ArrayType *Type::asArrayType() const
{ return dynamic_cast<const ArrayType *>(this); }
const NamedType *Type::asNamedType() const
{ return dynamic_cast<const NamedType *>(this); }
const Function *Type::asFunction() const
{ return dynamic_cast<const Function *>(this); }
const Namespace *Type::asNamespace() const
{ return dynamic_cast<const Namespace *>(this); }
const Class *Type::asClass() const
{ return dynamic_cast<const Class *>(this); }
const Enum *Type::asEnum() const
{ return dynamic_cast<const Enum *>(this); }
const ScopedSymbol *Type::asScopedSymbol() const
{ return dynamic_cast<const ScopedSymbol *>(this); }
VoidType *Type::asVoidType()
{ return dynamic_cast<VoidType *>(this); }
IntegerType *Type::asIntegerType()
{ return dynamic_cast<IntegerType *>(this); }
FloatType *Type::asFloatType()
{ return dynamic_cast<FloatType *>(this); }
PointerType *Type::asPointerType()
{ return dynamic_cast<PointerType *>(this); }
PointerToMemberType *Type::asPointerToMemberType()
{ return dynamic_cast<PointerToMemberType *>(this); }
ReferenceType *Type::asReferenceType()
{ return dynamic_cast<ReferenceType *>(this); }
ArrayType *Type::asArrayType()
{ return dynamic_cast<ArrayType *>(this); }
NamedType *Type::asNamedType()
{ return dynamic_cast<NamedType *>(this); }
Function *Type::asFunction()
{ return dynamic_cast<Function *>(this); }
Namespace *Type::asNamespace()
{ return dynamic_cast<Namespace *>(this); }
Class *Type::asClass()
{ return dynamic_cast<Class *>(this); }
Enum *Type::asEnum()
{ return dynamic_cast<Enum *>(this); }
ScopedSymbol *Type::asScopedSymbol()
{ return dynamic_cast<ScopedSymbol *>(this); }
void Type::accept(TypeVisitor *visitor)
{
if (visitor->preVisit(this))
accept0(visitor);
visitor->postVisit(this);
}
void Type::accept(Type *type, TypeVisitor *visitor)
{
if (! type)
return;
type->accept(visitor);
}
CPLUSPLUS_END_NAMESPACE

124
src/shared/cplusplus/Type.h Normal file
View File

@@ -0,0 +1,124 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_TYPE_H
#define CPLUSPLUS_TYPE_H
#include "CPlusPlusForwardDeclarations.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT Type
{
Type(const Type &other);
void operator =(const Type &other);
public:
Type();
virtual ~Type();
bool isVoidType() const;
bool isIntegerType() const;
bool isFloatType() const;
bool isPointerType() const;
bool isPointerToMemberType() const;
bool isReferenceType() const;
bool isArrayType() const;
bool isNamedType() const;
bool isFunction() const;
bool isNamespace() const;
bool isClass() const;
bool isEnum() const;
bool isScopedSymbol() const;
const VoidType *asVoidType() const;
const IntegerType *asIntegerType() const;
const FloatType *asFloatType() const;
const PointerType *asPointerType() const;
const PointerToMemberType *asPointerToMemberType() const;
const ReferenceType *asReferenceType() const;
const ArrayType *asArrayType() const;
const NamedType *asNamedType() const;
const Function *asFunction() const;
const Namespace *asNamespace() const;
const Class *asClass() const;
const Enum *asEnum() const;
const ScopedSymbol *asScopedSymbol() const;
VoidType *asVoidType();
IntegerType *asIntegerType();
FloatType *asFloatType();
PointerType *asPointerType();
PointerToMemberType *asPointerToMemberType();
ReferenceType *asReferenceType();
ArrayType *asArrayType();
NamedType *asNamedType();
Function *asFunction();
Namespace *asNamespace();
Class *asClass();
Enum *asEnum();
ScopedSymbol *asScopedSymbol();
void accept(TypeVisitor *visitor);
static void accept(Type *type, TypeVisitor *visitor);
virtual bool isEqualTo(const Type *other) const = 0;
protected:
virtual void accept0(TypeVisitor *visitor) = 0;
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_TYPE_H

View File

@@ -0,0 +1,67 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#include "TypeVisitor.h"
#include "Type.h"
CPLUSPLUS_BEGIN_NAMESPACE
TypeVisitor::TypeVisitor()
{ }
TypeVisitor::~TypeVisitor()
{ }
void TypeVisitor::accept(Type *type)
{ Type::accept(type, this); }
CPLUSPLUS_END_NAMESPACE

View File

@@ -0,0 +1,92 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
// Copyright (c) 2008 Roberto Raggi <roberto.raggi@gmail.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef CPLUSPLUS_TYPEVISITOR_H
#define CPLUSPLUS_TYPEVISITOR_H
#include "CPlusPlusForwardDeclarations.h"
CPLUSPLUS_BEGIN_HEADER
CPLUSPLUS_BEGIN_NAMESPACE
class CPLUSPLUS_EXPORT TypeVisitor
{
TypeVisitor(const TypeVisitor &other);
void operator =(const TypeVisitor &other);
public:
TypeVisitor();
virtual ~TypeVisitor();
void accept(Type *type);
virtual bool preVisit(Type *) { return true; }
virtual void postVisit(Type *) {}
virtual void visit(VoidType *) {}
virtual void visit(IntegerType *) {}
virtual void visit(FloatType *) {}
virtual void visit(PointerToMemberType *) {}
virtual void visit(PointerType *) {}
virtual void visit(ReferenceType *) {}
virtual void visit(ArrayType *) {}
virtual void visit(NamedType *) {}
virtual void visit(Function *) {}
virtual void visit(Namespace *) {}
virtual void visit(Class *) {}
virtual void visit(Enum *) {}
};
CPLUSPLUS_END_NAMESPACE
CPLUSPLUS_END_HEADER
#endif // CPLUSPLUS_TYPEVISITOR_H

View File

@@ -0,0 +1,77 @@
DEPENDPATH += $$PWD
INCLUDEPATH += $$PWD
HEADERS += \
$$PWD/AST.h \
$$PWD/ASTVisitor.h \
$$PWD/ASTfwd.h \
$$PWD/Array.h \
$$PWD/CPlusPlusForwardDeclarations.h \
$$PWD/CheckDeclaration.h \
$$PWD/CheckDeclarator.h \
$$PWD/CheckExpression.h \
$$PWD/CheckName.h \
$$PWD/CheckSpecifier.h \
$$PWD/CheckStatement.h \
$$PWD/Control.h \
$$PWD/CoreTypes.h \
$$PWD/DiagnosticClient.h \
$$PWD/FullySpecifiedType.h \
$$PWD/Lexer.h \
$$PWD/LiteralTable.h \
$$PWD/Literals.h \
$$PWD/MemoryPool.h \
$$PWD/Name.h \
$$PWD/NameVisitor.h \
$$PWD/Names.h \
$$PWD/Parser.h \
$$PWD/Scope.h \
$$PWD/Semantic.h \
$$PWD/SemanticCheck.h \
$$PWD/Symbol.h \
$$PWD/Symbols.h \
$$PWD/SymbolVisitor.h \
$$PWD/Token.h \
$$PWD/TranslationUnit.h \
$$PWD/Type.h \
$$PWD/TypeVisitor.h \
$$PWD/PrettyPrinter.h
SOURCES += \
$$PWD/AST.cpp \
$$PWD/ASTVisitor.cpp \
$$PWD/Array.cpp \
$$PWD/CheckDeclaration.cpp \
$$PWD/CheckDeclarator.cpp \
$$PWD/CheckExpression.cpp \
$$PWD/CheckName.cpp \
$$PWD/CheckSpecifier.cpp \
$$PWD/CheckStatement.cpp \
$$PWD/Control.cpp \
$$PWD/CoreTypes.cpp \
$$PWD/DiagnosticClient.cpp \
$$PWD/FullySpecifiedType.cpp \
$$PWD/Keywords.cpp \
$$PWD/ObjectiveCAtKeywords.cpp \
$$PWD/Lexer.cpp \
$$PWD/LiteralTable.cpp \
$$PWD/Literals.cpp \
$$PWD/MemoryPool.cpp \
$$PWD/Name.cpp \
$$PWD/NameVisitor.cpp \
$$PWD/Names.cpp \
$$PWD/Parser.cpp \
$$PWD/Scope.cpp \
$$PWD/Semantic.cpp \
$$PWD/SemanticCheck.cpp \
$$PWD/Symbol.cpp \
$$PWD/Symbols.cpp \
$$PWD/SymbolVisitor.cpp \
$$PWD/Token.cpp \
$$PWD/TranslationUnit.cpp \
$$PWD/Type.cpp \
$$PWD/TypeVisitor.cpp \
$$PWD/PrettyPrinter.cpp