Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1 | //===--- ParseOpenMP.cpp - OpenMP directives parsing ----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// \brief This file implements parsing of all OpenMP directives and clauses. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 14 | #include "RAIIObjectsForParser.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTConsumer.h" |
| 16 | #include "clang/AST/ASTContext.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 17 | #include "clang/AST/StmtOpenMP.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 18 | #include "clang/Parse/ParseDiagnostic.h" |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 19 | #include "clang/Parse/Parser.h" |
| 20 | #include "clang/Sema/Scope.h" |
| 21 | #include "llvm/ADT/PointerIntPair.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 22 | using namespace clang; |
| 23 | |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | // OpenMP declarative directives. |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 28 | /// \brief Parsing of declarative OpenMP directives. |
| 29 | /// |
| 30 | /// threadprivate-directive: |
| 31 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 32 | /// |
| 33 | Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() { |
| 34 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 35 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 36 | |
| 37 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 38 | SmallVector<Expr *, 5> Identifiers; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 39 | OpenMPDirectiveKind DKind = Tok.isAnnotation() |
| 40 | ? OMPD_unknown |
| 41 | : getOpenMPDirectiveKind(PP.getSpelling(Tok)); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 42 | |
| 43 | switch (DKind) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 44 | case OMPD_threadprivate: |
| 45 | ConsumeToken(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 46 | if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, true)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 47 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 48 | // extra tokens. |
| 49 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 50 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 51 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 52 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 53 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 54 | // Skip the last annot_pragma_openmp_end. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 55 | ConsumeToken(); |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 56 | return Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 57 | } |
| 58 | break; |
| 59 | case OMPD_unknown: |
| 60 | Diag(Tok, diag::err_omp_unknown_directive); |
| 61 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 62 | case OMPD_parallel: |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 63 | case OMPD_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 64 | case OMPD_task: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 65 | case OMPD_for: |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 66 | Diag(Tok, diag::err_omp_unexpected_directive) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 67 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 68 | break; |
| 69 | } |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 70 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 71 | return DeclGroupPtrTy(); |
| 72 | } |
| 73 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 74 | /// \brief Parsing of declarative or executable OpenMP directives. |
| 75 | /// |
| 76 | /// threadprivate-directive: |
| 77 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
| 78 | /// annot_pragma_openmp_end |
| 79 | /// |
| 80 | /// parallel-directive: |
| 81 | /// annot_pragma_openmp 'parallel' {clause} annot_pragma_openmp_end |
| 82 | /// |
| 83 | StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective() { |
| 84 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 85 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 86 | SmallVector<Expr *, 5> Identifiers; |
| 87 | SmallVector<OMPClause *, 5> Clauses; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 88 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1> |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 89 | FirstClauses(OMPC_unknown + 1); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 90 | unsigned ScopeFlags = |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 91 | Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 92 | SourceLocation Loc = ConsumeToken(), EndLoc; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 93 | OpenMPDirectiveKind DKind = Tok.isAnnotation() |
| 94 | ? OMPD_unknown |
| 95 | : getOpenMPDirectiveKind(PP.getSpelling(Tok)); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 96 | // Name of critical directive. |
| 97 | DeclarationNameInfo DirName; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 98 | StmtResult Directive = StmtError(); |
| 99 | |
| 100 | switch (DKind) { |
| 101 | case OMPD_threadprivate: |
| 102 | ConsumeToken(); |
| 103 | if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, false)) { |
| 104 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 105 | // extra tokens. |
| 106 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 107 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 108 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 109 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 110 | } |
| 111 | DeclGroupPtrTy Res = |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 112 | Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 113 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 114 | } |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 115 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 116 | break; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 117 | case OMPD_parallel: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 118 | case OMPD_simd: |
| 119 | case OMPD_for: { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 120 | ConsumeToken(); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 121 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 122 | if (isOpenMPLoopDirective(DKind)) |
| 123 | ScopeFlags |= Scope::OpenMPLoopDirectiveScope; |
| 124 | if (isOpenMPSimdDirective(DKind)) |
| 125 | ScopeFlags |= Scope::OpenMPSimdDirectiveScope; |
| 126 | ParseScope OMPDirectiveScope(this, ScopeFlags); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 127 | Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope()); |
| 128 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 129 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 130 | OpenMPClauseKind CKind = Tok.isAnnotation() |
| 131 | ? OMPC_unknown |
| 132 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
| 133 | OMPClause *Clause = |
| 134 | ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 135 | FirstClauses[CKind].setInt(true); |
| 136 | if (Clause) { |
| 137 | FirstClauses[CKind].setPointer(Clause); |
| 138 | Clauses.push_back(Clause); |
| 139 | } |
| 140 | |
| 141 | // Skip ',' if any. |
| 142 | if (Tok.is(tok::comma)) |
| 143 | ConsumeToken(); |
| 144 | } |
| 145 | // End location of the directive. |
| 146 | EndLoc = Tok.getLocation(); |
| 147 | // Consume final annot_pragma_openmp_end. |
| 148 | ConsumeToken(); |
| 149 | |
| 150 | StmtResult AssociatedStmt; |
| 151 | bool CreateDirective = true; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 152 | { |
| 153 | // The body is a block scope like in Lambdas and Blocks. |
| 154 | Sema::CompoundScopeRAII CompoundScope(Actions); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 155 | Actions.ActOnOpenMPRegionStart(DKind, Loc, getCurScope()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 156 | Actions.ActOnStartOfCompoundStmt(); |
| 157 | // Parse statement |
| 158 | AssociatedStmt = ParseStatement(); |
| 159 | Actions.ActOnFinishOfCompoundStmt(); |
| 160 | if (!AssociatedStmt.isUsable()) { |
| 161 | Actions.ActOnCapturedRegionError(); |
| 162 | CreateDirective = false; |
| 163 | } else { |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 164 | AssociatedStmt = Actions.ActOnCapturedRegionEnd(AssociatedStmt.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 165 | CreateDirective = AssociatedStmt.isUsable(); |
| 166 | } |
| 167 | } |
| 168 | if (CreateDirective) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 169 | Directive = Actions.ActOnOpenMPExecutableDirective( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 170 | DKind, Clauses, AssociatedStmt.get(), Loc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 171 | |
| 172 | // Exit scope. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 173 | Actions.EndOpenMPDSABlock(Directive.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 174 | OMPDirectiveScope.Exit(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 175 | break; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 176 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 177 | case OMPD_unknown: |
| 178 | Diag(Tok, diag::err_omp_unknown_directive); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 179 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 180 | break; |
| 181 | case OMPD_task: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 182 | Diag(Tok, diag::err_omp_unexpected_directive) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 183 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 184 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 185 | break; |
| 186 | } |
| 187 | return Directive; |
| 188 | } |
| 189 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 190 | /// \brief Parses list of simple variables for '#pragma omp threadprivate' |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 191 | /// directive. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 192 | /// |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 193 | /// simple-variable-list: |
| 194 | /// '(' id-expression {, id-expression} ')' |
| 195 | /// |
| 196 | bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind, |
| 197 | SmallVectorImpl<Expr *> &VarList, |
| 198 | bool AllowScopeSpecifier) { |
| 199 | VarList.clear(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 200 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 201 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 202 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 203 | getOpenMPDirectiveName(Kind))) |
| 204 | return true; |
| 205 | bool IsCorrect = true; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 206 | bool NoIdentIsFound = true; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 207 | |
| 208 | // Read tokens while ')' or annot_pragma_openmp_end is not found. |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 209 | while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 210 | CXXScopeSpec SS; |
| 211 | SourceLocation TemplateKWLoc; |
| 212 | UnqualifiedId Name; |
| 213 | // Read var name. |
| 214 | Token PrevTok = Tok; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 215 | NoIdentIsFound = false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 216 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 217 | if (AllowScopeSpecifier && getLangOpts().CPlusPlus && |
| 218 | ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 219 | IsCorrect = false; |
| 220 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 221 | StopBeforeMatch); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 222 | } else if (ParseUnqualifiedId(SS, false, false, false, ParsedType(), |
| 223 | TemplateKWLoc, Name)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 224 | IsCorrect = false; |
| 225 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 226 | StopBeforeMatch); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 227 | } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) && |
| 228 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 229 | IsCorrect = false; |
| 230 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 231 | StopBeforeMatch); |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 232 | Diag(PrevTok.getLocation(), diag::err_expected) |
| 233 | << tok::identifier |
| 234 | << SourceRange(PrevTok.getLocation(), PrevTokLocation); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 235 | } else { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 236 | DeclarationNameInfo NameInfo = Actions.GetNameFromUnqualifiedId(Name); |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 237 | ExprResult Res = |
| 238 | Actions.ActOnOpenMPIdExpression(getCurScope(), SS, NameInfo); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 239 | if (Res.isUsable()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 240 | VarList.push_back(Res.get()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 241 | } |
| 242 | // Consume ','. |
| 243 | if (Tok.is(tok::comma)) { |
| 244 | ConsumeToken(); |
| 245 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 246 | } |
| 247 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 248 | if (NoIdentIsFound) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 249 | Diag(Tok, diag::err_expected) << tok::identifier; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 250 | IsCorrect = false; |
| 251 | } |
| 252 | |
| 253 | // Parse ')'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 254 | IsCorrect = !T.consumeClose() && IsCorrect; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 255 | |
| 256 | return !IsCorrect && VarList.empty(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 257 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 258 | |
| 259 | /// \brief Parsing of OpenMP clauses. |
| 260 | /// |
| 261 | /// clause: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 262 | /// if-clause | num_threads-clause | safelen-clause | default-clause | |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 263 | /// private-clause | firstprivate-clause | shared-clause | linear-clause | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 264 | /// aligned-clause | collapse-clause | lastprivate-clause | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 265 | /// reduction-clause | proc_bind-clause | schedule-clause |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 266 | /// |
| 267 | OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, |
| 268 | OpenMPClauseKind CKind, bool FirstClause) { |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 269 | OMPClause *Clause = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 270 | bool ErrorFound = false; |
| 271 | // Check if clause is allowed for the given directive. |
| 272 | if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 273 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 274 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 275 | ErrorFound = true; |
| 276 | } |
| 277 | |
| 278 | switch (CKind) { |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 279 | case OMPC_if: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 280 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 281 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 282 | case OMPC_collapse: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 283 | // OpenMP [2.5, Restrictions] |
| 284 | // At most one if clause can appear on the directive. |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 285 | // At most one num_threads clause can appear on the directive. |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 286 | // OpenMP [2.8.1, simd construct, Restrictions] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 287 | // Only one safelen clause can appear on a simd directive. |
| 288 | // Only one collapse clause can appear on a simd directive. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 289 | if (!FirstClause) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 290 | Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) |
| 291 | << getOpenMPClauseName(CKind); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | Clause = ParseOpenMPSingleExprClause(CKind); |
| 295 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 296 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 297 | case OMPC_proc_bind: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 298 | // OpenMP [2.14.3.1, Restrictions] |
| 299 | // Only a single default clause may be specified on a parallel, task or |
| 300 | // teams directive. |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 301 | // OpenMP [2.5, parallel Construct, Restrictions] |
| 302 | // At most one proc_bind clause can appear on the directive. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 303 | if (!FirstClause) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 304 | Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) |
| 305 | << getOpenMPClauseName(CKind); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | Clause = ParseOpenMPSimpleClause(CKind); |
| 309 | break; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 310 | case OMPC_schedule: |
| 311 | // OpenMP [2.7.1, Restrictions, p. 3] |
| 312 | // Only one schedule clause can appear on a loop directive. |
| 313 | if (!FirstClause) { |
| 314 | Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) |
| 315 | << getOpenMPClauseName(CKind); |
| 316 | } |
| 317 | |
| 318 | Clause = ParseOpenMPSingleExprWithArgClause(CKind); |
| 319 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 320 | case OMPC_ordered: |
| 321 | // OpenMP [2.7.1, Restrictions, p. 9] |
| 322 | // Only one ordered clause can appear on a loop directive. |
| 323 | if (!FirstClause) { |
| 324 | Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) |
| 325 | << getOpenMPClauseName(CKind); |
| 326 | } |
| 327 | |
| 328 | Clause = ParseOpenMPClause(CKind); |
| 329 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 330 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 331 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 332 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 333 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 334 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 335 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 336 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 337 | case OMPC_copyin: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 338 | Clause = ParseOpenMPVarListClause(CKind); |
| 339 | break; |
| 340 | case OMPC_unknown: |
| 341 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 342 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 343 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 344 | break; |
| 345 | case OMPC_threadprivate: |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 346 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 347 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 348 | SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 349 | break; |
| 350 | } |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 351 | return ErrorFound ? nullptr : Clause; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 354 | /// \brief Parsing of OpenMP clauses with single expressions like 'if', |
| 355 | /// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams' or |
| 356 | /// 'thread_limit'. |
| 357 | /// |
| 358 | /// if-clause: |
| 359 | /// 'if' '(' expression ')' |
| 360 | /// |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 361 | /// num_threads-clause: |
| 362 | /// 'num_threads' '(' expression ')' |
| 363 | /// |
| 364 | /// safelen-clause: |
| 365 | /// 'safelen' '(' expression ')' |
| 366 | /// |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 367 | /// collapse-clause: |
| 368 | /// 'collapse' '(' expression ')' |
| 369 | /// |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 370 | OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) { |
| 371 | SourceLocation Loc = ConsumeToken(); |
| 372 | |
| 373 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 374 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 375 | getOpenMPClauseName(Kind))) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 376 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 377 | |
| 378 | ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); |
| 379 | ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional)); |
| 380 | |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 381 | // Parse ')'. |
| 382 | T.consumeClose(); |
| 383 | |
| 384 | if (Val.isInvalid()) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 385 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 386 | |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 387 | return Actions.ActOnOpenMPSingleExprClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 388 | Kind, Val.get(), Loc, T.getOpenLocation(), T.getCloseLocation()); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 389 | } |
| 390 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 391 | /// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 392 | /// |
| 393 | /// default-clause: |
| 394 | /// 'default' '(' 'none' | 'shared' ') |
| 395 | /// |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 396 | /// proc_bind-clause: |
| 397 | /// 'proc_bind' '(' 'master' | 'close' | 'spread' ') |
| 398 | /// |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 399 | OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) { |
| 400 | SourceLocation Loc = Tok.getLocation(); |
| 401 | SourceLocation LOpen = ConsumeToken(); |
| 402 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 403 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 404 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 405 | getOpenMPClauseName(Kind))) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 406 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 407 | |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 408 | unsigned Type = getOpenMPSimpleClauseType( |
| 409 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 410 | SourceLocation TypeLoc = Tok.getLocation(); |
| 411 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 412 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 413 | ConsumeAnyToken(); |
| 414 | |
| 415 | // Parse ')'. |
| 416 | T.consumeClose(); |
| 417 | |
| 418 | return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc, |
| 419 | Tok.getLocation()); |
| 420 | } |
| 421 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 422 | /// \brief Parsing of OpenMP clauses like 'ordered'. |
| 423 | /// |
| 424 | /// ordered-clause: |
| 425 | /// 'ordered' |
| 426 | /// |
| 427 | OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) { |
| 428 | SourceLocation Loc = Tok.getLocation(); |
| 429 | ConsumeAnyToken(); |
| 430 | |
| 431 | return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation()); |
| 432 | } |
| 433 | |
| 434 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 435 | /// \brief Parsing of OpenMP clauses with single expressions and some additional |
| 436 | /// argument like 'schedule' or 'dist_schedule'. |
| 437 | /// |
| 438 | /// schedule-clause: |
| 439 | /// 'schedule' '(' kind [',' expression ] ')' |
| 440 | /// |
| 441 | OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) { |
| 442 | SourceLocation Loc = ConsumeToken(); |
| 443 | SourceLocation CommaLoc; |
| 444 | // Parse '('. |
| 445 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 446 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 447 | getOpenMPClauseName(Kind))) |
| 448 | return nullptr; |
| 449 | |
| 450 | ExprResult Val; |
| 451 | unsigned Type = getOpenMPSimpleClauseType( |
| 452 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 453 | SourceLocation KLoc = Tok.getLocation(); |
| 454 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 455 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 456 | ConsumeAnyToken(); |
| 457 | |
| 458 | if (Kind == OMPC_schedule && |
| 459 | (Type == OMPC_SCHEDULE_static || Type == OMPC_SCHEDULE_dynamic || |
| 460 | Type == OMPC_SCHEDULE_guided) && |
| 461 | Tok.is(tok::comma)) { |
| 462 | CommaLoc = ConsumeAnyToken(); |
| 463 | ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); |
| 464 | Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional); |
| 465 | if (Val.isInvalid()) |
| 466 | return nullptr; |
| 467 | } |
| 468 | |
| 469 | // Parse ')'. |
| 470 | T.consumeClose(); |
| 471 | |
| 472 | return Actions.ActOnOpenMPSingleExprWithArgClause( |
| 473 | Kind, Type, Val.get(), Loc, T.getOpenLocation(), KLoc, CommaLoc, |
| 474 | T.getCloseLocation()); |
| 475 | } |
| 476 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 477 | static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec, |
| 478 | UnqualifiedId &ReductionId) { |
| 479 | SourceLocation TemplateKWLoc; |
| 480 | if (ReductionIdScopeSpec.isEmpty()) { |
| 481 | auto OOK = OO_None; |
| 482 | switch (P.getCurToken().getKind()) { |
| 483 | case tok::plus: |
| 484 | OOK = OO_Plus; |
| 485 | break; |
| 486 | case tok::minus: |
| 487 | OOK = OO_Minus; |
| 488 | break; |
| 489 | case tok::star: |
| 490 | OOK = OO_Star; |
| 491 | break; |
| 492 | case tok::amp: |
| 493 | OOK = OO_Amp; |
| 494 | break; |
| 495 | case tok::pipe: |
| 496 | OOK = OO_Pipe; |
| 497 | break; |
| 498 | case tok::caret: |
| 499 | OOK = OO_Caret; |
| 500 | break; |
| 501 | case tok::ampamp: |
| 502 | OOK = OO_AmpAmp; |
| 503 | break; |
| 504 | case tok::pipepipe: |
| 505 | OOK = OO_PipePipe; |
| 506 | break; |
| 507 | default: |
| 508 | break; |
| 509 | } |
| 510 | if (OOK != OO_None) { |
| 511 | SourceLocation OpLoc = P.ConsumeToken(); |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 512 | SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()}; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 513 | ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations); |
| 514 | return false; |
| 515 | } |
| 516 | } |
| 517 | return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false, |
| 518 | /*AllowDestructorName*/ false, |
| 519 | /*AllowConstructorName*/ false, ParsedType(), |
| 520 | TemplateKWLoc, ReductionId); |
| 521 | } |
| 522 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 523 | /// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate', |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 524 | /// 'shared', 'copyin', or 'reduction'. |
| 525 | /// |
| 526 | /// private-clause: |
| 527 | /// 'private' '(' list ')' |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 528 | /// firstprivate-clause: |
| 529 | /// 'firstprivate' '(' list ')' |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 530 | /// lastprivate-clause: |
| 531 | /// 'lastprivate' '(' list ')' |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 532 | /// shared-clause: |
| 533 | /// 'shared' '(' list ')' |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 534 | /// linear-clause: |
| 535 | /// 'linear' '(' list [ ':' linear-step ] ')' |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 536 | /// aligned-clause: |
| 537 | /// 'aligned' '(' list [ ':' alignment ] ')' |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 538 | /// reduction-clause: |
| 539 | /// 'reduction' '(' reduction-identifier ':' list ')' |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 540 | /// |
| 541 | OMPClause *Parser::ParseOpenMPVarListClause(OpenMPClauseKind Kind) { |
| 542 | SourceLocation Loc = Tok.getLocation(); |
| 543 | SourceLocation LOpen = ConsumeToken(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 544 | SourceLocation ColonLoc = SourceLocation(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 545 | // Optional scope specifier and unqualified id for reduction identifier. |
| 546 | CXXScopeSpec ReductionIdScopeSpec; |
| 547 | UnqualifiedId ReductionId; |
| 548 | bool InvalidReductionId = false; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 549 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 550 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 551 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 552 | getOpenMPClauseName(Kind))) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 553 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 554 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 555 | // Handle reduction-identifier for reduction clause. |
| 556 | if (Kind == OMPC_reduction) { |
| 557 | ColonProtectionRAIIObject ColonRAII(*this); |
| 558 | if (getLangOpts().CPlusPlus) { |
| 559 | ParseOptionalCXXScopeSpecifier(ReductionIdScopeSpec, ParsedType(), false); |
| 560 | } |
| 561 | InvalidReductionId = |
| 562 | ParseReductionId(*this, ReductionIdScopeSpec, ReductionId); |
| 563 | if (InvalidReductionId) { |
| 564 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 565 | StopBeforeMatch); |
| 566 | } |
| 567 | if (Tok.is(tok::colon)) { |
| 568 | ColonLoc = ConsumeToken(); |
| 569 | } else { |
| 570 | Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier"; |
| 571 | } |
| 572 | } |
| 573 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 574 | SmallVector<Expr *, 5> Vars; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 575 | bool IsComma = !InvalidReductionId; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 576 | const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 577 | while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) && |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 578 | Tok.isNot(tok::annot_pragma_openmp_end))) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 579 | ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 580 | // Parse variable |
| 581 | ExprResult VarExpr = ParseAssignmentExpression(); |
| 582 | if (VarExpr.isUsable()) { |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 583 | Vars.push_back(VarExpr.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 584 | } else { |
| 585 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 586 | StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 587 | } |
| 588 | // Skip ',' if any |
| 589 | IsComma = Tok.is(tok::comma); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 590 | if (IsComma) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 591 | ConsumeToken(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 592 | else if (Tok.isNot(tok::r_paren) && |
| 593 | Tok.isNot(tok::annot_pragma_openmp_end) && |
| 594 | (!MayHaveTail || Tok.isNot(tok::colon))) |
| 595 | Diag(Tok, diag::err_omp_expected_punc) << getOpenMPClauseName(Kind); |
| 596 | } |
| 597 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 598 | // Parse ':' linear-step (or ':' alignment). |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 599 | Expr *TailExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 600 | const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon); |
| 601 | if (MustHaveTail) { |
| 602 | ColonLoc = Tok.getLocation(); |
| 603 | ConsumeToken(); |
| 604 | ExprResult Tail = ParseAssignmentExpression(); |
| 605 | if (Tail.isUsable()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 606 | TailExpr = Tail.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 607 | else |
| 608 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 609 | StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | // Parse ')'. |
| 613 | T.consumeClose(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 614 | if (Vars.empty() || (MustHaveTail && !TailExpr) || InvalidReductionId) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 615 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 616 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 617 | return Actions.ActOnOpenMPVarListClause( |
| 618 | Kind, Vars, TailExpr, Loc, LOpen, ColonLoc, Tok.getLocation(), |
| 619 | ReductionIdScopeSpec, |
| 620 | ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId) |
| 621 | : DeclarationNameInfo()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 622 | } |
| 623 | |