[cfe-commits] r40584 - in /cfe/trunk: AST/Expr.cpp Sema/SemaExpr.cpp include/clang/AST/Expr.h include/clang/Basic/DiagnosticKinds.def test/Parser/ocu_vector_components.c

Steve Naroff snaroff at apple.com
Sun Jul 29 20:29:10 PDT 2007


Author: snaroff
Date: Sun Jul 29 22:29:09 2007
New Revision: 40584

URL: http://llvm.org/viewvc/llvm-project?rev=40584&view=rev
Log:
Finish up semantic analysis for vector components.

Modified:
    cfe/trunk/AST/Expr.cpp
    cfe/trunk/Sema/SemaExpr.cpp
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/include/clang/Basic/DiagnosticKinds.def
    cfe/trunk/test/Parser/ocu_vector_components.c

Modified: cfe/trunk/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Expr.cpp?rev=40584&r1=40583&r2=40584&view=diff

==============================================================================
--- cfe/trunk/AST/Expr.cpp (original)
+++ cfe/trunk/AST/Expr.cpp Sun Jul 29 22:29:09 2007
@@ -226,6 +226,10 @@
     break;
   case ParenExprClass: // C99 6.5.1p5
     return cast<ParenExpr>(this)->getSubExpr()->isLvalue();
+  case OCUVectorComponentClass:
+    if (cast<OCUVectorComponent>(this)->containsDuplicateComponents())
+      return LV_DuplicateVectorComponents;
+    return LV_Valid;
   default:
     break;
   }
@@ -244,6 +248,7 @@
   case LV_Valid: break;
   case LV_NotObjectType: return MLV_NotObjectType;
   case LV_IncompleteVoidType: return MLV_IncompleteVoidType;
+  case LV_DuplicateVectorComponents: return MLV_DuplicateVectorComponents;
   case LV_InvalidExpression: return MLV_InvalidExpression;
   }
   if (TR.isConstQualified())
@@ -581,3 +586,16 @@
   if (VT->isTextureAccessor(*compStr)) return Texture;
   assert(0 && "getComponentType(): Illegal accessor");
 }
+
+bool OCUVectorComponent::containsDuplicateComponents() const {
+  const char *compStr = Accessor.getName();
+  unsigned length = strlen(compStr);
+  
+  for (unsigned i = 0; i < length-1; i++) {
+    const char *s = compStr+i;
+    for (const char c = *s++; *s; s++)
+      if (c == *s) 
+        return true;
+  }
+  return false;
+}

Modified: cfe/trunk/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaExpr.cpp?rev=40584&r1=40583&r2=40584&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/Sema/SemaExpr.cpp Sun Jul 29 22:29:09 2007
@@ -1136,6 +1136,10 @@
       Diag(loc, diag::err_typecheck_incomplete_type_not_modifiable_lvalue,
            lhsType.getAsString(), lex->getSourceRange());
       return QualType();
+    case Expr::MLV_DuplicateVectorComponents:
+      Diag(loc, diag::err_typecheck_duplicate_vector_components_not_mlvalue,
+           lex->getSourceRange());
+      return QualType();
   }
   AssignmentCheckResult result;
   

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=40584&r1=40583&r2=40584&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sun Jul 29 22:29:09 2007
@@ -67,6 +67,7 @@
     LV_Valid,
     LV_NotObjectType,
     LV_IncompleteVoidType,
+    LV_DuplicateVectorComponents,
     LV_InvalidExpression
   };
   isLvalueResult isLvalue() const;
@@ -80,6 +81,7 @@
     MLV_Valid,
     MLV_NotObjectType,
     MLV_IncompleteVoidType,
+    MLV_DuplicateVectorComponents,
     MLV_InvalidExpression,
     MLV_IncompleteType,
     MLV_ConstQualified,
@@ -464,17 +466,15 @@
 /// OCUVectorComponent
 ///
 class OCUVectorComponent : public Expr {
+  Expr *Base;
+  IdentifierInfo &Accessor;
+  SourceLocation AccessorLoc;
 public:
   enum ComponentType {
     Point,
     Color,
     Texture
   };
-private:
-  Expr *Base;
-  IdentifierInfo &Accessor;
-  SourceLocation AccessorLoc;
-public:
   OCUVectorComponent(QualType ty, Expr *base, IdentifierInfo &accessor,
                      SourceLocation loc) : Expr(OCUVectorComponentClass, ty), 
                      Base(base), Accessor(accessor), AccessorLoc(loc) {}
@@ -483,6 +483,8 @@
   IdentifierInfo & getAccessor() const { return Accessor; }
   ComponentType getComponentType() const;
 
+  bool containsDuplicateComponents() const;
+  
   virtual SourceRange getSourceRange() const {
     return SourceRange(getBase()->getLocStart(), AccessorLoc);
   }

Modified: cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=40584&r1=40583&r2=40584&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticKinds.def Sun Jul 29 22:29:09 2007
@@ -628,6 +628,8 @@
      "expression is not assignable")
 DIAG(err_typecheck_incomplete_type_not_modifiable_lvalue, ERROR,
      "incomplete type '%0' is not assignable")
+DIAG(err_typecheck_duplicate_vector_components_not_mlvalue, ERROR,
+     "vector is not assignable (contains duplicate components)")
 DIAG(err_typecheck_call_not_function, ERROR,
      "called object is not a function or function pointer")
 DIAG(err_typecheck_call_too_few_args, ERROR,

Modified: cfe/trunk/test/Parser/ocu_vector_components.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/ocu_vector_components.c?rev=40584&r1=40583&r2=40584&view=diff

==============================================================================
--- cfe/trunk/test/Parser/ocu_vector_components.c (original)
+++ cfe/trunk/test/Parser/ocu_vector_components.c Sun Jul 29 22:29:09 2007
@@ -5,16 +5,23 @@
 typedef __attribute__(( ocu_vector_type(4) )) float float4;
 
 static void test() {
-    float2 vec2;
+    float2 vec2, vec2_2;
     float3 vec3;
-    float4 vec4;
+    float4 vec4, vec4_2;
     float f;
 
-    vec2.z; // // expected-error {{vector component access exceeds type 'float2'}}
-    vec2.rgba; // // expected-error {{vector component access exceeds type 'float2'}}
-    vec4.rgba;
-    vec4.rgbc; // // expected-error {{illegal vector component name 'c'}}
+    vec2.z; // expected-error {{vector component access exceeds type 'float2'}}
+    vec2.rgba; // expected-error {{vector component access exceeds type 'float2'}}
+    vec4.rgba; // expected-warning {{expression result unused}}
+    vec4.rgbc; // expected-error {{illegal vector component name 'c'}}
     vec3 = vec4.rgb; // legal, shorten
     f = vec2.x; // legal, shorten
+    
+    vec4_2.rgbr = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+    vec4_2.rgbb = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+    vec4_2.rgga = vec4.rgba; // expected-error {{vector is not assignable (contains duplicate components)}}
+    vec2.x = f;
+    vec2.xx = vec2_2.xy; // expected-error {{vector is not assignable (contains duplicate components)}}
+    vec2.yx = vec2_2.xy;
     vec4 = (float4){ 1,2,3,4 };
 }





More information about the cfe-commits mailing list