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