changeset 58:01c954c1b51b

include setjmp.h automatically without checking __code
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Sun, 02 Feb 2014 17:07:04 +0900
parents 88b0e1f890d7
children 322ba4588e4f
files tools/clang/include/clang/Lex/Preprocessor.h tools/clang/include/clang/Parse/Parser.h tools/clang/lib/Lex/PPDirectives.cpp tools/clang/lib/Lex/Preprocessor.cpp tools/clang/lib/Parse/ParseCbC.cpp tools/clang/lib/Parse/Parser.cpp
diffstat 6 files changed, 22 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/tools/clang/include/clang/Lex/Preprocessor.h	Sun Feb 02 16:01:05 2014 +0900
+++ b/tools/clang/include/clang/Lex/Preprocessor.h	Sun Feb 02 17:07:04 2014 +0900
@@ -1559,8 +1559,8 @@
   /// warnings.
   void markMacroAsUsed(MacroInfo *MI);
 #ifndef noCbC
-  void LexHeader(Token Tok, const char* Name);
-  unsigned long SavedDepth;
+  bool IncludeHeader(Token Tok, const char* Name);
+  unsigned int SavedDepth;
   Token SavedToken;
   bool SavedTokenFlag;
 #endif
--- a/tools/clang/include/clang/Parse/Parser.h	Sun Feb 02 16:01:05 2014 +0900
+++ b/tools/clang/include/clang/Parse/Parser.h	Sun Feb 02 17:07:04 2014 +0900
@@ -1718,7 +1718,7 @@
   ParmVarDecl* CreateParam(IdentifierInfo *II = 0, int pointerNum = 0, DeclSpec::TST T = DeclSpec::TST_int);
   Decl* HandleDeclAndChangeDeclType(Declarator &D);
   void setTST(DeclSpec *DS = 0, DeclSpec::TST T = DeclSpec::TST_int, IdentifierInfo *Name = 0);
-  void IncludeHeader(const char* HeaderName);
+  void CheckTheSjHeader();
   ExprResult IIToExpr(IdentifierInfo *II, tok::TokenKind Kind);
   StmtResult CreateComplexStmtRet(IdentifierInfo *II, bool IsAddressOfOperand);
   ExprResult Prepare__retForGotoWithTheEnvExpr();
--- a/tools/clang/lib/Lex/PPDirectives.cpp	Sun Feb 02 16:01:05 2014 +0900
+++ b/tools/clang/lib/Lex/PPDirectives.cpp	Sun Feb 02 17:07:04 2014 +0900
@@ -2393,7 +2393,12 @@
                                ElifToken.getLocation());
 }
 #ifndef noCbC
-void Preprocessor::LexHeader(Token Tok, const char* Name) {
+/// IncludeHeader - Include a header file.
+/// Current Token is saved for returning current file because it has been already lexed from buffer of input file.
+/// When the lexer has already entered a header file, this function return false.
+bool Preprocessor::IncludeHeader(Token Tok, const char* Name) {
+  if (SavedTokenFlag) // If the lexer has already entered a header file, we have to leave this function.
+    return false;
   SourceLocation Loc = Tok.getLocation();
   SavedToken = Tok;
   SavedDepth = IncludeMacroStack.size();
@@ -2423,7 +2428,7 @@
   SrcMgr::CharacteristicKind FileCharacter = std::max(HeaderInfo.getFileDirFlavor(File), SourceMgr.getFileCharacteristic(Loc));
 
   if (!HeaderInfo.ShouldEnterIncludeFile(File, false)) {
-    return;
+    return false;
   }
 
   FileID FID = SourceMgr.createFileID(File, Loc, FileCharacter);      
@@ -2431,5 +2436,6 @@
   EnterSourceFile(FID, CurDir, FilenameTok.getLocation(), static_cast<bool>(BuildingModule));
   if (BuildingModule)
     EnterAnnotationToken(*this, Loc, Loc, tok::annot_module_begin, BuildingModule.getModule());
+  return true;
 }
 #endif
--- a/tools/clang/lib/Lex/Preprocessor.cpp	Sun Feb 02 16:01:05 2014 +0900
+++ b/tools/clang/lib/Lex/Preprocessor.cpp	Sun Feb 02 17:07:04 2014 +0900
@@ -137,6 +137,7 @@
     Initialize(*Target);
   }
 #ifndef noCbC
+  SavedDepth = 0;
   SavedTokenFlag = false;
 #endif  
 }
--- a/tools/clang/lib/Parse/ParseCbC.cpp	Sun Feb 02 16:01:05 2014 +0900
+++ b/tools/clang/lib/Parse/ParseCbC.cpp	Sun Feb 02 17:07:04 2014 +0900
@@ -831,12 +831,14 @@
   }
 }
 
-void Parser::IncludeHeader(const char* HeaderName){
+/// CheckTheSjHeader - Check whether setjmp.h has been already included or not.
+/// If not, include it.
+void Parser::CheckTheSjHeader(){
   SourceLocation Loc = Tok.getLocation();
   LookupResult R(Actions, CreateIdentifierInfo("setjmp", Loc), Loc, Actions.LookupOrdinaryName, Actions.ForRedeclaration);
-  if (!Actions.LookupName(R, getCurScope())){
-    PP.LexHeader(Tok, HeaderName);
-    ConsumeToken();
+  if (!Actions.LookupName(R, getCurScope())){ // look up the setjmp
+    if (PP.IncludeHeader(Tok, "setjmp.h"))
+      ConsumeToken();
   }
 }
 #endif
--- a/tools/clang/lib/Parse/Parser.cpp	Sun Feb 02 16:01:05 2014 +0900
+++ b/tools/clang/lib/Parse/Parser.cpp	Sun Feb 02 17:07:04 2014 +0900
@@ -586,6 +586,10 @@
   if (PP.isIncrementalProcessingEnabled() && Tok.is(tok::eof))
     ConsumeToken();
 
+#ifndef noCbC
+  CheckTheSjHeader();
+#endif
+
   Result = DeclGroupPtrTy();
   switch (Tok.getKind()) {
   case tok::annot_pragma_unused:
@@ -885,11 +889,6 @@
 Parser::ParseDeclOrFunctionDefInternal(ParsedAttributesWithRange &attrs,
                                        ParsingDeclSpec &DS,
                                        AccessSpecifier AS) {
-#ifndef noCbC
-  if (Tok.is(tok::kw___code)) {
-    IncludeHeader("setjmp.h");
-  }
-#endif
 
   // Parse the common declaration-specifiers piece.
   ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS, DSC_top_level);