]> granicus.if.org Git - clang/commitdiff
Extract code dealing with typedef declarators into a separate function.
authorZhongxing Xu <xuzhongxing@gmail.com>
Fri, 16 Jan 2009 03:34:13 +0000 (03:34 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Fri, 16 Jan 2009 03:34:13 +0000 (03:34 +0000)
No functionality change.

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

lib/Sema/Sema.h
lib/Sema/SemaDecl.cpp

index aabc9c17cbadbaf1d8fc87f8009c3d5377ec6097..9bfa1ffefc1ab8d5a41ed473e5d6bd6b56d1bb67 100644 (file)
@@ -277,6 +277,9 @@ public:
   }
   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);
index a7ebd810d80b0981ae68b09ced177e4d59ba9e40..0927576b5166d5f8b880548556fc030649bc060b 100644 (file)
@@ -1287,43 +1287,8 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl,
   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);
@@ -1349,6 +1314,50 @@ Sema::ActOnDeclarator(Scope *S, Declarator &D, DeclTy *lastDecl,
   return New;
 }
 
+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,