Type.cpp 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246
  1. //===--- Type.cpp - Type representation and manipulation ------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements type-related functionality.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/AST/ASTContext.h"
  14. #include "clang/AST/CharUnits.h"
  15. #include "clang/AST/Type.h"
  16. #include "clang/AST/DeclCXX.h"
  17. #include "clang/AST/DeclObjC.h"
  18. #include "clang/AST/DeclTemplate.h"
  19. #include "clang/AST/Expr.h"
  20. #include "clang/AST/PrettyPrinter.h"
  21. #include "clang/AST/TypeVisitor.h"
  22. #include "clang/Basic/Specifiers.h"
  23. #include "llvm/ADT/APSInt.h"
  24. #include "llvm/ADT/StringExtras.h"
  25. #include "llvm/Support/raw_ostream.h"
  26. #include <algorithm>
  27. using namespace clang;
  28. bool Qualifiers::isStrictSupersetOf(Qualifiers Other) const {
  29. return (*this != Other) &&
  30. // CVR qualifiers superset
  31. (((Mask & CVRMask) | (Other.Mask & CVRMask)) == (Mask & CVRMask)) &&
  32. // ObjC GC qualifiers superset
  33. ((getObjCGCAttr() == Other.getObjCGCAttr()) ||
  34. (hasObjCGCAttr() && !Other.hasObjCGCAttr())) &&
  35. // Address space superset.
  36. ((getAddressSpace() == Other.getAddressSpace()) ||
  37. (hasAddressSpace()&& !Other.hasAddressSpace())) &&
  38. // Lifetime qualifier superset.
  39. ((getObjCLifetime() == Other.getObjCLifetime()) ||
  40. (hasObjCLifetime() && !Other.hasObjCLifetime()));
  41. }
  42. const IdentifierInfo* QualType::getBaseTypeIdentifier() const {
  43. const Type* ty = getTypePtr();
  44. NamedDecl *ND = NULL;
  45. if (ty->isPointerType() || ty->isReferenceType())
  46. return ty->getPointeeType().getBaseTypeIdentifier();
  47. else if (ty->isRecordType())
  48. ND = ty->getAs<RecordType>()->getDecl();
  49. else if (ty->isEnumeralType())
  50. ND = ty->getAs<EnumType>()->getDecl();
  51. else if (ty->getTypeClass() == Type::Typedef)
  52. ND = ty->getAs<TypedefType>()->getDecl();
  53. else if (ty->isArrayType())
  54. return ty->castAsArrayTypeUnsafe()->
  55. getElementType().getBaseTypeIdentifier();
  56. if (ND)
  57. return ND->getIdentifier();
  58. return NULL;
  59. }
  60. bool QualType::isConstant(QualType T, ASTContext &Ctx) {
  61. if (T.isConstQualified())
  62. return true;
  63. if (const ArrayType *AT = Ctx.getAsArrayType(T))
  64. return AT->getElementType().isConstant(Ctx);
  65. return false;
  66. }
  67. unsigned ConstantArrayType::getNumAddressingBits(ASTContext &Context,
  68. QualType ElementType,
  69. const llvm::APInt &NumElements) {
  70. llvm::APSInt SizeExtended(NumElements, true);
  71. unsigned SizeTypeBits = Context.getTypeSize(Context.getSizeType());
  72. SizeExtended = SizeExtended.extend(std::max(SizeTypeBits,
  73. SizeExtended.getBitWidth()) * 2);
  74. uint64_t ElementSize
  75. = Context.getTypeSizeInChars(ElementType).getQuantity();
  76. llvm::APSInt TotalSize(llvm::APInt(SizeExtended.getBitWidth(), ElementSize));
  77. TotalSize *= SizeExtended;
  78. return TotalSize.getActiveBits();
  79. }
  80. unsigned ConstantArrayType::getMaxSizeBits(ASTContext &Context) {
  81. unsigned Bits = Context.getTypeSize(Context.getSizeType());
  82. // GCC appears to only allow 63 bits worth of address space when compiling
  83. // for 64-bit, so we do the same.
  84. if (Bits == 64)
  85. --Bits;
  86. return Bits;
  87. }
  88. DependentSizedArrayType::DependentSizedArrayType(const ASTContext &Context,
  89. QualType et, QualType can,
  90. Expr *e, ArraySizeModifier sm,
  91. unsigned tq,
  92. SourceRange brackets)
  93. : ArrayType(DependentSizedArray, et, can, sm, tq,
  94. (et->containsUnexpandedParameterPack() ||
  95. (e && e->containsUnexpandedParameterPack()))),
  96. Context(Context), SizeExpr((Stmt*) e), Brackets(brackets)
  97. {
  98. }
  99. void DependentSizedArrayType::Profile(llvm::FoldingSetNodeID &ID,
  100. const ASTContext &Context,
  101. QualType ET,
  102. ArraySizeModifier SizeMod,
  103. unsigned TypeQuals,
  104. Expr *E) {
  105. ID.AddPointer(ET.getAsOpaquePtr());
  106. ID.AddInteger(SizeMod);
  107. ID.AddInteger(TypeQuals);
  108. E->Profile(ID, Context, true);
  109. }
  110. DependentSizedExtVectorType::DependentSizedExtVectorType(const
  111. ASTContext &Context,
  112. QualType ElementType,
  113. QualType can,
  114. Expr *SizeExpr,
  115. SourceLocation loc)
  116. : Type(DependentSizedExtVector, can, /*Dependent=*/true,
  117. /*InstantiationDependent=*/true,
  118. ElementType->isVariablyModifiedType(),
  119. (ElementType->containsUnexpandedParameterPack() ||
  120. (SizeExpr && SizeExpr->containsUnexpandedParameterPack()))),
  121. Context(Context), SizeExpr(SizeExpr), ElementType(ElementType),
  122. loc(loc)
  123. {
  124. }
  125. void
  126. DependentSizedExtVectorType::Profile(llvm::FoldingSetNodeID &ID,
  127. const ASTContext &Context,
  128. QualType ElementType, Expr *SizeExpr) {
  129. ID.AddPointer(ElementType.getAsOpaquePtr());
  130. SizeExpr->Profile(ID, Context, true);
  131. }
  132. VectorType::VectorType(QualType vecType, unsigned nElements, QualType canonType,
  133. VectorKind vecKind)
  134. : Type(Vector, canonType, vecType->isDependentType(),
  135. vecType->isInstantiationDependentType(),
  136. vecType->isVariablyModifiedType(),
  137. vecType->containsUnexpandedParameterPack()),
  138. ElementType(vecType)
  139. {
  140. VectorTypeBits.VecKind = vecKind;
  141. VectorTypeBits.NumElements = nElements;
  142. }
  143. VectorType::VectorType(TypeClass tc, QualType vecType, unsigned nElements,
  144. QualType canonType, VectorKind vecKind)
  145. : Type(tc, canonType, vecType->isDependentType(),
  146. vecType->isInstantiationDependentType(),
  147. vecType->isVariablyModifiedType(),
  148. vecType->containsUnexpandedParameterPack()),
  149. ElementType(vecType)
  150. {
  151. VectorTypeBits.VecKind = vecKind;
  152. VectorTypeBits.NumElements = nElements;
  153. }
  154. /// getArrayElementTypeNoTypeQual - If this is an array type, return the
  155. /// element type of the array, potentially with type qualifiers missing.
  156. /// This method should never be used when type qualifiers are meaningful.
  157. const Type *Type::getArrayElementTypeNoTypeQual() const {
  158. // If this is directly an array type, return it.
  159. if (const ArrayType *ATy = dyn_cast<ArrayType>(this))
  160. return ATy->getElementType().getTypePtr();
  161. // If the canonical form of this type isn't the right kind, reject it.
  162. if (!isa<ArrayType>(CanonicalType))
  163. return 0;
  164. // If this is a typedef for an array type, strip the typedef off without
  165. // losing all typedef information.
  166. return cast<ArrayType>(getUnqualifiedDesugaredType())
  167. ->getElementType().getTypePtr();
  168. }
  169. /// getDesugaredType - Return the specified type with any "sugar" removed from
  170. /// the type. This takes off typedefs, typeof's etc. If the outer level of
  171. /// the type is already concrete, it returns it unmodified. This is similar
  172. /// to getting the canonical type, but it doesn't remove *all* typedefs. For
  173. /// example, it returns "T*" as "T*", (not as "int*"), because the pointer is
  174. /// concrete.
  175. QualType QualType::getDesugaredType(QualType T, const ASTContext &Context) {
  176. SplitQualType split = getSplitDesugaredType(T);
  177. return Context.getQualifiedType(split.Ty, split.Quals);
  178. }
  179. QualType QualType::getSingleStepDesugaredTypeImpl(QualType type,
  180. const ASTContext &Context) {
  181. SplitQualType split = type.split();
  182. QualType desugar = split.Ty->getLocallyUnqualifiedSingleStepDesugaredType();
  183. return Context.getQualifiedType(desugar, split.Quals);
  184. }
  185. QualType Type::getLocallyUnqualifiedSingleStepDesugaredType() const {
  186. switch (getTypeClass()) {
  187. #define ABSTRACT_TYPE(Class, Parent)
  188. #define TYPE(Class, Parent) \
  189. case Type::Class: { \
  190. const Class##Type *ty = cast<Class##Type>(this); \
  191. if (!ty->isSugared()) return QualType(ty, 0); \
  192. return ty->desugar(); \
  193. }
  194. #include "clang/AST/TypeNodes.def"
  195. }
  196. llvm_unreachable("bad type kind!");
  197. }
  198. SplitQualType QualType::getSplitDesugaredType(QualType T) {
  199. QualifierCollector Qs;
  200. QualType Cur = T;
  201. while (true) {
  202. const Type *CurTy = Qs.strip(Cur);
  203. switch (CurTy->getTypeClass()) {
  204. #define ABSTRACT_TYPE(Class, Parent)
  205. #define TYPE(Class, Parent) \
  206. case Type::Class: { \
  207. const Class##Type *Ty = cast<Class##Type>(CurTy); \
  208. if (!Ty->isSugared()) \
  209. return SplitQualType(Ty, Qs); \
  210. Cur = Ty->desugar(); \
  211. break; \
  212. }
  213. #include "clang/AST/TypeNodes.def"
  214. }
  215. }
  216. }
  217. SplitQualType QualType::getSplitUnqualifiedTypeImpl(QualType type) {
  218. SplitQualType split = type.split();
  219. // All the qualifiers we've seen so far.
  220. Qualifiers quals = split.Quals;
  221. // The last type node we saw with any nodes inside it.
  222. const Type *lastTypeWithQuals = split.Ty;
  223. while (true) {
  224. QualType next;
  225. // Do a single-step desugar, aborting the loop if the type isn't
  226. // sugared.
  227. switch (split.Ty->getTypeClass()) {
  228. #define ABSTRACT_TYPE(Class, Parent)
  229. #define TYPE(Class, Parent) \
  230. case Type::Class: { \
  231. const Class##Type *ty = cast<Class##Type>(split.Ty); \
  232. if (!ty->isSugared()) goto done; \
  233. next = ty->desugar(); \
  234. break; \
  235. }
  236. #include "clang/AST/TypeNodes.def"
  237. }
  238. // Otherwise, split the underlying type. If that yields qualifiers,
  239. // update the information.
  240. split = next.split();
  241. if (!split.Quals.empty()) {
  242. lastTypeWithQuals = split.Ty;
  243. quals.addConsistentQualifiers(split.Quals);
  244. }
  245. }
  246. done:
  247. return SplitQualType(lastTypeWithQuals, quals);
  248. }
  249. QualType QualType::IgnoreParens(QualType T) {
  250. // FIXME: this seems inherently un-qualifiers-safe.
  251. while (const ParenType *PT = T->getAs<ParenType>())
  252. T = PT->getInnerType();
  253. return T;
  254. }
  255. /// getUnqualifiedDesugaredType - Pull any qualifiers and syntactic
  256. /// sugar off the given type. This should produce an object of the
  257. /// same dynamic type as the canonical type.
  258. const Type *Type::getUnqualifiedDesugaredType() const {
  259. const Type *Cur = this;
  260. while (true) {
  261. switch (Cur->getTypeClass()) {
  262. #define ABSTRACT_TYPE(Class, Parent)
  263. #define TYPE(Class, Parent) \
  264. case Class: { \
  265. const Class##Type *Ty = cast<Class##Type>(Cur); \
  266. if (!Ty->isSugared()) return Cur; \
  267. Cur = Ty->desugar().getTypePtr(); \
  268. break; \
  269. }
  270. #include "clang/AST/TypeNodes.def"
  271. }
  272. }
  273. }
  274. bool Type::isDerivedType() const {
  275. switch (CanonicalType->getTypeClass()) {
  276. case Pointer:
  277. case VariableArray:
  278. case ConstantArray:
  279. case IncompleteArray:
  280. case FunctionProto:
  281. case FunctionNoProto:
  282. case LValueReference:
  283. case RValueReference:
  284. case Record:
  285. return true;
  286. default:
  287. return false;
  288. }
  289. }
  290. bool Type::isClassType() const {
  291. if (const RecordType *RT = getAs<RecordType>())
  292. return RT->getDecl()->isClass();
  293. return false;
  294. }
  295. bool Type::isStructureType() const {
  296. if (const RecordType *RT = getAs<RecordType>())
  297. return RT->getDecl()->isStruct();
  298. return false;
  299. }
  300. bool Type::isStructureOrClassType() const {
  301. if (const RecordType *RT = getAs<RecordType>())
  302. return RT->getDecl()->isStruct() || RT->getDecl()->isClass();
  303. return false;
  304. }
  305. bool Type::isVoidPointerType() const {
  306. if (const PointerType *PT = getAs<PointerType>())
  307. return PT->getPointeeType()->isVoidType();
  308. return false;
  309. }
  310. bool Type::isUnionType() const {
  311. if (const RecordType *RT = getAs<RecordType>())
  312. return RT->getDecl()->isUnion();
  313. return false;
  314. }
  315. bool Type::isComplexType() const {
  316. if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
  317. return CT->getElementType()->isFloatingType();
  318. return false;
  319. }
  320. bool Type::isComplexIntegerType() const {
  321. // Check for GCC complex integer extension.
  322. return getAsComplexIntegerType();
  323. }
  324. const ComplexType *Type::getAsComplexIntegerType() const {
  325. if (const ComplexType *Complex = getAs<ComplexType>())
  326. if (Complex->getElementType()->isIntegerType())
  327. return Complex;
  328. return 0;
  329. }
  330. QualType Type::getPointeeType() const {
  331. if (const PointerType *PT = getAs<PointerType>())
  332. return PT->getPointeeType();
  333. if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>())
  334. return OPT->getPointeeType();
  335. if (const BlockPointerType *BPT = getAs<BlockPointerType>())
  336. return BPT->getPointeeType();
  337. if (const ReferenceType *RT = getAs<ReferenceType>())
  338. return RT->getPointeeType();
  339. return QualType();
  340. }
  341. const RecordType *Type::getAsStructureType() const {
  342. // If this is directly a structure type, return it.
  343. if (const RecordType *RT = dyn_cast<RecordType>(this)) {
  344. if (RT->getDecl()->isStruct())
  345. return RT;
  346. }
  347. // If the canonical form of this type isn't the right kind, reject it.
  348. if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
  349. if (!RT->getDecl()->isStruct())
  350. return 0;
  351. // If this is a typedef for a structure type, strip the typedef off without
  352. // losing all typedef information.
  353. return cast<RecordType>(getUnqualifiedDesugaredType());
  354. }
  355. return 0;
  356. }
  357. const RecordType *Type::getAsUnionType() const {
  358. // If this is directly a union type, return it.
  359. if (const RecordType *RT = dyn_cast<RecordType>(this)) {
  360. if (RT->getDecl()->isUnion())
  361. return RT;
  362. }
  363. // If the canonical form of this type isn't the right kind, reject it.
  364. if (const RecordType *RT = dyn_cast<RecordType>(CanonicalType)) {
  365. if (!RT->getDecl()->isUnion())
  366. return 0;
  367. // If this is a typedef for a union type, strip the typedef off without
  368. // losing all typedef information.
  369. return cast<RecordType>(getUnqualifiedDesugaredType());
  370. }
  371. return 0;
  372. }
  373. ObjCObjectType::ObjCObjectType(QualType Canonical, QualType Base,
  374. ObjCProtocolDecl * const *Protocols,
  375. unsigned NumProtocols)
  376. : Type(ObjCObject, Canonical, false, false, false, false),
  377. BaseType(Base)
  378. {
  379. ObjCObjectTypeBits.NumProtocols = NumProtocols;
  380. assert(getNumProtocols() == NumProtocols &&
  381. "bitfield overflow in protocol count");
  382. if (NumProtocols)
  383. memcpy(getProtocolStorage(), Protocols,
  384. NumProtocols * sizeof(ObjCProtocolDecl*));
  385. }
  386. const ObjCObjectType *Type::getAsObjCQualifiedInterfaceType() const {
  387. // There is no sugar for ObjCObjectType's, just return the canonical
  388. // type pointer if it is the right class. There is no typedef information to
  389. // return and these cannot be Address-space qualified.
  390. if (const ObjCObjectType *T = getAs<ObjCObjectType>())
  391. if (T->getNumProtocols() && T->getInterface())
  392. return T;
  393. return 0;
  394. }
  395. bool Type::isObjCQualifiedInterfaceType() const {
  396. return getAsObjCQualifiedInterfaceType() != 0;
  397. }
  398. const ObjCObjectPointerType *Type::getAsObjCQualifiedIdType() const {
  399. // There is no sugar for ObjCQualifiedIdType's, just return the canonical
  400. // type pointer if it is the right class.
  401. if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) {
  402. if (OPT->isObjCQualifiedIdType())
  403. return OPT;
  404. }
  405. return 0;
  406. }
  407. const ObjCObjectPointerType *Type::getAsObjCQualifiedClassType() const {
  408. // There is no sugar for ObjCQualifiedClassType's, just return the canonical
  409. // type pointer if it is the right class.
  410. if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) {
  411. if (OPT->isObjCQualifiedClassType())
  412. return OPT;
  413. }
  414. return 0;
  415. }
  416. const ObjCObjectPointerType *Type::getAsObjCInterfacePointerType() const {
  417. if (const ObjCObjectPointerType *OPT = getAs<ObjCObjectPointerType>()) {
  418. if (OPT->getInterfaceType())
  419. return OPT;
  420. }
  421. return 0;
  422. }
  423. const CXXRecordDecl *Type::getCXXRecordDeclForPointerType() const {
  424. if (const PointerType *PT = getAs<PointerType>())
  425. if (const RecordType *RT = PT->getPointeeType()->getAs<RecordType>())
  426. return dyn_cast<CXXRecordDecl>(RT->getDecl());
  427. return 0;
  428. }
  429. CXXRecordDecl *Type::getAsCXXRecordDecl() const {
  430. if (const RecordType *RT = getAs<RecordType>())
  431. return dyn_cast<CXXRecordDecl>(RT->getDecl());
  432. else if (const InjectedClassNameType *Injected
  433. = getAs<InjectedClassNameType>())
  434. return Injected->getDecl();
  435. return 0;
  436. }
  437. namespace {
  438. class GetContainedAutoVisitor :
  439. public TypeVisitor<GetContainedAutoVisitor, AutoType*> {
  440. public:
  441. using TypeVisitor<GetContainedAutoVisitor, AutoType*>::Visit;
  442. AutoType *Visit(QualType T) {
  443. if (T.isNull())
  444. return 0;
  445. return Visit(T.getTypePtr());
  446. }
  447. // The 'auto' type itself.
  448. AutoType *VisitAutoType(const AutoType *AT) {
  449. return const_cast<AutoType*>(AT);
  450. }
  451. // Only these types can contain the desired 'auto' type.
  452. AutoType *VisitPointerType(const PointerType *T) {
  453. return Visit(T->getPointeeType());
  454. }
  455. AutoType *VisitBlockPointerType(const BlockPointerType *T) {
  456. return Visit(T->getPointeeType());
  457. }
  458. AutoType *VisitReferenceType(const ReferenceType *T) {
  459. return Visit(T->getPointeeTypeAsWritten());
  460. }
  461. AutoType *VisitMemberPointerType(const MemberPointerType *T) {
  462. return Visit(T->getPointeeType());
  463. }
  464. AutoType *VisitArrayType(const ArrayType *T) {
  465. return Visit(T->getElementType());
  466. }
  467. AutoType *VisitDependentSizedExtVectorType(
  468. const DependentSizedExtVectorType *T) {
  469. return Visit(T->getElementType());
  470. }
  471. AutoType *VisitVectorType(const VectorType *T) {
  472. return Visit(T->getElementType());
  473. }
  474. AutoType *VisitFunctionType(const FunctionType *T) {
  475. return Visit(T->getResultType());
  476. }
  477. AutoType *VisitParenType(const ParenType *T) {
  478. return Visit(T->getInnerType());
  479. }
  480. AutoType *VisitAttributedType(const AttributedType *T) {
  481. return Visit(T->getModifiedType());
  482. }
  483. };
  484. }
  485. AutoType *Type::getContainedAutoType() const {
  486. return GetContainedAutoVisitor().Visit(this);
  487. }
  488. bool Type::hasIntegerRepresentation() const {
  489. if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
  490. return VT->getElementType()->isIntegerType();
  491. else
  492. return isIntegerType();
  493. }
  494. /// \brief Determine whether this type is an integral type.
  495. ///
  496. /// This routine determines whether the given type is an integral type per
  497. /// C++ [basic.fundamental]p7. Although the C standard does not define the
  498. /// term "integral type", it has a similar term "integer type", and in C++
  499. /// the two terms are equivalent. However, C's "integer type" includes
  500. /// enumeration types, while C++'s "integer type" does not. The \c ASTContext
  501. /// parameter is used to determine whether we should be following the C or
  502. /// C++ rules when determining whether this type is an integral/integer type.
  503. ///
  504. /// For cases where C permits "an integer type" and C++ permits "an integral
  505. /// type", use this routine.
  506. ///
  507. /// For cases where C permits "an integer type" and C++ permits "an integral
  508. /// or enumeration type", use \c isIntegralOrEnumerationType() instead.
  509. ///
  510. /// \param Ctx The context in which this type occurs.
  511. ///
  512. /// \returns true if the type is considered an integral type, false otherwise.
  513. bool Type::isIntegralType(ASTContext &Ctx) const {
  514. if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
  515. return BT->getKind() >= BuiltinType::Bool &&
  516. BT->getKind() <= BuiltinType::Int128;
  517. if (!Ctx.getLangOpts().CPlusPlus)
  518. if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
  519. return ET->getDecl()->isComplete(); // Complete enum types are integral in C.
  520. return false;
  521. }
  522. bool Type::isIntegralOrUnscopedEnumerationType() const {
  523. if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
  524. return BT->getKind() >= BuiltinType::Bool &&
  525. BT->getKind() <= BuiltinType::Int128;
  526. // Check for a complete enum type; incomplete enum types are not properly an
  527. // enumeration type in the sense required here.
  528. // C++0x: However, if the underlying type of the enum is fixed, it is
  529. // considered complete.
  530. if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
  531. return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped();
  532. return false;
  533. }
  534. bool Type::isCharType() const {
  535. if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
  536. return BT->getKind() == BuiltinType::Char_U ||
  537. BT->getKind() == BuiltinType::UChar ||
  538. BT->getKind() == BuiltinType::Char_S ||
  539. BT->getKind() == BuiltinType::SChar;
  540. return false;
  541. }
  542. bool Type::isWideCharType() const {
  543. if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
  544. return BT->getKind() == BuiltinType::WChar_S ||
  545. BT->getKind() == BuiltinType::WChar_U;
  546. return false;
  547. }
  548. bool Type::isChar16Type() const {
  549. if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
  550. return BT->getKind() == BuiltinType::Char16;
  551. return false;
  552. }
  553. bool Type::isChar32Type() const {
  554. if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
  555. return BT->getKind() == BuiltinType::Char32;
  556. return false;
  557. }
  558. /// \brief Determine whether this type is any of the built-in character
  559. /// types.
  560. bool Type::isAnyCharacterType() const {
  561. const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType);
  562. if (BT == 0) return false;
  563. switch (BT->getKind()) {
  564. default: return false;
  565. case BuiltinType::Char_U:
  566. case BuiltinType::UChar:
  567. case BuiltinType::WChar_U:
  568. case BuiltinType::Char16:
  569. case BuiltinType::Char32:
  570. case BuiltinType::Char_S:
  571. case BuiltinType::SChar:
  572. case BuiltinType::WChar_S:
  573. return true;
  574. }
  575. }
  576. /// isSignedIntegerType - Return true if this is an integer type that is
  577. /// signed, according to C99 6.2.5p4 [char, signed char, short, int, long..],
  578. /// an enum decl which has a signed representation
  579. bool Type::isSignedIntegerType() const {
  580. if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
  581. return BT->getKind() >= BuiltinType::Char_S &&
  582. BT->getKind() <= BuiltinType::Int128;
  583. }
  584. if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
  585. // Incomplete enum types are not treated as integer types.
  586. // FIXME: In C++, enum types are never integer types.
  587. if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
  588. return ET->getDecl()->getIntegerType()->isSignedIntegerType();
  589. }
  590. return false;
  591. }
  592. bool Type::isSignedIntegerOrEnumerationType() const {
  593. if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
  594. return BT->getKind() >= BuiltinType::Char_S &&
  595. BT->getKind() <= BuiltinType::Int128;
  596. }
  597. if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
  598. if (ET->getDecl()->isComplete())
  599. return ET->getDecl()->getIntegerType()->isSignedIntegerType();
  600. }
  601. return false;
  602. }
  603. bool Type::hasSignedIntegerRepresentation() const {
  604. if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
  605. return VT->getElementType()->isSignedIntegerType();
  606. else
  607. return isSignedIntegerType();
  608. }
  609. /// isUnsignedIntegerType - Return true if this is an integer type that is
  610. /// unsigned, according to C99 6.2.5p6 [which returns true for _Bool], an enum
  611. /// decl which has an unsigned representation
  612. bool Type::isUnsignedIntegerType() const {
  613. if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
  614. return BT->getKind() >= BuiltinType::Bool &&
  615. BT->getKind() <= BuiltinType::UInt128;
  616. }
  617. if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
  618. // Incomplete enum types are not treated as integer types.
  619. // FIXME: In C++, enum types are never integer types.
  620. if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped())
  621. return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
  622. }
  623. return false;
  624. }
  625. bool Type::isUnsignedIntegerOrEnumerationType() const {
  626. if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType)) {
  627. return BT->getKind() >= BuiltinType::Bool &&
  628. BT->getKind() <= BuiltinType::UInt128;
  629. }
  630. if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType)) {
  631. if (ET->getDecl()->isComplete())
  632. return ET->getDecl()->getIntegerType()->isUnsignedIntegerType();
  633. }
  634. return false;
  635. }
  636. bool Type::hasUnsignedIntegerRepresentation() const {
  637. if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
  638. return VT->getElementType()->isUnsignedIntegerType();
  639. else
  640. return isUnsignedIntegerType();
  641. }
  642. bool Type::isFloatingType() const {
  643. if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
  644. return BT->getKind() >= BuiltinType::Half &&
  645. BT->getKind() <= BuiltinType::LongDouble;
  646. if (const ComplexType *CT = dyn_cast<ComplexType>(CanonicalType))
  647. return CT->getElementType()->isFloatingType();
  648. return false;
  649. }
  650. bool Type::hasFloatingRepresentation() const {
  651. if (const VectorType *VT = dyn_cast<VectorType>(CanonicalType))
  652. return VT->getElementType()->isFloatingType();
  653. else
  654. return isFloatingType();
  655. }
  656. bool Type::isRealFloatingType() const {
  657. if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
  658. return BT->isFloatingPoint();
  659. return false;
  660. }
  661. bool Type::isRealType() const {
  662. if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
  663. return BT->getKind() >= BuiltinType::Bool &&
  664. BT->getKind() <= BuiltinType::LongDouble;
  665. if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
  666. return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped();
  667. return false;
  668. }
  669. bool Type::isArithmeticType() const {
  670. if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
  671. return BT->getKind() >= BuiltinType::Bool &&
  672. BT->getKind() <= BuiltinType::LongDouble;
  673. if (const EnumType *ET = dyn_cast<EnumType>(CanonicalType))
  674. // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
  675. // If a body isn't seen by the time we get here, return false.
  676. //
  677. // C++0x: Enumerations are not arithmetic types. For now, just return
  678. // false for scoped enumerations since that will disable any
  679. // unwanted implicit conversions.
  680. return !ET->getDecl()->isScoped() && ET->getDecl()->isComplete();
  681. return isa<ComplexType>(CanonicalType);
  682. }
  683. Type::ScalarTypeKind Type::getScalarTypeKind() const {
  684. assert(isScalarType());
  685. const Type *T = CanonicalType.getTypePtr();
  686. if (const BuiltinType *BT = dyn_cast<BuiltinType>(T)) {
  687. if (BT->getKind() == BuiltinType::Bool) return STK_Bool;
  688. if (BT->getKind() == BuiltinType::NullPtr) return STK_CPointer;
  689. if (BT->isInteger()) return STK_Integral;
  690. if (BT->isFloatingPoint()) return STK_Floating;
  691. llvm_unreachable("unknown scalar builtin type");
  692. } else if (isa<PointerType>(T)) {
  693. return STK_CPointer;
  694. } else if (isa<BlockPointerType>(T)) {
  695. return STK_BlockPointer;
  696. } else if (isa<ObjCObjectPointerType>(T)) {
  697. return STK_ObjCObjectPointer;
  698. } else if (isa<MemberPointerType>(T)) {
  699. return STK_MemberPointer;
  700. } else if (isa<EnumType>(T)) {
  701. assert(cast<EnumType>(T)->getDecl()->isComplete());
  702. return STK_Integral;
  703. } else if (const ComplexType *CT = dyn_cast<ComplexType>(T)) {
  704. if (CT->getElementType()->isRealFloatingType())
  705. return STK_FloatingComplex;
  706. return STK_IntegralComplex;
  707. }
  708. llvm_unreachable("unknown scalar type");
  709. }
  710. /// \brief Determines whether the type is a C++ aggregate type or C
  711. /// aggregate or union type.
  712. ///
  713. /// An aggregate type is an array or a class type (struct, union, or
  714. /// class) that has no user-declared constructors, no private or
  715. /// protected non-static data members, no base classes, and no virtual
  716. /// functions (C++ [dcl.init.aggr]p1). The notion of an aggregate type
  717. /// subsumes the notion of C aggregates (C99 6.2.5p21) because it also
  718. /// includes union types.
  719. bool Type::isAggregateType() const {
  720. if (const RecordType *Record = dyn_cast<RecordType>(CanonicalType)) {
  721. if (CXXRecordDecl *ClassDecl = dyn_cast<CXXRecordDecl>(Record->getDecl()))
  722. return ClassDecl->isAggregate();
  723. return true;
  724. }
  725. return isa<ArrayType>(CanonicalType);
  726. }
  727. /// isConstantSizeType - Return true if this is not a variable sized type,
  728. /// according to the rules of C99 6.7.5p3. It is not legal to call this on
  729. /// incomplete types or dependent types.
  730. bool Type::isConstantSizeType() const {
  731. assert(!isIncompleteType() && "This doesn't make sense for incomplete types");
  732. assert(!isDependentType() && "This doesn't make sense for dependent types");
  733. // The VAT must have a size, as it is known to be complete.
  734. return !isa<VariableArrayType>(CanonicalType);
  735. }
  736. /// isIncompleteType - Return true if this is an incomplete type (C99 6.2.5p1)
  737. /// - a type that can describe objects, but which lacks information needed to
  738. /// determine its size.
  739. bool Type::isIncompleteType(NamedDecl **Def) const {
  740. if (Def)
  741. *Def = 0;
  742. switch (CanonicalType->getTypeClass()) {
  743. default: return false;
  744. case Builtin:
  745. // Void is the only incomplete builtin type. Per C99 6.2.5p19, it can never
  746. // be completed.
  747. return isVoidType();
  748. case Enum: {
  749. EnumDecl *EnumD = cast<EnumType>(CanonicalType)->getDecl();
  750. if (Def)
  751. *Def = EnumD;
  752. // An enumeration with fixed underlying type is complete (C++0x 7.2p3).
  753. if (EnumD->isFixed())
  754. return false;
  755. return !EnumD->isCompleteDefinition();
  756. }
  757. case Record: {
  758. // A tagged type (struct/union/enum/class) is incomplete if the decl is a
  759. // forward declaration, but not a full definition (C99 6.2.5p22).
  760. RecordDecl *Rec = cast<RecordType>(CanonicalType)->getDecl();
  761. if (Def)
  762. *Def = Rec;
  763. return !Rec->isCompleteDefinition();
  764. }
  765. case ConstantArray:
  766. // An array is incomplete if its element type is incomplete
  767. // (C++ [dcl.array]p1).
  768. // We don't handle variable arrays (they're not allowed in C++) or
  769. // dependent-sized arrays (dependent types are never treated as incomplete).
  770. return cast<ArrayType>(CanonicalType)->getElementType()
  771. ->isIncompleteType(Def);
  772. case IncompleteArray:
  773. // An array of unknown size is an incomplete type (C99 6.2.5p22).
  774. return true;
  775. case ObjCObject:
  776. return cast<ObjCObjectType>(CanonicalType)->getBaseType()
  777. ->isIncompleteType(Def);
  778. case ObjCInterface: {
  779. // ObjC interfaces are incomplete if they are @class, not @interface.
  780. ObjCInterfaceDecl *Interface
  781. = cast<ObjCInterfaceType>(CanonicalType)->getDecl();
  782. if (Def)
  783. *Def = Interface;
  784. return !Interface->hasDefinition();
  785. }
  786. }
  787. }
  788. bool QualType::isPODType(ASTContext &Context) const {
  789. // The compiler shouldn't query this for incomplete types, but the user might.
  790. // We return false for that case. Except for incomplete arrays of PODs, which
  791. // are PODs according to the standard.
  792. if (isNull())
  793. return 0;
  794. if ((*this)->isIncompleteArrayType())
  795. return Context.getBaseElementType(*this).isPODType(Context);
  796. if ((*this)->isIncompleteType())
  797. return false;
  798. if (Context.getLangOpts().ObjCAutoRefCount) {
  799. switch (getObjCLifetime()) {
  800. case Qualifiers::OCL_ExplicitNone:
  801. return true;
  802. case Qualifiers::OCL_Strong:
  803. case Qualifiers::OCL_Weak:
  804. case Qualifiers::OCL_Autoreleasing:
  805. return false;
  806. case Qualifiers::OCL_None:
  807. break;
  808. }
  809. }
  810. QualType CanonicalType = getTypePtr()->CanonicalType;
  811. switch (CanonicalType->getTypeClass()) {
  812. // Everything not explicitly mentioned is not POD.
  813. default: return false;
  814. case Type::VariableArray:
  815. case Type::ConstantArray:
  816. // IncompleteArray is handled above.
  817. return Context.getBaseElementType(*this).isPODType(Context);
  818. case Type::ObjCObjectPointer:
  819. case Type::BlockPointer:
  820. case Type::Builtin:
  821. case Type::Complex:
  822. case Type::Pointer:
  823. case Type::MemberPointer:
  824. case Type::Vector:
  825. case Type::ExtVector:
  826. return true;
  827. case Type::Enum:
  828. return true;
  829. case Type::Record:
  830. if (CXXRecordDecl *ClassDecl
  831. = dyn_cast<CXXRecordDecl>(cast<RecordType>(CanonicalType)->getDecl()))
  832. return ClassDecl->isPOD();
  833. // C struct/union is POD.
  834. return true;
  835. }
  836. }
  837. bool QualType::isTrivialType(ASTContext &Context) const {
  838. // The compiler shouldn't query this for incomplete types, but the user might.
  839. // We return false for that case. Except for incomplete arrays of PODs, which
  840. // are PODs according to the standard.
  841. if (isNull())
  842. return 0;
  843. if ((*this)->isArrayType())
  844. return Context.getBaseElementType(*this).isTrivialType(Context);
  845. // Return false for incomplete types after skipping any incomplete array
  846. // types which are expressly allowed by the standard and thus our API.
  847. if ((*this)->isIncompleteType())
  848. return false;
  849. if (Context.getLangOpts().ObjCAutoRefCount) {
  850. switch (getObjCLifetime()) {
  851. case Qualifiers::OCL_ExplicitNone:
  852. return true;
  853. case Qualifiers::OCL_Strong:
  854. case Qualifiers::OCL_Weak:
  855. case Qualifiers::OCL_Autoreleasing:
  856. return false;
  857. case Qualifiers::OCL_None:
  858. if ((*this)->isObjCLifetimeType())
  859. return false;
  860. break;
  861. }
  862. }
  863. QualType CanonicalType = getTypePtr()->CanonicalType;
  864. if (CanonicalType->isDependentType())
  865. return false;
  866. // C++0x [basic.types]p9:
  867. // Scalar types, trivial class types, arrays of such types, and
  868. // cv-qualified versions of these types are collectively called trivial
  869. // types.
  870. // As an extension, Clang treats vector types as Scalar types.
  871. if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
  872. return true;
  873. if (const RecordType *RT = CanonicalType->getAs<RecordType>()) {
  874. if (const CXXRecordDecl *ClassDecl =
  875. dyn_cast<CXXRecordDecl>(RT->getDecl())) {
  876. // C++0x [class]p5:
  877. // A trivial class is a class that has a trivial default constructor
  878. if (!ClassDecl->hasTrivialDefaultConstructor()) return false;
  879. // and is trivially copyable.
  880. if (!ClassDecl->isTriviallyCopyable()) return false;
  881. }
  882. return true;
  883. }
  884. // No other types can match.
  885. return false;
  886. }
  887. bool QualType::isTriviallyCopyableType(ASTContext &Context) const {
  888. if ((*this)->isArrayType())
  889. return Context.getBaseElementType(*this).isTrivialType(Context);
  890. if (Context.getLangOpts().ObjCAutoRefCount) {
  891. switch (getObjCLifetime()) {
  892. case Qualifiers::OCL_ExplicitNone:
  893. return true;
  894. case Qualifiers::OCL_Strong:
  895. case Qualifiers::OCL_Weak:
  896. case Qualifiers::OCL_Autoreleasing:
  897. return false;
  898. case Qualifiers::OCL_None:
  899. if ((*this)->isObjCLifetimeType())
  900. return false;
  901. break;
  902. }
  903. }
  904. // C++0x [basic.types]p9
  905. // Scalar types, trivially copyable class types, arrays of such types, and
  906. // cv-qualified versions of these types are collectively called trivial
  907. // types.
  908. QualType CanonicalType = getCanonicalType();
  909. if (CanonicalType->isDependentType())
  910. return false;
  911. // Return false for incomplete types after skipping any incomplete array types
  912. // which are expressly allowed by the standard and thus our API.
  913. if (CanonicalType->isIncompleteType())
  914. return false;
  915. // As an extension, Clang treats vector types as Scalar types.
  916. if (CanonicalType->isScalarType() || CanonicalType->isVectorType())
  917. return true;
  918. if (const RecordType *RT = CanonicalType->getAs<RecordType>()) {
  919. if (const CXXRecordDecl *ClassDecl =
  920. dyn_cast<CXXRecordDecl>(RT->getDecl())) {
  921. if (!ClassDecl->isTriviallyCopyable()) return false;
  922. }
  923. return true;
  924. }
  925. // No other types can match.
  926. return false;
  927. }
  928. bool Type::isLiteralType() const {
  929. if (isDependentType())
  930. return false;
  931. // C++0x [basic.types]p10:
  932. // A type is a literal type if it is:
  933. // [...]
  934. // -- an array of literal type.
  935. // Extension: variable arrays cannot be literal types, since they're
  936. // runtime-sized.
  937. if (isVariableArrayType())
  938. return false;
  939. const Type *BaseTy = getBaseElementTypeUnsafe();
  940. assert(BaseTy && "NULL element type");
  941. // Return false for incomplete types after skipping any incomplete array
  942. // types; those are expressly allowed by the standard and thus our API.
  943. if (BaseTy->isIncompleteType())
  944. return false;
  945. // C++0x [basic.types]p10:
  946. // A type is a literal type if it is:
  947. // -- a scalar type; or
  948. // As an extension, Clang treats vector types and complex types as
  949. // literal types.
  950. if (BaseTy->isScalarType() || BaseTy->isVectorType() ||
  951. BaseTy->isAnyComplexType())
  952. return true;
  953. // -- a reference type; or
  954. if (BaseTy->isReferenceType())
  955. return true;
  956. // -- a class type that has all of the following properties:
  957. if (const RecordType *RT = BaseTy->getAs<RecordType>()) {
  958. // -- a trivial destructor,
  959. // -- every constructor call and full-expression in the
  960. // brace-or-equal-initializers for non-static data members (if any)
  961. // is a constant expression,
  962. // -- it is an aggregate type or has at least one constexpr
  963. // constructor or constructor template that is not a copy or move
  964. // constructor, and
  965. // -- all non-static data members and base classes of literal types
  966. //
  967. // We resolve DR1361 by ignoring the second bullet.
  968. if (const CXXRecordDecl *ClassDecl =
  969. dyn_cast<CXXRecordDecl>(RT->getDecl()))
  970. return ClassDecl->isLiteral();
  971. return true;
  972. }
  973. return false;
  974. }
  975. bool Type::isStandardLayoutType() const {
  976. if (isDependentType())
  977. return false;
  978. // C++0x [basic.types]p9:
  979. // Scalar types, standard-layout class types, arrays of such types, and
  980. // cv-qualified versions of these types are collectively called
  981. // standard-layout types.
  982. const Type *BaseTy = getBaseElementTypeUnsafe();
  983. assert(BaseTy && "NULL element type");
  984. // Return false for incomplete types after skipping any incomplete array
  985. // types which are expressly allowed by the standard and thus our API.
  986. if (BaseTy->isIncompleteType())
  987. return false;
  988. // As an extension, Clang treats vector types as Scalar types.
  989. if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true;
  990. if (const RecordType *RT = BaseTy->getAs<RecordType>()) {
  991. if (const CXXRecordDecl *ClassDecl =
  992. dyn_cast<CXXRecordDecl>(RT->getDecl()))
  993. if (!ClassDecl->isStandardLayout())
  994. return false;
  995. // Default to 'true' for non-C++ class types.
  996. // FIXME: This is a bit dubious, but plain C structs should trivially meet
  997. // all the requirements of standard layout classes.
  998. return true;
  999. }
  1000. // No other types can match.
  1001. return false;
  1002. }
  1003. // This is effectively the intersection of isTrivialType and
  1004. // isStandardLayoutType. We implement it directly to avoid redundant
  1005. // conversions from a type to a CXXRecordDecl.
  1006. bool QualType::isCXX11PODType(ASTContext &Context) const {
  1007. const Type *ty = getTypePtr();
  1008. if (ty->isDependentType())
  1009. return false;
  1010. if (Context.getLangOpts().ObjCAutoRefCount) {
  1011. switch (getObjCLifetime()) {
  1012. case Qualifiers::OCL_ExplicitNone:
  1013. return true;
  1014. case Qualifiers::OCL_Strong:
  1015. case Qualifiers::OCL_Weak:
  1016. case Qualifiers::OCL_Autoreleasing:
  1017. return false;
  1018. case Qualifiers::OCL_None:
  1019. if (ty->isObjCLifetimeType())
  1020. return false;
  1021. break;
  1022. }
  1023. }
  1024. // C++11 [basic.types]p9:
  1025. // Scalar types, POD classes, arrays of such types, and cv-qualified
  1026. // versions of these types are collectively called trivial types.
  1027. const Type *BaseTy = ty->getBaseElementTypeUnsafe();
  1028. assert(BaseTy && "NULL element type");
  1029. // Return false for incomplete types after skipping any incomplete array
  1030. // types which are expressly allowed by the standard and thus our API.
  1031. if (BaseTy->isIncompleteType())
  1032. return false;
  1033. // As an extension, Clang treats vector types as Scalar types.
  1034. if (BaseTy->isScalarType() || BaseTy->isVectorType()) return true;
  1035. if (const RecordType *RT = BaseTy->getAs<RecordType>()) {
  1036. if (const CXXRecordDecl *ClassDecl =
  1037. dyn_cast<CXXRecordDecl>(RT->getDecl())) {
  1038. // C++11 [class]p10:
  1039. // A POD struct is a non-union class that is both a trivial class [...]
  1040. if (!ClassDecl->isTrivial()) return false;
  1041. // C++11 [class]p10:
  1042. // A POD struct is a non-union class that is both a trivial class and
  1043. // a standard-layout class [...]
  1044. if (!ClassDecl->isStandardLayout()) return false;
  1045. // C++11 [class]p10:
  1046. // A POD struct is a non-union class that is both a trivial class and
  1047. // a standard-layout class, and has no non-static data members of type
  1048. // non-POD struct, non-POD union (or array of such types). [...]
  1049. //
  1050. // We don't directly query the recursive aspect as the requiremets for
  1051. // both standard-layout classes and trivial classes apply recursively
  1052. // already.
  1053. }
  1054. return true;
  1055. }
  1056. // No other types can match.
  1057. return false;
  1058. }
  1059. bool Type::isPromotableIntegerType() const {
  1060. if (const BuiltinType *BT = getAs<BuiltinType>())
  1061. switch (BT->getKind()) {
  1062. case BuiltinType::Bool:
  1063. case BuiltinType::Char_S:
  1064. case BuiltinType::Char_U:
  1065. case BuiltinType::SChar:
  1066. case BuiltinType::UChar:
  1067. case BuiltinType::Short:
  1068. case BuiltinType::UShort:
  1069. case BuiltinType::WChar_S:
  1070. case BuiltinType::WChar_U:
  1071. case BuiltinType::Char16:
  1072. case BuiltinType::Char32:
  1073. return true;
  1074. default:
  1075. return false;
  1076. }
  1077. // Enumerated types are promotable to their compatible integer types
  1078. // (C99 6.3.1.1) a.k.a. its underlying type (C++ [conv.prom]p2).
  1079. if (const EnumType *ET = getAs<EnumType>()){
  1080. if (this->isDependentType() || ET->getDecl()->getPromotionType().isNull()
  1081. || ET->getDecl()->isScoped())
  1082. return false;
  1083. return true;
  1084. }
  1085. return false;
  1086. }
  1087. bool Type::isSpecifierType() const {
  1088. // Note that this intentionally does not use the canonical type.
  1089. switch (getTypeClass()) {
  1090. case Builtin:
  1091. case Record:
  1092. case Enum:
  1093. case Typedef:
  1094. case Complex:
  1095. case TypeOfExpr:
  1096. case TypeOf:
  1097. case TemplateTypeParm:
  1098. case SubstTemplateTypeParm:
  1099. case TemplateSpecialization:
  1100. case Elaborated:
  1101. case DependentName:
  1102. case DependentTemplateSpecialization:
  1103. case ObjCInterface:
  1104. case ObjCObject:
  1105. case ObjCObjectPointer: // FIXME: object pointers aren't really specifiers
  1106. return true;
  1107. default:
  1108. return false;
  1109. }
  1110. }
  1111. ElaboratedTypeKeyword
  1112. TypeWithKeyword::getKeywordForTypeSpec(unsigned TypeSpec) {
  1113. switch (TypeSpec) {
  1114. default: return ETK_None;
  1115. case TST_typename: return ETK_Typename;
  1116. case TST_class: return ETK_Class;
  1117. case TST_struct: return ETK_Struct;
  1118. case TST_union: return ETK_Union;
  1119. case TST_enum: return ETK_Enum;
  1120. }
  1121. }
  1122. TagTypeKind
  1123. TypeWithKeyword::getTagTypeKindForTypeSpec(unsigned TypeSpec) {
  1124. switch(TypeSpec) {
  1125. case TST_class: return TTK_Class;
  1126. case TST_struct: return TTK_Struct;
  1127. case TST_union: return TTK_Union;
  1128. case TST_enum: return TTK_Enum;
  1129. }
  1130. llvm_unreachable("Type specifier is not a tag type kind.");
  1131. }
  1132. ElaboratedTypeKeyword
  1133. TypeWithKeyword::getKeywordForTagTypeKind(TagTypeKind Kind) {
  1134. switch (Kind) {
  1135. case TTK_Class: return ETK_Class;
  1136. case TTK_Struct: return ETK_Struct;
  1137. case TTK_Union: return ETK_Union;
  1138. case TTK_Enum: return ETK_Enum;
  1139. }
  1140. llvm_unreachable("Unknown tag type kind.");
  1141. }
  1142. TagTypeKind
  1143. TypeWithKeyword::getTagTypeKindForKeyword(ElaboratedTypeKeyword Keyword) {
  1144. switch (Keyword) {
  1145. case ETK_Class: return TTK_Class;
  1146. case ETK_Struct: return TTK_Struct;
  1147. case ETK_Union: return TTK_Union;
  1148. case ETK_Enum: return TTK_Enum;
  1149. case ETK_None: // Fall through.
  1150. case ETK_Typename:
  1151. llvm_unreachable("Elaborated type keyword is not a tag type kind.");
  1152. }
  1153. llvm_unreachable("Unknown elaborated type keyword.");
  1154. }
  1155. bool
  1156. TypeWithKeyword::KeywordIsTagTypeKind(ElaboratedTypeKeyword Keyword) {
  1157. switch (Keyword) {
  1158. case ETK_None:
  1159. case ETK_Typename:
  1160. return false;
  1161. case ETK_Class:
  1162. case ETK_Struct:
  1163. case ETK_Union:
  1164. case ETK_Enum:
  1165. return true;
  1166. }
  1167. llvm_unreachable("Unknown elaborated type keyword.");
  1168. }
  1169. const char*
  1170. TypeWithKeyword::getKeywordName(ElaboratedTypeKeyword Keyword) {
  1171. switch (Keyword) {
  1172. case ETK_None: return "";
  1173. case ETK_Typename: return "typename";
  1174. case ETK_Class: return "class";
  1175. case ETK_Struct: return "struct";
  1176. case ETK_Union: return "union";
  1177. case ETK_Enum: return "enum";
  1178. }
  1179. llvm_unreachable("Unknown elaborated type keyword.");
  1180. }
  1181. DependentTemplateSpecializationType::DependentTemplateSpecializationType(
  1182. ElaboratedTypeKeyword Keyword,
  1183. NestedNameSpecifier *NNS, const IdentifierInfo *Name,
  1184. unsigned NumArgs, const TemplateArgument *Args,
  1185. QualType Canon)
  1186. : TypeWithKeyword(Keyword, DependentTemplateSpecialization, Canon, true, true,
  1187. /*VariablyModified=*/false,
  1188. NNS && NNS->containsUnexpandedParameterPack()),
  1189. NNS(NNS), Name(Name), NumArgs(NumArgs) {
  1190. assert((!NNS || NNS->isDependent()) &&
  1191. "DependentTemplateSpecializatonType requires dependent qualifier");
  1192. for (unsigned I = 0; I != NumArgs; ++I) {
  1193. if (Args[I].containsUnexpandedParameterPack())
  1194. setContainsUnexpandedParameterPack();
  1195. new (&getArgBuffer()[I]) TemplateArgument(Args[I]);
  1196. }
  1197. }
  1198. void
  1199. DependentTemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
  1200. const ASTContext &Context,
  1201. ElaboratedTypeKeyword Keyword,
  1202. NestedNameSpecifier *Qualifier,
  1203. const IdentifierInfo *Name,
  1204. unsigned NumArgs,
  1205. const TemplateArgument *Args) {
  1206. ID.AddInteger(Keyword);
  1207. ID.AddPointer(Qualifier);
  1208. ID.AddPointer(Name);
  1209. for (unsigned Idx = 0; Idx < NumArgs; ++Idx)
  1210. Args[Idx].Profile(ID, Context);
  1211. }
  1212. bool Type::isElaboratedTypeSpecifier() const {
  1213. ElaboratedTypeKeyword Keyword;
  1214. if (const ElaboratedType *Elab = dyn_cast<ElaboratedType>(this))
  1215. Keyword = Elab->getKeyword();
  1216. else if (const DependentNameType *DepName = dyn_cast<DependentNameType>(this))
  1217. Keyword = DepName->getKeyword();
  1218. else if (const DependentTemplateSpecializationType *DepTST =
  1219. dyn_cast<DependentTemplateSpecializationType>(this))
  1220. Keyword = DepTST->getKeyword();
  1221. else
  1222. return false;
  1223. return TypeWithKeyword::KeywordIsTagTypeKind(Keyword);
  1224. }
  1225. const char *Type::getTypeClassName() const {
  1226. switch (TypeBits.TC) {
  1227. #define ABSTRACT_TYPE(Derived, Base)
  1228. #define TYPE(Derived, Base) case Derived: return #Derived;
  1229. #include "clang/AST/TypeNodes.def"
  1230. }
  1231. llvm_unreachable("Invalid type class.");
  1232. }
  1233. const char *BuiltinType::getName(const PrintingPolicy &Policy) const {
  1234. switch (getKind()) {
  1235. case Void: return "void";
  1236. case Bool: return Policy.Bool ? "bool" : "_Bool";
  1237. case Char_S: return "char";
  1238. case Char_U: return "char";
  1239. case SChar: return "signed char";
  1240. case Short: return "short";
  1241. case Int: return "int";
  1242. case Long: return "long";
  1243. case LongLong: return "long long";
  1244. case Int128: return "__int128_t";
  1245. case UChar: return "unsigned char";
  1246. case UShort: return "unsigned short";
  1247. case UInt: return "unsigned int";
  1248. case ULong: return "unsigned long";
  1249. case ULongLong: return "unsigned long long";
  1250. case UInt128: return "__uint128_t";
  1251. case Half: return "half";
  1252. case Float: return "float";
  1253. case Double: return "double";
  1254. case LongDouble: return "long double";
  1255. case WChar_S:
  1256. case WChar_U: return "wchar_t";
  1257. case Char16: return "char16_t";
  1258. case Char32: return "char32_t";
  1259. case NullPtr: return "nullptr_t";
  1260. case Overload: return "<overloaded function type>";
  1261. case BoundMember: return "<bound member function type>";
  1262. case PseudoObject: return "<pseudo-object type>";
  1263. case Dependent: return "<dependent type>";
  1264. case UnknownAny: return "<unknown type>";
  1265. case ARCUnbridgedCast: return "<ARC unbridged cast type>";
  1266. case ObjCId: return "id";
  1267. case ObjCClass: return "Class";
  1268. case ObjCSel: return "SEL";
  1269. }
  1270. llvm_unreachable("Invalid builtin type.");
  1271. }
  1272. QualType QualType::getNonLValueExprType(ASTContext &Context) const {
  1273. if (const ReferenceType *RefType = getTypePtr()->getAs<ReferenceType>())
  1274. return RefType->getPointeeType();
  1275. // C++0x [basic.lval]:
  1276. // Class prvalues can have cv-qualified types; non-class prvalues always
  1277. // have cv-unqualified types.
  1278. //
  1279. // See also C99 6.3.2.1p2.
  1280. if (!Context.getLangOpts().CPlusPlus ||
  1281. (!getTypePtr()->isDependentType() && !getTypePtr()->isRecordType()))
  1282. return getUnqualifiedType();
  1283. return *this;
  1284. }
  1285. StringRef FunctionType::getNameForCallConv(CallingConv CC) {
  1286. switch (CC) {
  1287. case CC_Default:
  1288. llvm_unreachable("no name for default cc");
  1289. case CC_C: return "cdecl";
  1290. case CC_X86StdCall: return "stdcall";
  1291. case CC_X86FastCall: return "fastcall";
  1292. case CC_X86ThisCall: return "thiscall";
  1293. case CC_X86Pascal: return "pascal";
  1294. case CC_AAPCS: return "aapcs";
  1295. case CC_AAPCS_VFP: return "aapcs-vfp";
  1296. }
  1297. llvm_unreachable("Invalid calling convention.");
  1298. }
  1299. FunctionProtoType::FunctionProtoType(QualType result, const QualType *args,
  1300. unsigned numArgs, QualType canonical,
  1301. const ExtProtoInfo &epi)
  1302. : FunctionType(FunctionProto, result, epi.TypeQuals, epi.RefQualifier,
  1303. canonical,
  1304. result->isDependentType(),
  1305. result->isInstantiationDependentType(),
  1306. result->isVariablyModifiedType(),
  1307. result->containsUnexpandedParameterPack(),
  1308. epi.ExtInfo),
  1309. NumArgs(numArgs), NumExceptions(epi.NumExceptions),
  1310. ExceptionSpecType(epi.ExceptionSpecType),
  1311. HasAnyConsumedArgs(epi.ConsumedArguments != 0),
  1312. Variadic(epi.Variadic), HasTrailingReturn(epi.HasTrailingReturn)
  1313. {
  1314. // Fill in the trailing argument array.
  1315. QualType *argSlot = reinterpret_cast<QualType*>(this+1);
  1316. for (unsigned i = 0; i != numArgs; ++i) {
  1317. if (args[i]->isDependentType())
  1318. setDependent();
  1319. else if (args[i]->isInstantiationDependentType())
  1320. setInstantiationDependent();
  1321. if (args[i]->containsUnexpandedParameterPack())
  1322. setContainsUnexpandedParameterPack();
  1323. argSlot[i] = args[i];
  1324. }
  1325. if (getExceptionSpecType() == EST_Dynamic) {
  1326. // Fill in the exception array.
  1327. QualType *exnSlot = argSlot + numArgs;
  1328. for (unsigned i = 0, e = epi.NumExceptions; i != e; ++i) {
  1329. if (epi.Exceptions[i]->isDependentType())
  1330. setDependent();
  1331. else if (epi.Exceptions[i]->isInstantiationDependentType())
  1332. setInstantiationDependent();
  1333. if (epi.Exceptions[i]->containsUnexpandedParameterPack())
  1334. setContainsUnexpandedParameterPack();
  1335. exnSlot[i] = epi.Exceptions[i];
  1336. }
  1337. } else if (getExceptionSpecType() == EST_ComputedNoexcept) {
  1338. // Store the noexcept expression and context.
  1339. Expr **noexSlot = reinterpret_cast<Expr**>(argSlot + numArgs);
  1340. *noexSlot = epi.NoexceptExpr;
  1341. if (epi.NoexceptExpr) {
  1342. if (epi.NoexceptExpr->isValueDependent()
  1343. || epi.NoexceptExpr->isTypeDependent())
  1344. setDependent();
  1345. else if (epi.NoexceptExpr->isInstantiationDependent())
  1346. setInstantiationDependent();
  1347. }
  1348. }
  1349. if (epi.ConsumedArguments) {
  1350. bool *consumedArgs = const_cast<bool*>(getConsumedArgsBuffer());
  1351. for (unsigned i = 0; i != numArgs; ++i)
  1352. consumedArgs[i] = epi.ConsumedArguments[i];
  1353. }
  1354. }
  1355. FunctionProtoType::NoexceptResult
  1356. FunctionProtoType::getNoexceptSpec(ASTContext &ctx) const {
  1357. ExceptionSpecificationType est = getExceptionSpecType();
  1358. if (est == EST_BasicNoexcept)
  1359. return NR_Nothrow;
  1360. if (est != EST_ComputedNoexcept)
  1361. return NR_NoNoexcept;
  1362. Expr *noexceptExpr = getNoexceptExpr();
  1363. if (!noexceptExpr)
  1364. return NR_BadNoexcept;
  1365. if (noexceptExpr->isValueDependent())
  1366. return NR_Dependent;
  1367. llvm::APSInt value;
  1368. bool isICE = noexceptExpr->isIntegerConstantExpr(value, ctx, 0,
  1369. /*evaluated*/false);
  1370. (void)isICE;
  1371. assert(isICE && "AST should not contain bad noexcept expressions.");
  1372. return value.getBoolValue() ? NR_Nothrow : NR_Throw;
  1373. }
  1374. bool FunctionProtoType::isTemplateVariadic() const {
  1375. for (unsigned ArgIdx = getNumArgs(); ArgIdx; --ArgIdx)
  1376. if (isa<PackExpansionType>(getArgType(ArgIdx - 1)))
  1377. return true;
  1378. return false;
  1379. }
  1380. void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID, QualType Result,
  1381. const QualType *ArgTys, unsigned NumArgs,
  1382. const ExtProtoInfo &epi,
  1383. const ASTContext &Context) {
  1384. // We have to be careful not to get ambiguous profile encodings.
  1385. // Note that valid type pointers are never ambiguous with anything else.
  1386. //
  1387. // The encoding grammar begins:
  1388. // type type* bool int bool
  1389. // If that final bool is true, then there is a section for the EH spec:
  1390. // bool type*
  1391. // This is followed by an optional "consumed argument" section of the
  1392. // same length as the first type sequence:
  1393. // bool*
  1394. // Finally, we have the ext info and trailing return type flag:
  1395. // int bool
  1396. //
  1397. // There is no ambiguity between the consumed arguments and an empty EH
  1398. // spec because of the leading 'bool' which unambiguously indicates
  1399. // whether the following bool is the EH spec or part of the arguments.
  1400. ID.AddPointer(Result.getAsOpaquePtr());
  1401. for (unsigned i = 0; i != NumArgs; ++i)
  1402. ID.AddPointer(ArgTys[i].getAsOpaquePtr());
  1403. // This method is relatively performance sensitive, so as a performance
  1404. // shortcut, use one AddInteger call instead of four for the next four
  1405. // fields.
  1406. assert(!(unsigned(epi.Variadic) & ~1) &&
  1407. !(unsigned(epi.TypeQuals) & ~255) &&
  1408. !(unsigned(epi.RefQualifier) & ~3) &&
  1409. !(unsigned(epi.ExceptionSpecType) & ~7) &&
  1410. "Values larger than expected.");
  1411. ID.AddInteger(unsigned(epi.Variadic) +
  1412. (epi.TypeQuals << 1) +
  1413. (epi.RefQualifier << 9) +
  1414. (epi.ExceptionSpecType << 11));
  1415. if (epi.ExceptionSpecType == EST_Dynamic) {
  1416. for (unsigned i = 0; i != epi.NumExceptions; ++i)
  1417. ID.AddPointer(epi.Exceptions[i].getAsOpaquePtr());
  1418. } else if (epi.ExceptionSpecType == EST_ComputedNoexcept && epi.NoexceptExpr){
  1419. epi.NoexceptExpr->Profile(ID, Context, false);
  1420. }
  1421. if (epi.ConsumedArguments) {
  1422. for (unsigned i = 0; i != NumArgs; ++i)
  1423. ID.AddBoolean(epi.ConsumedArguments[i]);
  1424. }
  1425. epi.ExtInfo.Profile(ID);
  1426. ID.AddBoolean(epi.HasTrailingReturn);
  1427. }
  1428. void FunctionProtoType::Profile(llvm::FoldingSetNodeID &ID,
  1429. const ASTContext &Ctx) {
  1430. Profile(ID, getResultType(), arg_type_begin(), NumArgs, getExtProtoInfo(),
  1431. Ctx);
  1432. }
  1433. QualType TypedefType::desugar() const {
  1434. return getDecl()->getUnderlyingType();
  1435. }
  1436. TypeOfExprType::TypeOfExprType(Expr *E, QualType can)
  1437. : Type(TypeOfExpr, can, E->isTypeDependent(),
  1438. E->isInstantiationDependent(),
  1439. E->getType()->isVariablyModifiedType(),
  1440. E->containsUnexpandedParameterPack()),
  1441. TOExpr(E) {
  1442. }
  1443. bool TypeOfExprType::isSugared() const {
  1444. return !TOExpr->isTypeDependent();
  1445. }
  1446. QualType TypeOfExprType::desugar() const {
  1447. if (isSugared())
  1448. return getUnderlyingExpr()->getType();
  1449. return QualType(this, 0);
  1450. }
  1451. void DependentTypeOfExprType::Profile(llvm::FoldingSetNodeID &ID,
  1452. const ASTContext &Context, Expr *E) {
  1453. E->Profile(ID, Context, true);
  1454. }
  1455. DecltypeType::DecltypeType(Expr *E, QualType underlyingType, QualType can)
  1456. // C++11 [temp.type]p2: "If an expression e involves a template parameter,
  1457. // decltype(e) denotes a unique dependent type." Hence a decltype type is
  1458. // type-dependent even if its expression is only instantiation-dependent.
  1459. : Type(Decltype, can, E->isInstantiationDependent(),
  1460. E->isInstantiationDependent(),
  1461. E->getType()->isVariablyModifiedType(),
  1462. E->containsUnexpandedParameterPack()),
  1463. E(E),
  1464. UnderlyingType(underlyingType) {
  1465. }
  1466. bool DecltypeType::isSugared() const { return !E->isInstantiationDependent(); }
  1467. QualType DecltypeType::desugar() const {
  1468. if (isSugared())
  1469. return getUnderlyingType();
  1470. return QualType(this, 0);
  1471. }
  1472. DependentDecltypeType::DependentDecltypeType(const ASTContext &Context, Expr *E)
  1473. : DecltypeType(E, Context.DependentTy), Context(Context) { }
  1474. void DependentDecltypeType::Profile(llvm::FoldingSetNodeID &ID,
  1475. const ASTContext &Context, Expr *E) {
  1476. E->Profile(ID, Context, true);
  1477. }
  1478. TagType::TagType(TypeClass TC, const TagDecl *D, QualType can)
  1479. : Type(TC, can, D->isDependentType(),
  1480. /*InstantiationDependent=*/D->isDependentType(),
  1481. /*VariablyModified=*/false,
  1482. /*ContainsUnexpandedParameterPack=*/false),
  1483. decl(const_cast<TagDecl*>(D)) {}
  1484. static TagDecl *getInterestingTagDecl(TagDecl *decl) {
  1485. for (TagDecl::redecl_iterator I = decl->redecls_begin(),
  1486. E = decl->redecls_end();
  1487. I != E; ++I) {
  1488. if (I->isCompleteDefinition() || I->isBeingDefined())
  1489. return *I;
  1490. }
  1491. // If there's no definition (not even in progress), return what we have.
  1492. return decl;
  1493. }
  1494. UnaryTransformType::UnaryTransformType(QualType BaseType,
  1495. QualType UnderlyingType,
  1496. UTTKind UKind,
  1497. QualType CanonicalType)
  1498. : Type(UnaryTransform, CanonicalType, UnderlyingType->isDependentType(),
  1499. UnderlyingType->isInstantiationDependentType(),
  1500. UnderlyingType->isVariablyModifiedType(),
  1501. BaseType->containsUnexpandedParameterPack())
  1502. , BaseType(BaseType), UnderlyingType(UnderlyingType), UKind(UKind)
  1503. {}
  1504. TagDecl *TagType::getDecl() const {
  1505. return getInterestingTagDecl(decl);
  1506. }
  1507. bool TagType::isBeingDefined() const {
  1508. return getDecl()->isBeingDefined();
  1509. }
  1510. CXXRecordDecl *InjectedClassNameType::getDecl() const {
  1511. return cast<CXXRecordDecl>(getInterestingTagDecl(Decl));
  1512. }
  1513. IdentifierInfo *TemplateTypeParmType::getIdentifier() const {
  1514. return isCanonicalUnqualified() ? 0 : getDecl()->getIdentifier();
  1515. }
  1516. SubstTemplateTypeParmPackType::
  1517. SubstTemplateTypeParmPackType(const TemplateTypeParmType *Param,
  1518. QualType Canon,
  1519. const TemplateArgument &ArgPack)
  1520. : Type(SubstTemplateTypeParmPack, Canon, true, true, false, true),
  1521. Replaced(Param),
  1522. Arguments(ArgPack.pack_begin()), NumArguments(ArgPack.pack_size())
  1523. {
  1524. }
  1525. TemplateArgument SubstTemplateTypeParmPackType::getArgumentPack() const {
  1526. return TemplateArgument(Arguments, NumArguments);
  1527. }
  1528. void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID) {
  1529. Profile(ID, getReplacedParameter(), getArgumentPack());
  1530. }
  1531. void SubstTemplateTypeParmPackType::Profile(llvm::FoldingSetNodeID &ID,
  1532. const TemplateTypeParmType *Replaced,
  1533. const TemplateArgument &ArgPack) {
  1534. ID.AddPointer(Replaced);
  1535. ID.AddInteger(ArgPack.pack_size());
  1536. for (TemplateArgument::pack_iterator P = ArgPack.pack_begin(),
  1537. PEnd = ArgPack.pack_end();
  1538. P != PEnd; ++P)
  1539. ID.AddPointer(P->getAsType().getAsOpaquePtr());
  1540. }
  1541. bool TemplateSpecializationType::
  1542. anyDependentTemplateArguments(const TemplateArgumentListInfo &Args,
  1543. bool &InstantiationDependent) {
  1544. return anyDependentTemplateArguments(Args.getArgumentArray(), Args.size(),
  1545. InstantiationDependent);
  1546. }
  1547. bool TemplateSpecializationType::
  1548. anyDependentTemplateArguments(const TemplateArgumentLoc *Args, unsigned N,
  1549. bool &InstantiationDependent) {
  1550. for (unsigned i = 0; i != N; ++i) {
  1551. if (Args[i].getArgument().isDependent()) {
  1552. InstantiationDependent = true;
  1553. return true;
  1554. }
  1555. if (Args[i].getArgument().isInstantiationDependent())
  1556. InstantiationDependent = true;
  1557. }
  1558. return false;
  1559. }
  1560. bool TemplateSpecializationType::
  1561. anyDependentTemplateArguments(const TemplateArgument *Args, unsigned N,
  1562. bool &InstantiationDependent) {
  1563. for (unsigned i = 0; i != N; ++i) {
  1564. if (Args[i].isDependent()) {
  1565. InstantiationDependent = true;
  1566. return true;
  1567. }
  1568. if (Args[i].isInstantiationDependent())
  1569. InstantiationDependent = true;
  1570. }
  1571. return false;
  1572. }
  1573. TemplateSpecializationType::
  1574. TemplateSpecializationType(TemplateName T,
  1575. const TemplateArgument *Args, unsigned NumArgs,
  1576. QualType Canon, QualType AliasedType)
  1577. : Type(TemplateSpecialization,
  1578. Canon.isNull()? QualType(this, 0) : Canon,
  1579. Canon.isNull()? T.isDependent() : Canon->isDependentType(),
  1580. Canon.isNull()? T.isDependent()
  1581. : Canon->isInstantiationDependentType(),
  1582. false,
  1583. Canon.isNull()? T.containsUnexpandedParameterPack()
  1584. : Canon->containsUnexpandedParameterPack()),
  1585. Template(T), NumArgs(NumArgs), TypeAlias(!AliasedType.isNull()) {
  1586. assert(!T.getAsDependentTemplateName() &&
  1587. "Use DependentTemplateSpecializationType for dependent template-name");
  1588. assert((T.getKind() == TemplateName::Template ||
  1589. T.getKind() == TemplateName::SubstTemplateTemplateParm ||
  1590. T.getKind() == TemplateName::SubstTemplateTemplateParmPack) &&
  1591. "Unexpected template name for TemplateSpecializationType");
  1592. bool InstantiationDependent;
  1593. (void)InstantiationDependent;
  1594. assert((!Canon.isNull() ||
  1595. T.isDependent() ||
  1596. anyDependentTemplateArguments(Args, NumArgs,
  1597. InstantiationDependent)) &&
  1598. "No canonical type for non-dependent class template specialization");
  1599. TemplateArgument *TemplateArgs
  1600. = reinterpret_cast<TemplateArgument *>(this + 1);
  1601. for (unsigned Arg = 0; Arg < NumArgs; ++Arg) {
  1602. // Update dependent and variably-modified bits.
  1603. // If the canonical type exists and is non-dependent, the template
  1604. // specialization type can be non-dependent even if one of the type
  1605. // arguments is. Given:
  1606. // template<typename T> using U = int;
  1607. // U<T> is always non-dependent, irrespective of the type T.
  1608. if (Canon.isNull() && Args[Arg].isDependent())
  1609. setDependent();
  1610. else if (Args[Arg].isInstantiationDependent())
  1611. setInstantiationDependent();
  1612. if (Args[Arg].getKind() == TemplateArgument::Type &&
  1613. Args[Arg].getAsType()->isVariablyModifiedType())
  1614. setVariablyModified();
  1615. if (Canon.isNull() && Args[Arg].containsUnexpandedParameterPack())
  1616. setContainsUnexpandedParameterPack();
  1617. new (&TemplateArgs[Arg]) TemplateArgument(Args[Arg]);
  1618. }
  1619. // Store the aliased type if this is a type alias template specialization.
  1620. if (TypeAlias) {
  1621. TemplateArgument *Begin = reinterpret_cast<TemplateArgument *>(this + 1);
  1622. *reinterpret_cast<QualType*>(Begin + getNumArgs()) = AliasedType;
  1623. }
  1624. }
  1625. void
  1626. TemplateSpecializationType::Profile(llvm::FoldingSetNodeID &ID,
  1627. TemplateName T,
  1628. const TemplateArgument *Args,
  1629. unsigned NumArgs,
  1630. const ASTContext &Context) {
  1631. T.Profile(ID);
  1632. for (unsigned Idx = 0; Idx < NumArgs; ++Idx)
  1633. Args[Idx].Profile(ID, Context);
  1634. }
  1635. QualType
  1636. QualifierCollector::apply(const ASTContext &Context, QualType QT) const {
  1637. if (!hasNonFastQualifiers())
  1638. return QT.withFastQualifiers(getFastQualifiers());
  1639. return Context.getQualifiedType(QT, *this);
  1640. }
  1641. QualType
  1642. QualifierCollector::apply(const ASTContext &Context, const Type *T) const {
  1643. if (!hasNonFastQualifiers())
  1644. return QualType(T, getFastQualifiers());
  1645. return Context.getQualifiedType(T, *this);
  1646. }
  1647. void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID,
  1648. QualType BaseType,
  1649. ObjCProtocolDecl * const *Protocols,
  1650. unsigned NumProtocols) {
  1651. ID.AddPointer(BaseType.getAsOpaquePtr());
  1652. for (unsigned i = 0; i != NumProtocols; i++)
  1653. ID.AddPointer(Protocols[i]);
  1654. }
  1655. void ObjCObjectTypeImpl::Profile(llvm::FoldingSetNodeID &ID) {
  1656. Profile(ID, getBaseType(), qual_begin(), getNumProtocols());
  1657. }
  1658. namespace {
  1659. /// \brief The cached properties of a type.
  1660. class CachedProperties {
  1661. NamedDecl::LinkageInfo LV;
  1662. bool local;
  1663. public:
  1664. CachedProperties(NamedDecl::LinkageInfo LV, bool local)
  1665. : LV(LV), local(local) {}
  1666. Linkage getLinkage() const { return LV.linkage(); }
  1667. Visibility getVisibility() const { return LV.visibility(); }
  1668. bool isVisibilityExplicit() const { return LV.visibilityExplicit(); }
  1669. bool hasLocalOrUnnamedType() const { return local; }
  1670. friend CachedProperties merge(CachedProperties L, CachedProperties R) {
  1671. NamedDecl::LinkageInfo MergedLV = L.LV;
  1672. MergedLV.merge(R.LV);
  1673. return CachedProperties(MergedLV,
  1674. L.hasLocalOrUnnamedType() | R.hasLocalOrUnnamedType());
  1675. }
  1676. };
  1677. }
  1678. static CachedProperties computeCachedProperties(const Type *T);
  1679. namespace clang {
  1680. /// The type-property cache. This is templated so as to be
  1681. /// instantiated at an internal type to prevent unnecessary symbol
  1682. /// leakage.
  1683. template <class Private> class TypePropertyCache {
  1684. public:
  1685. static CachedProperties get(QualType T) {
  1686. return get(T.getTypePtr());
  1687. }
  1688. static CachedProperties get(const Type *T) {
  1689. ensure(T);
  1690. NamedDecl::LinkageInfo LV(T->TypeBits.getLinkage(),
  1691. T->TypeBits.getVisibility(),
  1692. T->TypeBits.isVisibilityExplicit());
  1693. return CachedProperties(LV, T->TypeBits.hasLocalOrUnnamedType());
  1694. }
  1695. static void ensure(const Type *T) {
  1696. // If the cache is valid, we're okay.
  1697. if (T->TypeBits.isCacheValid()) return;
  1698. // If this type is non-canonical, ask its canonical type for the
  1699. // relevant information.
  1700. if (!T->isCanonicalUnqualified()) {
  1701. const Type *CT = T->getCanonicalTypeInternal().getTypePtr();
  1702. ensure(CT);
  1703. T->TypeBits.CacheValidAndVisibility =
  1704. CT->TypeBits.CacheValidAndVisibility;
  1705. T->TypeBits.CachedExplicitVisibility =
  1706. CT->TypeBits.CachedExplicitVisibility;
  1707. T->TypeBits.CachedLinkage = CT->TypeBits.CachedLinkage;
  1708. T->TypeBits.CachedLocalOrUnnamed = CT->TypeBits.CachedLocalOrUnnamed;
  1709. return;
  1710. }
  1711. // Compute the cached properties and then set the cache.
  1712. CachedProperties Result = computeCachedProperties(T);
  1713. T->TypeBits.CacheValidAndVisibility = Result.getVisibility() + 1U;
  1714. T->TypeBits.CachedExplicitVisibility = Result.isVisibilityExplicit();
  1715. assert(T->TypeBits.isCacheValid() &&
  1716. T->TypeBits.getVisibility() == Result.getVisibility());
  1717. T->TypeBits.CachedLinkage = Result.getLinkage();
  1718. T->TypeBits.CachedLocalOrUnnamed = Result.hasLocalOrUnnamedType();
  1719. }
  1720. };
  1721. }
  1722. // Instantiate the friend template at a private class. In a
  1723. // reasonable implementation, these symbols will be internal.
  1724. // It is terrible that this is the best way to accomplish this.
  1725. namespace { class Private {}; }
  1726. typedef TypePropertyCache<Private> Cache;
  1727. static CachedProperties computeCachedProperties(const Type *T) {
  1728. switch (T->getTypeClass()) {
  1729. #define TYPE(Class,Base)
  1730. #define NON_CANONICAL_TYPE(Class,Base) case Type::Class:
  1731. #include "clang/AST/TypeNodes.def"
  1732. llvm_unreachable("didn't expect a non-canonical type here");
  1733. #define TYPE(Class,Base)
  1734. #define DEPENDENT_TYPE(Class,Base) case Type::Class:
  1735. #define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class,Base) case Type::Class:
  1736. #include "clang/AST/TypeNodes.def"
  1737. // Treat instantiation-dependent types as external.
  1738. assert(T->isInstantiationDependentType());
  1739. return CachedProperties(NamedDecl::LinkageInfo(), false);
  1740. case Type::Builtin:
  1741. // C++ [basic.link]p8:
  1742. // A type is said to have linkage if and only if:
  1743. // - it is a fundamental type (3.9.1); or
  1744. return CachedProperties(NamedDecl::LinkageInfo(), false);
  1745. case Type::Record:
  1746. case Type::Enum: {
  1747. const TagDecl *Tag = cast<TagType>(T)->getDecl();
  1748. // C++ [basic.link]p8:
  1749. // - it is a class or enumeration type that is named (or has a name
  1750. // for linkage purposes (7.1.3)) and the name has linkage; or
  1751. // - it is a specialization of a class template (14); or
  1752. NamedDecl::LinkageInfo LV = Tag->getLinkageAndVisibility();
  1753. bool IsLocalOrUnnamed =
  1754. Tag->getDeclContext()->isFunctionOrMethod() ||
  1755. (!Tag->getIdentifier() && !Tag->getTypedefNameForAnonDecl());
  1756. return CachedProperties(LV, IsLocalOrUnnamed);
  1757. }
  1758. // C++ [basic.link]p8:
  1759. // - it is a compound type (3.9.2) other than a class or enumeration,
  1760. // compounded exclusively from types that have linkage; or
  1761. case Type::Complex:
  1762. return Cache::get(cast<ComplexType>(T)->getElementType());
  1763. case Type::Pointer:
  1764. return Cache::get(cast<PointerType>(T)->getPointeeType());
  1765. case Type::BlockPointer:
  1766. return Cache::get(cast<BlockPointerType>(T)->getPointeeType());
  1767. case Type::LValueReference:
  1768. case Type::RValueReference:
  1769. return Cache::get(cast<ReferenceType>(T)->getPointeeType());
  1770. case Type::MemberPointer: {
  1771. const MemberPointerType *MPT = cast<MemberPointerType>(T);
  1772. return merge(Cache::get(MPT->getClass()),
  1773. Cache::get(MPT->getPointeeType()));
  1774. }
  1775. case Type::ConstantArray:
  1776. case Type::IncompleteArray:
  1777. case Type::VariableArray:
  1778. return Cache::get(cast<ArrayType>(T)->getElementType());
  1779. case Type::Vector:
  1780. case Type::ExtVector:
  1781. return Cache::get(cast<VectorType>(T)->getElementType());
  1782. case Type::FunctionNoProto:
  1783. return Cache::get(cast<FunctionType>(T)->getResultType());
  1784. case Type::FunctionProto: {
  1785. const FunctionProtoType *FPT = cast<FunctionProtoType>(T);
  1786. CachedProperties result = Cache::get(FPT->getResultType());
  1787. for (FunctionProtoType::arg_type_iterator ai = FPT->arg_type_begin(),
  1788. ae = FPT->arg_type_end(); ai != ae; ++ai)
  1789. result = merge(result, Cache::get(*ai));
  1790. return result;
  1791. }
  1792. case Type::ObjCInterface: {
  1793. NamedDecl::LinkageInfo LV =
  1794. cast<ObjCInterfaceType>(T)->getDecl()->getLinkageAndVisibility();
  1795. return CachedProperties(LV, false);
  1796. }
  1797. case Type::ObjCObject:
  1798. return Cache::get(cast<ObjCObjectType>(T)->getBaseType());
  1799. case Type::ObjCObjectPointer:
  1800. return Cache::get(cast<ObjCObjectPointerType>(T)->getPointeeType());
  1801. case Type::Atomic:
  1802. return Cache::get(cast<AtomicType>(T)->getValueType());
  1803. }
  1804. llvm_unreachable("unhandled type class");
  1805. }
  1806. /// \brief Determine the linkage of this type.
  1807. Linkage Type::getLinkage() const {
  1808. Cache::ensure(this);
  1809. return TypeBits.getLinkage();
  1810. }
  1811. /// \brief Determine the linkage of this type.
  1812. Visibility Type::getVisibility() const {
  1813. Cache::ensure(this);
  1814. return TypeBits.getVisibility();
  1815. }
  1816. bool Type::isVisibilityExplicit() const {
  1817. Cache::ensure(this);
  1818. return TypeBits.isVisibilityExplicit();
  1819. }
  1820. bool Type::hasUnnamedOrLocalType() const {
  1821. Cache::ensure(this);
  1822. return TypeBits.hasLocalOrUnnamedType();
  1823. }
  1824. std::pair<Linkage,Visibility> Type::getLinkageAndVisibility() const {
  1825. Cache::ensure(this);
  1826. return std::make_pair(TypeBits.getLinkage(), TypeBits.getVisibility());
  1827. }
  1828. void Type::ClearLinkageCache() {
  1829. TypeBits.CacheValidAndVisibility = 0;
  1830. if (QualType(this, 0) != CanonicalType)
  1831. CanonicalType->TypeBits.CacheValidAndVisibility = 0;
  1832. }
  1833. Qualifiers::ObjCLifetime Type::getObjCARCImplicitLifetime() const {
  1834. if (isObjCARCImplicitlyUnretainedType())
  1835. return Qualifiers::OCL_ExplicitNone;
  1836. return Qualifiers::OCL_Strong;
  1837. }
  1838. bool Type::isObjCARCImplicitlyUnretainedType() const {
  1839. assert(isObjCLifetimeType() &&
  1840. "cannot query implicit lifetime for non-inferrable type");
  1841. const Type *canon = getCanonicalTypeInternal().getTypePtr();
  1842. // Walk down to the base type. We don't care about qualifiers for this.
  1843. while (const ArrayType *array = dyn_cast<ArrayType>(canon))
  1844. canon = array->getElementType().getTypePtr();
  1845. if (const ObjCObjectPointerType *opt
  1846. = dyn_cast<ObjCObjectPointerType>(canon)) {
  1847. // Class and Class<Protocol> don't require retension.
  1848. if (opt->getObjectType()->isObjCClass())
  1849. return true;
  1850. }
  1851. return false;
  1852. }
  1853. bool Type::isObjCNSObjectType() const {
  1854. if (const TypedefType *typedefType = dyn_cast<TypedefType>(this))
  1855. return typedefType->getDecl()->hasAttr<ObjCNSObjectAttr>();
  1856. return false;
  1857. }
  1858. bool Type::isObjCRetainableType() const {
  1859. return isObjCObjectPointerType() ||
  1860. isBlockPointerType() ||
  1861. isObjCNSObjectType();
  1862. }
  1863. bool Type::isObjCIndirectLifetimeType() const {
  1864. if (isObjCLifetimeType())
  1865. return true;
  1866. if (const PointerType *OPT = getAs<PointerType>())
  1867. return OPT->getPointeeType()->isObjCIndirectLifetimeType();
  1868. if (const ReferenceType *Ref = getAs<ReferenceType>())
  1869. return Ref->getPointeeType()->isObjCIndirectLifetimeType();
  1870. if (const MemberPointerType *MemPtr = getAs<MemberPointerType>())
  1871. return MemPtr->getPointeeType()->isObjCIndirectLifetimeType();
  1872. return false;
  1873. }
  1874. /// Returns true if objects of this type have lifetime semantics under
  1875. /// ARC.
  1876. bool Type::isObjCLifetimeType() const {
  1877. const Type *type = this;
  1878. while (const ArrayType *array = type->getAsArrayTypeUnsafe())
  1879. type = array->getElementType().getTypePtr();
  1880. return type->isObjCRetainableType();
  1881. }
  1882. /// \brief Determine whether the given type T is a "bridgable" Objective-C type,
  1883. /// which is either an Objective-C object pointer type or an
  1884. bool Type::isObjCARCBridgableType() const {
  1885. return isObjCObjectPointerType() || isBlockPointerType();
  1886. }
  1887. /// \brief Determine whether the given type T is a "bridgeable" C type.
  1888. bool Type::isCARCBridgableType() const {
  1889. const PointerType *Pointer = getAs<PointerType>();
  1890. if (!Pointer)
  1891. return false;
  1892. QualType Pointee = Pointer->getPointeeType();
  1893. return Pointee->isVoidType() || Pointee->isRecordType();
  1894. }
  1895. bool Type::hasSizedVLAType() const {
  1896. if (!isVariablyModifiedType()) return false;
  1897. if (const PointerType *ptr = getAs<PointerType>())
  1898. return ptr->getPointeeType()->hasSizedVLAType();
  1899. if (const ReferenceType *ref = getAs<ReferenceType>())
  1900. return ref->getPointeeType()->hasSizedVLAType();
  1901. if (const ArrayType *arr = getAsArrayTypeUnsafe()) {
  1902. if (isa<VariableArrayType>(arr) &&
  1903. cast<VariableArrayType>(arr)->getSizeExpr())
  1904. return true;
  1905. return arr->getElementType()->hasSizedVLAType();
  1906. }
  1907. return false;
  1908. }
  1909. QualType::DestructionKind QualType::isDestructedTypeImpl(QualType type) {
  1910. switch (type.getObjCLifetime()) {
  1911. case Qualifiers::OCL_None:
  1912. case Qualifiers::OCL_ExplicitNone:
  1913. case Qualifiers::OCL_Autoreleasing:
  1914. break;
  1915. case Qualifiers::OCL_Strong:
  1916. return DK_objc_strong_lifetime;
  1917. case Qualifiers::OCL_Weak:
  1918. return DK_objc_weak_lifetime;
  1919. }
  1920. /// Currently, the only destruction kind we recognize is C++ objects
  1921. /// with non-trivial destructors.
  1922. const CXXRecordDecl *record =
  1923. type->getBaseElementTypeUnsafe()->getAsCXXRecordDecl();
  1924. if (record && record->hasDefinition() && !record->hasTrivialDestructor())
  1925. return DK_cxx_destructor;
  1926. return DK_none;
  1927. }
  1928. bool QualType::hasTrivialAssignment(ASTContext &Context, bool Copying) const {
  1929. switch (getObjCLifetime()) {
  1930. case Qualifiers::OCL_None:
  1931. break;
  1932. case Qualifiers::OCL_ExplicitNone:
  1933. return true;
  1934. case Qualifiers::OCL_Autoreleasing:
  1935. case Qualifiers::OCL_Strong:
  1936. case Qualifiers::OCL_Weak:
  1937. return !Context.getLangOpts().ObjCAutoRefCount;
  1938. }
  1939. if (const CXXRecordDecl *Record
  1940. = getTypePtr()->getBaseElementTypeUnsafe()->getAsCXXRecordDecl())
  1941. return Copying ? Record->hasTrivialCopyAssignment() :
  1942. Record->hasTrivialMoveAssignment();
  1943. return true;
  1944. }