diff options
author | Eli Friedman <eli.friedman@gmail.com> | 2009-07-22 21:45:50 +0000 |
---|---|---|
committer | Eli Friedman <eli.friedman@gmail.com> | 2009-07-22 21:45:50 +0000 |
commit | 3af2a777176e916f830825cae3d2720b13129929 (patch) | |
tree | a2e97f449d6703f18262a6f923c9928e7c7b633b /clang/lib/Parse/ParseDeclCXX.cpp | |
parent | b1c170e64b76eeb4586d597ce628d4bf3e6c2907 (diff) | |
download | bcm5719-llvm-3af2a777176e916f830825cae3d2720b13129929.tar.gz bcm5719-llvm-3af2a777176e916f830825cae3d2720b13129929.zip |
Fix the parsing of default arguments for inline member function
definitions.
I'm not very familiar with this code, so please review.
llvm-svn: 76796
Diffstat (limited to 'clang/lib/Parse/ParseDeclCXX.cpp')
-rw-r--r-- | clang/lib/Parse/ParseDeclCXX.cpp | 63 |
1 files changed, 34 insertions, 29 deletions
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index b9b2979911e..930d58dd262 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -852,6 +852,39 @@ AccessSpecifier Parser::getAccessSpecifierIfPresent() const } } +void Parser::HandleMemberFunctionDefaultArgs(Declarator& DeclaratorInfo, + DeclPtrTy ThisDecl) { + // We just declared a member function. If this member function + // has any default arguments, we'll need to parse them later. + LateParsedMethodDeclaration *LateMethod = 0; + DeclaratorChunk::FunctionTypeInfo &FTI + = DeclaratorInfo.getTypeObject(0).Fun; + for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) { + if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) { + if (!LateMethod) { + // Push this method onto the stack of late-parsed method + // declarations. + getCurrentClass().MethodDecls.push_back( + LateParsedMethodDeclaration(ThisDecl)); + LateMethod = &getCurrentClass().MethodDecls.back(); + + // Add all of the parameters prior to this one (they don't + // have default arguments). + LateMethod->DefaultArgs.reserve(FTI.NumArgs); + for (unsigned I = 0; I < ParamIdx; ++I) + LateMethod->DefaultArgs.push_back( + LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param)); + } + + // Add this parameter to the list of parameters (it or may + // not have a default argument). + LateMethod->DefaultArgs.push_back( + LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param, + FTI.ArgInfo[ParamIdx].DefaultArgTokens)); + } + } +} + /// ParseCXXClassMemberDeclaration - Parse a C++ class member declaration. /// /// member-declaration: @@ -1047,35 +1080,7 @@ void Parser::ParseCXXClassMemberDeclaration(AccessSpecifier AS) { if (DeclaratorInfo.isFunctionDeclarator() && DeclaratorInfo.getDeclSpec().getStorageClassSpec() != DeclSpec::SCS_typedef) { - // We just declared a member function. If this member function - // has any default arguments, we'll need to parse them later. - LateParsedMethodDeclaration *LateMethod = 0; - DeclaratorChunk::FunctionTypeInfo &FTI - = DeclaratorInfo.getTypeObject(0).Fun; - for (unsigned ParamIdx = 0; ParamIdx < FTI.NumArgs; ++ParamIdx) { - if (LateMethod || FTI.ArgInfo[ParamIdx].DefaultArgTokens) { - if (!LateMethod) { - // Push this method onto the stack of late-parsed method - // declarations. - getCurrentClass().MethodDecls.push_back( - LateParsedMethodDeclaration(ThisDecl)); - LateMethod = &getCurrentClass().MethodDecls.back(); - - // Add all of the parameters prior to this one (they don't - // have default arguments). - LateMethod->DefaultArgs.reserve(FTI.NumArgs); - for (unsigned I = 0; I < ParamIdx; ++I) - LateMethod->DefaultArgs.push_back( - LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param)); - } - - // Add this parameter to the list of parameters (it or may - // not have a default argument). - LateMethod->DefaultArgs.push_back( - LateParsedDefaultArgument(FTI.ArgInfo[ParamIdx].Param, - FTI.ArgInfo[ParamIdx].DefaultArgTokens)); - } - } + HandleMemberFunctionDefaultArgs(DeclaratorInfo, ThisDecl); } // If we don't have a comma, it is either the end of the list (a ';') |