[cfe-commits] r38821 - in /cfe/cfe/trunk: Parse/Parser.cpp Parse/Scope.cpp clang.xcodeproj/project.pbxproj include/clang/Parse/Parser.h include/clang/Parse/Scope.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:24:55 PDT 2007


Author: sabre
Date: Wed Jul 11 11:24:55 2007
New Revision: 38821

URL: http://llvm.org/viewvc/llvm-project?rev=38821&view=rev
Log:
Add scaffolding for scopes.

Added:
    cfe/cfe/trunk/Parse/Scope.cpp   (with props)
    cfe/cfe/trunk/include/clang/Parse/Scope.h   (with props)
Modified:
    cfe/cfe/trunk/Parse/Parser.cpp
    cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/cfe/trunk/include/clang/Parse/Parser.h

Modified: cfe/cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/Parser.cpp?rev=38821&r1=38820&r2=38821&view=diff

==============================================================================
--- cfe/cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/cfe/trunk/Parse/Parser.cpp Wed Jul 11 11:24:55 2007
@@ -13,11 +13,20 @@
 
 #include "clang/Parse/Parser.h"
 #include "clang/Parse/Declarations.h"
+#include "clang/Parse/Scope.h"
 using namespace llvm;
 using namespace clang;
 
 Parser::Parser(Preprocessor &pp, ParserActions &actions)
-  : PP(pp), Actions(actions), Diags(PP.getDiagnostics()) {}
+  : PP(pp), Actions(actions), Diags(PP.getDiagnostics()) {
+  // Create the global scope, install it as the current scope.
+  CurScope = new Scope(0);
+}
+
+Parser::~Parser() {
+  delete CurScope;
+}
+
 
 void Parser::Diag(SourceLocation Loc, unsigned DiagID,
                   const std::string &Msg) {

Added: cfe/cfe/trunk/Parse/Scope.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Parse/Scope.cpp?rev=38821&view=auto

==============================================================================
    (empty)

Propchange: cfe/cfe/trunk/Parse/Scope.cpp

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/cfe/trunk/Parse/Scope.cpp

------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/clang.xcodeproj/project.pbxproj?rev=38821&r1=38820&r2=38821&view=diff

==============================================================================
--- cfe/cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/cfe/trunk/clang.xcodeproj/project.pbxproj Wed Jul 11 11:24:55 2007
@@ -8,6 +8,8 @@
 
 /* Begin PBXBuildFile section */
 		DE06B73E0A8307640050E87E /* LangOptions.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE06B73D0A8307640050E87E /* LangOptions.h */; };
+		DE06BEC90A854E390050E87E /* Scope.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE06BEC80A854E390050E87E /* Scope.cpp */; };
+		DE06BECB0A854E4B0050E87E /* Scope.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE06BECA0A854E4B0050E87E /* Scope.h */; };
 		DE1F22030A7D852A00FBF588 /* Parser.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE1F22020A7D852A00FBF588 /* Parser.h */; };
 		DE1F22200A7D879000FBF588 /* ParserActions.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DE1F221F0A7D879000FBF588 /* ParserActions.h */; };
 		DE1F24700A7DC99000FBF588 /* Actions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DE1F246D0A7DC99000FBF588 /* Actions.cpp */; };
@@ -98,6 +100,7 @@
 				DE1F22200A7D879000FBF588 /* ParserActions.h in CopyFiles */,
 				DE1F24820A7DCD3800FBF588 /* Declarations.h in CopyFiles */,
 				DE06B73E0A8307640050E87E /* LangOptions.h in CopyFiles */,
+				DE06BECB0A854E4B0050E87E /* Scope.h in CopyFiles */,
 			);
 			runOnlyForDeploymentPostprocessing = 1;
 		};
