]> granicus.if.org Git - clang/commitdiff
Initialize the translation-unit scope before lexing the first
authorDouglas Gregor <dgregor@apple.com>
Wed, 25 Aug 2010 18:07:12 +0000 (18:07 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 25 Aug 2010 18:07:12 +0000 (18:07 +0000)
token. The first token might be something that ends up triggering code
completion, which in turn requires a valid Scope. Test case forthcoming.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@112066 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Action.h
include/clang/Sema/Sema.h
lib/Parse/Parser.cpp
lib/Sema/Sema.cpp

index e7fb732c34296216abfa54b1b3a591002e8b0249..5fb6d1f00f8bb528216e8a7d8633fd26a028afb7 100644 (file)
@@ -574,7 +574,7 @@ public:
 
   /// ActOnTranslationUnitScope - This callback is called once, immediately
   /// after creating the translation unit scope (in Parser::Initialize).
-  virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {}
+  virtual void ActOnTranslationUnitScope(Scope *S) {}
 
   /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
   /// no declarator (e.g. "struct foo;") is parsed.
index ba1122e1eee8c9393e0e188a1cf5c27d82ab8d18..491a38668ad1b30634d9ef3b8d7dae72f6983bdc 100644 (file)
@@ -829,7 +829,7 @@ public:
 
   /// Scope actions.
   virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
-  virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);
+  virtual void ActOnTranslationUnitScope(Scope *S);
 
   /// ParsedFreeStandingDeclSpec - This method is invoked when a declspec with
   /// no declarator (e.g. "struct foo;") is parsed.
index e277c3f80e14d69cc5dbc5938c419f4b8066efe9..23c13ebf9d526539e2531d30495203796c9fb1a0 100644 (file)
@@ -324,13 +324,13 @@ Parser::~Parser() {
 /// Initialize - Warm up the parser.
 ///
 void Parser::Initialize() {
-  // Prime the lexer look-ahead.
-  ConsumeToken();
-
   // Create the translation unit scope.  Install it as the current scope.
   assert(getCurScope() == 0 && "A scope is already active?");
   EnterScope(Scope::DeclScope);
-  Actions.ActOnTranslationUnitScope(Tok.getLocation(), getCurScope());
+  Actions.ActOnTranslationUnitScope(getCurScope());
+
+  // Prime the lexer look-ahead.
+  ConsumeToken();
 
   if (Tok.is(tok::eof) &&
       !getLang().CPlusPlus)  // Empty source file is an extension in C
index 31d6f0dd324f90add6890bc529f43d354fc8ee04..2e8827ddec99025f5062a53e47f878d8c82d69af 100644 (file)
@@ -48,7 +48,7 @@ void FunctionScopeInfo::Clear(unsigned NumErrors) {
 
 BlockScopeInfo::~BlockScopeInfo() { }
 
-void Sema::ActOnTranslationUnitScope(SourceLocation Loc, Scope *S) {
+void Sema::ActOnTranslationUnitScope(Scope *S) {
   TUScope = S;
   PushDeclContext(S, Context.getTranslationUnitDecl());