blob: 037dd36fc77253318d115bf4c79776c868247a7e [file] [log] [blame]
Alexey Bataeva769e072013-03-22 06:34:35 +00001//===--- 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
14#include "clang/AST/ASTConsumer.h"
Chandler Carruth5553d0d2014-01-07 11:51:46 +000015#include "RAIIObjectsForParser.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000016#include "clang/AST/StmtOpenMP.h"
Alexey Bataeva769e072013-03-22 06:34:35 +000017#include "clang/Parse/ParseDiagnostic.h"
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000018#include "clang/Parse/Parser.h"
19#include "clang/Sema/Scope.h"
20#include "llvm/ADT/PointerIntPair.h"
Alexey Bataeva769e072013-03-22 06:34:35 +000021using namespace clang;
22
23//===----------------------------------------------------------------------===//
24// OpenMP declarative directives.
25//===----------------------------------------------------------------------===//
26
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000027/// \brief Parsing of declarative OpenMP directives.
28///
29/// threadprivate-directive:
30/// annot_pragma_openmp 'threadprivate' simple-variable-list
Alexey Bataeva769e072013-03-22 06:34:35 +000031///
32Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() {
33 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
Alexey Bataevee6507d2013-11-18 08:17:37 +000034 ParenBraceBracketBalancer BalancerRAIIObj(*this);
Alexey Bataeva769e072013-03-22 06:34:35 +000035
36 SourceLocation Loc = ConsumeToken();
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000037 SmallVector<Expr *, 5> Identifiers;
38 OpenMPDirectiveKind DKind = Tok.isAnnotation() ?
39 OMPD_unknown :
40 getOpenMPDirectiveKind(PP.getSpelling(Tok));
41
42 switch (DKind) {
Alexey Bataeva769e072013-03-22 06:34:35 +000043 case OMPD_threadprivate:
44 ConsumeToken();
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000045 if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, true)) {
Alexey Bataeva769e072013-03-22 06:34:35 +000046 // The last seen token is annot_pragma_openmp_end - need to check for
47 // extra tokens.
48 if (Tok.isNot(tok::annot_pragma_openmp_end)) {
49 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
50 << getOpenMPDirectiveName(OMPD_threadprivate);
Alp Tokerd751fa72013-12-18 19:10:49 +000051 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataeva769e072013-03-22 06:34:35 +000052 }
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000053 // Skip the last annot_pragma_openmp_end.
Alexey Bataeva769e072013-03-22 06:34:35 +000054 ConsumeToken();
55 return Actions.ActOnOpenMPThreadprivateDirective(Loc,
Alexey Bataeva769e072013-03-22 06:34:35 +000056 Identifiers);
57 }
58 break;
59 case OMPD_unknown:
60 Diag(Tok, diag::err_omp_unknown_directive);
61 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000062 case OMPD_parallel:
Alexey Bataev1b59ab52014-02-27 08:29:12 +000063 case OMPD_simd:
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000064 case OMPD_task:
65 case NUM_OPENMP_DIRECTIVES:
Alexey Bataeva769e072013-03-22 06:34:35 +000066 Diag(Tok, diag::err_omp_unexpected_directive)
Alexey Bataev6f6f3b42013-05-13 04:18:18 +000067 << getOpenMPDirectiveName(DKind);
Alexey Bataeva769e072013-03-22 06:34:35 +000068 break;
69 }
Alp Tokerd751fa72013-12-18 19:10:49 +000070 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataeva769e072013-03-22 06:34:35 +000071 return DeclGroupPtrTy();
72}
73
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000074/// \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///
83StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective() {
84 assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!");
Alexey Bataevee6507d2013-11-18 08:17:37 +000085 ParenBraceBracketBalancer BalancerRAIIObj(*this);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000086 SmallVector<Expr *, 5> Identifiers;
87 SmallVector<OMPClause *, 5> Clauses;
88 SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, NUM_OPENMP_CLAUSES>
89 FirstClauses(NUM_OPENMP_CLAUSES);
Alexey Bataev758e55e2013-09-06 18:03:48 +000090 const unsigned ScopeFlags = Scope::FnScope | Scope::DeclScope |
91 Scope::OpenMPDirectiveScope;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000092 SourceLocation Loc = ConsumeToken(), EndLoc;
93 OpenMPDirectiveKind DKind = Tok.isAnnotation() ?
94 OMPD_unknown :
95 getOpenMPDirectiveKind(PP.getSpelling(Tok));
Alexey Bataev758e55e2013-09-06 18:03:48 +000096 // Name of critical directive.
97 DeclarationNameInfo DirName;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000098 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)
108 << getOpenMPDirectiveName(OMPD_threadprivate);
Alp Tokerd751fa72013-12-18 19:10:49 +0000109 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000110 }
111 DeclGroupPtrTy Res =
112 Actions.ActOnOpenMPThreadprivateDirective(Loc,
113 Identifiers);
114 Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation());
115 }
Alp Tokerd751fa72013-12-18 19:10:49 +0000116 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000117 break;
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000118 case OMPD_parallel:
119 case OMPD_simd: {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000120 ConsumeToken();
Alexey Bataev758e55e2013-09-06 18:03:48 +0000121
122 Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope());
123
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000124 while (Tok.isNot(tok::annot_pragma_openmp_end)) {
125 OpenMPClauseKind CKind = Tok.isAnnotation() ?
126 OMPC_unknown :
127 getOpenMPClauseKind(PP.getSpelling(Tok));
128 OMPClause *Clause = ParseOpenMPClause(DKind, CKind,
129 !FirstClauses[CKind].getInt());
130 FirstClauses[CKind].setInt(true);
131 if (Clause) {
132 FirstClauses[CKind].setPointer(Clause);
133 Clauses.push_back(Clause);
134 }
135
136 // Skip ',' if any.
137 if (Tok.is(tok::comma))
138 ConsumeToken();
139 }
140 // End location of the directive.
141 EndLoc = Tok.getLocation();
142 // Consume final annot_pragma_openmp_end.
143 ConsumeToken();
144
145 StmtResult AssociatedStmt;
146 bool CreateDirective = true;
147 ParseScope OMPDirectiveScope(this, ScopeFlags);
148 {
149 // The body is a block scope like in Lambdas and Blocks.
150 Sema::CompoundScopeRAII CompoundScope(Actions);
Alexey Bataev758e55e2013-09-06 18:03:48 +0000151 Actions.ActOnCapturedRegionStart(Loc, getCurScope(), CR_OpenMP, 1);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000152 Actions.ActOnStartOfCompoundStmt();
153 // Parse statement
154 AssociatedStmt = ParseStatement();
155 Actions.ActOnFinishOfCompoundStmt();
156 if (!AssociatedStmt.isUsable()) {
157 Actions.ActOnCapturedRegionError();
158 CreateDirective = false;
159 } else {
160 AssociatedStmt = Actions.ActOnCapturedRegionEnd(AssociatedStmt.take());
161 CreateDirective = AssociatedStmt.isUsable();
162 }
163 }
164 if (CreateDirective)
165 Directive = Actions.ActOnOpenMPExecutableDirective(DKind, Clauses,
166 AssociatedStmt.take(),
167 Loc, EndLoc);
168
169 // Exit scope.
Alexey Bataev758e55e2013-09-06 18:03:48 +0000170 Actions.EndOpenMPDSABlock(Directive.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000171 OMPDirectiveScope.Exit();
172 }
173 break;
174 case OMPD_unknown:
175 Diag(Tok, diag::err_omp_unknown_directive);
Alp Tokerd751fa72013-12-18 19:10:49 +0000176 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000177 break;
178 case OMPD_task:
179 case NUM_OPENMP_DIRECTIVES:
180 Diag(Tok, diag::err_omp_unexpected_directive)
181 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000182 SkipUntil(tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000183 break;
184 }
185 return Directive;
186}
187
Alexey Bataeva769e072013-03-22 06:34:35 +0000188/// \brief Parses list of simple variables for '#pragma omp threadprivate'
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000189/// directive.
Alexey Bataeva769e072013-03-22 06:34:35 +0000190///
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000191/// simple-variable-list:
192/// '(' id-expression {, id-expression} ')'
193///
194bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind,
195 SmallVectorImpl<Expr *> &VarList,
196 bool AllowScopeSpecifier) {
197 VarList.clear();
Alexey Bataeva769e072013-03-22 06:34:35 +0000198 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000199 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000200 if (T.expectAndConsume(diag::err_expected_lparen_after,
201 getOpenMPDirectiveName(Kind)))
202 return true;
203 bool IsCorrect = true;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000204 bool NoIdentIsFound = true;
Alexey Bataeva769e072013-03-22 06:34:35 +0000205
206 // Read tokens while ')' or annot_pragma_openmp_end is not found.
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000207 while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000208 CXXScopeSpec SS;
209 SourceLocation TemplateKWLoc;
210 UnqualifiedId Name;
211 // Read var name.
212 Token PrevTok = Tok;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000213 NoIdentIsFound = false;
Alexey Bataeva769e072013-03-22 06:34:35 +0000214
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000215 if (AllowScopeSpecifier && getLangOpts().CPlusPlus &&
216 ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000217 IsCorrect = false;
218 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000219 StopBeforeMatch);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000220 } else if (ParseUnqualifiedId(SS, false, false, false, ParsedType(),
221 TemplateKWLoc, Name)) {
Alexey Bataeva769e072013-03-22 06:34:35 +0000222 IsCorrect = false;
223 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000224 StopBeforeMatch);
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000225 } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) &&
226 Tok.isNot(tok::annot_pragma_openmp_end)) {
227 IsCorrect = false;
228 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000229 StopBeforeMatch);
Alp Tokerec543272013-12-24 09:48:30 +0000230 Diag(PrevTok.getLocation(), diag::err_expected)
231 << tok::identifier
232 << SourceRange(PrevTok.getLocation(), PrevTokLocation);
Alexey Bataeva769e072013-03-22 06:34:35 +0000233 } else {
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000234 DeclarationNameInfo NameInfo = Actions.GetNameFromUnqualifiedId(Name);
235 ExprResult Res = Actions.ActOnOpenMPIdExpression(getCurScope(), SS,
236 NameInfo);
237 if (Res.isUsable())
238 VarList.push_back(Res.take());
Alexey Bataeva769e072013-03-22 06:34:35 +0000239 }
240 // Consume ','.
241 if (Tok.is(tok::comma)) {
242 ConsumeToken();
243 }
Alexey Bataeva769e072013-03-22 06:34:35 +0000244 }
245
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000246 if (NoIdentIsFound) {
Alp Tokerec543272013-12-24 09:48:30 +0000247 Diag(Tok, diag::err_expected) << tok::identifier;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000248 IsCorrect = false;
249 }
250
251 // Parse ')'.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000252 IsCorrect = !T.consumeClose() && IsCorrect;
Alexey Bataev6f6f3b42013-05-13 04:18:18 +0000253
254 return !IsCorrect && VarList.empty();
Alexey Bataeva769e072013-03-22 06:34:35 +0000255}
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000256
257/// \brief Parsing of OpenMP clauses.
258///
259/// clause:
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000260/// default-clause|private-clause|firstprivate-clause|shared-clause
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000261///
262OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind,
263 OpenMPClauseKind CKind, bool FirstClause) {
264 OMPClause *Clause = 0;
265 bool ErrorFound = false;
266 // Check if clause is allowed for the given directive.
267 if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) {
268 Diag(Tok, diag::err_omp_unexpected_clause)
269 << getOpenMPClauseName(CKind) << getOpenMPDirectiveName(DKind);
270 ErrorFound = true;
271 }
272
273 switch (CKind) {
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000274 case OMPC_if:
Alexey Bataev568a8332014-03-06 06:15:19 +0000275 case OMPC_num_threads:
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000276 // OpenMP [2.5, Restrictions]
277 // At most one if clause can appear on the directive.
Alexey Bataev568a8332014-03-06 06:15:19 +0000278 // At most one num_threads clause can appear on the directive.
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000279 if (!FirstClause) {
280 Diag(Tok, diag::err_omp_more_one_clause)
281 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind);
282 }
283
284 Clause = ParseOpenMPSingleExprClause(CKind);
285 break;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000286 case OMPC_default:
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000287 // OpenMP [2.14.3.1, Restrictions]
288 // Only a single default clause may be specified on a parallel, task or
289 // teams directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000290 if (!FirstClause) {
291 Diag(Tok, diag::err_omp_more_one_clause)
292 << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind);
293 }
294
295 Clause = ParseOpenMPSimpleClause(CKind);
296 break;
297 case OMPC_private:
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000298 case OMPC_firstprivate:
Alexey Bataev758e55e2013-09-06 18:03:48 +0000299 case OMPC_shared:
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000300 Clause = ParseOpenMPVarListClause(CKind);
301 break;
302 case OMPC_unknown:
303 Diag(Tok, diag::warn_omp_extra_tokens_at_eol)
304 << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000305 SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000306 break;
307 case OMPC_threadprivate:
308 case NUM_OPENMP_CLAUSES:
309 Diag(Tok, diag::err_omp_unexpected_clause)
310 << getOpenMPClauseName(CKind) << getOpenMPDirectiveName(DKind);
Alp Tokerd751fa72013-12-18 19:10:49 +0000311 SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000312 break;
313 }
314 return ErrorFound ? 0 : Clause;
315}
316
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000317/// \brief Parsing of OpenMP clauses with single expressions like 'if',
318/// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams' or
319/// 'thread_limit'.
320///
321/// if-clause:
322/// 'if' '(' expression ')'
323///
324OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) {
325 SourceLocation Loc = ConsumeToken();
326
327 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
328 if (T.expectAndConsume(diag::err_expected_lparen_after,
329 getOpenMPClauseName(Kind)))
330 return 0;
331
332 ExprResult LHS(ParseCastExpression(false, false, NotTypeCast));
333 ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional));
334
Alexey Bataevaadd52e2014-02-13 05:29:23 +0000335 // Parse ')'.
336 T.consumeClose();
337
338 if (Val.isInvalid())
339 return 0;
340
341 return Actions.ActOnOpenMPSingleExprClause(Kind, Val.take(), Loc,
342 T.getOpenLocation(),
343 T.getCloseLocation());
344}
345
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000346/// \brief Parsing of simple OpenMP clauses like 'default'.
347///
348/// default-clause:
349/// 'default' '(' 'none' | 'shared' ')
350///
351OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) {
352 SourceLocation Loc = Tok.getLocation();
353 SourceLocation LOpen = ConsumeToken();
354 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000355 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000356 if (T.expectAndConsume(diag::err_expected_lparen_after,
357 getOpenMPClauseName(Kind)))
358 return 0;
359
360 unsigned Type = Tok.isAnnotation() ?
Benjamin Kramera3d53042013-07-20 12:06:17 +0000361 unsigned(OMPC_DEFAULT_unknown) :
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000362 getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok));
363 SourceLocation TypeLoc = Tok.getLocation();
364 if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) &&
365 Tok.isNot(tok::annot_pragma_openmp_end))
366 ConsumeAnyToken();
367
368 // Parse ')'.
369 T.consumeClose();
370
371 return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc,
372 Tok.getLocation());
373}
374
375/// \brief Parsing of OpenMP clause 'private', 'firstprivate',
376/// 'shared', 'copyin', or 'reduction'.
377///
378/// private-clause:
379/// 'private' '(' list ')'
Alexey Bataevd5af8e42013-10-01 05:32:34 +0000380/// firstprivate-clause:
381/// 'firstprivate' '(' list ')'
Alexey Bataev758e55e2013-09-06 18:03:48 +0000382/// shared-clause:
383/// 'shared' '(' list ')'
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000384///
385OMPClause *Parser::ParseOpenMPVarListClause(OpenMPClauseKind Kind) {
386 SourceLocation Loc = Tok.getLocation();
387 SourceLocation LOpen = ConsumeToken();
388 // Parse '('.
Alp Tokerd751fa72013-12-18 19:10:49 +0000389 BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000390 if (T.expectAndConsume(diag::err_expected_lparen_after,
391 getOpenMPClauseName(Kind)))
392 return 0;
393
394 SmallVector<Expr *, 5> Vars;
395 bool IsComma = true;
396 while (IsComma || (Tok.isNot(tok::r_paren) &&
397 Tok.isNot(tok::annot_pragma_openmp_end))) {
398 // Parse variable
399 ExprResult VarExpr = ParseAssignmentExpression();
400 if (VarExpr.isUsable()) {
401 Vars.push_back(VarExpr.take());
402 } else {
403 SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end,
Alp Tokerd751fa72013-12-18 19:10:49 +0000404 StopBeforeMatch);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000405 }
406 // Skip ',' if any
407 IsComma = Tok.is(tok::comma);
408 if (IsComma) {
409 ConsumeToken();
410 } else if (Tok.isNot(tok::r_paren) &&
411 Tok.isNot(tok::annot_pragma_openmp_end)) {
412 Diag(Tok, diag::err_omp_expected_punc)
David Majnemer88969812014-02-10 19:06:37 +0000413 << getOpenMPClauseName(Kind);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000414 }
415 }
416
417 // Parse ')'.
418 T.consumeClose();
419 if (Vars.empty())
420 return 0;
421
422 return Actions.ActOnOpenMPVarListClause(Kind, Vars, Loc, LOpen,
423 Tok.getLocation());
424}
425