ParseObjc.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //===--- ParseObjc.cpp - Objective C Parsing ------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file was developed by Steve Naroff and is distributed under
  6. // the University of Illinois Open Source License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements the Objective-C portions of the Parser interface.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "clang/Parse/Parser.h"
  14. #include "clang/Basic/Diagnostic.h"
  15. #include "llvm/ADT/SmallVector.h"
  16. using namespace clang;
  17. /// ParseExternalDeclaration:
  18. /// external-declaration: [C99 6.9]
  19. /// [OBJC] objc-class-definition
  20. /// [OBJC] objc-class-declaration [TODO]
  21. /// [OBJC] objc-alias-declaration [TODO]
  22. /// [OBJC] objc-protocol-definition [TODO]
  23. /// [OBJC] objc-method-definition [TODO]
  24. /// [OBJC] '@' 'end' [TODO]
  25. void Parser::ParseObjCAtDirectives() {
  26. SourceLocation AtLoc = ConsumeToken(); // the "@"
  27. IdentifierInfo *II = Tok.getIdentifierInfo();
  28. switch (II ? II->getObjCKeywordID() : tok::objc_not_keyword) {
  29. case tok::objc_class:
  30. return ParseObjCAtClassDeclaration(AtLoc);
  31. case tok::objc_interface:
  32. return ParseObjCAtInterfaceDeclaration();
  33. case tok::objc_protocol:
  34. return ParseObjCAtProtocolDeclaration();
  35. case tok::objc_implementation:
  36. return ParseObjCAtImplementationDeclaration();
  37. case tok::objc_end:
  38. return ParseObjCAtEndDeclaration();
  39. case tok::objc_compatibility_alias:
  40. return ParseObjCAtAliasDeclaration();
  41. default:
  42. Diag(AtLoc, diag::err_unexpected_at);
  43. SkipUntil(tok::semi);
  44. }
  45. }
  46. ///
  47. /// objc-class-declaration:
  48. /// '@' 'class' identifier-list ';'
  49. ///
  50. void Parser::ParseObjCAtClassDeclaration(SourceLocation atLoc) {
  51. ConsumeToken(); // the identifier "class"
  52. llvm::SmallVector<IdentifierInfo *, 8> ClassNames;
  53. while (1) {
  54. if (Tok.getKind() != tok::identifier) {
  55. Diag(Tok, diag::err_expected_ident);
  56. SkipUntil(tok::semi);
  57. return;
  58. }
  59. ClassNames.push_back(Tok.getIdentifierInfo());
  60. ConsumeToken();
  61. if (Tok.getKind() != tok::comma)
  62. break;
  63. ConsumeToken();
  64. }
  65. // Consume the ';'.
  66. if (ExpectAndConsume(tok::semi, diag::err_expected_semi_after, "@class"))
  67. return;
  68. Actions.ParsedObjcClassDeclaration(CurScope,
  69. &ClassNames[0], ClassNames.size());
  70. }
  71. void Parser::ParseObjCAtInterfaceDeclaration() {
  72. assert(0 && "Unimp");
  73. }
  74. void Parser::ParseObjCAtProtocolDeclaration() {
  75. assert(0 && "Unimp");
  76. }
  77. void Parser::ParseObjCAtImplementationDeclaration() {
  78. assert(0 && "Unimp");
  79. }
  80. void Parser::ParseObjCAtEndDeclaration() {
  81. assert(0 && "Unimp");
  82. }
  83. void Parser::ParseObjCAtAliasDeclaration() {
  84. assert(0 && "Unimp");
  85. }
  86. void Parser::ParseObjCInstanceMethodDeclaration() {
  87. assert(0 && "Unimp");
  88. }
  89. void Parser::ParseObjCClassMethodDeclaration() {
  90. assert(0 && "Unimp");
  91. }