[cfe-commits] r62303 - in /cfe/trunk/lib/Sema: Sema.h SemaDecl.cpp

Zhongxing Xu xuzhongxing at gmail.com
Thu Jan 15 19:34:14 PST 2009


Author: zhongxingxu
Date: Thu Jan 15 21:34:13 2009
New Revision: 62303

URL: http://llvm.org/viewvc/llvm-project?rev=62303&view=rev
Log:
Extract code dealing with typedef declarators into a separate function.

No functionality change.

Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaDecl.cpp

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

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Thu Jan 15 21:34:13 2009
@@ -277,6 +277,9 @@
   }
   DeclTy *ActOnDeclarator(Scope *S, Declarator &D, DeclTy *LastInGroup,
                           bool IsFunctionDefinition);
+  ScopedDecl* ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
+                                     QualType R, ScopedDecl* LastDeclarator,
+                                     Decl* PrevDecl, bool& InvalidDecl);
   ScopedDecl* ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
                                       QualType R, ScopedDecl* LastDeclarator,
                                       Decl* PrevDecl, bool& InvalidDecl);

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jan 15 21:34:13 2009
@@ -1287,43 +1287,8 @@
   assert(!R.isNull() && "GetTypeForDeclarator() returned null type");
 
   if (D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef) {
-    // Typedef declarators cannot be qualified (C++ [dcl.meaning]p1).
-    if (D.getCXXScopeSpec().isSet()) {
-      Diag(D.getIdentifierLoc(), diag::err_qualified_typedef_declarator)
-        << D.getCXXScopeSpec().getRange();
-      InvalidDecl = true;
-      // Pretend we didn't see the scope specifier.
-      DC = 0;
-    }
-
-    // Check that there are no default arguments (C++ only).
-    if (getLangOptions().CPlusPlus)
-      CheckExtraCXXDefaultArguments(D);
-
-    TypedefDecl *NewTD = ParseTypedefDecl(S, D, R, LastDeclarator);
-    if (!NewTD) return 0;
-
-    // Handle attributes prior to checking for duplicates in MergeVarDecl
-    ProcessDeclAttributes(NewTD, D);
-    // Merge the decl with the existing one if appropriate. If the decl is
-    // in an outer scope, it isn't the same thing.
-    if (PrevDecl && isDeclInScope(PrevDecl, DC, S)) {
-      NewTD = MergeTypeDefDecl(NewTD, PrevDecl);
-      if (NewTD == 0) return 0;
-    }
-    New = NewTD;
-    if (S->getFnParent() == 0) {
-      // C99 6.7.7p2: If a typedef name specifies a variably modified type
-      // then it shall have block scope.
-      if (NewTD->getUnderlyingType()->isVariablyModifiedType()) {
-        if (NewTD->getUnderlyingType()->isVariableArrayType())
-          Diag(D.getIdentifierLoc(), diag::err_vla_decl_in_file_scope);
-        else
-          Diag(D.getIdentifierLoc(), diag::err_vm_decl_in_file_scope);
-
-        InvalidDecl = true;
-      }
-    }
+    New = ActOnTypedefDeclarator(S, D, DC, R, LastDeclarator, PrevDecl,
+                                 InvalidDecl);
   } else if (R.getTypePtr()->isFunctionType()) {
     New = ActOnFunctionDeclarator(S, D, DC, R, LastDeclarator, PrevDecl, 
                                   IsFunctionDefinition, InvalidDecl);
@@ -1350,6 +1315,50 @@
 }
 
 ScopedDecl*
+Sema::ActOnTypedefDeclarator(Scope* S, Declarator& D, DeclContext* DC,
+                             QualType R, ScopedDecl* LastDeclarator,
+                             Decl* PrevDecl, bool& InvalidDecl) {
+  // Typedef declarators cannot be qualified (C++ [dcl.meaning]p1).
+  if (D.getCXXScopeSpec().isSet()) {
+    Diag(D.getIdentifierLoc(), diag::err_qualified_typedef_declarator)
+      << D.getCXXScopeSpec().getRange();
+    InvalidDecl = true;
+    // Pretend we didn't see the scope specifier.
+    DC = 0;
+  }
+
+  // Check that there are no default arguments (C++ only).
+  if (getLangOptions().CPlusPlus)
+    CheckExtraCXXDefaultArguments(D);
+
+  TypedefDecl *NewTD = ParseTypedefDecl(S, D, R, LastDeclarator);
+  if (!NewTD) return 0;
+
+  // Handle attributes prior to checking for duplicates in MergeVarDecl
+  ProcessDeclAttributes(NewTD, D);
+  // Merge the decl with the existing one if appropriate. If the decl is
+  // in an outer scope, it isn't the same thing.
+  if (PrevDecl && isDeclInScope(PrevDecl, DC, S)) {
+    NewTD = MergeTypeDefDecl(NewTD, PrevDecl);
+    if (NewTD == 0) return 0;
+  }
+
+  if (S->getFnParent() == 0) {
+    // C99 6.7.7p2: If a typedef name specifies a variably modified type
+    // then it shall have block scope.
+    if (NewTD->getUnderlyingType()->isVariablyModifiedType()) {
+      if (NewTD->getUnderlyingType()->isVariableArrayType())
+        Diag(D.getIdentifierLoc(), diag::err_vla_decl_in_file_scope);
+      else
+        Diag(D.getIdentifierLoc(), diag::err_vm_decl_in_file_scope);
+
+      InvalidDecl = true;
+    }
+  }
+  return NewTD;
+}
+
+ScopedDecl*
 Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC,
                               QualType R, ScopedDecl* LastDeclarator,
                               Decl* PrevDecl, bool& InvalidDecl) {





More information about the cfe-commits mailing list