@@ -106,6 +109,8 @@
 /* Begin PBXFileReference section */
 		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
 		DE06B73D0A8307640050E87E /* LangOptions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = LangOptions.h; sourceTree = "<group>"; };
+		DE06BEC80A854E390050E87E /* Scope.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Scope.cpp; path = Parse/Scope.cpp; sourceTree = "<group>"; };
+		DE06BECA0A854E4B0050E87E /* Scope.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Scope.h; path = clang/Parse/Scope.h; sourceTree = "<group>"; };
 		DE1F22020A7D852A00FBF588 /* Parser.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Parser.h; path = clang/Parse/Parser.h; sourceTree = "<group>"; };
 		DE1F221F0A7D879000FBF588 /* ParserActions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ParserActions.h; path = clang/Parse/ParserActions.h; sourceTree = "<group>"; };
 		DE1F246D0A7DC99000FBF588 /* Actions.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Actions.cpp; path = Parse/Actions.cpp; sourceTree = "<group>"; };
@@ -206,6 +211,7 @@
 				DE1F24810A7DCD3800FBF588 /* Declarations.h */,
 				DE1F22020A7D852A00FBF588 /* Parser.h */,
 				DE1F221F0A7D879000FBF588 /* ParserActions.h */,
+				DE06BECA0A854E4B0050E87E /* Scope.h */,
 			);
 			name = Parse;
 			sourceTree = "<group>";
@@ -217,6 +223,7 @@
 				DE1F257A0A7DD86800FBF588 /* Declarations.cpp */,
 				DE1F246E0A7DC99000FBF588 /* Parse.cpp */,
 				DE1F246F0A7DC99000FBF588 /* ParseDeclarations.cpp */,
+				DE06BEC80A854E390050E87E /* Scope.cpp */,
 			);
 			name = Parse;
 			sourceTree = "<group>";
@@ -370,6 +377,7 @@
 				DE1F24710A7DC99000FBF588 /* Parse.cpp in Sources */,
 				DE1F24720A7DC99000FBF588 /* ParseDeclarations.cpp in Sources */,
 				DE1F257B0A7DD86800FBF588 /* Declarations.cpp in Sources */,
+				DE06BEC90A854E390050E87E /* Scope.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: cfe/cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Parser.h?rev=38821&r1=38820&r2=38821&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Parser.h Wed Jul 11 11:24:55 2007
@@ -21,22 +21,24 @@
 namespace clang {
   class ParserActions;
   class DeclSpec;
+  class Scope;
 
 /// Parser - This implements a parser for the C family of languages.  After
 /// parsing units of the grammar, productions are invoked to handle whatever has
 /// been read.
 ///
 class Parser {
-  // SYMBOL TABLE
   Preprocessor &PP;
   ParserActions &Actions;
   Diagnostic &Diags;
+  Scope *CurScope;
   
   /// Tok - The current token we are peeking head.  All parsing methods assume
   /// that this is valid.
   LexerToken Tok;
 public:
   Parser(Preprocessor &PP, ParserActions &Actions);
+  ~Parser();
 
   const LangOptions &getLang() const { return PP.getLangOptions(); }
   

Added: cfe/cfe/trunk/include/clang/Parse/Scope.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Parse/Scope.h?rev=38821&view=auto

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Scope.h (added)
+++ cfe/cfe/trunk/include/clang/Parse/Scope.h Wed Jul 11 11:24:55 2007
@@ -0,0 +1,51 @@
+//===--- Scope.h - Scope interface ------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+//  This file defines the Scope interface.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_PARSE_SCOPE_H
+#define LLVM_CLANG_PARSE_SCOPE_H
+
+#include "llvm/ADT/SmallVector.h"
+
+namespace llvm {
+namespace clang {
+  class Decl;
+    
+/// Scope - A scope is a transient data structure that is used while parsing the
+/// program.  It assists with resolving identifiers to the appropriate
+/// declaration.
+///
+class Scope {
+  /// The parent scope for this scope.  This is null for the translation-unit
+  /// scope.
+  Scope *Parent;
+  
+  /// Depth - This is the depth of this scope.  The translation-unit scope has
+  /// depth 0.
+  unsigned Depth;
+  
+  /// DeclsInScope - This keeps track of all declarations in this scope.  When
+  /// the declaration is added to the scope, it is set as the current
+  /// declaration for the identifier in the IdentifierTable.  When the scope is
+  /// popped, these declarations are removed from the IdentifierTable's notion
+  /// of current declaration.
+  SmallVector<Decl*, 32> DeclsInScope;
+public:
+  Scope(Scope *parent) : Parent(parent), Depth(Parent ? Parent->Depth+1 : 0) {
+  }
+  
+};
+    
+}  // end namespace clang
+}  // end namespace llvm
+
+#endif

Propchange: cfe/cfe/trunk/include/clang/Parse/Scope.h

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/cfe/trunk/include/clang/Parse/Scope.h

------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision





More information about the cfe-commits mailing list