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