Fixed FunctionTypeLoc range for trailing return type.
llvm-svn: 165974
This commit is contained in:
parent
bbd469bef3
commit
2fc03caee8
|
@ -98,64 +98,27 @@ void TypeLoc::initializeImpl(ASTContext &Context, TypeLoc TL,
|
||||||
|
|
||||||
SourceLocation TypeLoc::getBeginLoc() const {
|
SourceLocation TypeLoc::getBeginLoc() const {
|
||||||
TypeLoc Cur = *this;
|
TypeLoc Cur = *this;
|
||||||
SourceLocation SavedParenLoc;
|
|
||||||
while (true) {
|
while (true) {
|
||||||
switch (Cur.getTypeLocClass()) {
|
switch (Cur.getTypeLocClass()) {
|
||||||
// FIXME: Currently QualifiedTypeLoc does not have a source range
|
|
||||||
// case Qualified:
|
|
||||||
case Elaborated:
|
|
||||||
case DependentName:
|
|
||||||
case DependentTemplateSpecialization:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Paren:
|
|
||||||
// Save local source begin, if still unset.
|
|
||||||
if (SavedParenLoc.isInvalid())
|
|
||||||
SavedParenLoc = Cur.getLocalSourceRange().getBegin();
|
|
||||||
Cur = Cur.getNextTypeLoc();
|
|
||||||
assert(!Cur.isNull());
|
|
||||||
continue;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Pointer:
|
|
||||||
case BlockPointer:
|
|
||||||
case MemberPointer:
|
|
||||||
case ObjCObjectPointer:
|
|
||||||
case LValueReference:
|
|
||||||
case RValueReference:
|
|
||||||
case ConstantArray:
|
|
||||||
case DependentSizedArray:
|
|
||||||
case IncompleteArray:
|
|
||||||
case VariableArray:
|
|
||||||
case FunctionNoProto:
|
|
||||||
// Discard previously saved paren loc, if any.
|
|
||||||
SavedParenLoc = SourceLocation();
|
|
||||||
Cur = Cur.getNextTypeLoc();
|
|
||||||
assert(!Cur.isNull());
|
|
||||||
continue;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FunctionProto:
|
case FunctionProto:
|
||||||
// Discard previously saved paren loc, if any.
|
|
||||||
SavedParenLoc = SourceLocation();
|
|
||||||
if (cast<FunctionProtoTypeLoc>(&Cur)->getTypePtr()->hasTrailingReturn())
|
if (cast<FunctionProtoTypeLoc>(&Cur)->getTypePtr()->hasTrailingReturn())
|
||||||
return Cur.getLocalSourceRange().getBegin();
|
return Cur.getLocalSourceRange().getBegin();
|
||||||
Cur = Cur.getNextTypeLoc();
|
Cur = Cur.getNextTypeLoc();
|
||||||
assert(!Cur.isNull());
|
assert(!Cur.isNull());
|
||||||
continue;
|
continue;
|
||||||
break;
|
|
||||||
|
// FIXME: Currently QualifiedTypeLoc does not have a source range
|
||||||
|
// case Qualified:
|
||||||
|
case Elaborated:
|
||||||
|
return Cur.getLocalSourceRange().getBegin();
|
||||||
|
|
||||||
default:
|
default:
|
||||||
TypeLoc Next = Cur.getNextTypeLoc();
|
if (Cur.getNextTypeLoc().isNull())
|
||||||
if (Next.isNull()) break;
|
return Cur.getLocalSourceRange().getBegin();
|
||||||
Cur = Next;
|
Cur = Cur.getNextTypeLoc();
|
||||||
continue;
|
continue;
|
||||||
}
|
} // switch
|
||||||
break;
|
} // while
|
||||||
}
|
|
||||||
return SavedParenLoc.isValid()
|
|
||||||
? SavedParenLoc
|
|
||||||
: Cur.getLocalSourceRange().getBegin();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SourceLocation TypeLoc::getEndLoc() const {
|
SourceLocation TypeLoc::getEndLoc() const {
|
||||||
|
|
|
@ -4582,7 +4582,10 @@ void Parser::ParseFunctionDeclarator(Declarator &D,
|
||||||
|
|
||||||
Actions.ActOnStartFunctionDeclarator();
|
Actions.ActOnStartFunctionDeclarator();
|
||||||
|
|
||||||
SourceLocation StartLoc, EndLoc;
|
/* LocalEndLoc is the end location for the local FunctionTypeLoc.
|
||||||
|
EndLoc is the end location for the function declarator.
|
||||||
|
They differ for trailing return types. */
|
||||||
|
SourceLocation StartLoc, LocalEndLoc, EndLoc;
|
||||||
SourceLocation LParenLoc, RParenLoc;
|
SourceLocation LParenLoc, RParenLoc;
|
||||||
LParenLoc = Tracker.getOpenLocation();
|
LParenLoc = Tracker.getOpenLocation();
|
||||||
StartLoc = LParenLoc;
|
StartLoc = LParenLoc;
|
||||||
|
@ -4595,6 +4598,7 @@ void Parser::ParseFunctionDeclarator(Declarator &D,
|
||||||
|
|
||||||
Tracker.consumeClose();
|
Tracker.consumeClose();
|
||||||
RParenLoc = Tracker.getCloseLocation();
|
RParenLoc = Tracker.getCloseLocation();
|
||||||
|
LocalEndLoc = RParenLoc;
|
||||||
EndLoc = RParenLoc;
|
EndLoc = RParenLoc;
|
||||||
} else {
|
} else {
|
||||||
if (Tok.isNot(tok::r_paren))
|
if (Tok.isNot(tok::r_paren))
|
||||||
|
@ -4607,6 +4611,7 @@ void Parser::ParseFunctionDeclarator(Declarator &D,
|
||||||
// If we have the closing ')', eat it.
|
// If we have the closing ')', eat it.
|
||||||
Tracker.consumeClose();
|
Tracker.consumeClose();
|
||||||
RParenLoc = Tracker.getCloseLocation();
|
RParenLoc = Tracker.getCloseLocation();
|
||||||
|
LocalEndLoc = RParenLoc;
|
||||||
EndLoc = RParenLoc;
|
EndLoc = RParenLoc;
|
||||||
|
|
||||||
if (getLangOpts().CPlusPlus) {
|
if (getLangOpts().CPlusPlus) {
|
||||||
|
@ -4663,13 +4668,15 @@ void Parser::ParseFunctionDeclarator(Declarator &D,
|
||||||
MaybeParseCXX0XAttributes(FnAttrs);
|
MaybeParseCXX0XAttributes(FnAttrs);
|
||||||
|
|
||||||
// Parse trailing-return-type[opt].
|
// Parse trailing-return-type[opt].
|
||||||
|
LocalEndLoc = EndLoc;
|
||||||
if (getLangOpts().CPlusPlus0x && Tok.is(tok::arrow)) {
|
if (getLangOpts().CPlusPlus0x && Tok.is(tok::arrow)) {
|
||||||
Diag(Tok, diag::warn_cxx98_compat_trailing_return_type);
|
Diag(Tok, diag::warn_cxx98_compat_trailing_return_type);
|
||||||
if (D.getDeclSpec().getTypeSpecType() == TST_auto)
|
if (D.getDeclSpec().getTypeSpecType() == TST_auto)
|
||||||
StartLoc = D.getDeclSpec().getTypeSpecTypeLoc();
|
StartLoc = D.getDeclSpec().getTypeSpecTypeLoc();
|
||||||
EndLoc = Tok.getLocation();
|
LocalEndLoc = Tok.getLocation();
|
||||||
SourceRange Range;
|
SourceRange Range;
|
||||||
TrailingReturnType = ParseTrailingReturnType(Range);
|
TrailingReturnType = ParseTrailingReturnType(Range);
|
||||||
|
EndLoc = Range.getEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4691,7 +4698,7 @@ void Parser::ParseFunctionDeclarator(Declarator &D,
|
||||||
DynamicExceptions.size(),
|
DynamicExceptions.size(),
|
||||||
NoexceptExpr.isUsable() ?
|
NoexceptExpr.isUsable() ?
|
||||||
NoexceptExpr.get() : 0,
|
NoexceptExpr.get() : 0,
|
||||||
StartLoc, EndLoc, D,
|
StartLoc, LocalEndLoc, D,
|
||||||
TrailingReturnType),
|
TrailingReturnType),
|
||||||
FnAttrs, EndLoc);
|
FnAttrs, EndLoc);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue