2008-12-02 12:01:29 +01:00
|
|
|
// 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.
|
|
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include "CPlusPlusForwardDeclarations.h"
|
|
|
|
|
#include "Name.h"
|
|
|
|
|
#include "FullySpecifiedType.h"
|
2021-01-13 12:36:53 +01:00
|
|
|
#include <functional>
|
2009-12-01 12:46:15 +01:00
|
|
|
#include <vector>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-10-20 11:21:25 +02:00
|
|
|
namespace CPlusPlus {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
class CPLUSPLUS_EXPORT QualifiedNameId: public Name
|
|
|
|
|
{
|
|
|
|
|
public:
|
2010-07-12 13:41:54 +02:00
|
|
|
QualifiedNameId(const Name *base, const Name *name)
|
|
|
|
|
: _base(base), _name(name) {}
|
2009-12-01 14:38:42 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
virtual ~QualifiedNameId();
|
|
|
|
|
|
2020-11-23 16:44:16 +01:00
|
|
|
const Identifier *identifier() const override;
|
2009-05-28 11:49:59 +02:00
|
|
|
|
2010-07-12 13:41:54 +02:00
|
|
|
const Name *base() const;
|
|
|
|
|
const Name *name() const;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-11-23 16:44:16 +01:00
|
|
|
const QualifiedNameId *asQualifiedNameId() const override
|
2009-02-09 16:32:56 +01:00
|
|
|
{ return this; }
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
protected:
|
2020-11-23 16:44:16 +01:00
|
|
|
void accept0(NameVisitor *visitor) const override;
|
|
|
|
|
bool match0(const Name *otherName, Matcher *matcher) const override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
private:
|
2010-07-12 13:41:54 +02:00
|
|
|
const Name *_base;
|
|
|
|
|
const Name *_name;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CPLUSPLUS_EXPORT DestructorNameId: public Name
|
|
|
|
|
{
|
|
|
|
|
public:
|
2012-02-16 10:54:44 +01:00
|
|
|
DestructorNameId(const Name *name);
|
2008-12-02 12:01:29 +01:00
|
|
|
virtual ~DestructorNameId();
|
|
|
|
|
|
2020-11-23 16:44:16 +01:00
|
|
|
const Name *name() const;
|
2012-02-16 10:54:44 +01:00
|
|
|
|
2020-11-23 16:44:16 +01:00
|
|
|
const Identifier *identifier() const override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-11-23 16:44:16 +01:00
|
|
|
const DestructorNameId *asDestructorNameId() const override
|
2009-02-09 16:32:56 +01:00
|
|
|
{ return this; }
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
protected:
|
2020-11-23 16:44:16 +01:00
|
|
|
void accept0(NameVisitor *visitor) const override;
|
|
|
|
|
bool match0(const Name *otherName, Matcher *matcher) const override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
private:
|
2012-02-16 10:54:44 +01:00
|
|
|
const Name *_name;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2020-05-14 23:07:05 +03:00
|
|
|
class CPLUSPLUS_EXPORT TemplateArgument
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
TemplateArgument()
|
|
|
|
|
: _expressionTy(nullptr)
|
|
|
|
|
, _numericLiteral(nullptr)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
TemplateArgument(const FullySpecifiedType &type, const NumericLiteral *numericLiteral = nullptr)
|
|
|
|
|
: _expressionTy(type)
|
|
|
|
|
, _numericLiteral(numericLiteral)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
bool hasType() const { return _expressionTy.isValid(); }
|
|
|
|
|
|
|
|
|
|
bool hasNumericLiteral() const { return _numericLiteral != nullptr; }
|
|
|
|
|
|
|
|
|
|
const FullySpecifiedType &type() const { return _expressionTy; }
|
|
|
|
|
FullySpecifiedType &type() { return _expressionTy; }
|
|
|
|
|
|
|
|
|
|
const NumericLiteral *numericLiteral() const { return _numericLiteral; }
|
|
|
|
|
|
|
|
|
|
bool operator==(const TemplateArgument &other) const
|
|
|
|
|
{
|
|
|
|
|
return _expressionTy == other._expressionTy && _numericLiteral == other._numericLiteral;
|
|
|
|
|
}
|
|
|
|
|
bool operator!=(const TemplateArgument &other) const
|
|
|
|
|
{
|
|
|
|
|
return _expressionTy != other._expressionTy || _numericLiteral != other._numericLiteral;
|
|
|
|
|
}
|
|
|
|
|
bool operator<(const TemplateArgument &other) const
|
|
|
|
|
{
|
|
|
|
|
if (_expressionTy == other._expressionTy) {
|
|
|
|
|
return _numericLiteral < other._numericLiteral;
|
|
|
|
|
}
|
|
|
|
|
return _expressionTy < other._expressionTy;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool match(const TemplateArgument &otherTy, Matcher *matcher = nullptr) const;
|
|
|
|
|
|
2020-12-17 07:14:28 +01:00
|
|
|
size_t hash() const
|
|
|
|
|
{
|
|
|
|
|
return _expressionTy.hash() ^ std::hash<const NumericLiteral *>()(_numericLiteral);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-14 23:07:05 +03:00
|
|
|
private:
|
|
|
|
|
FullySpecifiedType _expressionTy;
|
|
|
|
|
const NumericLiteral *_numericLiteral = nullptr;
|
|
|
|
|
};
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
class CPLUSPLUS_EXPORT TemplateNameId: public Name
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-08-28 14:56:04 +02:00
|
|
|
template <typename Iterator>
|
|
|
|
|
TemplateNameId(const Identifier *identifier, bool isSpecialization, Iterator first,
|
|
|
|
|
Iterator last)
|
2013-01-12 22:05:41 +01:00
|
|
|
: _identifier(identifier)
|
|
|
|
|
, _templateArguments(first, last)
|
|
|
|
|
, _isSpecialization(isSpecialization) {}
|
2009-12-01 14:38:42 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
virtual ~TemplateNameId();
|
|
|
|
|
|
2020-11-23 16:44:16 +01:00
|
|
|
const Identifier *identifier() const override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// ### find a better name
|
2019-07-24 18:40:10 +02:00
|
|
|
int templateArgumentCount() const;
|
2020-05-14 23:07:05 +03:00
|
|
|
const TemplateArgument &templateArgumentAt(int index) const;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-11-23 16:44:16 +01:00
|
|
|
const TemplateNameId *asTemplateNameId() const override
|
2009-02-09 16:32:56 +01:00
|
|
|
{ return this; }
|
|
|
|
|
|
2020-05-14 23:07:05 +03:00
|
|
|
typedef std::vector<TemplateArgument>::const_iterator TemplateArgumentIterator;
|
2009-12-01 14:38:42 +01:00
|
|
|
|
|
|
|
|
TemplateArgumentIterator firstTemplateArgument() const { return _templateArguments.begin(); }
|
|
|
|
|
TemplateArgumentIterator lastTemplateArgument() const { return _templateArguments.end(); }
|
2013-01-12 22:05:41 +01:00
|
|
|
bool isSpecialization() const { return _isSpecialization; }
|
|
|
|
|
|
2020-12-17 07:14:28 +01:00
|
|
|
// Comparator needed to distinguish between two different TemplateNameId(e.g.:used in std::unordered_map)
|
|
|
|
|
struct Equals {
|
2013-01-12 22:05:41 +01:00
|
|
|
bool operator()(const TemplateNameId *name, const TemplateNameId *other) const;
|
|
|
|
|
};
|
2020-12-17 07:14:28 +01:00
|
|
|
struct Hash {
|
|
|
|
|
size_t operator()(const TemplateNameId *name) const;
|
|
|
|
|
};
|
2009-12-01 14:38:42 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
protected:
|
2020-11-23 16:44:16 +01:00
|
|
|
void accept0(NameVisitor *visitor) const override;
|
|
|
|
|
bool match0(const Name *otherName, Matcher *matcher) const override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
private:
|
2009-12-01 11:33:13 +01:00
|
|
|
const Identifier *_identifier;
|
2020-05-14 23:07:05 +03:00
|
|
|
std::vector<TemplateArgument> _templateArguments;
|
2013-01-12 22:05:41 +01:00
|
|
|
// now TemplateNameId can be a specialization or an instantiation
|
|
|
|
|
bool _isSpecialization;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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:
|
2010-09-03 12:11:15 +02:00
|
|
|
OperatorNameId(Kind kind);
|
2008-12-02 12:01:29 +01:00
|
|
|
virtual ~OperatorNameId();
|
|
|
|
|
|
2010-09-03 12:11:15 +02:00
|
|
|
Kind kind() const;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-11-23 16:44:16 +01:00
|
|
|
const Identifier *identifier() const override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-11-23 16:44:16 +01:00
|
|
|
const OperatorNameId *asOperatorNameId() const override
|
2009-02-09 16:32:56 +01:00
|
|
|
{ return this; }
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
protected:
|
2020-11-23 16:44:16 +01:00
|
|
|
void accept0(NameVisitor *visitor) const override;
|
|
|
|
|
bool match0(const Name *otherName, Matcher *matcher) const override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
private:
|
2010-09-03 12:11:15 +02:00
|
|
|
Kind _kind;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CPLUSPLUS_EXPORT ConversionNameId: public Name
|
|
|
|
|
{
|
|
|
|
|
public:
|
2009-11-17 14:37:45 +01:00
|
|
|
ConversionNameId(const FullySpecifiedType &type);
|
2008-12-02 12:01:29 +01:00
|
|
|
virtual ~ConversionNameId();
|
|
|
|
|
|
|
|
|
|
FullySpecifiedType type() const;
|
|
|
|
|
|
2020-11-23 16:44:16 +01:00
|
|
|
const Identifier *identifier() const override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-11-23 16:44:16 +01:00
|
|
|
const ConversionNameId *asConversionNameId() const override
|
2009-02-09 16:32:56 +01:00
|
|
|
{ return this; }
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
protected:
|
2020-11-23 16:44:16 +01:00
|
|
|
void accept0(NameVisitor *visitor) const override;
|
|
|
|
|
bool match0(const Name *otherName, Matcher *matcher) const override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
FullySpecifiedType _type;
|
|
|
|
|
};
|
|
|
|
|
|
2009-07-31 16:03:48 +02:00
|
|
|
class CPLUSPLUS_EXPORT SelectorNameId: public Name
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-08-28 14:56:04 +02:00
|
|
|
template <typename Iterator>
|
|
|
|
|
SelectorNameId(Iterator first, Iterator last, bool hasArguments)
|
2009-12-01 14:38:42 +01:00
|
|
|
: _names(first, last), _hasArguments(hasArguments) {}
|
|
|
|
|
|
2009-07-31 16:03:48 +02:00
|
|
|
virtual ~SelectorNameId();
|
|
|
|
|
|
2020-11-23 16:44:16 +01:00
|
|
|
const Identifier *identifier() const override;
|
2009-07-31 16:03:48 +02:00
|
|
|
|
2019-07-24 18:40:10 +02:00
|
|
|
int nameCount() const;
|
|
|
|
|
const Name *nameAt(int index) const;
|
2009-07-31 16:03:48 +02:00
|
|
|
bool hasArguments() const;
|
|
|
|
|
|
2020-11-23 16:44:16 +01:00
|
|
|
const SelectorNameId *asSelectorNameId() const override
|
2009-07-31 16:03:48 +02:00
|
|
|
{ return this; }
|
|
|
|
|
|
2009-12-01 14:38:42 +01:00
|
|
|
typedef std::vector<const Name *>::const_iterator NameIterator;
|
|
|
|
|
|
|
|
|
|
NameIterator firstName() const { return _names.begin(); }
|
|
|
|
|
NameIterator lastName() const { return _names.end(); }
|
|
|
|
|
|
2009-07-31 16:03:48 +02:00
|
|
|
protected:
|
2020-11-23 16:44:16 +01:00
|
|
|
void accept0(NameVisitor *visitor) const override;
|
|
|
|
|
bool match0(const Name *otherName, Matcher *matcher) const override;
|
2009-07-31 16:03:48 +02:00
|
|
|
|
|
|
|
|
private:
|
2009-12-01 12:46:15 +01:00
|
|
|
std::vector<const Name *> _names;
|
2009-07-31 16:03:48 +02:00
|
|
|
bool _hasArguments;
|
|
|
|
|
};
|
|
|
|
|
|
2013-04-10 23:30:18 +02:00
|
|
|
class CPLUSPLUS_EXPORT AnonymousNameId: public Name
|
|
|
|
|
{
|
|
|
|
|
public:
|
2019-07-24 18:40:10 +02:00
|
|
|
AnonymousNameId(int classTokenIndex);
|
2013-04-10 23:30:18 +02:00
|
|
|
virtual ~AnonymousNameId();
|
|
|
|
|
|
2019-07-24 18:40:10 +02:00
|
|
|
int classTokenIndex() const;
|
2013-04-10 23:30:18 +02:00
|
|
|
|
2020-11-23 16:44:16 +01:00
|
|
|
const Identifier *identifier() const override;
|
2013-04-10 23:30:18 +02:00
|
|
|
|
2020-11-23 16:44:16 +01:00
|
|
|
const AnonymousNameId *asAnonymousNameId() const override
|
2013-04-10 23:30:18 +02:00
|
|
|
{ return this; }
|
|
|
|
|
|
|
|
|
|
protected:
|
2020-11-23 16:44:16 +01:00
|
|
|
void accept0(NameVisitor *visitor) const override;
|
|
|
|
|
bool match0(const Name *otherName, Matcher *matcher) const override;
|
2013-04-10 23:30:18 +02:00
|
|
|
|
|
|
|
|
private:
|
2019-07-24 18:40:10 +02:00
|
|
|
int _classTokenIndex;
|
2013-04-10 23:30:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-02-04 09:52:39 +01:00
|
|
|
} // namespace CPlusPlus
|