@@ -36,9 +36,12 @@ enum class OpenACCDirectiveKindEx {
36
36
// identifies the first token), and doesn't fully handle 'enter data', 'exit
37
37
// data', nor any of the 'atomic' variants, just the first token of each. So
38
38
// this should only be used by `ParseOpenACCDirectiveKind`.
39
- OpenACCDirectiveKindEx getOpenACCDirectiveKind (StringRef Name) {
39
+ OpenACCDirectiveKindEx getOpenACCDirectiveKind (Token Tok) {
40
+ if (!Tok.is (tok::identifier))
41
+ return OpenACCDirectiveKindEx::Invalid;
40
42
OpenACCDirectiveKind DirKind =
41
- llvm::StringSwitch<OpenACCDirectiveKind>(Name)
43
+ llvm::StringSwitch<OpenACCDirectiveKind>(
44
+ Tok.getIdentifierInfo ()->getName ())
42
45
.Case (" parallel" , OpenACCDirectiveKind::Parallel)
43
46
.Case (" serial" , OpenACCDirectiveKind::Serial)
44
47
.Case (" kernels" , OpenACCDirectiveKind::Kernels)
@@ -58,39 +61,46 @@ OpenACCDirectiveKindEx getOpenACCDirectiveKind(StringRef Name) {
58
61
if (DirKind != OpenACCDirectiveKind::Invalid)
59
62
return static_cast <OpenACCDirectiveKindEx>(DirKind);
60
63
61
- return llvm::StringSwitch<OpenACCDirectiveKindEx>(Name)
64
+ return llvm::StringSwitch<OpenACCDirectiveKindEx>(
65
+ Tok.getIdentifierInfo ()->getName ())
62
66
.Case (" enter" , OpenACCDirectiveKindEx::Enter)
63
67
.Case (" exit" , OpenACCDirectiveKindEx::Exit)
64
68
.Default (OpenACCDirectiveKindEx::Invalid);
65
69
}
66
70
67
71
// Since 'atomic' is effectively a compound directive, this will decode the
68
72
// second part of the directive.
69
- OpenACCAtomicKind getOpenACCAtomicKind (StringRef Name) {
70
- return llvm::StringSwitch<OpenACCAtomicKind>(Name)
73
+ OpenACCAtomicKind getOpenACCAtomicKind (Token Tok) {
74
+ if (!Tok.is (tok::identifier))
75
+ return OpenACCAtomicKind::Invalid;
76
+ return llvm::StringSwitch<OpenACCAtomicKind>(
77
+ Tok.getIdentifierInfo ()->getName ())
71
78
.Case (" read" , OpenACCAtomicKind::Read)
72
79
.Case (" write" , OpenACCAtomicKind::Write)
73
80
.Case (" update" , OpenACCAtomicKind::Update)
74
81
.Case (" capture" , OpenACCAtomicKind::Capture)
75
82
.Default (OpenACCAtomicKind::Invalid);
76
83
}
77
84
78
- bool isOpenACCDirectiveKind (OpenACCDirectiveKind Kind, StringRef Tok) {
85
+ bool isOpenACCDirectiveKind (OpenACCDirectiveKind Kind, Token Tok) {
86
+ if (!Tok.is (tok::identifier))
87
+ return false ;
88
+
79
89
switch (Kind) {
80
90
case OpenACCDirectiveKind::Parallel:
81
- return Tok == " parallel" ;
91
+ return Tok. getIdentifierInfo ()-> isStr ( " parallel" ) ;
82
92
case OpenACCDirectiveKind::Serial:
83
- return Tok == " serial" ;
93
+ return Tok. getIdentifierInfo ()-> isStr ( " serial" ) ;
84
94
case OpenACCDirectiveKind::Kernels:
85
- return Tok == " kernels" ;
95
+ return Tok. getIdentifierInfo ()-> isStr ( " kernels" ) ;
86
96
case OpenACCDirectiveKind::Data:
87
- return Tok == " data" ;
97
+ return Tok. getIdentifierInfo ()-> isStr ( " data" ) ;
88
98
case OpenACCDirectiveKind::HostData:
89
- return Tok == " host_data" ;
99
+ return Tok. getIdentifierInfo ()-> isStr ( " host_data" ) ;
90
100
case OpenACCDirectiveKind::Loop:
91
- return Tok == " loop" ;
101
+ return Tok. getIdentifierInfo ()-> isStr ( " loop" ) ;
92
102
case OpenACCDirectiveKind::Cache:
93
- return Tok == " cache" ;
103
+ return Tok. getIdentifierInfo ()-> isStr ( " cache" ) ;
94
104
95
105
case OpenACCDirectiveKind::ParallelLoop:
96
106
case OpenACCDirectiveKind::SerialLoop:
@@ -100,19 +110,19 @@ bool isOpenACCDirectiveKind(OpenACCDirectiveKind Kind, StringRef Tok) {
100
110
return false ;
101
111
102
112
case OpenACCDirectiveKind::Atomic:
103
- return Tok == " atomic" ;
113
+ return Tok. getIdentifierInfo ()-> isStr ( " atomic" ) ;
104
114
case OpenACCDirectiveKind::Routine:
105
- return Tok == " routine" ;
115
+ return Tok. getIdentifierInfo ()-> isStr ( " routine" ) ;
106
116
case OpenACCDirectiveKind::Declare:
107
- return Tok == " declare" ;
117
+ return Tok. getIdentifierInfo ()-> isStr ( " declare" ) ;
108
118
case OpenACCDirectiveKind::Init:
109
- return Tok == " init" ;
119
+ return Tok. getIdentifierInfo ()-> isStr ( " init" ) ;
110
120
case OpenACCDirectiveKind::Shutdown:
111
- return Tok == " shutdown" ;
121
+ return Tok. getIdentifierInfo ()-> isStr ( " shutdown" ) ;
112
122
case OpenACCDirectiveKind::Set:
113
- return Tok == " set" ;
123
+ return Tok. getIdentifierInfo ()-> isStr ( " set" ) ;
114
124
case OpenACCDirectiveKind::Update:
115
- return Tok == " update" ;
125
+ return Tok. getIdentifierInfo ()-> isStr ( " update" ) ;
116
126
case OpenACCDirectiveKind::Invalid:
117
127
return false ;
118
128
}
@@ -121,20 +131,22 @@ bool isOpenACCDirectiveKind(OpenACCDirectiveKind Kind, StringRef Tok) {
121
131
122
132
OpenACCDirectiveKind
123
133
ParseOpenACCEnterExitDataDirective (Parser &P, Token FirstTok,
124
- StringRef FirstTokSpelling,
125
134
OpenACCDirectiveKindEx ExtDirKind) {
126
135
Token SecondTok = P.getCurToken ();
127
136
128
137
if (SecondTok.isAnnotation ()) {
129
- P.Diag (FirstTok, diag::err_acc_invalid_directive) << 0 << FirstTokSpelling;
138
+ P.Diag (FirstTok, diag::err_acc_invalid_directive)
139
+ << 0 << FirstTok.getIdentifierInfo ();
130
140
return OpenACCDirectiveKind::Invalid;
131
141
}
132
142
133
- std::string SecondTokSpelling = P.getPreprocessor ().getSpelling (SecondTok);
134
-
135
- if (!isOpenACCDirectiveKind (OpenACCDirectiveKind::Data, SecondTokSpelling)) {
136
- P.Diag (FirstTok, diag::err_acc_invalid_directive)
137
- << 1 << FirstTokSpelling << SecondTokSpelling;
143
+ if (!isOpenACCDirectiveKind (OpenACCDirectiveKind::Data, SecondTok)) {
144
+ if (!SecondTok.is (tok::identifier))
145
+ P.Diag (SecondTok, diag::err_expected) << tok::identifier;
146
+ else
147
+ P.Diag (FirstTok, diag::err_acc_invalid_directive)
148
+ << 1 << FirstTok.getIdentifierInfo ()->getName ()
149
+ << SecondTok.getIdentifierInfo ()->getName ();
138
150
return OpenACCDirectiveKind::Invalid;
139
151
}
140
152
@@ -152,9 +164,7 @@ OpenACCAtomicKind ParseOpenACCAtomicKind(Parser &P) {
152
164
if (AtomicClauseToken.isAnnotation ())
153
165
return OpenACCAtomicKind::Update;
154
166
155
- std::string AtomicClauseSpelling =
156
- P.getPreprocessor ().getSpelling (AtomicClauseToken);
157
- OpenACCAtomicKind AtomicKind = getOpenACCAtomicKind (AtomicClauseSpelling);
167
+ OpenACCAtomicKind AtomicKind = getOpenACCAtomicKind (AtomicClauseToken);
158
168
159
169
// If we don't know what this is, treat it as 'nothing', and treat the rest of
160
170
// this as a clause list, which, despite being invalid, is likely what the
@@ -178,9 +188,8 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) {
178
188
}
179
189
180
190
P.ConsumeToken ();
181
- std::string FirstTokSpelling = P.getPreprocessor ().getSpelling (FirstTok);
182
191
183
- OpenACCDirectiveKindEx ExDirKind = getOpenACCDirectiveKind (FirstTokSpelling );
192
+ OpenACCDirectiveKindEx ExDirKind = getOpenACCDirectiveKind (FirstTok );
184
193
185
194
// OpenACCDirectiveKindEx is meant to be an extended list
186
195
// over OpenACCDirectiveKind, so any value below Invalid is one of the
@@ -190,14 +199,17 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) {
190
199
// immediately cast it and use it as that.
191
200
if (ExDirKind >= OpenACCDirectiveKindEx::Invalid) {
192
201
switch (ExDirKind) {
193
- case OpenACCDirectiveKindEx::Invalid:
194
- P.Diag (FirstTok, diag::err_acc_invalid_directive)
195
- << 0 << FirstTokSpelling;
202
+ case OpenACCDirectiveKindEx::Invalid: {
203
+ if (!FirstTok.is (tok::identifier))
204
+ P.Diag (FirstTok, diag::err_expected) << tok::identifier;
205
+ else
206
+ P.Diag (FirstTok, diag::err_acc_invalid_directive)
207
+ << 0 << FirstTok.getIdentifierInfo ();
196
208
return OpenACCDirectiveKind::Invalid;
209
+ }
197
210
case OpenACCDirectiveKindEx::Enter:
198
211
case OpenACCDirectiveKindEx::Exit:
199
- return ParseOpenACCEnterExitDataDirective (P, FirstTok, FirstTokSpelling,
200
- ExDirKind);
212
+ return ParseOpenACCEnterExitDataDirective (P, FirstTok, ExDirKind);
201
213
}
202
214
}
203
215
@@ -208,8 +220,7 @@ OpenACCDirectiveKind ParseOpenACCDirectiveKind(Parser &P) {
208
220
// clause.
209
221
Token SecondTok = P.getCurToken ();
210
222
if (!SecondTok.isAnnotation () &&
211
- isOpenACCDirectiveKind (OpenACCDirectiveKind::Loop,
212
- P.getPreprocessor ().getSpelling (SecondTok))) {
223
+ isOpenACCDirectiveKind (OpenACCDirectiveKind::Loop, SecondTok)) {
213
224
switch (DirKind) {
214
225
default :
215
226
// Nothing to do except in the below cases, as they should be diagnosed as
0 commit comments