[cfe-commits] r73641 - in /cfe/trunk: include/clang/AST/ASTContext.h include/clang/AST/Type.h include/clang/AST/TypeNodes.def lib/AST/ASTContext.cpp lib/AST/Type.cpp lib/Sema/Sema.h lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaDeclObjC.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaTemplate.cpp lib/Sema/SemaTemplateDeduction.cpp lib/Sema/SemaTemplateInstantiate.cpp lib/Sema/SemaType.cpp test/SemaTemplate/ext-vector-type.cpp

Douglas Gregor dgregor at apple.com
Thu Jun 18 15:08:15 PDT 2009


On Jun 17, 2009, at 5:28 PM, Chris Lattner wrote:

> On Jun 17, 2009, at 2:52 PM, Douglas Gregor wrote:
>> URL: http://llvm.org/viewvc/llvm-project?rev=73641&view=rev
>> Log:
>> Support dependent extended vector types and template instantiation
>> thereof. Patch by Anders Johnsen!
>
> Very cool!  This is a big enough feature that we should probably  
> mention this in the user's manual, this is incredibly useful for  
> vector programming.

Once we can deduce the length of a vector as part of template argument  
deduction, it will become incredibly useful. We're not quite there yet.

>
> +  /// getDependentSizedExtVectorType - Returns a non-unique  
> reference to
> +  /// the type for a dependently-sized vector of the specified  
> element
> +  /// type. FIXME: We will need these to be uniqued, or at least
> +  /// comparable, at some point.
> +  QualType getDependentSizedExtVectorType(QualType VectorType,
> +                                          Expr *SizeExpr,
> +                                          SourceLocation AttrLoc);
>
> If this includes a Loc, uniquing will never reuse a type.  Is there  
> really any reason to unique these?

Yeah, we'll need it for matching partial specializations, function  
templates, and out-of-line function definitions.

>> +++ cfe/trunk/include/clang/AST/Type.h Wed Jun 17 16:51:59 2009
>> @@ -992,6 +992,41 @@
>>
>> +/// DependentSizedExtVectorType - This type represent an ext  
>> vectory type
>
> "This type represents an extended vector type..."

Missed that; fixed.

>> +class DependentSizedExtVectorType : public Type {
>> +  Expr *SizeExpr;
>> +  /// ElementType - The element type of the array.
>> +  QualType ElementType;
>> +  SourceLocation loc;
>> +
>> +  DependentSizedExtVectorType(QualType ElementType, QualType can,
>> +                              Expr *SizeExpr, SourceLocation loc)
>> +    : Type (DependentSizedExtVector, can, true),
>> +    SizeExpr(SizeExpr), ElementType(ElementType), loc(loc) {}
>> +  friend class ASTContext;
>> +  virtual void Destroy(ASTContext& C);
>> +
>> +public:
>> +  Expr *getSizeExpr() const { return SizeExpr; }
>
> This should return a const Expr*.

Sure.

>> @@ -1356,6 +1363,19 @@
>>  getElementType().getAsStringInternal(S, Policy);
>> }
>>
>> +void DependentSizedExtVectorType::getAsStringInternal(std::string  
>> &S, const PrintingPolicy &Policy) const {
>> +  getElementType().getAsStringInternal(S, Policy);
>> +
>> +  S += " __attribute__((ext_vector_  type(";
>
> "  " typo?

Fixed.

>> +++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Wed Jun 17  
>> 16:51:59 2009
>> @@ -802,6 +802,14 @@
>>                                  Deduced);
>>    break;
>>
>> +  case Type::DependentSizedExtVector: {
>> +    const DependentSizedExtVectorType *VecType
>> +    = cast<DependentSizedExtVectorType>(T.getTypePtr());
>
> You shouldn't need ".getTypePtr()" here.  It looks like this file  
> has the same issue in many places.

What isa/cast/dyn_cast devilry is this, and how did I go so long  
without realizing it?

I'll clean these up as I see them.

>> +++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Wed Jun 17  
>> 16:51:59 2009
>> @@ -431,6 +431,32 @@
>> }
>>
>> QualType
>> +TemplateTypeInstantiator::
>> +InstantiateDependentSizedExtVectorType(const  
>> DependentSizedExtVectorType *T,
>> +                                   unsigned Quals) const {
>> +
>> +  // Instantiate the element type if needed
>
> Please end sentence comments with proper punctuation ("." in this  
> case).
>>
>> +
>> +  // Instantiate the size expression
>
> likewise.

Both fixed.

Thanks!

	- Doug



More information about the cfe-commits mailing list