changeset 53:f679cc5126db

include setjmp.h automatically
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Sat, 18 Jan 2014 23:56:19 +0900
parents c22698ecb2a9
children d48478628b39
files tools/clang/include/clang/Lex/Preprocessor.h tools/clang/include/clang/Parse/Parser.h tools/clang/lib/Lex/PPDirectives.cpp tools/clang/lib/Parse/ParseCbC.cpp tools/clang/lib/Parse/Parser.cpp
diffstat 5 files changed, 56 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tools/clang/include/clang/Lex/Preprocessor.h	Wed Jan 15 21:01:33 2014 +0900
+++ b/tools/clang/include/clang/Lex/Preprocessor.h	Sat Jan 18 23:56:19 2014 +0900
@@ -1558,6 +1558,9 @@
   /// \brief A macro is used, update information about macros that need unused
   /// warnings.
   void markMacroAsUsed(MacroInfo *MI);
+#ifndef noCbC
+  void LexHeader(SourceLocation Loc, const char* Name);
+#endif
 };
 
 /// \brief Abstract base class that describes a handler that will receive
--- a/tools/clang/include/clang/Parse/Parser.h	Wed Jan 15 21:01:33 2014 +0900
+++ b/tools/clang/include/clang/Parse/Parser.h	Sat Jan 18 23:56:19 2014 +0900
@@ -284,6 +284,11 @@
       return handleUnexpectedCodeCompletionToken();
 
     PrevTokLocation = Tok.getLocation();
+#ifndef noCbC
+    if (NextToken().is(tok::kw___code)) {
+	IncludeHeader("setjmp.h");
+    }
+#endif
     PP.Lex(Tok);
     return PrevTokLocation;
   }
@@ -1719,6 +1724,7 @@
   IdentifierInfo* CreateUniqueIdentifierInfo(const char* Name, SourceLocation Loc);
   void CreateParam(DeclSpec::TST T, IdentifierInfo *II, int pointerNum, SmallVector<DeclaratorChunk::ParamInfo, 16> *ParamInfo);
   void setTST(DeclSpec *DS=0, DeclSpec::TST T = DeclSpec::TST_int, IdentifierInfo *Name=0);
+  void IncludeHeader(const char* HeaderName);
 #endif
 
   bool isDeclarationSpecifier(bool DisambiguatingWithExpression = false);
--- a/tools/clang/lib/Lex/PPDirectives.cpp	Wed Jan 15 21:01:33 2014 +0900
+++ b/tools/clang/lib/Lex/PPDirectives.cpp	Sat Jan 18 23:56:19 2014 +0900
@@ -26,6 +26,10 @@
 #include "llvm/ADT/APInt.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/SaveAndRestore.h"
+
+#ifndef noCbC
+#include <string>
+#endif
 using namespace clang;
 
 //===----------------------------------------------------------------------===//
@@ -2388,3 +2392,39 @@
                                /*FoundElse*/CI.FoundElse,
                                ElifToken.getLocation());
 }
+#ifndef noCbC
+void Preprocessor::LexHeader(SourceLocation Loc, const char* Name) {
+  CurPPLexer->ParsingPreprocessorDirective = true;
+  if (CurLexer) CurLexer->SetKeepWhitespaceMode(false);
+  CurPPLexer->MIOpt.resetImmediatelyAfterTopLevelIfndef();
+  ++NumDirectives; // number of preprocessor directives.
+  const int Len = strlen(Name);
+  const DirectoryLookup *LookupFrom = 0;
+  Token FilenameTok;
+  FilenameTok.setKind(tok::angle_string_literal);
+  FilenameTok.setLocation(Loc);
+  FilenameTok.setLength(Len);
+  FilenameTok.setLiteralData(Name);
+  StringRef Filename;
+  Filename = StringRef(Name, Len);
+  bool isAngled = true; // '<' header name '>'
+  const DirectoryLookup *CurDir;
+  ModuleMap::KnownHeader SuggestedModule;
+  const FileEntry *File = LookupFile(Loc, Filename, isAngled, LookupFrom, CurDir, NULL, NULL,
+				     HeaderInfo.getHeaderSearchOpts().ModuleMaps ? &SuggestedModule : 0);
+  if (File == 0) {
+    Diag(FilenameTok, diag::err_pp_file_not_found) << Filename; // setjmp.h was not found
+  }
+  SrcMgr::CharacteristicKind FileCharacter = std::max(HeaderInfo.getFileDirFlavor(File), SourceMgr.getFileCharacteristic(Loc));
+
+  if (!HeaderInfo.ShouldEnterIncludeFile(File, false)) {
+    return;
+  }
+
+  FileID FID = SourceMgr.createFileID(File, Loc, FileCharacter);      
+  ModuleMap::KnownHeader BuildingModule;
+  EnterSourceFile(FID, CurDir, FilenameTok.getLocation(), static_cast<bool>(BuildingModule));
+  if (BuildingModule)
+    EnterAnnotationToken(*this, Loc, Loc, tok::annot_module_begin, BuildingModule.getModule());
+}
+#endif
--- a/tools/clang/lib/Parse/ParseCbC.cpp	Wed Jan 15 21:01:33 2014 +0900
+++ b/tools/clang/lib/Parse/ParseCbC.cpp	Sat Jan 18 23:56:19 2014 +0900
@@ -723,4 +723,11 @@
   }
 }
 
+void Parser::IncludeHeader(const char* HeaderName){
+  SourceLocation Loc = Tok.getLocation();
+  LookupResult R(Actions, CreateIdentifierInfo("setjmp", Loc), Loc, Actions.LookupOrdinaryName, Actions.ForRedeclaration);
+  if (!Actions.LookupName(R, getCurScope())){
+    PP.LexHeader(Tok.getLocation(), HeaderName);
+  }
+}
 #endif
--- a/tools/clang/lib/Parse/Parser.cpp	Wed Jan 15 21:01:33 2014 +0900
+++ b/tools/clang/lib/Parse/Parser.cpp	Sat Jan 18 23:56:19 2014 +0900
@@ -23,7 +23,6 @@
 #include "llvm/Support/raw_ostream.h"
 using namespace clang;
 
-
 namespace {
 /// \brief A comment handler that passes comments found by the preprocessor
 /// to the parser action.