[cfe-commits] r73821 - in /cfe/trunk: include/clang/AST/Decl.h include/clang/AST/DeclBase.h lib/AST/Decl.cpp
Argyrios Kyrtzidis
kyrtzidis at apple.com
Mon Jun 22 10:18:29 PDT 2009
On Jun 22, 2009, at 9:37 AM, Douglas Gregor wrote:
>
>>
>> +void FunctionDecl::setBody(Stmt *B) {
>> + Body = B;
>> + if (B && EndRangeLoc < B->getLocEnd())
>> + EndRangeLoc = B->getLocEnd();
>> +}
>
> Why do we need this < check? The body of the function definition will
> always have an end location later in the file than the last function
> parameter.
Yep, this is redundant, no matter what value EndRangeLoc had before,
it should be updated here. I removed the check.
>
> I was about to point out that EndRangeLoc is unnecessary, because we
> could compute the full range in getSourceRange(). However, when we're
> dealing with a function definition deserialized from a PCH/AST file,
> we can only compute the full range once the function body has been de-
> serialized... so it's far better to have the (sometimes-redundant)
> EndRangeLoc. Please add a comment to that effect.
Done.
>
>> bool FunctionDecl::isMain() const {
>> return getDeclContext()->getLookupContext()->isTranslationUnit() &&
>> getIdentifier() && getIdentifier()->isStr("main");
>> @@ -481,6 +493,10 @@
>> void *Mem = C.Allocate(sizeof(ParmVarDecl*)*NumParams);
>> ParamInfo = new (Mem) ParmVarDecl*[NumParams];
>> memcpy(ParamInfo, NewParamInfo, sizeof(ParmVarDecl*)*NumParams);
>> +
>> + // Update source range.
>> + if (EndRangeLoc < NewParamInfo[NumParams-1]->getLocEnd())
>> + EndRangeLoc = NewParamInfo[NumParams-1]->getLocEnd();
>> }
>> }
>
>
> I don't think we need to use the < here.
This is to allow the flexibility to set EndRangeLoc before setting the
parameters.
i.e. at PCHDeclReader::VisitFunctionDecl, EndRangeLoc is set before
the setParams() call. If the check was missing we would have to be
careful about the exact order of the calls to "reconstruct" the
FunctionDecl.
-Argiris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20090622/bedac327/attachment.html>
More information about the cfe-commits
mailing list