FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
daScript/src/simulate/simulate_tracking.cpp at master · harold-b/daScript · GitHub
harold-b
/
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
/
src
/
simulate
/
simulate_tracking.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
102 lines (96 loc) · 3.64 KB
Breadcrumbs
daScript
/
src
/
simulate
/
simulate_tracking.cpp
Copy path
File metadata and controls
102 lines (96 loc) · 3.64 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#
include
"
daScript/misc/platform.h
"
#
include
"
daScript/ast/ast.h
"
#
include
"
daScript/ast/ast_expressions.h
"
namespace
das
{
#
if
DAS_ENABLE_SMART_PTR_TRACKING
vector<smart_ptr<ptr_ref_count>> Context::sptrAllocations;
#
endif
string
around
(
const
LineInfo & info ) {
TextWriter tw;
tw <<
"
:
"
<< info.
line
<<
"
:
"
<< info.
column
;
return
tw.
str
();
}
#
if
DAS_ENABLE_SMART_PTR_TRACKING
void
safeDumpType
( TextWriter & tp,
const
TypeDeclPtr & td ) {
if
( td->
baseType
==Type::tStructure ) {
tp <<
"
structure
"
;
}
else
if
( td->
baseType
==Type::tHandle ) {
tp <<
"
handle
"
;
}
else
if
( td->
baseType
==Type::tPointer ) {
if
( td->
firstType
) {
safeDumpType
(tp,td->
firstType
);
tp <<
"
?
"
;
}
else
{
tp <<
"
void?
"
;
}
}
else
if
( td->
baseType
==Type::tTuple || td->
baseType
==Type::tVariant ) {
tp <<
das_to_string
(td->
baseType
) <<
"
<
"
;
for
(
auto
& st : td->
argTypes
) {
safeDumpType
(tp, st);
if
( st != td->
argTypes
.
back
() ) tp <<
"
;
"
;
}
tp <<
"
>
"
;
}
else
{
tp <<
das_to_string
(td->
baseType
);
}
for
(
auto
i : td->
dim
) {
tp <<
"
[
"
<< i <<
"
]
"
;
}
if
( td->
constant
) tp <<
"
const
"
;
if
( td->
ref
) tp <<
"
&
"
;
if
( td->
temporary
) tp <<
"
#
"
;
}
#
endif
void
dumpTrackingLeaks
( ) {
TextPrinter tp;
#
if
DAS_ENABLE_SMART_PTR_TRACKING
bool
any =
true
;
tp <<
"
cleaning up tracking...
\n
"
;
while
( any ) {
any =
false
;
for
(
auto
it = Context::sptrAllocations.
begin
(); it!=Context::sptrAllocations.
end
(); ) {
auto
& ptr = *it;
if
( ptr->
use_count
()==
1
) {
it = Context::sptrAllocations.
erase
(it);
any =
true
;
}
else
{
++it;
}
}
}
int
total =
0
;
for
(
auto
& ptr : Context::sptrAllocations ) {
tp <<
"
0x
"
<<
HEX
<<
intptr_t
(ptr.
get
()) <<
DEC
<<
"
(
"
<< ptr->
use_count
() <<
"
)
"
;
#
if
DAS_SMART_PTR_ID
tp <<
"
id=
"
<<
HEX
<< ptr->
ref_count_id
<<
DEC
;
#
endif
if
(
auto
td =
dynamic_cast
<TypeDecl *>(ptr.
get
()) ) {
tp <<
"
TypeDecl at
"
<<
around
(td->
at
) <<
"
"
;
safeDumpType
(tp,td);
}
else
if
(
auto
ex =
dynamic_cast
<Expression *>(ptr.
get
()) ) {
tp <<
"
"
<< ex->
__rtti
<<
"
at
"
<<
around
(ex->
at
);
if
(
strcmp
(ex->
__rtti
,
"
ExprConstString
"
)==
0
) {
auto
excs =
static_cast
<ExprConstString *>(ex);
tp <<
"
\"
"
<< excs->
text
<<
"
\"
"
;
}
else
if
(
strcmp
(ex->
__rtti
,
"
ExprField
"
)==
0
) {
auto
exf =
static_cast
<ExprField *>(ex);
tp <<
"
.
"
<< exf->
field
;
}
else
if
(
strcmp
(ex->
__rtti
,
"
ExprCall
"
)==
0
) {
auto
exc =
static_cast
<ExprCall *>(ex);
tp <<
"
"
<< exc->
name
<<
"
(with
"
<< exc->
arguments
.
size
() <<
"
arguments)
"
;
}
}
else
if
(
auto
vp =
dynamic_cast
<Variable *>(ptr.
get
()) ) {
tp <<
"
Variable
"
<< vp->
name
<<
"
at
"
<<
around
(vp->
at
);
}
else
if
(
auto
fp =
dynamic_cast
<Function *>(ptr.
get
()) ) {
tp <<
"
Function
"
<< fp->
name
<<
"
at
"
<<
around
(fp->
at
);
}
tp <<
"
\n
"
;
total ++;
}
tp <<
"
total
"
<< total <<
"
leaks
\n
"
;
#
else
tp <<
"
smart_ptr tracking is disabled
\n
"
;
#
endif
}
}
Back
|
FazBrowse Home
|
New Git URL