[cfe-dev] can we know if an array definition has an explicit size ??

kevinlynx kevinlynx at gmail.com
Sun Jan 6 00:59:47 PST 2013


The code 

    cast<ArrayTypeLoc>(A->getTypeSourceInfo()->getTypeLoc())->getSizeExpr()is not valid in my clang version becaues getTypeLoc do not return a pointer, but 

   inline TypeLoc TypeSourceInfo::getTypeLoc() const


But by your helpful information, i can check whether an array definition has an explicit size by :

        TypeLoc loc = decl->getTypeSourceInfo()->getTypeLoc();
        if (loc.getType()->isIncompleteArrayType())  // works

On the other hand, can you explan what a `TypeSourceInfo` is ?  I check out the class comments, but still don't get the meaning. And what a `canonical` is ? Thanks a lot.



------------------ Original ------------------
From:  "Sean Silva"<silvas at purdue.edu>;
Date:  Sun, Jan 6, 2013 04:31 PM
To:  "kevinlynx"<kevinlynx at gmail.com>; 
Cc:  "cfe-dev"<cfe-dev at cs.uiuc.edu>; 
Subject:  Re: [cfe-dev] can we know if an array definition has an explicit size ??



Oh sorry, I misunderstood your question. See
<http://lists.cs.uiuc.edu/pipermail/cfe-dev/2012-August/023849.html>
for an answer to almost exactly the same question. I'm pretty sure
that the getSizeExpr() will be null if there was none written.

-- Sean Silva

On Sun, Jan 6, 2013 at 3:14 AM, kevinlynx <kevinlynx at gmail.com> wrote:
> No.
>
>     int arr[3] = { 1, 2, 3 }
>
> still get a ConstantArrayType.
>
> Actually, if there's no explict size,
> RecursiveASTVisitor::VisitIncompleteArrayType will get called, but in this
> function context, i can not get the source location (because the argument to
> VisitIncompleteArrayType is only a type, not a stmt).
>
> Thanks
>
> ------------------ Original ------------------
> From:  "Sean Silva"<silvas at purdue.edu>;
> Date:  Sun, Jan 6, 2013 04:09 PM
> To:  "kevinlynx"<kevinlynx at gmail.com>;
> Cc:  "cfe-dev"<cfe-dev at cs.uiuc.edu>;
> Subject:  Re: [cfe-dev] can we know if an array definition has an explicit
> size ??
>
> You can probably check that it is a ConstantArrayType
> <http://clang.llvm.org/doxygen/classclang_1_1ConstantArrayType.html>.
>
> -- Sean Silva
>
> On Sun, Jan 6, 2013 at 1:10 AM, kevinlynx <kevinlynx at gmail.com> wrote:
>> say,
>>
>>     int arr[] = { 1, 2, 3 }
>>
>> here `arr` size is determined by the initializer expression automatically,
>> but how to know this ? I implement `RecursiveASTVisitor::VisitVarDecl` and
>> get a `VarDecl` object.
>>
>> Thanks
>>
>>
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130106/50b3b58f/attachment.html>


More information about the cfe-dev mailing list