Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
magicseteditor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
magicseteditor
Commits
fcb1bb84
Commit
fcb1bb84
authored
Jun 28, 2008
by
twanvl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fancier error messages for assert(X == Y)
parent
f6bc7498
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
11 deletions
+37
-11
src/script/parser.cpp
src/script/parser.cpp
+37
-11
No files found.
src/script/parser.cpp
View file @
fcb1bb84
...
...
@@ -559,18 +559,44 @@ void parseExpr(TokenIterator& input, Script& script, Precedence minPrec) {
int
line
=
input
.
getLineNumber
();
parseOper
(
input
,
script
,
PREC_ALL
);
// condition
size_t
end
=
input
.
peek
().
pos
;
String
message
=
String
::
Format
(
_
(
"Assertion failure on line %d: "
),
line
)
+
input
.
getSourceCode
(
start
,
end
);
String
message
=
String
::
Format
(
_
(
"Assertion failure on line %d:
\n
expected:
"
),
line
)
+
input
.
getSourceCode
(
start
,
end
);
expectToken
(
input
,
_
(
")"
),
&
token
);
// compile into: if condition then nil else warning("condition")
unsigned
jmpElse
=
script
.
addInstruction
(
I_JUMP_IF_NOT
);
// jnz lbl_else
script
.
addInstruction
(
I_PUSH_CONST
,
script_nil
);
// push nil
unsigned
jmpEnd
=
script
.
addInstruction
(
I_JUMP
);
// jump lbl_end
script
.
comeFrom
(
jmpElse
);
// lbl_else:
script
.
addInstruction
(
I_PUSH_CONST
,
script_warning
);
// push warning
script
.
addInstruction
(
I_PUSH_CONST
,
message
);
// push "condition"
script
.
addInstruction
(
I_CALL
,
1
);
// call
script
.
addInstruction
(
I_NOP
,
SCRIPT_VAR_input
);
// (input:)
script
.
comeFrom
(
jmpEnd
);
// lbl_end:
if
(
script
.
getInstructions
().
back
().
instr
==
I_BINARY
&&
script
.
getInstructions
().
back
().
instr2
==
I_EQ
)
{
// compile "assert(x == y)" into "
message
+=
_
(
"
\n
found: "
);
script
.
getInstructions
().
pop_back
();
// remove ==
script
.
addInstruction
(
I_DUP
,
1
);
// duplicate X
script
.
addInstruction
(
I_DUP
,
1
);
// duplicate Y
script
.
addInstruction
(
I_BINARY
,
I_EQ
);
//
unsigned
jmpElse
=
script
.
addInstruction
(
I_JUMP_IF_NOT
);
// jnz lbl_else
script
.
addInstruction
(
I_PUSH_CONST
,
script_nil
);
// push nil
unsigned
jmpEnd
=
script
.
addInstruction
(
I_JUMP
);
// jump lbl_end
script
.
comeFrom
(
jmpElse
);
// lbl_else:
script
.
addInstruction
(
I_PUSH_CONST
,
script_warning
);
// push warning
script
.
addInstruction
(
I_PUSH_CONST
,
message
);
// push "condition"
script
.
addInstruction
(
I_DUP
,
3
);
// duplicate X
script
.
addInstruction
(
I_BINARY
,
I_ADD
);
// add
script
.
addInstruction
(
I_PUSH_CONST
,
String
(
_
(
" != "
)));
// push " != "
script
.
addInstruction
(
I_BINARY
,
I_ADD
);
// add
script
.
addInstruction
(
I_DUP
,
2
);
// duplicate Y
script
.
addInstruction
(
I_BINARY
,
I_ADD
);
// add
script
.
addInstruction
(
I_CALL
,
1
);
// call
script
.
addInstruction
(
I_NOP
,
SCRIPT_VAR_input
);
// (input:)
script
.
comeFrom
(
jmpEnd
);
// lbl_end:
script
.
addInstruction
(
I_BINARY
,
I_POP
);
// pop Y_copy
script
.
addInstruction
(
I_BINARY
,
I_POP
);
// pop X_copy
}
else
{
// compile into: if condition then nil else warning("condition")
unsigned
jmpElse
=
script
.
addInstruction
(
I_JUMP_IF_NOT
);
// jnz lbl_else
script
.
addInstruction
(
I_PUSH_CONST
,
script_nil
);
// push nil
unsigned
jmpEnd
=
script
.
addInstruction
(
I_JUMP
);
// jump lbl_end
script
.
comeFrom
(
jmpElse
);
// lbl_else:
script
.
addInstruction
(
I_PUSH_CONST
,
script_warning
);
// push warning
script
.
addInstruction
(
I_PUSH_CONST
,
message
);
// push "condition"
script
.
addInstruction
(
I_CALL
,
1
);
// call
script
.
addInstruction
(
I_NOP
,
SCRIPT_VAR_input
);
// (input:)
script
.
comeFrom
(
jmpEnd
);
// lbl_end:
}
}
else
{
// variable
Variable
var
=
string_to_variable
(
token
.
value
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment