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