aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/include/clang/AST/TypeLoc.h
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/clang/include/clang/AST/TypeLoc.h')
-rw-r--r--contrib/llvm-project/clang/include/clang/AST/TypeLoc.h316
1 files changed, 201 insertions, 115 deletions
diff --git a/contrib/llvm-project/clang/include/clang/AST/TypeLoc.h b/contrib/llvm-project/clang/include/clang/AST/TypeLoc.h
index 65e95d52c303..471deb14aba5 100644
--- a/contrib/llvm-project/clang/include/clang/AST/TypeLoc.h
+++ b/contrib/llvm-project/clang/include/clang/AST/TypeLoc.h
@@ -14,6 +14,7 @@
#ifndef LLVM_CLANG_AST_TYPELOC_H
#define LLVM_CLANG_AST_TYPELOC_H
+#include "clang/AST/ASTConcept.h"
#include "clang/AST/DeclarationName.h"
#include "clang/AST/NestedNameSpecifier.h"
#include "clang/AST/TemplateBase.h"
@@ -240,6 +241,11 @@ private:
static SourceRange getLocalSourceRangeImpl(TypeLoc TL);
};
+inline TypeSourceInfo::TypeSourceInfo(QualType ty, size_t DataSize) : Ty(ty) {
+ // Init data attached to the object. See getTypeLoc.
+ memset(static_cast<void *>(this + 1), 0, DataSize);
+}
+
/// Return the TypeLoc for a type source info.
inline TypeLoc TypeSourceInfo::getTypeLoc() const {
// TODO: is this alignment already sufficient?
@@ -430,7 +436,7 @@ protected:
unsigned size = sizeof(LocalData);
unsigned extraAlign = asDerived()->getExtraLocalDataAlignment();
size = llvm::alignTo(size, extraAlign);
- return reinterpret_cast<char*>(Base::Data) + size;
+ return reinterpret_cast<char *>(Base::Data) + size;
}
void *getNonLocalData() const {
@@ -581,10 +587,9 @@ public:
bool needsExtraLocalData() const {
BuiltinType::Kind bk = getTypePtr()->getKind();
- return (bk >= BuiltinType::UShort && bk <= BuiltinType::UInt128)
- || (bk >= BuiltinType::Short && bk <= BuiltinType::Float128)
- || bk == BuiltinType::UChar
- || bk == BuiltinType::SChar;
+ return (bk >= BuiltinType::UShort && bk <= BuiltinType::UInt128) ||
+ (bk >= BuiltinType::Short && bk <= BuiltinType::Ibm128) ||
+ bk == BuiltinType::UChar || bk == BuiltinType::SChar;
}
unsigned getExtraLocalDataSize() const {
@@ -666,6 +671,16 @@ public:
}
};
+/// Wrapper for source info for types used via transparent aliases.
+class UsingTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
+ UsingTypeLoc, UsingType> {
+public:
+ QualType getUnderlyingType() const {
+ return getTypePtr()->getUnderlyingType();
+ }
+ UsingShadowDecl *getFoundDecl() const { return getTypePtr()->getFoundDecl(); }
+};
+
/// Wrapper for source info for typedefs.
class TypedefTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
TypedefTypeLoc,
@@ -805,7 +820,7 @@ public:
}
ArrayRef<SourceLocation> getProtocolLocs() const {
- return llvm::makeArrayRef(getProtocolLocArray(), getNumProtocols());
+ return llvm::ArrayRef(getProtocolLocArray(), getNumProtocols());
}
void initializeLocal(ASTContext &Context, SourceLocation Loc);
@@ -892,6 +907,29 @@ public:
}
};
+struct BTFTagAttributedLocInfo {}; // Nothing.
+
+/// Type source information for an btf_tag attributed type.
+class BTFTagAttributedTypeLoc
+ : public ConcreteTypeLoc<UnqualTypeLoc, BTFTagAttributedTypeLoc,
+ BTFTagAttributedType, BTFTagAttributedLocInfo> {
+public:
+ TypeLoc getWrappedLoc() const { return getInnerTypeLoc(); }
+
+ /// The btf_type_tag attribute.
+ const BTFTypeTagAttr *getAttr() const { return getTypePtr()->getAttr(); }
+
+ template <typename T> T *getAttrAs() {
+ return dyn_cast_or_null<T>(getAttr());
+ }
+
+ SourceRange getLocalSourceRange() const;
+
+ void initializeLocal(ASTContext &Context, SourceLocation loc) {}
+
+ QualType getInnerType() const { return getTypePtr()->getWrappedType(); }
+};
+
struct ObjCObjectTypeLocInfo {
SourceLocation TypeArgsLAngleLoc;
SourceLocation TypeArgsRAngleLoc;
@@ -988,7 +1026,7 @@ public:
ArrayRef<SourceLocation> getProtocolLocs() const {
- return llvm::makeArrayRef(getProtocolLocArray(), getNumProtocols());
+ return llvm::ArrayRef(getProtocolLocArray(), getNumProtocols());
}
bool hasBaseTypeAsWritten() const {
@@ -1415,7 +1453,7 @@ public:
}
ArrayRef<ParmVarDecl *> getParams() const {
- return llvm::makeArrayRef(getParmArray(), getNumParams());
+ return llvm::ArrayRef(getParmArray(), getNumParams());
}
// ParmVarDecls* are stored after Info, one for each parameter.
@@ -1602,7 +1640,7 @@ public:
}
unsigned getNumArgs() const {
- return getTypePtr()->getNumArgs();
+ return getTypePtr()->template_arguments().size();
}
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) {
@@ -1614,7 +1652,8 @@ public:
}
TemplateArgumentLoc getArgLoc(unsigned i) const {
- return TemplateArgumentLoc(getTypePtr()->getArg(i), getArgLocInfo(i));
+ return TemplateArgumentLoc(getTypePtr()->template_arguments()[i],
+ getArgLocInfo(i));
}
SourceLocation getTemplateNameLoc() const {
@@ -1649,12 +1688,12 @@ public:
setTemplateNameLoc(Loc);
setLAngleLoc(Loc);
setRAngleLoc(Loc);
- initializeArgLocs(Context, getNumArgs(), getTypePtr()->getArgs(),
+ initializeArgLocs(Context, getTypePtr()->template_arguments(),
getArgInfos(), Loc);
}
- static void initializeArgLocs(ASTContext &Context, unsigned NumArgs,
- const TemplateArgument *Args,
+ static void initializeArgLocs(ASTContext &Context,
+ ArrayRef<TemplateArgument> Args,
TemplateArgumentLocInfo *ArgInfos,
SourceLocation Loc);
@@ -1902,7 +1941,7 @@ struct TypeOfExprTypeLocInfo : public TypeofLocInfo {
};
struct TypeOfTypeLocInfo : public TypeofLocInfo {
- TypeSourceInfo* UnderlyingTInfo;
+ TypeSourceInfo *UnmodifiedTInfo;
};
template <class Derived, class TypeClass, class LocalData = TypeofLocInfo>
@@ -1970,27 +2009,50 @@ public:
class TypeOfTypeLoc
: public TypeofLikeTypeLoc<TypeOfTypeLoc, TypeOfType, TypeOfTypeLocInfo> {
public:
- QualType getUnderlyingType() const {
- return this->getTypePtr()->getUnderlyingType();
+ QualType getUnmodifiedType() const {
+ return this->getTypePtr()->getUnmodifiedType();
}
- TypeSourceInfo* getUnderlyingTInfo() const {
- return this->getLocalData()->UnderlyingTInfo;
+ TypeSourceInfo *getUnmodifiedTInfo() const {
+ return this->getLocalData()->UnmodifiedTInfo;
}
- void setUnderlyingTInfo(TypeSourceInfo* TI) const {
- this->getLocalData()->UnderlyingTInfo = TI;
+ void setUnmodifiedTInfo(TypeSourceInfo *TI) const {
+ this->getLocalData()->UnmodifiedTInfo = TI;
}
void initializeLocal(ASTContext &Context, SourceLocation Loc);
};
-// FIXME: location of the 'decltype' and parens.
-class DecltypeTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
- DecltypeTypeLoc,
- DecltypeType> {
+// decltype(expression) abc;
+// ~~~~~~~~ DecltypeLoc
+// ~ RParenLoc
+// FIXME: add LParenLoc, it is tricky to support due to the limitation of
+// annotated-decltype token.
+struct DecltypeTypeLocInfo {
+ SourceLocation DecltypeLoc;
+ SourceLocation RParenLoc;
+};
+class DecltypeTypeLoc
+ : public ConcreteTypeLoc<UnqualTypeLoc, DecltypeTypeLoc, DecltypeType,
+ DecltypeTypeLocInfo> {
public:
Expr *getUnderlyingExpr() const { return getTypePtr()->getUnderlyingExpr(); }
+
+ SourceLocation getDecltypeLoc() const { return getLocalData()->DecltypeLoc; }
+ void setDecltypeLoc(SourceLocation Loc) { getLocalData()->DecltypeLoc = Loc; }
+
+ SourceLocation getRParenLoc() const { return getLocalData()->RParenLoc; }
+ void setRParenLoc(SourceLocation Loc) { getLocalData()->RParenLoc = Loc; }
+
+ SourceRange getLocalSourceRange() const {
+ return SourceRange(getDecltypeLoc(), getRParenLoc());
+ }
+
+ void initializeLocal(ASTContext &Context, SourceLocation Loc) {
+ setDecltypeLoc(Loc);
+ setRParenLoc(Loc);
+ }
};
struct UnaryTransformTypeLocInfo {
@@ -2043,12 +2105,10 @@ class DeducedTypeLoc
DeducedType> {};
struct AutoTypeLocInfo : TypeSpecLocInfo {
- NestedNameSpecifierLoc NestedNameSpec;
- SourceLocation TemplateKWLoc;
- SourceLocation ConceptNameLoc;
- NamedDecl *FoundDecl;
- SourceLocation LAngleLoc;
- SourceLocation RAngleLoc;
+ // For decltype(auto).
+ SourceLocation RParenLoc;
+
+ ConceptReference *CR = nullptr;
};
class AutoTypeLoc
@@ -2061,96 +2121,95 @@ public:
return getTypePtr()->getKeyword();
}
+ bool isDecltypeAuto() const { return getTypePtr()->isDecltypeAuto(); }
+ SourceLocation getRParenLoc() const { return getLocalData()->RParenLoc; }
+ void setRParenLoc(SourceLocation Loc) { getLocalData()->RParenLoc = Loc; }
+
bool isConstrained() const {
return getTypePtr()->isConstrained();
}
- const NestedNameSpecifierLoc &getNestedNameSpecifierLoc() const {
- return getLocalData()->NestedNameSpec;
- }
+ void setConceptReference(ConceptReference *CR) { getLocalData()->CR = CR; }
- void setNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) {
- getLocalData()->NestedNameSpec = NNS;
- }
+ ConceptReference *getConceptReference() const { return getLocalData()->CR; }
- SourceLocation getTemplateKWLoc() const {
- return getLocalData()->TemplateKWLoc;
+ // FIXME: Several of the following functions can be removed. Instead the
+ // caller can directly work with the ConceptReference.
+ const NestedNameSpecifierLoc getNestedNameSpecifierLoc() const {
+ if (const auto *CR = getConceptReference())
+ return CR->getNestedNameSpecifierLoc();
+ return NestedNameSpecifierLoc();
}
- void setTemplateKWLoc(SourceLocation Loc) {
- getLocalData()->TemplateKWLoc = Loc;
+ SourceLocation getTemplateKWLoc() const {
+ if (const auto *CR = getConceptReference())
+ return CR->getTemplateKWLoc();
+ return SourceLocation();
}
SourceLocation getConceptNameLoc() const {
- return getLocalData()->ConceptNameLoc;
- }
-
- void setConceptNameLoc(SourceLocation Loc) {
- getLocalData()->ConceptNameLoc = Loc;
+ if (const auto *CR = getConceptReference())
+ return CR->getConceptNameLoc();
+ return SourceLocation();
}
NamedDecl *getFoundDecl() const {
- return getLocalData()->FoundDecl;
- }
-
- void setFoundDecl(NamedDecl *D) {
- getLocalData()->FoundDecl = D;
+ if (const auto *CR = getConceptReference())
+ return CR->getFoundDecl();
+ return nullptr;
}
ConceptDecl *getNamedConcept() const {
- return getTypePtr()->getTypeConstraintConcept();
+ if (const auto *CR = getConceptReference())
+ return CR->getNamedConcept();
+ return nullptr;
}
- DeclarationNameInfo getConceptNameInfo() const;
+ DeclarationNameInfo getConceptNameInfo() const {
+ return getConceptReference()->getConceptNameInfo();
+ }
bool hasExplicitTemplateArgs() const {
- return getLocalData()->LAngleLoc.isValid();
+ return (getConceptReference() &&
+ getConceptReference()->getTemplateArgsAsWritten() &&
+ getConceptReference()
+ ->getTemplateArgsAsWritten()
+ ->getLAngleLoc()
+ .isValid());
}
SourceLocation getLAngleLoc() const {
- return this->getLocalData()->LAngleLoc;
- }
-
- void setLAngleLoc(SourceLocation Loc) {
- this->getLocalData()->LAngleLoc = Loc;
+ if (const auto *CR = getConceptReference())
+ if (const auto *TAAW = CR->getTemplateArgsAsWritten())
+ return TAAW->getLAngleLoc();
+ return SourceLocation();
}
SourceLocation getRAngleLoc() const {
- return this->getLocalData()->RAngleLoc;
- }
-
- void setRAngleLoc(SourceLocation Loc) {
- this->getLocalData()->RAngleLoc = Loc;
+ if (const auto *CR = getConceptReference())
+ if (const auto *TAAW = CR->getTemplateArgsAsWritten())
+ return TAAW->getRAngleLoc();
+ return SourceLocation();
}
unsigned getNumArgs() const {
- return getTypePtr()->getNumArgs();
- }
-
- void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) {
- getArgInfos()[i] = AI;
- }
-
- TemplateArgumentLocInfo getArgLocInfo(unsigned i) const {
- return getArgInfos()[i];
+ return getTypePtr()->getTypeConstraintArguments().size();
}
TemplateArgumentLoc getArgLoc(unsigned i) const {
- return TemplateArgumentLoc(getTypePtr()->getTypeConstraintArguments()[i],
- getArgLocInfo(i));
+ const auto *CR = getConceptReference();
+ assert(CR && "No ConceptReference");
+ return CR->getTemplateArgsAsWritten()->getTemplateArgs()[i];
}
SourceRange getLocalSourceRange() const {
- return{
- isConstrained()
- ? (getNestedNameSpecifierLoc()
- ? getNestedNameSpecifierLoc().getBeginLoc()
- : (getTemplateKWLoc().isValid()
- ? getTemplateKWLoc()
- : getConceptNameLoc()))
- : getNameLoc(),
- getNameLoc()
- };
+ return {isConstrained()
+ ? (getNestedNameSpecifierLoc()
+ ? getNestedNameSpecifierLoc().getBeginLoc()
+ : (getTemplateKWLoc().isValid() ? getTemplateKWLoc()
+ : getConceptNameLoc()))
+ : getNameLoc(),
+ isDecltypeAuto() ? getRParenLoc() : getNameLoc()};
}
void copy(AutoTypeLoc Loc) {
@@ -2160,19 +2219,6 @@ public:
}
void initializeLocal(ASTContext &Context, SourceLocation Loc);
-
- unsigned getExtraLocalDataSize() const {
- return getNumArgs() * sizeof(TemplateArgumentLocInfo);
- }
-
- unsigned getExtraLocalDataAlignment() const {
- return alignof(TemplateArgumentLocInfo);
- }
-
-private:
- TemplateArgumentLocInfo *getArgInfos() const {
- return static_cast<TemplateArgumentLocInfo*>(getExtraLocalData());
- }
};
class DeducedTemplateSpecializationTypeLoc
@@ -2202,22 +2248,31 @@ class ElaboratedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
ElaboratedLocInfo> {
public:
SourceLocation getElaboratedKeywordLoc() const {
- return this->getLocalData()->ElaboratedKWLoc;
+ return !isEmpty() ? getLocalData()->ElaboratedKWLoc : SourceLocation();
}
void setElaboratedKeywordLoc(SourceLocation Loc) {
- this->getLocalData()->ElaboratedKWLoc = Loc;
+ if (isEmpty()) {
+ assert(Loc.isInvalid());
+ return;
+ }
+ getLocalData()->ElaboratedKWLoc = Loc;
}
NestedNameSpecifierLoc getQualifierLoc() const {
- return NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
- getLocalData()->QualifierData);
+ return !isEmpty() ? NestedNameSpecifierLoc(getTypePtr()->getQualifier(),
+ getLocalData()->QualifierData)
+ : NestedNameSpecifierLoc();
}
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc) {
- assert(QualifierLoc.getNestedNameSpecifier()
- == getTypePtr()->getQualifier() &&
+ assert(QualifierLoc.getNestedNameSpecifier() ==
+ getTypePtr()->getQualifier() &&
"Inconsistent nested-name-specifier pointer");
+ if (isEmpty()) {
+ assert(!QualifierLoc.hasQualifier());
+ return;
+ }
getLocalData()->QualifierData = QualifierLoc.getOpaqueData();
}
@@ -2234,12 +2289,24 @@ public:
void initializeLocal(ASTContext &Context, SourceLocation Loc);
- TypeLoc getNamedTypeLoc() const {
- return getInnerTypeLoc();
+ TypeLoc getNamedTypeLoc() const { return getInnerTypeLoc(); }
+
+ QualType getInnerType() const { return getTypePtr()->getNamedType(); }
+
+ bool isEmpty() const {
+ return getTypePtr()->getKeyword() == ElaboratedTypeKeyword::None &&
+ !getTypePtr()->getQualifier();
}
- QualType getInnerType() const {
- return getTypePtr()->getNamedType();
+ unsigned getLocalDataAlignment() const {
+ // FIXME: We want to return 1 here in the empty case, but
+ // there are bugs in how alignment is handled in TypeLocs
+ // that prevent this from working.
+ return ConcreteTypeLoc::getLocalDataAlignment();
+ }
+
+ unsigned getLocalDataSize() const {
+ return !isEmpty() ? ConcreteTypeLoc::getLocalDataSize() : 0;
}
void copy(ElaboratedTypeLoc Loc) {
@@ -2382,7 +2449,7 @@ public:
}
unsigned getNumArgs() const {
- return getTypePtr()->getNumArgs();
+ return getTypePtr()->template_arguments().size();
}
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) {
@@ -2394,7 +2461,8 @@ public:
}
TemplateArgumentLoc getArgLoc(unsigned i) const {
- return TemplateArgumentLoc(getTypePtr()->getArg(i), getArgLocInfo(i));
+ return TemplateArgumentLoc(getTypePtr()->template_arguments()[i],
+ getArgLocInfo(i));
}
SourceRange getLocalSourceRange() const {
@@ -2551,6 +2619,8 @@ inline T TypeLoc::getAsAdjusted() const {
Cur = PTL.getInnerLoc();
else if (auto ATL = Cur.getAs<AttributedTypeLoc>())
Cur = ATL.getModifiedLoc();
+ else if (auto ATL = Cur.getAs<BTFTagAttributedTypeLoc>())
+ Cur = ATL.getWrappedLoc();
else if (auto ETL = Cur.getAs<ElaboratedTypeLoc>())
Cur = ETL.getNamedTypeLoc();
else if (auto ATL = Cur.getAs<AdjustedTypeLoc>())
@@ -2562,12 +2632,28 @@ inline T TypeLoc::getAsAdjusted() const {
}
return Cur.getAs<T>();
}
-class ExtIntTypeLoc final
- : public InheritingConcreteTypeLoc<TypeSpecTypeLoc, ExtIntTypeLoc,
- ExtIntType> {};
-class DependentExtIntTypeLoc final
- : public InheritingConcreteTypeLoc<TypeSpecTypeLoc, DependentExtIntTypeLoc,
- DependentExtIntType> {};
+class BitIntTypeLoc final
+ : public InheritingConcreteTypeLoc<TypeSpecTypeLoc, BitIntTypeLoc,
+ BitIntType> {};
+class DependentBitIntTypeLoc final
+ : public InheritingConcreteTypeLoc<TypeSpecTypeLoc, DependentBitIntTypeLoc,
+ DependentBitIntType> {};
+
+class ObjCProtocolLoc {
+ ObjCProtocolDecl *Protocol = nullptr;
+ SourceLocation Loc = SourceLocation();
+
+public:
+ ObjCProtocolLoc(ObjCProtocolDecl *protocol, SourceLocation loc)
+ : Protocol(protocol), Loc(loc) {}
+ ObjCProtocolDecl *getProtocol() const { return Protocol; }
+ SourceLocation getLocation() const { return Loc; }
+
+ /// The source range is just the protocol name.
+ SourceRange getSourceRange() const LLVM_READONLY {
+ return SourceRange(Loc, Loc);
+ }
+};
} // namespace clang