Guest User

Untitled

a guest
Jul 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.92 KB | None | 0 0
  1. Index: test/Parser/cxx0x-literal-operators.cpp
  2. ===================================================================
  3. --- test/Parser/cxx0x-literal-operators.cpp (revision 90045)
  4. +++ test/Parser/cxx0x-literal-operators.cpp (working copy)
  5. @@ -1,5 +1,5 @@
  6. // RUN: clang-cc -fsyntax-only -verify -std=c++0x %s
  7.  
  8. void operator "" (); // expected-error {{expected identifier}}
  9. -void operator "k" foo(); // expected-error {{string literal after 'operator' must be '""'}} \
  10. - // expected-error {{C++0x literal operator support is currently under development}}
  11. +void operator "k" foo(); // expected-error {{string literal after 'operator' must be '""'}}
  12. +void operator "" tester (int);
  13. Index: include/clang/Basic/IdentifierTable.h
  14. ===================================================================
  15. --- include/clang/Basic/IdentifierTable.h (revision 90045)
  16. +++ include/clang/Basic/IdentifierTable.h (working copy)
  17. @@ -496,6 +496,7 @@
  18. #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
  19. CXXOperator##Name,
  20. #include "clang/Basic/OperatorKinds.def"
  21. + CXXLiteralOperator,
  22. CXXUsingDirective,
  23. NUM_EXTRA_KINDS
  24. };
  25. @@ -503,10 +504,10 @@
  26. /// ExtraKindOrNumArgs - Either the kind of C++ special name or
  27. /// operator-id (if the value is one of the CXX* enumerators of
  28. /// ExtraKind), in which case the DeclarationNameExtra is also a
  29. - /// CXXSpecialName (for CXXConstructor, CXXDestructor, or
  30. - /// CXXConversionFunction) or CXXOperatorIdName, it may be also
  31. - /// name common to C++ using-directives (CXXUsingDirective), otherwise
  32. - /// it is NUM_EXTRA_KINDS+NumArgs, where NumArgs is the number of
  33. + /// CXXSpecialName, (for CXXConstructor, CXXDestructor, or
  34. + /// CXXConversionFunction) CXXOperatorIdName, or CXXLiteralOperatorName,
  35. + /// it may be also name common to C++ using-directives (CXXUsingDirective),
  36. + /// otherwise it is NUM_EXTRA_KINDS+NumArgs, where NumArgs is the number of
  37. /// arguments in the Objective-C selector, in which case the
  38. /// DeclarationNameExtra is also a MultiKeywordSelector.
  39. unsigned ExtraKindOrNumArgs;
  40. Index: include/clang/Basic/DiagnosticParseKinds.td
  41. ===================================================================
  42. --- include/clang/Basic/DiagnosticParseKinds.td (revision 90045)
  43. +++ include/clang/Basic/DiagnosticParseKinds.td (working copy)
  44. @@ -244,8 +244,6 @@
  45. "missing type specifier after 'operator'">;
  46. def err_operator_string_not_empty : Error<
  47. "string literal after 'operator' must be '\"\"'">;
  48. -def err_unsupported_literal_operator : Error<
  49. - "C++0x literal operator support is currently under development">;
  50.  
  51. // Classes.
  52. def err_anon_type_definition : Error<
  53. Index: include/clang/AST/DeclarationName.h
  54. ===================================================================
  55. --- include/clang/AST/DeclarationName.h (revision 90045)
  56. +++ include/clang/AST/DeclarationName.h (working copy)
  57. @@ -25,6 +25,7 @@
  58. namespace clang {
  59. class CXXSpecialName;
  60. class CXXOperatorIdName;
  61. + class CXXLiteralOperatorIdName;
  62. class DeclarationNameExtra;
  63. class IdentifierInfo;
  64. class MultiKeywordSelector;
  65. @@ -48,6 +49,7 @@
  66. CXXDestructorName,
  67. CXXConversionFunctionName,
  68. CXXOperatorName,
  69. + CXXLiteralOperatorName,
  70. CXXUsingDirective
  71. };
  72.  
  73. @@ -115,6 +117,12 @@
  74. return 0;
  75. }
  76.  
  77. + CXXLiteralOperatorIdName *getAsCXXLiteralOperatorIdName() const {
  78. + if (getNameKind() == CXXLiteralOperatorName)
  79. + return reinterpret_cast<CXXLiteralOperatorIdName *>(Ptr & ~PtrMask);
  80. + return 0;
  81. + }
  82. +
  83. // Construct a declaration name from the name of a C++ constructor,
  84. // destructor, or conversion function.
  85. DeclarationName(CXXSpecialName *Name)
  86. @@ -131,6 +139,12 @@
  87. Ptr |= StoredDeclarationNameExtra;
  88. }
  89.  
  90. + DeclarationName(CXXLiteralOperatorIdName *Name)
  91. + : Ptr(reinterpret_cast<uintptr_t>(Name)) {
  92. + assert((Ptr & PtrMask) == 0 && "Improperly aligned CXXLiteralOperatorId");
  93. + Ptr |= StoredDeclarationNameExtra;
  94. + }
  95. +
  96. /// Construct a declaration name from a raw pointer.
  97. DeclarationName(uintptr_t Ptr) : Ptr(Ptr) { }
  98.  
  99. @@ -201,7 +215,7 @@
  100. N.Ptr = reinterpret_cast<uintptr_t> (P);
  101. return N;
  102. }
  103. -
  104. +
  105. static DeclarationName getFromOpaqueInteger(uintptr_t P) {
  106. DeclarationName N;
  107. N.Ptr = P;
  108. @@ -218,6 +232,10 @@
  109. /// kind of overloaded operator.
  110. OverloadedOperatorKind getCXXOverloadedOperator() const;
  111.  
  112. + /// getCXXLiteralIdentifier - If this name is the name of a literal
  113. + /// operator, retrieve the identifier associated with it.
  114. + IdentifierInfo *getCXXLiteralIdentifier() const;
  115. +
  116. /// getObjCSelector - Get the Objective-C selector stored in this
  117. /// declaration name.
  118. Selector getObjCSelector() const;
  119. @@ -324,6 +342,10 @@
  120. /// getCXXOperatorName - Get the name of the overloadable C++
  121. /// operator corresponding to Op.
  122. DeclarationName getCXXOperatorName(OverloadedOperatorKind Op);
  123. +
  124. + /// getCXXLiteralOperatorName - Get the name of the literal operator function
  125. + /// with II as the identifier.
  126. + DeclarationName getCXXLiteralOperatorName(IdentifierInfo *II);
  127. };
  128.  
  129. /// Insertion operator for diagnostics. This allows sending DeclarationName's
  130. Index: lib/Frontend/PCHWriter.cpp
  131. ===================================================================
  132. --- lib/Frontend/PCHWriter.cpp (revision 90045)
  133. +++ lib/Frontend/PCHWriter.cpp (working copy)
  134. @@ -2284,6 +2284,10 @@
  135. Record.push_back(Name.getCXXOverloadedOperator());
  136. break;
  137.  
  138. + case DeclarationName::CXXLiteralOperatorName:
  139. + AddIdentifierRef(Name.getCXXLiteralIdentifier(), Record);
  140. + break;
  141. +
  142. case DeclarationName::CXXUsingDirective:
  143. // No extra data to emit
  144. break;
  145. Index: lib/Frontend/PCHReader.cpp
  146. ===================================================================
  147. --- lib/Frontend/PCHReader.cpp (revision 90045)
  148. +++ lib/Frontend/PCHReader.cpp (working copy)
  149. @@ -2589,6 +2589,10 @@
  150. return Context->DeclarationNames.getCXXOperatorName(
  151. (OverloadedOperatorKind)Record[Idx++]);
  152.  
  153. + case DeclarationName::CXXLiteralOperatorName:
  154. + return Context->DeclarationNames.getCXXLiteralOperatorName(
  155. + GetIdentifierInfo(Record, Idx));
  156. +
  157. case DeclarationName::CXXUsingDirective:
  158. return DeclarationName::getUsingDirectiveName();
  159. }
  160. Index: lib/CodeGen/Mangle.cpp
  161. ===================================================================
  162. --- lib/CodeGen/Mangle.cpp (revision 90045)
  163. +++ lib/CodeGen/Mangle.cpp (working copy)
  164. @@ -455,6 +455,12 @@
  165. cast<FunctionDecl>(ND)->getNumParams());
  166. break;
  167.  
  168. + case DeclarationName::CXXLiteralOperatorName:
  169. + // Guessing based on existing ABI.
  170. + Out << "ul";
  171. + mangleSourceName(Name.getCXXLiteralIdentifier());
  172. + break;
  173. +
  174. case DeclarationName::CXXUsingDirective:
  175. assert(false && "Can't mangle a using directive name!");
  176. break;
  177. Index: lib/Sema/TreeTransform.h
  178. ===================================================================
  179. --- lib/Sema/TreeTransform.h (revision 90045)
  180. +++ lib/Sema/TreeTransform.h (working copy)
  181. @@ -1800,6 +1800,7 @@
  182. case DeclarationName::ObjCOneArgSelector:
  183. case DeclarationName::ObjCMultiArgSelector:
  184. case DeclarationName::CXXOperatorName:
  185. + case DeclarationName::CXXLiteralOperatorName:
  186. case DeclarationName::CXXUsingDirective:
  187. return Name;
  188.  
  189. Index: lib/Sema/SemaDecl.cpp
  190. ===================================================================
  191. --- lib/Sema/SemaDecl.cpp (revision 90057)
  192. +++ lib/Sema/SemaDecl.cpp (working copy)
  193. @@ -1767,7 +1767,8 @@
  194. Name.OperatorFunctionId.Operator);
  195.  
  196. case UnqualifiedId::IK_LiteralOperatorId:
  197. - assert(false && "We don't support these; Parse shouldn't have allowed propagation");
  198. + return Context.DeclarationNames.getCXXLiteralOperatorName(
  199. + Name.Identifier);
  200.  
  201. case UnqualifiedId::IK_ConversionFunctionId: {
  202. QualType Ty = GetTypeFromParser(Name.ConversionFunctionId);
  203. Index: lib/Sema/SemaTemplate.cpp
  204. ===================================================================
  205. --- lib/Sema/SemaTemplate.cpp (revision 90045)
  206. +++ lib/Sema/SemaTemplate.cpp (working copy)
  207. @@ -130,9 +130,9 @@
  208. break;
  209.  
  210. case UnqualifiedId::IK_LiteralOperatorId:
  211. - assert(false && "We don't support these; Parse shouldn't have allowed propagation");
  212. + TName = Context.DeclarationNames.getCXXLiteralOperatorName(Name.Identifier);
  213. + break;
  214.  
  215. -
  216. default:
  217. return TNK_Non_template;
  218. }
  219. Index: lib/Sema/SemaExpr.cpp
  220. ===================================================================
  221. --- lib/Sema/SemaExpr.cpp (revision 90045)
  222. +++ lib/Sema/SemaExpr.cpp (working copy)
  223. @@ -729,6 +729,7 @@
  224. << Name << computeDeclContext(SS, false)
  225. << SS.getRange());
  226. else if (Name.getNameKind() == DeclarationName::CXXOperatorName ||
  227. + Name.getNameKind() == DeclarationName::CXXLiteralOperatorName ||
  228. Name.getNameKind() == DeclarationName::CXXConversionFunctionName)
  229. return ExprError(Diag(NameLoc, diag::err_undeclared_use)
  230. << Name);
  231. Index: lib/AST/DeclarationName.cpp
  232. ===================================================================
  233. --- lib/AST/DeclarationName.cpp (revision 90045)
  234. +++ lib/AST/DeclarationName.cpp (working copy)
  235. @@ -50,6 +50,17 @@
  236. void *FETokenInfo;
  237. };
  238.  
  239. +/// CXXLiberalOperatorName - Contains the actual identifier that makes up the
  240. +/// name.
  241. +///
  242. +/// This identifier is stored here rather than directly in DeclarationName so as
  243. +/// to allow Objective-C selectors, which are about a million imes more common,
  244. +/// to consume minimal memory.
  245. +class CXXLiteralOperatorIdName : public DeclarationNameExtra {
  246. +public:
  247. + IdentifierInfo *ID;
  248. +};
  249. +
  250. bool operator<(DeclarationName LHS, DeclarationName RHS) {
  251. if (LHS.getNameKind() != RHS.getNameKind())
  252. return LHS.getNameKind() < RHS.getNameKind();
  253. @@ -89,6 +100,10 @@
  254.  
  255. case DeclarationName::CXXOperatorName:
  256. return LHS.getCXXOverloadedOperator() < RHS.getCXXOverloadedOperator();
  257. +
  258. + case DeclarationName::CXXLiteralOperatorName:
  259. + return LHS.getCXXLiteralIdentifier()->getName() <
  260. + RHS.getCXXLiteralIdentifier()->getName();
  261.  
  262. case DeclarationName::CXXUsingDirective:
  263. return false;
  264. @@ -143,6 +158,9 @@
  265. case DeclarationNameExtra::CXXConversionFunction:
  266. return CXXConversionFunctionName;
  267.  
  268. + case DeclarationNameExtra::CXXLiteralOperator:
  269. + return CXXLiteralOperatorName;
  270. +
  271. case DeclarationNameExtra::CXXUsingDirective:
  272. return CXXUsingDirective;
  273.  
  274. @@ -208,6 +226,10 @@
  275. return Result;
  276. }
  277.  
  278. + case CXXLiteralOperatorName: {
  279. + return "operator \"\" " + std::string(getCXXLiteralIdentifier()->getName());
  280. + }
  281. +
  282. case CXXConversionFunctionName: {
  283. std::string Result = "operator ";
  284. QualType Type = getCXXNameType();
  285. @@ -242,6 +264,13 @@
  286. }
  287. }
  288.  
  289. +IdentifierInfo *DeclarationName::getCXXLiteralIdentifier() const {
  290. + if (CXXLiteralOperatorIdName *CXXLit = getAsCXXLiteralOperatorIdName())
  291. + return CXXLit->ID;
  292. + else
  293. + return 0;
  294. +}
  295. +
  296. Selector DeclarationName::getObjCSelector() const {
  297. switch (getNameKind()) {
  298. case ObjCZeroArgSelector:
  299. @@ -273,6 +302,9 @@
  300. case CXXOperatorName:
  301. return getAsCXXOperatorIdName()->FETokenInfo;
  302.  
  303. + case CXXLiteralOperatorName:
  304. + return getCXXLiteralIdentifier()->getFETokenInfo<void>();
  305. +
  306. default:
  307. assert(false && "Declaration name has no FETokenInfo");
  308. }
  309. @@ -295,6 +327,10 @@
  310. getAsCXXOperatorIdName()->FETokenInfo = T;
  311. break;
  312.  
  313. + case CXXLiteralOperatorName:
  314. + getCXXLiteralIdentifier()->setFETokenInfo(T);
  315. + break;
  316. +
  317. default:
  318. assert(false && "Declaration name has no FETokenInfo");
  319. }
  320. @@ -390,6 +426,14 @@
  321. return DeclarationName(&CXXOperatorNames[(unsigned)Op]);
  322. }
  323.  
  324. +DeclarationName
  325. +DeclarationNameTable::getCXXLiteralOperatorName(IdentifierInfo *II) {
  326. + CXXLiteralOperatorIdName *LiteralName = new CXXLiteralOperatorIdName;
  327. + LiteralName->ExtraKindOrNumArgs = DeclarationNameExtra::CXXLiteralOperator;
  328. + LiteralName->ID = II;
  329. + return DeclarationName(LiteralName);
  330. +}
  331. +
  332. unsigned
  333. llvm::DenseMapInfo<clang::DeclarationName>::
  334. getHashValue(clang::DeclarationName N) {
  335. Index: lib/Parse/ParseExprCXX.cpp
  336. ===================================================================
  337. --- lib/Parse/ParseExprCXX.cpp (revision 90045)
  338. +++ lib/Parse/ParseExprCXX.cpp (working copy)
  339. @@ -1052,8 +1052,7 @@
  340.  
  341. IdentifierInfo *II = Tok.getIdentifierInfo();
  342. Result.setLiteralOperatorId(II, KeywordLoc, ConsumeToken());
  343. - Diag(KeywordLoc, diag::err_unsupported_literal_operator);
  344. - return true;
  345. + return false;
  346. }
  347.  
  348. // Parse a conversion-function-id.
Add Comment
Please, Sign In to add comment