Code cleanup
Parser::ParseLexedMethodDeclaration: Use local var for Param Sema::MergeCXXFunctionDecls: Use hasInheritedDefaultArg llvm-svn: 227577
This commit is contained in:
parent
1efa12d6d8
commit
55d53fe79f
|
@ -306,9 +306,9 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
|
||||||
ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope |
|
ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope |
|
||||||
Scope::FunctionDeclarationScope | Scope::DeclScope);
|
Scope::FunctionDeclarationScope | Scope::DeclScope);
|
||||||
for (unsigned I = 0, N = LM.DefaultArgs.size(); I != N; ++I) {
|
for (unsigned I = 0, N = LM.DefaultArgs.size(); I != N; ++I) {
|
||||||
|
auto Param = LM.DefaultArgs[I].Param;
|
||||||
// Introduce the parameter into scope.
|
// Introduce the parameter into scope.
|
||||||
Actions.ActOnDelayedCXXMethodParameter(getCurScope(),
|
Actions.ActOnDelayedCXXMethodParameter(getCurScope(), Param);
|
||||||
LM.DefaultArgs[I].Param);
|
|
||||||
if (CachedTokens *Toks = LM.DefaultArgs[I].Toks) {
|
if (CachedTokens *Toks = LM.DefaultArgs[I].Toks) {
|
||||||
// Mark the end of the default argument so that we know when to stop when
|
// Mark the end of the default argument so that we know when to stop when
|
||||||
// we parse it later on.
|
// we parse it later on.
|
||||||
|
@ -318,7 +318,7 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
|
||||||
DefArgEnd.setKind(tok::eof);
|
DefArgEnd.setKind(tok::eof);
|
||||||
DefArgEnd.setLocation(LastDefaultArgToken.getLocation().getLocWithOffset(
|
DefArgEnd.setLocation(LastDefaultArgToken.getLocation().getLocWithOffset(
|
||||||
LastDefaultArgToken.getLength()));
|
LastDefaultArgToken.getLength()));
|
||||||
DefArgEnd.setEofData(LM.DefaultArgs[I].Param);
|
DefArgEnd.setEofData(Param);
|
||||||
Toks->push_back(DefArgEnd);
|
Toks->push_back(DefArgEnd);
|
||||||
|
|
||||||
// Parse the default argument from its saved token stream.
|
// Parse the default argument from its saved token stream.
|
||||||
|
@ -336,7 +336,7 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
|
||||||
// used.
|
// used.
|
||||||
EnterExpressionEvaluationContext Eval(Actions,
|
EnterExpressionEvaluationContext Eval(Actions,
|
||||||
Sema::PotentiallyEvaluatedIfUsed,
|
Sema::PotentiallyEvaluatedIfUsed,
|
||||||
LM.DefaultArgs[I].Param);
|
Param);
|
||||||
|
|
||||||
ExprResult DefArgResult;
|
ExprResult DefArgResult;
|
||||||
if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
|
if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
|
||||||
|
@ -346,11 +346,9 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
|
||||||
DefArgResult = ParseAssignmentExpression();
|
DefArgResult = ParseAssignmentExpression();
|
||||||
DefArgResult = Actions.CorrectDelayedTyposInExpr(DefArgResult);
|
DefArgResult = Actions.CorrectDelayedTyposInExpr(DefArgResult);
|
||||||
if (DefArgResult.isInvalid()) {
|
if (DefArgResult.isInvalid()) {
|
||||||
Actions.ActOnParamDefaultArgumentError(LM.DefaultArgs[I].Param,
|
Actions.ActOnParamDefaultArgumentError(Param, EqualLoc);
|
||||||
EqualLoc);
|
|
||||||
} else {
|
} else {
|
||||||
if (Tok.isNot(tok::eof) ||
|
if (Tok.isNot(tok::eof) || Tok.getEofData() != Param) {
|
||||||
Tok.getEofData() != LM.DefaultArgs[I].Param) {
|
|
||||||
// The last two tokens are the terminator and the saved value of
|
// The last two tokens are the terminator and the saved value of
|
||||||
// Tok; the last token in the default argument is the one before
|
// Tok; the last token in the default argument is the one before
|
||||||
// those.
|
// those.
|
||||||
|
@ -359,7 +357,7 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
|
||||||
<< SourceRange(Tok.getLocation(),
|
<< SourceRange(Tok.getLocation(),
|
||||||
(*Toks)[Toks->size() - 3].getLocation());
|
(*Toks)[Toks->size() - 3].getLocation());
|
||||||
}
|
}
|
||||||
Actions.ActOnParamDefaultArgument(LM.DefaultArgs[I].Param, EqualLoc,
|
Actions.ActOnParamDefaultArgument(Param, EqualLoc,
|
||||||
DefArgResult.get());
|
DefArgResult.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -368,7 +366,7 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
|
||||||
while (Tok.isNot(tok::eof))
|
while (Tok.isNot(tok::eof))
|
||||||
ConsumeAnyToken();
|
ConsumeAnyToken();
|
||||||
|
|
||||||
if (Tok.is(tok::eof) && Tok.getEofData() == LM.DefaultArgs[I].Param)
|
if (Tok.is(tok::eof) && Tok.getEofData() == Param)
|
||||||
ConsumeAnyToken();
|
ConsumeAnyToken();
|
||||||
|
|
||||||
delete Toks;
|
delete Toks;
|
||||||
|
|
|
@ -509,11 +509,8 @@ bool Sema::MergeCXXFunctionDecl(FunctionDecl *New, FunctionDecl *Old,
|
||||||
|
|
||||||
// Look for the function declaration where the default argument was
|
// Look for the function declaration where the default argument was
|
||||||
// actually written, which may be a declaration prior to Old.
|
// actually written, which may be a declaration prior to Old.
|
||||||
for (FunctionDecl *Older = Old->getPreviousDecl();
|
for (auto Older = Old; OldParam->hasInheritedDefaultArg();) {
|
||||||
Older; Older = Older->getPreviousDecl()) {
|
Older = Older->getPreviousDecl();
|
||||||
if (!Older->getParamDecl(p)->hasDefaultArg())
|
|
||||||
break;
|
|
||||||
|
|
||||||
OldParam = Older->getParamDecl(p);
|
OldParam = Older->getParamDecl(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ void f0(int i, int j = 2, int k);
|
||||||
void f0(int i, int j, int k);
|
void f0(int i, int j, int k);
|
||||||
void f0(int i = 1, // expected-note{{previous definition}}
|
void f0(int i = 1, // expected-note{{previous definition}}
|
||||||
int j, int k);
|
int j, int k);
|
||||||
|
void f0(int i, int j, int k); // want 2 decls before next default arg
|
||||||
void f0(int i, int j, int k);
|
void f0(int i, int j, int k);
|
||||||
|
|
||||||
namespace N0 {
|
namespace N0 {
|
||||||
|
|
Loading…
Reference in New Issue