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 | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 28 | static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) { |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 29 | // Array of foldings: F[i][0] F[i][1] ===> F[i][2]. |
| 30 | // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd |
| 31 | // TODO: add other combined directives in topological order. |
| 32 | const OpenMPDirectiveKind F[][3] = { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 33 | {OMPD_unknown /*cancellation*/, OMPD_unknown /*point*/, |
| 34 | OMPD_cancellation_point}, |
| 35 | {OMPD_for, OMPD_simd, OMPD_for_simd}, |
| 36 | {OMPD_parallel, OMPD_for, OMPD_parallel_for}, |
| 37 | {OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd}, |
| 38 | {OMPD_parallel, OMPD_sections, OMPD_parallel_sections}}; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 39 | auto Tok = P.getCurToken(); |
| 40 | auto DKind = |
| 41 | Tok.isAnnotation() |
| 42 | ? OMPD_unknown |
| 43 | : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok)); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 44 | bool TokenMatched = false; |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 45 | for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 46 | if (!Tok.isAnnotation() && DKind == OMPD_unknown) { |
| 47 | TokenMatched = |
| 48 | (i == 0) && |
| 49 | !P.getPreprocessor().getSpelling(Tok).compare("cancellation"); |
| 50 | } else { |
| 51 | TokenMatched = DKind == F[i][0] && DKind != OMPD_unknown; |
| 52 | } |
| 53 | if (TokenMatched) { |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 54 | Tok = P.getPreprocessor().LookAhead(0); |
| 55 | auto SDKind = |
| 56 | Tok.isAnnotation() |
| 57 | ? OMPD_unknown |
| 58 | : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok)); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 59 | if (!Tok.isAnnotation() && DKind == OMPD_unknown) { |
| 60 | TokenMatched = |
| 61 | (i == 0) && !P.getPreprocessor().getSpelling(Tok).compare("point"); |
| 62 | } else { |
| 63 | TokenMatched = SDKind == F[i][1] && SDKind != OMPD_unknown; |
| 64 | } |
| 65 | if (TokenMatched) { |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 66 | P.ConsumeToken(); |
| 67 | DKind = F[i][2]; |
| 68 | } |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | return DKind; |
| 72 | } |
| 73 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 74 | /// \brief Parsing of declarative OpenMP directives. |
| 75 | /// |
| 76 | /// threadprivate-directive: |
| 77 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 78 | /// |
| 79 | Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() { |
| 80 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 81 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 82 | |
| 83 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 84 | SmallVector<Expr *, 5> Identifiers; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 85 | auto DKind = ParseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 86 | |
| 87 | switch (DKind) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 88 | case OMPD_threadprivate: |
| 89 | ConsumeToken(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 90 | if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, true)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 91 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 92 | // extra tokens. |
| 93 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 94 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 95 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 96 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 97 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 98 | // Skip the last annot_pragma_openmp_end. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 99 | ConsumeToken(); |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 100 | return Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 101 | } |
| 102 | break; |
| 103 | case OMPD_unknown: |
| 104 | Diag(Tok, diag::err_omp_unknown_directive); |
| 105 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 106 | case OMPD_parallel: |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 107 | case OMPD_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 108 | case OMPD_task: |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 109 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 110 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 111 | case OMPD_taskwait: |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 112 | case OMPD_taskgroup: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 113 | case OMPD_flush: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 114 | case OMPD_for: |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 115 | case OMPD_for_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 116 | case OMPD_sections: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 117 | case OMPD_section: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 118 | case OMPD_single: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 119 | case OMPD_master: |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 120 | case OMPD_ordered: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 121 | case OMPD_critical: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 122 | case OMPD_parallel_for: |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 123 | case OMPD_parallel_for_simd: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 124 | case OMPD_parallel_sections: |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 125 | case OMPD_atomic: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 126 | case OMPD_target: |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 127 | case OMPD_teams: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 128 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame^] | 129 | case OMPD_cancel: |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 130 | Diag(Tok, diag::err_omp_unexpected_directive) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 131 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 132 | break; |
| 133 | } |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 134 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 135 | return DeclGroupPtrTy(); |
| 136 | } |
| 137 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 138 | /// \brief Parsing of declarative or executable OpenMP directives. |
| 139 | /// |
| 140 | /// threadprivate-directive: |
| 141 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
| 142 | /// annot_pragma_openmp_end |
| 143 | /// |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 144 | /// executable-directive: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 145 | /// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 146 | /// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] | |
| 147 | /// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 148 | /// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' | |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 149 | /// 'for simd' | 'parallel for simd' | 'target' | 'teams' | 'taskgroup' |
| 150 | /// {clause} |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 151 | /// annot_pragma_openmp_end |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 152 | /// |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 153 | StmtResult |
| 154 | Parser::ParseOpenMPDeclarativeOrExecutableDirective(bool StandAloneAllowed) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 155 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 156 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 157 | SmallVector<Expr *, 5> Identifiers; |
| 158 | SmallVector<OMPClause *, 5> Clauses; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 159 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1> |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 160 | FirstClauses(OMPC_unknown + 1); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 161 | unsigned ScopeFlags = |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 162 | Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 163 | SourceLocation Loc = ConsumeToken(), EndLoc; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 164 | auto DKind = ParseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 165 | OpenMPDirectiveKind CancelRegion = OMPD_unknown; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 166 | // Name of critical directive. |
| 167 | DeclarationNameInfo DirName; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 168 | StmtResult Directive = StmtError(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 169 | bool HasAssociatedStatement = true; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 170 | bool FlushHasClause = false; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 171 | |
| 172 | switch (DKind) { |
| 173 | case OMPD_threadprivate: |
| 174 | ConsumeToken(); |
| 175 | if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, false)) { |
| 176 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 177 | // extra tokens. |
| 178 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 179 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 180 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 181 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 182 | } |
| 183 | DeclGroupPtrTy Res = |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 184 | Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 185 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 186 | } |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 187 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 188 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 189 | case OMPD_flush: |
| 190 | if (PP.LookAhead(0).is(tok::l_paren)) { |
| 191 | FlushHasClause = true; |
| 192 | // Push copy of the current token back to stream to properly parse |
| 193 | // pseudo-clause OMPFlushClause. |
| 194 | PP.EnterToken(Tok); |
| 195 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 196 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 197 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 198 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 199 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame^] | 200 | case OMPD_cancel: |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 201 | if (!StandAloneAllowed) { |
| 202 | Diag(Tok, diag::err_omp_immediate_directive) |
| 203 | << getOpenMPDirectiveName(DKind); |
| 204 | } |
| 205 | HasAssociatedStatement = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 206 | // Fall through for further analysis. |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 207 | case OMPD_parallel: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 208 | case OMPD_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 209 | case OMPD_for: |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 210 | case OMPD_for_simd: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 211 | case OMPD_sections: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 212 | case OMPD_single: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 213 | case OMPD_section: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 214 | case OMPD_master: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 215 | case OMPD_critical: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 216 | case OMPD_parallel_for: |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 217 | case OMPD_parallel_for_simd: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 218 | case OMPD_parallel_sections: |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 219 | case OMPD_task: |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 220 | case OMPD_ordered: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 221 | case OMPD_atomic: |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 222 | case OMPD_target: |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 223 | case OMPD_teams: |
| 224 | case OMPD_taskgroup: { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 225 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 226 | // Parse directive name of the 'critical' directive if any. |
| 227 | if (DKind == OMPD_critical) { |
| 228 | BalancedDelimiterTracker T(*this, tok::l_paren, |
| 229 | tok::annot_pragma_openmp_end); |
| 230 | if (!T.consumeOpen()) { |
| 231 | if (Tok.isAnyIdentifier()) { |
| 232 | DirName = |
| 233 | DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation()); |
| 234 | ConsumeAnyToken(); |
| 235 | } else { |
| 236 | Diag(Tok, diag::err_omp_expected_identifier_for_critical); |
| 237 | } |
| 238 | T.consumeClose(); |
| 239 | } |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame^] | 240 | } else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 241 | CancelRegion = ParseOpenMPDirectiveKind(*this); |
| 242 | if (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 243 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 244 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 245 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 246 | if (isOpenMPLoopDirective(DKind)) |
| 247 | ScopeFlags |= Scope::OpenMPLoopDirectiveScope; |
| 248 | if (isOpenMPSimdDirective(DKind)) |
| 249 | ScopeFlags |= Scope::OpenMPSimdDirectiveScope; |
| 250 | ParseScope OMPDirectiveScope(this, ScopeFlags); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 251 | Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 252 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 253 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 254 | OpenMPClauseKind CKind = |
| 255 | Tok.isAnnotation() |
| 256 | ? OMPC_unknown |
| 257 | : FlushHasClause ? OMPC_flush |
| 258 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 259 | Actions.StartOpenMPClause(CKind); |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 260 | FlushHasClause = false; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 261 | OMPClause *Clause = |
| 262 | ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 263 | FirstClauses[CKind].setInt(true); |
| 264 | if (Clause) { |
| 265 | FirstClauses[CKind].setPointer(Clause); |
| 266 | Clauses.push_back(Clause); |
| 267 | } |
| 268 | |
| 269 | // Skip ',' if any. |
| 270 | if (Tok.is(tok::comma)) |
| 271 | ConsumeToken(); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 272 | Actions.EndOpenMPClause(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 273 | } |
| 274 | // End location of the directive. |
| 275 | EndLoc = Tok.getLocation(); |
| 276 | // Consume final annot_pragma_openmp_end. |
| 277 | ConsumeToken(); |
| 278 | |
| 279 | StmtResult AssociatedStmt; |
| 280 | bool CreateDirective = true; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 281 | if (HasAssociatedStatement) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 282 | // The body is a block scope like in Lambdas and Blocks. |
| 283 | Sema::CompoundScopeRAII CompoundScope(Actions); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 284 | Actions.ActOnOpenMPRegionStart(DKind, getCurScope()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 285 | Actions.ActOnStartOfCompoundStmt(); |
| 286 | // Parse statement |
| 287 | AssociatedStmt = ParseStatement(); |
| 288 | Actions.ActOnFinishOfCompoundStmt(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 289 | AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses); |
| 290 | CreateDirective = AssociatedStmt.isUsable(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 291 | } |
| 292 | if (CreateDirective) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 293 | Directive = Actions.ActOnOpenMPExecutableDirective( |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 294 | DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc, |
| 295 | EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 296 | |
| 297 | // Exit scope. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 298 | Actions.EndOpenMPDSABlock(Directive.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 299 | OMPDirectiveScope.Exit(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 300 | break; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 301 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 302 | case OMPD_unknown: |
| 303 | Diag(Tok, diag::err_omp_unknown_directive); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 304 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 305 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 306 | } |
| 307 | return Directive; |
| 308 | } |
| 309 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 310 | /// \brief Parses list of simple variables for '#pragma omp threadprivate' |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 311 | /// directive. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 312 | /// |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 313 | /// simple-variable-list: |
| 314 | /// '(' id-expression {, id-expression} ')' |
| 315 | /// |
| 316 | bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind, |
| 317 | SmallVectorImpl<Expr *> &VarList, |
| 318 | bool AllowScopeSpecifier) { |
| 319 | VarList.clear(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 320 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 321 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 322 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 323 | getOpenMPDirectiveName(Kind))) |
| 324 | return true; |
| 325 | bool IsCorrect = true; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 326 | bool NoIdentIsFound = true; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 327 | |
| 328 | // Read tokens while ')' or annot_pragma_openmp_end is not found. |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 329 | 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] | 330 | CXXScopeSpec SS; |
| 331 | SourceLocation TemplateKWLoc; |
| 332 | UnqualifiedId Name; |
| 333 | // Read var name. |
| 334 | Token PrevTok = Tok; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 335 | NoIdentIsFound = false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 336 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 337 | if (AllowScopeSpecifier && getLangOpts().CPlusPlus && |
| 338 | ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 339 | IsCorrect = false; |
| 340 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 341 | StopBeforeMatch); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 342 | } else if (ParseUnqualifiedId(SS, false, false, false, ParsedType(), |
| 343 | TemplateKWLoc, Name)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 344 | IsCorrect = false; |
| 345 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 346 | StopBeforeMatch); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 347 | } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) && |
| 348 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 349 | IsCorrect = false; |
| 350 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 351 | StopBeforeMatch); |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 352 | Diag(PrevTok.getLocation(), diag::err_expected) |
| 353 | << tok::identifier |
| 354 | << SourceRange(PrevTok.getLocation(), PrevTokLocation); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 355 | } else { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 356 | DeclarationNameInfo NameInfo = Actions.GetNameFromUnqualifiedId(Name); |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 357 | ExprResult Res = |
| 358 | Actions.ActOnOpenMPIdExpression(getCurScope(), SS, NameInfo); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 359 | if (Res.isUsable()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 360 | VarList.push_back(Res.get()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 361 | } |
| 362 | // Consume ','. |
| 363 | if (Tok.is(tok::comma)) { |
| 364 | ConsumeToken(); |
| 365 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 368 | if (NoIdentIsFound) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 369 | Diag(Tok, diag::err_expected) << tok::identifier; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 370 | IsCorrect = false; |
| 371 | } |
| 372 | |
| 373 | // Parse ')'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 374 | IsCorrect = !T.consumeClose() && IsCorrect; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 375 | |
| 376 | return !IsCorrect && VarList.empty(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 377 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 378 | |
| 379 | /// \brief Parsing of OpenMP clauses. |
| 380 | /// |
| 381 | /// clause: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 382 | /// if-clause | final-clause | num_threads-clause | safelen-clause | |
| 383 | /// default-clause | private-clause | firstprivate-clause | shared-clause |
| 384 | /// | linear-clause | aligned-clause | collapse-clause | |
| 385 | /// lastprivate-clause | reduction-clause | proc_bind-clause | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 386 | /// schedule-clause | copyin-clause | copyprivate-clause | untied-clause | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 387 | /// mergeable-clause | flush-clause | read-clause | write-clause | |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 388 | /// update-clause | capture-clause | seq_cst-clause |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 389 | /// |
| 390 | OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, |
| 391 | OpenMPClauseKind CKind, bool FirstClause) { |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 392 | OMPClause *Clause = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 393 | bool ErrorFound = false; |
| 394 | // Check if clause is allowed for the given directive. |
| 395 | if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 396 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 397 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 398 | ErrorFound = true; |
| 399 | } |
| 400 | |
| 401 | switch (CKind) { |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 402 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 403 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 404 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 405 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 406 | case OMPC_collapse: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 407 | // OpenMP [2.5, Restrictions] |
| 408 | // At most one if clause can appear on the directive. |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 409 | // At most one num_threads clause can appear on the directive. |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 410 | // OpenMP [2.8.1, simd construct, Restrictions] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 411 | // Only one safelen clause can appear on a simd directive. |
| 412 | // Only one collapse clause can appear on a simd directive. |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 413 | // OpenMP [2.11.1, task Construct, Restrictions] |
| 414 | // At most one if clause can appear on the directive. |
| 415 | // At most one final clause can appear on the directive. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 416 | if (!FirstClause) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 417 | Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) |
| 418 | << getOpenMPClauseName(CKind); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 419 | ErrorFound = true; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | Clause = ParseOpenMPSingleExprClause(CKind); |
| 423 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 424 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 425 | case OMPC_proc_bind: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 426 | // OpenMP [2.14.3.1, Restrictions] |
| 427 | // Only a single default clause may be specified on a parallel, task or |
| 428 | // teams directive. |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 429 | // OpenMP [2.5, parallel Construct, Restrictions] |
| 430 | // At most one proc_bind clause can appear on the directive. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 431 | if (!FirstClause) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 432 | Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) |
| 433 | << getOpenMPClauseName(CKind); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 434 | ErrorFound = true; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | Clause = ParseOpenMPSimpleClause(CKind); |
| 438 | break; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 439 | case OMPC_schedule: |
| 440 | // OpenMP [2.7.1, Restrictions, p. 3] |
| 441 | // Only one schedule clause can appear on a loop directive. |
| 442 | if (!FirstClause) { |
| 443 | Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) |
| 444 | << getOpenMPClauseName(CKind); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 445 | ErrorFound = true; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | Clause = ParseOpenMPSingleExprWithArgClause(CKind); |
| 449 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 450 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 451 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 452 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 453 | case OMPC_mergeable: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 454 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 455 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 456 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 457 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 458 | case OMPC_seq_cst: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 459 | // OpenMP [2.7.1, Restrictions, p. 9] |
| 460 | // Only one ordered clause can appear on a loop directive. |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 461 | // OpenMP [2.7.1, Restrictions, C/C++, p. 4] |
| 462 | // Only one nowait clause can appear on a for directive. |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 463 | if (!FirstClause) { |
| 464 | Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) |
| 465 | << getOpenMPClauseName(CKind); |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 466 | ErrorFound = true; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | Clause = ParseOpenMPClause(CKind); |
| 470 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 471 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 472 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 473 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 474 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 475 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 476 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 477 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 478 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 479 | case OMPC_copyprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 480 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 481 | case OMPC_depend: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 482 | Clause = ParseOpenMPVarListClause(CKind); |
| 483 | break; |
| 484 | case OMPC_unknown: |
| 485 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 486 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 487 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 488 | break; |
| 489 | case OMPC_threadprivate: |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 490 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 491 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 492 | SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 493 | break; |
| 494 | } |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 495 | return ErrorFound ? nullptr : Clause; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 498 | /// \brief Parsing of OpenMP clauses with single expressions like 'if', |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 499 | /// 'final', 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams' or |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 500 | /// 'thread_limit'. |
| 501 | /// |
| 502 | /// if-clause: |
| 503 | /// 'if' '(' expression ')' |
| 504 | /// |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 505 | /// final-clause: |
| 506 | /// 'final' '(' expression ')' |
| 507 | /// |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 508 | /// num_threads-clause: |
| 509 | /// 'num_threads' '(' expression ')' |
| 510 | /// |
| 511 | /// safelen-clause: |
| 512 | /// 'safelen' '(' expression ')' |
| 513 | /// |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 514 | /// collapse-clause: |
| 515 | /// 'collapse' '(' expression ')' |
| 516 | /// |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 517 | OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) { |
| 518 | SourceLocation Loc = ConsumeToken(); |
| 519 | |
| 520 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 521 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 522 | getOpenMPClauseName(Kind))) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 523 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 524 | |
| 525 | ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); |
| 526 | ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional)); |
| 527 | |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 528 | // Parse ')'. |
| 529 | T.consumeClose(); |
| 530 | |
| 531 | if (Val.isInvalid()) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 532 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 533 | |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 534 | return Actions.ActOnOpenMPSingleExprClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 535 | Kind, Val.get(), Loc, T.getOpenLocation(), T.getCloseLocation()); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 536 | } |
| 537 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 538 | /// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 539 | /// |
| 540 | /// default-clause: |
| 541 | /// 'default' '(' 'none' | 'shared' ') |
| 542 | /// |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 543 | /// proc_bind-clause: |
| 544 | /// 'proc_bind' '(' 'master' | 'close' | 'spread' ') |
| 545 | /// |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 546 | OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) { |
| 547 | SourceLocation Loc = Tok.getLocation(); |
| 548 | SourceLocation LOpen = ConsumeToken(); |
| 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 | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 555 | unsigned Type = getOpenMPSimpleClauseType( |
| 556 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 557 | SourceLocation TypeLoc = Tok.getLocation(); |
| 558 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 559 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 560 | ConsumeAnyToken(); |
| 561 | |
| 562 | // Parse ')'. |
| 563 | T.consumeClose(); |
| 564 | |
| 565 | return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc, |
| 566 | Tok.getLocation()); |
| 567 | } |
| 568 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 569 | /// \brief Parsing of OpenMP clauses like 'ordered'. |
| 570 | /// |
| 571 | /// ordered-clause: |
| 572 | /// 'ordered' |
| 573 | /// |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 574 | /// nowait-clause: |
| 575 | /// 'nowait' |
| 576 | /// |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 577 | /// untied-clause: |
| 578 | /// 'untied' |
| 579 | /// |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 580 | /// mergeable-clause: |
| 581 | /// 'mergeable' |
| 582 | /// |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 583 | /// read-clause: |
| 584 | /// 'read' |
| 585 | /// |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 586 | OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) { |
| 587 | SourceLocation Loc = Tok.getLocation(); |
| 588 | ConsumeAnyToken(); |
| 589 | |
| 590 | return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation()); |
| 591 | } |
| 592 | |
| 593 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 594 | /// \brief Parsing of OpenMP clauses with single expressions and some additional |
| 595 | /// argument like 'schedule' or 'dist_schedule'. |
| 596 | /// |
| 597 | /// schedule-clause: |
| 598 | /// 'schedule' '(' kind [',' expression ] ')' |
| 599 | /// |
| 600 | OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) { |
| 601 | SourceLocation Loc = ConsumeToken(); |
| 602 | SourceLocation CommaLoc; |
| 603 | // Parse '('. |
| 604 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 605 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 606 | getOpenMPClauseName(Kind))) |
| 607 | return nullptr; |
| 608 | |
| 609 | ExprResult Val; |
| 610 | unsigned Type = getOpenMPSimpleClauseType( |
| 611 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 612 | SourceLocation KLoc = Tok.getLocation(); |
| 613 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 614 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 615 | ConsumeAnyToken(); |
| 616 | |
| 617 | if (Kind == OMPC_schedule && |
| 618 | (Type == OMPC_SCHEDULE_static || Type == OMPC_SCHEDULE_dynamic || |
| 619 | Type == OMPC_SCHEDULE_guided) && |
| 620 | Tok.is(tok::comma)) { |
| 621 | CommaLoc = ConsumeAnyToken(); |
| 622 | ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); |
| 623 | Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional); |
| 624 | if (Val.isInvalid()) |
| 625 | return nullptr; |
| 626 | } |
| 627 | |
| 628 | // Parse ')'. |
| 629 | T.consumeClose(); |
| 630 | |
| 631 | return Actions.ActOnOpenMPSingleExprWithArgClause( |
| 632 | Kind, Type, Val.get(), Loc, T.getOpenLocation(), KLoc, CommaLoc, |
| 633 | T.getCloseLocation()); |
| 634 | } |
| 635 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 636 | static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec, |
| 637 | UnqualifiedId &ReductionId) { |
| 638 | SourceLocation TemplateKWLoc; |
| 639 | if (ReductionIdScopeSpec.isEmpty()) { |
| 640 | auto OOK = OO_None; |
| 641 | switch (P.getCurToken().getKind()) { |
| 642 | case tok::plus: |
| 643 | OOK = OO_Plus; |
| 644 | break; |
| 645 | case tok::minus: |
| 646 | OOK = OO_Minus; |
| 647 | break; |
| 648 | case tok::star: |
| 649 | OOK = OO_Star; |
| 650 | break; |
| 651 | case tok::amp: |
| 652 | OOK = OO_Amp; |
| 653 | break; |
| 654 | case tok::pipe: |
| 655 | OOK = OO_Pipe; |
| 656 | break; |
| 657 | case tok::caret: |
| 658 | OOK = OO_Caret; |
| 659 | break; |
| 660 | case tok::ampamp: |
| 661 | OOK = OO_AmpAmp; |
| 662 | break; |
| 663 | case tok::pipepipe: |
| 664 | OOK = OO_PipePipe; |
| 665 | break; |
| 666 | default: |
| 667 | break; |
| 668 | } |
| 669 | if (OOK != OO_None) { |
| 670 | SourceLocation OpLoc = P.ConsumeToken(); |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 671 | SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()}; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 672 | ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations); |
| 673 | return false; |
| 674 | } |
| 675 | } |
| 676 | return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false, |
| 677 | /*AllowDestructorName*/ false, |
| 678 | /*AllowConstructorName*/ false, ParsedType(), |
| 679 | TemplateKWLoc, ReductionId); |
| 680 | } |
| 681 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 682 | /// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate', |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 683 | /// 'shared', 'copyin', 'copyprivate', 'flush' or 'reduction'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 684 | /// |
| 685 | /// private-clause: |
| 686 | /// 'private' '(' list ')' |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 687 | /// firstprivate-clause: |
| 688 | /// 'firstprivate' '(' list ')' |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 689 | /// lastprivate-clause: |
| 690 | /// 'lastprivate' '(' list ')' |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 691 | /// shared-clause: |
| 692 | /// 'shared' '(' list ')' |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 693 | /// linear-clause: |
| 694 | /// 'linear' '(' list [ ':' linear-step ] ')' |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 695 | /// aligned-clause: |
| 696 | /// 'aligned' '(' list [ ':' alignment ] ')' |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 697 | /// reduction-clause: |
| 698 | /// 'reduction' '(' reduction-identifier ':' list ')' |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 699 | /// copyprivate-clause: |
| 700 | /// 'copyprivate' '(' list ')' |
| 701 | /// flush-clause: |
| 702 | /// 'flush' '(' list ')' |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 703 | /// depend-clause: |
| 704 | /// 'depend' '(' in | out | inout : list ')' |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 705 | /// |
| 706 | OMPClause *Parser::ParseOpenMPVarListClause(OpenMPClauseKind Kind) { |
| 707 | SourceLocation Loc = Tok.getLocation(); |
| 708 | SourceLocation LOpen = ConsumeToken(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 709 | SourceLocation ColonLoc = SourceLocation(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 710 | // Optional scope specifier and unqualified id for reduction identifier. |
| 711 | CXXScopeSpec ReductionIdScopeSpec; |
| 712 | UnqualifiedId ReductionId; |
| 713 | bool InvalidReductionId = false; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 714 | OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown; |
| 715 | SourceLocation DepLoc; |
| 716 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 717 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 718 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 719 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 720 | getOpenMPClauseName(Kind))) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 721 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 722 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 723 | // Handle reduction-identifier for reduction clause. |
| 724 | if (Kind == OMPC_reduction) { |
| 725 | ColonProtectionRAIIObject ColonRAII(*this); |
| 726 | if (getLangOpts().CPlusPlus) { |
| 727 | ParseOptionalCXXScopeSpecifier(ReductionIdScopeSpec, ParsedType(), false); |
| 728 | } |
| 729 | InvalidReductionId = |
| 730 | ParseReductionId(*this, ReductionIdScopeSpec, ReductionId); |
| 731 | if (InvalidReductionId) { |
| 732 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 733 | StopBeforeMatch); |
| 734 | } |
| 735 | if (Tok.is(tok::colon)) { |
| 736 | ColonLoc = ConsumeToken(); |
| 737 | } else { |
| 738 | Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier"; |
| 739 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 740 | } else if (Kind == OMPC_depend) { |
| 741 | // Handle dependency type for depend clause. |
| 742 | ColonProtectionRAIIObject ColonRAII(*this); |
| 743 | DepKind = static_cast<OpenMPDependClauseKind>(getOpenMPSimpleClauseType( |
| 744 | Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : "")); |
| 745 | DepLoc = Tok.getLocation(); |
| 746 | |
| 747 | if (DepKind == OMPC_DEPEND_unknown) { |
| 748 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 749 | StopBeforeMatch); |
| 750 | } else { |
| 751 | ConsumeToken(); |
| 752 | } |
| 753 | if (Tok.is(tok::colon)) { |
| 754 | ColonLoc = ConsumeToken(); |
| 755 | } else { |
| 756 | Diag(Tok, diag::warn_pragma_expected_colon) << "dependency type"; |
| 757 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 758 | } |
| 759 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 760 | SmallVector<Expr *, 5> Vars; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 761 | bool IsComma = ((Kind != OMPC_reduction) && (Kind != OMPC_depend)) || |
| 762 | ((Kind == OMPC_reduction) && !InvalidReductionId) || |
| 763 | ((Kind == OMPC_depend) && DepKind != OMPC_DEPEND_unknown); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 764 | const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 765 | while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) && |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 766 | Tok.isNot(tok::annot_pragma_openmp_end))) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 767 | ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 768 | // Parse variable |
Kaelyn Takata | 1586782 | 2014-11-21 18:48:04 +0000 | [diff] [blame] | 769 | ExprResult VarExpr = |
| 770 | Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 771 | if (VarExpr.isUsable()) { |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 772 | Vars.push_back(VarExpr.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 773 | } else { |
| 774 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 775 | StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 776 | } |
| 777 | // Skip ',' if any |
| 778 | IsComma = Tok.is(tok::comma); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 779 | if (IsComma) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 780 | ConsumeToken(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 781 | else if (Tok.isNot(tok::r_paren) && |
| 782 | Tok.isNot(tok::annot_pragma_openmp_end) && |
| 783 | (!MayHaveTail || Tok.isNot(tok::colon))) |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 784 | Diag(Tok, diag::err_omp_expected_punc) |
| 785 | << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush) |
| 786 | : getOpenMPClauseName(Kind)) |
| 787 | << (Kind == OMPC_flush); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 788 | } |
| 789 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 790 | // Parse ':' linear-step (or ':' alignment). |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 791 | Expr *TailExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 792 | const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon); |
| 793 | if (MustHaveTail) { |
| 794 | ColonLoc = Tok.getLocation(); |
| 795 | ConsumeToken(); |
Kaelyn Takata | b16e632 | 2014-11-20 22:06:40 +0000 | [diff] [blame] | 796 | ExprResult Tail = |
| 797 | Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 798 | if (Tail.isUsable()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 799 | TailExpr = Tail.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 800 | else |
| 801 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 802 | StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | // Parse ')'. |
| 806 | T.consumeClose(); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 807 | if ((Kind == OMPC_depend && DepKind != OMPC_DEPEND_unknown && Vars.empty()) || |
| 808 | (Kind != OMPC_depend && Vars.empty()) || (MustHaveTail && !TailExpr) || |
| 809 | InvalidReductionId) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 810 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 811 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 812 | return Actions.ActOnOpenMPVarListClause( |
| 813 | Kind, Vars, TailExpr, Loc, LOpen, ColonLoc, Tok.getLocation(), |
| 814 | ReductionIdScopeSpec, |
| 815 | ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId) |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 816 | : DeclarationNameInfo(), |
| 817 | DepKind, DepLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 818 | } |
| 819 | |