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