[cfe-commits] r39196 - in /cfe/cfe/trunk: AST/Sema.h AST/SemaDecl.cpp Driver/clang.cpp Parse/Parser.cpp Sema/Sema.h Sema/SemaDecl.cpp clang.xcodeproj/project.pbxproj include/clang/Parse/Action.h

sabre at cs.uiuc.edu sabre at cs.uiuc.edu
Wed Jul 11 09:41:00 PDT 2007


Author: sabre
Date: Wed Jul 11 11:40:59 2007
New Revision: 39196

URL: http://llvm.org/viewvc/llvm-project?rev=39196&view=rev
Log:
split the ParseFunctionDefinition action into two actions, one which is
called before and one which is called after function definition parsing.

Modified:
    cfe/cfe/trunk/AST/Sema.h
    cfe/cfe/trunk/AST/SemaDecl.cpp
    cfe/cfe/trunk/Driver/clang.cpp
    cfe/cfe/trunk/Parse/Parser.cpp
    cfe/cfe/trunk/Sema/Sema.h
    cfe/cfe/trunk/Sema/SemaDecl.cpp
    cfe/cfe/trunk/clang.xcodeproj/project.pbxproj
    cfe/cfe/trunk/include/clang/Parse/Action.h

Modified: cfe/cfe/trunk/AST/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/Sema.h?rev=39196&r1=39195&r2=39196&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/Sema.h (original)
+++ cfe/cfe/trunk/AST/Sema.h Wed Jul 11 11:40:59 2007
@@ -26,11 +26,16 @@
   class Decl;
   class TypeRef;
   class LangOptions;
+  class FunctionDecl;
   
 /// Sema - This implements semantic analysis and AST building for C.
 class Sema : public Action {
   ASTContext &Context;
   
+  /// CurFunctionDecl - If inside of a function body, this contains a pointer to
+  /// the function decl for the function being parsed.
+  FunctionDecl *CurFunctionDecl;
+  
   /// LastInGroupList - This vector is populated when there are multiple
   /// declarators in a single decl group (e.g. "int A, B, C").  In this case,
   /// all but the last decl will be entered into this.  This is used by the
@@ -38,7 +43,7 @@
   std::vector<Decl*> &LastInGroupList;
 public:
   Sema(ASTContext &ctx, std::vector<Decl*> &prevInGroup)
-    : Context(ctx), LastInGroupList(prevInGroup) {
+    : Context(ctx), CurFunctionDecl(0), LastInGroupList(prevInGroup) {
   }
   
   const LangOptions &getLangOptions() const;
@@ -59,8 +64,9 @@
   virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const;
   virtual DeclTy *ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
                                   DeclTy *LastInGroup);
-  virtual DeclTy *ParseFunctionDefinition(Scope *S, Declarator &D,
-                                          StmtTy *Body);
+  virtual DeclTy *ParseStartOfFunctionDef(Scope *S, Declarator &D
+                                          /* TODO: FORMAL ARG INFO.*/);
+  virtual DeclTy *ParseFunctionDefBody(DeclTy *Decl, StmtTy *Body);
   virtual void PopScope(SourceLocation Loc, Scope *S);
   
   Decl *ParseTypedefDecl(Scope *S, Declarator &D, Decl *PrevDecl);

Modified: cfe/cfe/trunk/AST/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaDecl.cpp?rev=39196&r1=39195&r2=39196&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/AST/SemaDecl.cpp Wed Jul 11 11:40:59 2007
@@ -33,13 +33,13 @@
     Decl *D = II.getFETokenInfo<Decl>();
     assert(D && "This decl didn't get pushed??");
     
-    Decl *Next = D->getNext();
+    II.setFETokenInfo(D->getNext());
     
     // FIXME: Push the decl on the parent function list if in a function.
     // FIXME: Don't delete the decl when it gets popped!
-    delete D;
+    // delete D;
+    
     
-    II.setFETokenInfo(Next);
   }
 }
 
@@ -96,15 +96,26 @@
 }
 
 
-Sema::DeclTy *
-Sema::ParseFunctionDefinition(Scope *S, Declarator &D, StmtTy *Body) {
-  FunctionDecl *FD = (FunctionDecl *)ParseDeclarator(S, D, 0, 0);
+
+Sema::DeclTy *Sema::ParseStartOfFunctionDef(Scope *S, Declarator &D
+                                            /* TODO: FORMAL ARG INFO.*/) {
+  assert(CurFunctionDecl == 0 && "Function parsing confused");
   
+  FunctionDecl *FD = static_cast<FunctionDecl*>(ParseDeclarator(S, D, 0, 0));
+  CurFunctionDecl = FD;
+  return FD;
+}
+
+Sema::DeclTy *Sema::ParseFunctionDefBody(DeclTy *D, StmtTy *Body) {
+  FunctionDecl *FD = static_cast<FunctionDecl*>(D);
   FD->setBody((Stmt*)Body);
   
+  assert(FD == CurFunctionDecl && "Function parsing confused");
+  CurFunctionDecl = 0;
   return FD;
 }
 
+
 /// ImplicitlyDefineFunction - An undeclared identifier was used in a function
 /// call, forming a call to an implicitly defined function (per C99 6.5.1p2).
 Decl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,

Modified: cfe/cfe/trunk/Driver/clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Driver/clang.cpp?rev=39196&r1=39195&r2=39196&view=diff

==============================================================================
--- cfe/cfe/trunk/Driver/clang.cpp (original)
+++ cfe/cfe/trunk/Driver/clang.cpp Wed Jul 11 11:40:59 2007
@@ -211,6 +211,7 @@
 LangStd("std", cl::desc("Language standard to compile for"),
         cl::init(lang_unspecified),
         cl::values(clEnumValN(lang_c89,      "c89",            "ISO C 1990"),
+                   clEnumValN(lang_c89,      "c90",            "ISO C 1990"),
                    clEnumValN(lang_c89,      "iso9899:1990",   "ISO C 1990"),
                    clEnumValN(lang_c94,      "iso9899:199409",
                               "ISO C 1990 with amendment 1"),

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

==============================================================================
--- cfe/cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/cfe/trunk/Parse/Parser.cpp Wed Jul 11 11:40:59 2007
@@ -399,6 +399,8 @@
   assert(FnTypeInfo.Kind == DeclaratorTypeInfo::Function &&
          "This isn't a function declarator!");
 
+  DeclTy *Res = Actions.ParseStartOfFunctionDef(CurScope, D);
+  
   // FIXME: Enter a scope for the arguments.
   //EnterScope(Scope::FnScope);
   
@@ -440,7 +442,7 @@
   // ExitScope();
 
   // TODO: Pass argument information.
-  return Actions.ParseFunctionDefinition(CurScope, D, FnBody.Val);
+  return Actions.ParseFunctionDefBody(Res, FnBody.Val);
 }
 
 /// ParseAsmStringLiteral - This is just a normal string-literal, but is not

Modified: cfe/cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/Sema.h?rev=39196&r1=39195&r2=39196&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/Sema.h (original)
+++ cfe/cfe/trunk/Sema/Sema.h Wed Jul 11 11:40:59 2007
@@ -26,11 +26,16 @@
   class Decl;
   class TypeRef;
   class LangOptions;
+  class FunctionDecl;
   
 /// Sema - This implements semantic analysis and AST building for C.
 class Sema : public Action {
   ASTContext &Context;
   
+  /// CurFunctionDecl - If inside of a function body, this contains a pointer to
+  /// the function decl for the function being parsed.
+  FunctionDecl *CurFunctionDecl;
+  
   /// LastInGroupList - This vector is populated when there are multiple
   /// declarators in a single decl group (e.g. "int A, B, C").  In this case,
   /// all but the last decl will be entered into this.  This is used by the
@@ -38,7 +43,7 @@
   std::vector<Decl*> &LastInGroupList;
 public:
   Sema(ASTContext &ctx, std::vector<Decl*> &prevInGroup)
-    : Context(ctx), LastInGroupList(prevInGroup) {
+    : Context(ctx), CurFunctionDecl(0), LastInGroupList(prevInGroup) {
   }
   
   const LangOptions &getLangOptions() const;
@@ -59,8 +64,9 @@
   virtual DeclTy *isTypeName(const IdentifierInfo &II, Scope *S) const;
   virtual DeclTy *ParseDeclarator(Scope *S, Declarator &D, ExprTy *Init,
                                   DeclTy *LastInGroup);
-  virtual DeclTy *ParseFunctionDefinition(Scope *S, Declarator &D,
-                                          StmtTy *Body);
+  virtual DeclTy *ParseStartOfFunctionDef(Scope *S, Declarator &D
+                                          /* TODO: FORMAL ARG INFO.*/);
+  virtual DeclTy *ParseFunctionDefBody(DeclTy *Decl, StmtTy *Body);
   virtual void PopScope(SourceLocation Loc, Scope *S);
   
   Decl *ParseTypedefDecl(Scope *S, Declarator &D, Decl *PrevDecl);

Modified: cfe/cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaDecl.cpp?rev=39196&r1=39195&r2=39196&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaDecl.cpp Wed Jul 11 11:40:59 2007
@@ -33,13 +33,13 @@
     Decl *D = II.getFETokenInfo<Decl>();
     assert(D && "This decl didn't get pushed??");
     
-    Decl *Next = D->getNext();
+    II.setFETokenInfo(D->getNext());
     
     // FIXME: Push the decl on the parent function list if in a function.
     // FIXME: Don't delete the decl when it gets popped!
-    delete D;
+    // delete D;
+    
     
-    II.setFETokenInfo(Next);
   }
 }
 
@@ -96,15 +96,26 @@
 }
 
 
-Sema::DeclTy *
-Sema::ParseFunctionDefinition(Scope *S, Declarator &D, StmtTy *Body) {
-  FunctionDecl *FD = (FunctionDecl *)ParseDeclarator(S, D, 0, 0);
+
+Sema::DeclTy *Sema::ParseStartOfFunctionDef(Scope *S, Declarator &D
+                                            /* TODO: FORMAL ARG INFO.*/) {
+  assert(CurFunctionDecl == 0 && "Function parsing confused");
   
+  FunctionDecl *FD = static_cast<FunctionDecl*>(ParseDeclarator(S, D, 0, 0));
+  CurFunctionDecl = FD;
+  return FD;
+}
+
+Sema::DeclTy *Sema::ParseFunctionDefBody(DeclTy *D, StmtTy *Body) {
+  FunctionDecl *FD = static_cast<FunctionDecl*>(D);
   FD->setBody((Stmt*)Body);
   
+  assert(FD == CurFunctionDecl && "Function parsing confused");
+  CurFunctionDecl = 0;
   return FD;
 }
 
+
 /// ImplicitlyDefineFunction - An undeclared identifier was used in a function
 /// call, forming a call to an implicitly defined function (per C99 6.5.1p2).
 Decl *Sema::ImplicitlyDefineFunction(SourceLocation Loc, IdentifierInfo &II,

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

==============================================================================
--- cfe/cfe/trunk/clang.xcodeproj/project.pbxproj (original)
+++ cfe/cfe/trunk/clang.xcodeproj/project.pbxproj Wed Jul 11 11:40:59 2007
@@ -138,7 +138,7 @@
 /* End PBXCopyFilesBuildPhase section */
 
 /* Begin PBXFileReference section */
-		8DD76F6C0486A84900D96B5E /* clang */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = clang; sourceTree = BUILT_PRODUCTS_DIR; };
+		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>"; };
 		DE06BECA0A854E4B0050E87E /* Scope.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = Scope.h; path = clang/Parse/Scope.h; sourceTree = "<group>"; };
 		DE06D42F0A8BB52D0050E87E /* Parser.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = Parser.cpp; path = Parse/Parser.cpp; sourceTree = "<group>"; };

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

==============================================================================
--- cfe/cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/cfe/trunk/include/clang/Parse/Action.h Wed Jul 11 11:40:59 2007
@@ -97,15 +97,21 @@
     return 0;
   }
 
-  /// ParseFunctionDefinition - This is called when a function definition is
-  /// parsed.  The declarator that is part of this is not passed to
-  /// ParseDeclarator.
-  virtual DeclTy *ParseFunctionDefinition(Scope *S, Declarator &D,
-                                          // TODO: FORMAL ARG INFO.
-                                          StmtTy *Body) {
-    return 0;
+  /// ParseStartOfFunctionDef - This is called at the start of a function
+  /// definition, instead of calling ParseDeclarator.
+  virtual DeclTy *ParseStartOfFunctionDef(Scope *S, Declarator &D
+                                          /* TODO: FORMAL ARG INFO.*/) {
+    // Default to ParseDeclarator.
+    return ParseDeclarator(S, D, 0, 0);
+  }
+
+  /// ParseFunctionDefBody - This is called when a function body has completed
+  /// parsing.  Decl is the DeclTy returned by ParseStartOfFunctionDef.
+  virtual DeclTy *ParseFunctionDefBody(DeclTy *Decl, StmtTy *Body) {
+    return Decl;
   }
 
+  
   /// PopScope - This callback is called immediately before the specified scope
   /// is popped and deleted.
   virtual void PopScope(SourceLocation Loc, Scope *S) {}





More information about the cfe-commits mailing list