FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
daScript/daslib/assert_once.das at master · feiyunwill/daScript · GitHub
feiyunwill
/
daScript
Public
forked from
GaijinEntertainment/daScript
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
daScript
/
daslib
/
assert_once.das
Copy path
More file actions
More file actions
Latest commit
History
History
History
44 lines (37 loc) · 1.44 KB
Breadcrumbs
daScript
/
daslib
/
assert_once.das
Copy path
File metadata and controls
44 lines (37 loc) · 1.44 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
options
gen2
options
indenting
=
4
options
strict_smart_pointers
module
assert_once
shared
private
//! One-shot assertion macro.
//!
//! ``assert_once`` works like ``assert`` but fires only on the first failure.
//! After the first failed check, the assertion is permanently disabled via
//! an auto-generated global flag variable.
require
daslib
/
ast
require
daslib
/
rtti
require
daslib
/
ast_boost
require
daslib
/
templates_boost
[
tag_function
(asset_once_tag),
unused_argument
(expr)]
def
public
assert_once
(
expr
:
bool
;
message
:
string
=
""
) {
//! Same as assert, only the check will be not be repeated after the assertion failed the first time.
pass
}
[
tag_function_macro
(
tag
=
"asset_once_tag"
)]
class
AssertOnceMacro
:
AstFunctionAnnotation
{
//! This macro converts ``assert_once(expr, message)`` to equivalent inline code.
def
override
transform
(
var
call
:
ExprCallFunc
?;
var
errors
:
das_string
) :
ExpressionPtr
{
let
once_name
=
make_unique_private_name
(
"__assert_once"
,
call
.
at
)
if
(
!
compiling_module
()
|
>
add_global_private_var
(
once_name
,
call
.
at
)
<
|
quote
(
true
)) {
errors
:=
"can't add global variable
{
once_name
}
"
return
null
}
var
qb
=
qmacro_block
() {
if
(
$
i(once_name) && !$e(call.arguments[0])) {
$
i(once_name) = false
assert
(
false
,
$
e
(
call
.
arguments
[
1
]))
}
}
qb |> force_at(call.at)
return <- qb
}
}
Back
|
FazBrowse Home
|
New Git URL