]> granicus.if.org Git - clang/commitdiff
simplify Sema::getTypeName a bit: if control gets out of the switch,
authorChris Lattner <sabre@nondot.org>
Sun, 25 Oct 2009 17:16:46 +0000 (17:16 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 25 Oct 2009 17:16:46 +0000 (17:16 +0000)
IIDecl cannot be null.  There is no need to check for both C++ mode and
presence of CXXRecordDecl.  ObjC interfaces can't have ScopeSpecs.

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

lib/Parse/ParseExpr.cpp
lib/Sema/SemaDecl.cpp

index 8ebb7c01d85ff37b952fa239eadb7cd1f341fd98..477e6fb005a93144642f7311a0905cfcc3b923f1 100644 (file)
@@ -345,7 +345,7 @@ Parser::ParseRHSOfBinaryExpression(OwningExprResult LHS, unsigned MinPrec) {
          && Tok.is(tok::identifier)) {
       CXXScopeSpec SS;
       if (Actions.getTypeName(*Tok.getIdentifierInfo(),
-                                           Tok.getLocation(), CurScope, &SS)) {
+                              Tok.getLocation(), CurScope, &SS)) {
         const char *Opc = OpToken.is(tok::periodstar) ? "'.*'" : "'->*'";
         Diag(OpToken, diag::err_pointer_to_member_type) << Opc;
         return ExprError();
index 4858321d51edec222953306e7738339e3ac48b10..d9da254588020b8c8a3a8b7fca98549fa91ee68b 100644 (file)
@@ -138,44 +138,40 @@ Sema::TypeTy *Sema::getTypeName(IdentifierInfo &II, SourceLocation NameLoc,
     break;
   }
 
-  if (IIDecl) {
-    QualType T;
-
-    if (TypeDecl *TD = dyn_cast<TypeDecl>(IIDecl)) {
-      // Check whether we can use this type.
-      (void)DiagnoseUseOfDecl(IIDecl, NameLoc);
-
-      if (getLangOptions().CPlusPlus) {
-        // C++ [temp.local]p2:
-        //   Within the scope of a class template specialization or
-        //   partial specialization, when the injected-class-name is
-        //   not followed by a <, it is equivalent to the
-        //   injected-class-name followed by the template-argument s
-        //   of the class template specialization or partial
-        //   specialization enclosed in <>.
-        if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(TD))
-          if (RD->isInjectedClassName())
-            if (ClassTemplateDecl *Template = RD->getDescribedClassTemplate())
-              T = Template->getInjectedClassNameType(Context);
-      }
-
-      if (T.isNull())
-        T = Context.getTypeDeclType(TD);
-    } else if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(IIDecl)) {
-      // Check whether we can use this interface.
-      (void)DiagnoseUseOfDecl(IIDecl, NameLoc);
-
-      T = Context.getObjCInterfaceType(IDecl);
-    } else
-      return 0;
-
+  assert(IIDecl && "Didn't find decl");
+  
+  QualType T;
+  if (TypeDecl *TD = dyn_cast<TypeDecl>(IIDecl)) {
+    // Check whether we can use this type.
+    (void)DiagnoseUseOfDecl(IIDecl, NameLoc);
+
+    // C++ [temp.local]p2:
+    //   Within the scope of a class template specialization or
+    //   partial specialization, when the injected-class-name is
+    //   not followed by a <, it is equivalent to the
+    //   injected-class-name followed by the template-argument s
+    //   of the class template specialization or partial
+    //   specialization enclosed in <>.
+    if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(TD))
+      if (RD->isInjectedClassName())
+        if (ClassTemplateDecl *Template = RD->getDescribedClassTemplate())
+          T = Template->getInjectedClassNameType(Context);
+
+    if (T.isNull())
+      T = Context.getTypeDeclType(TD);
+    
     if (SS)
       T = getQualifiedNameType(*SS, T);
+    
+  } else if (ObjCInterfaceDecl *IDecl = dyn_cast<ObjCInterfaceDecl>(IIDecl)) {
+    // Check whether we can use this interface.
+    (void)DiagnoseUseOfDecl(IIDecl, NameLoc);
 
-    return T.getAsOpaquePtr();
-  }
+    T = Context.getObjCInterfaceType(IDecl);
+  } else
+    return 0;
 
-  return 0;
+  return T.getAsOpaquePtr();
 }
 
 /// isTagName() - This method is called *for error recovery purposes only*