@@ -65,33 +65,27 @@ vector<dev::solidity::test::FunctionCall> TestFileParser::parseFunctionCalls()
65
65
{
66
66
FunctionCall call;
67
67
68
- // f()
69
68
expect (SoltToken::Newline);
70
69
call.signature = parseFunctionSignature ();
71
70
72
- // f(), 314 ether
73
71
if (accept (SoltToken::Comma, true ))
74
72
call.value = parseFunctionCallValue ();
75
-
76
- // f(), 314 ether: 1, 1
77
73
if (accept (SoltToken::Colon, true ))
78
74
call.arguments = parseFunctionCallArguments ();
79
75
80
- string comment = m_scanner.currentLiteral ();
81
- if (accept (SoltToken::Comment, true ))
82
- call.arguments .comment = comment;
76
+ call.displayMode = parseNewline ();
77
+ call.arguments .comment = parseComment ();
83
78
84
- // -> 1
85
- expect (SoltToken::Newline) ;
79
+ if ( accept (SoltToken::Newline, true ))
80
+ call. displayMode = FunctionCall::DisplayMode::MultiLine ;
86
81
expect (SoltToken::Arrow);
87
- if (m_scanner.peekToken () != SoltToken::Newline)
88
- {
89
- call.expectations = parseFunctionCallExpectations ();
90
-
91
- string comment = m_scanner.currentLiteral ();
92
- if (accept (SoltToken::Comment, true ))
93
- call.expectations .comment = comment;
94
- }
82
+
83
+ call.expectations = parseFunctionCallExpectations ();
84
+
85
+ if (accept (SoltToken::Newline, false ))
86
+ call.displayMode = parseNewline ();
87
+ call.expectations .comment = parseComment ();
88
+
95
89
calls.emplace_back (std::move (call));
96
90
}
97
91
else
@@ -127,7 +121,8 @@ bool TestFileParser::accept(SoltToken _token, bool const _expect)
127
121
bool TestFileParser::expect (SoltToken _token, bool const _advance)
128
122
{
129
123
if (m_scanner.currentToken () != _token)
130
- throw Error (Error::Type::ParserError,
124
+ throw Error
125
+ (Error::Type::ParserError,
131
126
" Unexpected " + formatToken (m_scanner.currentToken ()) + " : \" " +
132
127
m_scanner.currentLiteral () + " \" . " +
133
128
" Expected \" " + formatToken (_token) + " \" ."
@@ -164,10 +159,7 @@ string TestFileParser::parseFunctionSignature()
164
159
165
160
u256 TestFileParser::parseFunctionCallValue ()
166
161
{
167
- u256 value;
168
- string literal = m_scanner.currentLiteral ();
169
- expect (SoltToken::Number);
170
- value = convertNumber (literal);
162
+ u256 value = convertNumber (parseNumber ());
171
163
expect (SoltToken::Ether);
172
164
return value;
173
165
}
@@ -176,41 +168,46 @@ FunctionCallArgs TestFileParser::parseFunctionCallArguments()
176
168
{
177
169
FunctionCallArgs arguments;
178
170
179
- auto formattedBytes = parseABITypeLiteral ();
180
- arguments.rawBytes += formattedBytes.first ;
181
- arguments.formats .emplace_back (std::move (formattedBytes.second ));
171
+ auto param = parseParameter ();
172
+ if (param.abiType .type == ABIType::None)
173
+ throw Error (Error::Type::ParserError, " No argument provided." );
174
+ arguments.parameters .emplace_back (param);
175
+
182
176
while (accept (SoltToken::Comma, true ))
183
- {
184
- auto formattedBytes = parseABITypeLiteral ();
185
- arguments.rawBytes += formattedBytes.first ;
186
- arguments.formats .emplace_back (std::move (formattedBytes.second ));
187
- }
177
+ arguments.parameters .emplace_back (parseParameter ());
188
178
return arguments;
189
179
}
190
180
191
181
FunctionCallExpectations TestFileParser::parseFunctionCallExpectations ()
192
182
{
193
183
FunctionCallExpectations expectations;
194
- string token = m_scanner.currentLiteral ();
195
184
196
- if (accept (SoltToken::Failure, true ))
197
- expectations.status = false ;
198
- else
199
- {
200
- auto formattedBytes = parseABITypeLiteral ();
201
- expectations.rawBytes += formattedBytes.first ;
202
- expectations.formats .emplace_back (std::move (formattedBytes.second ));
185
+ auto param = parseParameter ();
186
+ if (param.abiType .type == ABIType::None)
187
+ return expectations;
188
+ expectations.parameters .emplace_back (param);
203
189
204
- while (accept (SoltToken::Comma, true ))
205
- {
206
- auto formattedBytes = parseABITypeLiteral ();
207
- expectations. rawBytes += formattedBytes. first ;
208
- expectations. formats . emplace_back ( std::move (formattedBytes. second ));
209
- }
210
- }
190
+ while (accept (SoltToken::Comma, true ))
191
+ expectations. parameters . emplace_back ( parseParameter ());
192
+
193
+ // / We have always one virtual parameter in the parameter list.
194
+ // / If its type is FAILURE, the expected result is also a REVERT etc.
195
+ if (expectations. parameters . at ( 0 ). abiType . type != ABIType::Failure)
196
+ expectations. failure = false ;
211
197
return expectations;
212
198
}
213
199
200
+ Parameter TestFileParser::parseParameter ()
201
+ {
202
+ Parameter parameter;
203
+ if (accept (SoltToken::Newline, true ))
204
+ parameter.format .newline = true ;
205
+ auto literal = parseABITypeLiteral ();
206
+ parameter.rawBytes = literal.first ;
207
+ parameter.abiType = literal.second ;
208
+ return parameter;
209
+ }
210
+
214
211
pair<bytes, ABIType> TestFileParser::parseABITypeLiteral ()
215
212
{
216
213
try
@@ -219,21 +216,23 @@ pair<bytes, ABIType> TestFileParser::parseABITypeLiteral()
219
216
ABIType abiType;
220
217
if (accept (SoltToken::Sub))
221
218
{
222
- abiType.type = ABIType::Type::SignedDec;
223
- abiType.size = 32 ;
224
-
219
+ abiType = ABIType{ABIType::SignedDec, 32 };
225
220
expect (SoltToken::Sub);
226
221
number = convertNumber (parseNumber ()) * -1 ;
227
222
}
228
223
else
224
+ {
229
225
if (accept (SoltToken::Number))
230
226
{
231
- abiType.type = ABIType::Type::UnsignedDec;
232
- abiType.size = 32 ;
233
-
227
+ abiType = ABIType{ABIType::UnsignedDec, 32 };
234
228
number = convertNumber (parseNumber ());
235
229
}
236
-
230
+ if (accept (SoltToken::Failure, true ))
231
+ {
232
+ abiType = ABIType{ABIType::Failure, 0 };
233
+ return make_pair (bytes{}, abiType);
234
+ }
235
+ }
237
236
return make_pair (toBigEndian (number), abiType);
238
237
}
239
238
catch (std::exception const &)
@@ -242,6 +241,21 @@ pair<bytes, ABIType> TestFileParser::parseABITypeLiteral()
242
241
}
243
242
}
244
243
244
+ solidity::test::FunctionCall::DisplayMode TestFileParser::parseNewline ()
245
+ {
246
+ if (accept (SoltToken::Newline, true ))
247
+ return FunctionCall::DisplayMode::MultiLine;
248
+ return FunctionCall::DisplayMode::SingleLine;
249
+ }
250
+
251
+ string TestFileParser::parseComment ()
252
+ {
253
+ string comment = m_scanner.currentLiteral ();
254
+ if (accept (SoltToken::Comment, true ))
255
+ return comment;
256
+ return string{};
257
+ }
258
+
245
259
string TestFileParser::parseNumber ()
246
260
{
247
261
string literal = m_scanner.currentLiteral ();
@@ -283,7 +297,8 @@ void TestFileParser::Scanner::scanNextToken()
283
297
};
284
298
285
299
TokenDesc token = make_pair (SoltToken::Unknown, " " );
286
- do {
300
+ do
301
+ {
287
302
switch (current ())
288
303
{
289
304
case ' /' :
0 commit comments