Guest User

Untitled

a guest
Jul 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1. Index: include/clang/Parse/Parser.h
  2. ===================================================================
  3. --- include/clang/Parse/Parser.h (revision 89660)
  4. +++ include/clang/Parse/Parser.h (working copy)
  5. @@ -83,6 +83,7 @@
  6. llvm::OwningPtr<PragmaHandler> PackHandler;
  7. llvm::OwningPtr<PragmaHandler> UnusedHandler;
  8. llvm::OwningPtr<PragmaHandler> WeakHandler;
  9. + llvm::OwningPtr<PragmaHandler> RedefineExtnameHandler;
  10. llvm::OwningPtr<clang::CommentHandler> CommentHandler;
  11.  
  12. /// Whether the '>' token acts as an operator or not. This will be
  13. Index: include/clang/Parse/Action.h
  14. ===================================================================
  15. --- include/clang/Parse/Action.h (revision 89660)
  16. +++ include/clang/Parse/Action.h (working copy)
  17. @@ -2212,6 +2212,15 @@
  18. SourceLocation AliasNameLoc) {
  19. return;
  20. }
  21. +
  22. + /// ActOnPragmaRedefineExtnameAlias - Called on well formed #pragma redefine_extname oldname newname.
  23. + virtual void ActOnPragmaRedefineExtnameAlias(IdentifierInfo* RedefineExtnameName,
  24. + IdentifierInfo* AliasName,
  25. + SourceLocation PragmaLoc,
  26. + SourceLocation RedefineExtnameNameLoc,
  27. + SourceLocation AliasNameLoc) {
  28. + return;
  29. + }
  30.  
  31. /// \name Code completion actions
  32. ///
  33. Index: lib/Sema/SemaDeclAttr.cpp
  34. ===================================================================
  35. --- lib/Sema/SemaDeclAttr.cpp (revision 89660)
  36. +++ lib/Sema/SemaDeclAttr.cpp (working copy)
  37. @@ -890,6 +890,18 @@
  38. D->addAttr(::new (S.Context) WeakImportAttr());
  39. }
  40.  
  41. +static void HandleRedefineExtnameAttr(Decl *D, const AttributeList &Attr, Sema &S) {
  42. + // check the attribute arguments.
  43. + if (Attr.getNumArgs() != 0) {
  44. + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 0;
  45. + return;
  46. + }
  47. +
  48. + // FIXME: missing stuff?
  49. +
  50. + D->addAttr(::new (S.Context) RedefineExtnameAttr());
  51. +}
  52. +
  53. static void HandleDLLImportAttr(Decl *D, const AttributeList &Attr, Sema &S) {
  54. // check the attribute arguments.
  55. if (Attr.getNumArgs() != 0) {
  56. @@ -1942,6 +1954,7 @@
  57. break;
  58. case AttributeList::AT_weak: HandleWeakAttr (D, Attr, S); break;
  59. case AttributeList::AT_weak_import: HandleWeakImportAttr(D, Attr, S); break;
  60. + case AttributeList::AT_redefine_extname: HandleRedefineExtnameAttr(D, Attr, S); break;
  61. case AttributeList::AT_transparent_union:
  62. HandleTransparentUnionAttr(D, Attr, S);
  63. break;
  64. Index: lib/Parse/ParsePragma.cpp
  65. ===================================================================
  66. --- lib/Parse/ParsePragma.cpp (revision 89660)
  67. +++ lib/Parse/ParsePragma.cpp (working copy)
  68. @@ -218,3 +218,45 @@
  69. Actions.ActOnPragmaWeakID(WeakName, WeakLoc, WeakNameLoc);
  70. }
  71. }
  72. +
  73. +// #pragma redefine_extname oldname newname
  74. +void PragmaRedefineExtnameHandler::HandlePragma(Preprocessor &PP, Token &RedefineExtnameTok) {
  75. +
  76. +// FIXME: ALL MY LOGIC IS WRONG... fix this function!
  77. +
  78. + // FIXME: Should we be expanding macros here? My guess is no.
  79. + SourceLocation RedefineExtnameLoc = RedefineExtnameTok.getLocation();
  80. +
  81. + Token Tok;
  82. + PP.Lex(Tok);
  83. + if (Tok.isNot(tok::identifier)) {
  84. + PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier) << "redefine_extname";
  85. + return;
  86. + }
  87. +
  88. + IdentifierInfo *RedefineExtnameName = Tok.getIdentifierInfo(), *AliasName = 0;
  89. + SourceLocation RedefineExtnameNameLoc = Tok.getLocation(), AliasNameLoc;
  90. +
  91. + PP.Lex(Tok);
  92. + if (Tok.is(tok::equal)) { // FIXME: space not a =
  93. + PP.Lex(Tok);
  94. + if (Tok.isNot(tok::identifier)) {
  95. + PP.Diag(Tok.getLocation(), diag::warn_pragma_expected_identifier)
  96. + << "redefine_extname";
  97. + return;
  98. + }
  99. + AliasName = Tok.getIdentifierInfo();
  100. + AliasNameLoc = Tok.getLocation();
  101. + PP.Lex(Tok);
  102. + }
  103. +
  104. + if (Tok.isNot(tok::eom)) {
  105. + PP.Diag(Tok.getLocation(), diag::warn_pragma_extra_tokens_at_eol) << "redefine_extname";
  106. + return;
  107. + }
  108. +
  109. + if (AliasName) {
  110. + Actions.ActOnPragmaRedefineExtname(RedefineExtnameName,
  111. + AliasName, RedefineExtnameLoc, RedefineExtnameNameLoc, AliasNameLoc);
  112. + }
  113. +}
  114. Index: lib/Parse/ParsePragma.h
  115. ===================================================================
  116. --- lib/Parse/ParsePragma.h (revision 89660)
  117. +++ lib/Parse/ParsePragma.h (working copy)
  118. @@ -48,6 +48,15 @@
  119. virtual void HandlePragma(Preprocessor &PP, Token &FirstToken);
  120. };
  121.  
  122. +class PragmaRedefineExtnameHandler : public PragmaHandler {
  123. + Action &Actions;
  124. +public:
  125. + PragmaRedefineExtnameHandler(const IdentifierInfo *N, Action &A)
  126. + : PragmaHandler(N), Actions(A) {}
  127. +
  128. + virtual void HandlePragma(Preprocessor &PP, Token &FirstToken);
  129. +};
  130. +
  131. } // end namespace clang
  132.  
  133. #endif
  134. Index: lib/Parse/Parser.cpp
  135. ===================================================================
  136. --- lib/Parse/Parser.cpp (revision 89660)
  137. +++ lib/Parse/Parser.cpp (working copy)
  138. @@ -58,6 +58,10 @@
  139. PragmaWeakHandler(&PP.getIdentifierTable().get("weak"), actions));
  140. PP.AddPragmaHandler(0, WeakHandler.get());
  141.  
  142. + RedefineExtnameHandler.reset(new
  143. + PragmaRedefineExtnameHandler(&PP.getIdentifierTable().get("redefine_extname"), actions));
  144. + PP.AddPragmaHandler(0, RedefineExtnameHandler.get());
  145. +
  146. CommentHandler.reset(new ActionCommentHandler(actions));
  147. PP.AddCommentHandler(CommentHandler.get());
  148. }
  149. @@ -314,6 +318,8 @@
  150. UnusedHandler.reset();
  151. PP.RemovePragmaHandler(0, WeakHandler.get());
  152. WeakHandler.reset();
  153. + PP.RemovePragmaHandler(0, RedefineExtnameHandler.get());
  154. + RedefineExtnameHandler.reset();
  155. PP.RemoveCommentHandler(CommentHandler.get());
  156. }
Add Comment
Please, Sign In to add comment