diff options
| author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2008-10-24 21:46:40 +0000 | 
|---|---|---|
| committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2008-10-24 21:46:40 +0000 | 
| commit | 22c40fa28551f0da487f399a2fe0d3d25edf3edc (patch) | |
| tree | bc2ce950d8e47e9a2ea3075d2d0ca232fb927385 /clang/lib/Parse | |
| parent | c15758659826d042658c2f8acc52a95d68741bb4 (diff) | |
| download | bcm5719-llvm-22c40fa28551f0da487f399a2fe0d3d25edf3edc.tar.gz bcm5719-llvm-22c40fa28551f0da487f399a2fe0d3d25edf3edc.zip | |
-Add support for cv-qualifiers after function declarators.
-Add withConst/withVolatile/withRestrict methods to QualType class, that return the QualType plus the respective qualifier.
llvm-svn: 58120
Diffstat (limited to 'clang/lib/Parse')
| -rw-r--r-- | clang/lib/Parse/ParseDecl.cpp | 42 | ||||
| -rw-r--r-- | clang/lib/Parse/ParseExpr.cpp | 2 | 
2 files changed, 33 insertions, 11 deletions
| diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 27133d683c9..6bcb90b8ae6 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -1213,6 +1213,8 @@ void Parser::ParseDeclaratorInternal(Declarator &D) {  ///         direct-declarator '(' identifier-list[opt] ')'  /// [GNU]   direct-declarator '(' parameter-forward-declarations  ///                    parameter-type-list[opt] ')' +/// [C++]   direct-declarator '(' parameter-declaration-clause ')' +///                    cv-qualifier-seq[opt] exception-specification[opt]  ///  void Parser::ParseDirectDeclarator(Declarator &D) {    // Parse the first direct-declarator seen. @@ -1371,6 +1373,9 @@ void Parser::ParseParenDeclarator(Declarator &D) {  ///           '=' assignment-expression  /// [GNU]   declaration-specifiers abstract-declarator[opt] attributes  /// +/// For C++, after the parameter-list, it also parses "cv-qualifier-seq[opt]" +/// and "exception-specification[opt]"(TODO). +///  void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,                                       AttributeList *AttrList,                                       bool RequiresArg) { @@ -1383,20 +1388,29 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,        Diag(Tok.getLocation(), diag::err_argument_required_after_attribute);        delete AttrList;      } -     + +    ConsumeParen();  // Eat the closing ')'. + +    // cv-qualifier-seq[opt]. +    DeclSpec DS; +    if (getLang().CPlusPlus) { +      ParseTypeQualifierListOpt(DS); +      // FIXME: Parse exception-specification[opt]. +    } +      // Remember that we parsed a function type, and remember the attributes.      // int() -> no prototype, no '...'. -    D.AddTypeInfo(DeclaratorChunk::getFunction(/*prototype*/ false, +    D.AddTypeInfo(DeclaratorChunk::getFunction(/*prototype*/getLang().CPlusPlus,                                                 /*variadic*/ false, -                                               /*arglist*/ 0, 0, LParenLoc)); -     -    ConsumeParen();  // Eat the closing ')'. +                                               /*arglist*/ 0, 0, +                                               DS.getTypeQualifiers(), +                                               LParenLoc));      return;    }     // Alternatively, this parameter list may be an identifier list form for a    // K&R-style function:  void foo(a,b,c) -  if (Tok.is(tok::identifier) && +  if (!getLang().CPlusPlus && Tok.is(tok::identifier) &&        // K&R identifier lists can't have typedefs as identifiers, per        // C99 6.7.5.3p11.        !Actions.isTypeName(*Tok.getIdentifierInfo(), CurScope)) { @@ -1508,13 +1522,21 @@ void Parser::ParseFunctionDeclarator(SourceLocation LParenLoc, Declarator &D,    // Leave prototype scope.    ExitScope(); +  // If we have the closing ')', eat it. +  MatchRHSPunctuation(tok::r_paren, LParenLoc); + +  // cv-qualifier-seq[opt]. +  DeclSpec DS; +  if (getLang().CPlusPlus) { +    ParseTypeQualifierListOpt(DS); +    // FIXME: Parse exception-specification[opt]. +  } +    // Remember that we parsed a function type, and remember the attributes.    D.AddTypeInfo(DeclaratorChunk::getFunction(/*proto*/true, IsVariadic,                                               &ParamInfo[0], ParamInfo.size(), +                                             DS.getTypeQualifiers(),                                               LParenLoc)); -   -  // If we have the closing ')', eat it and we're done. -  MatchRHSPunctuation(tok::r_paren, LParenLoc);  }  /// ParseFunctionDeclaratorIdentifierList - While parsing a function declarator @@ -1581,7 +1603,7 @@ void Parser::ParseFunctionDeclaratorIdentifierList(SourceLocation LParenLoc,    // has no prototype.    D.AddTypeInfo(DeclaratorChunk::getFunction(/*proto*/false, /*varargs*/false,                                               &ParamInfo[0], ParamInfo.size(), -                                             LParenLoc)); +                                             /*TypeQuals*/0, LParenLoc));    // If we have the closing ')', eat it and we're done.    MatchRHSPunctuation(tok::r_paren, LParenLoc); diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index f6d7037ad12..7ab9d869c2d 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/lib/Parse/ParseExpr.cpp @@ -1116,7 +1116,7 @@ Parser::ExprResult Parser::ParseBlockLiteralExpression() {    } else {      // Otherwise, pretend we saw (void).      ParamInfo.AddTypeInfo(DeclaratorChunk::getFunction(true, false, -                                                       0, 0, CaretLoc)); +                                                       0, 0, 0, CaretLoc));    }    // Inform sema that we are starting a block. | 

