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