#include "WfAnalyzer.h"
namespace
{
namespace
{
namespace
{
using
namespace
collections
;
using
namespace
parsing
;
using
namespace
reflection
::
description
;
class
:
public
traverse_visitor
::
{
public
:
;
bool
;
(
,
bool
)
:range(
)
, asOffset(
)
{
}
void
(
&
)
{
if
(
.
== -
1
||
.
== -
1
)
{
.
;
}
else
{
if
(
.
==
0
)
{
.
+=
.
.
;
}
.
+=
.
.
;
}
}
void
(
*
)
override
{
if
(
->
())
{
->
;
}
else
if
(
)
{
(
->
.
);
(
->
.
);
if
(
->
.
== -
1
)
{
->
.
=
.
;
}
}
}
void
(
&
)
override
{
if
(
.
())
{
.
;
}
else
if
(
)
{
(
.
.
);
(
.
.
);
if
(
.
.
== -
1
)
{
.
.
=
.
;
}
}
}
};
void
(
<
> ,
parsing
::
,
bool
)
{
(
,
).
(
.
());
}
void
(
<
> ,
parsing
::
,
bool
)
{
(
,
).
(
.
());
}
void
(
<
> ,
parsing
::
,
bool
)
{
(
,
).
(
.
());
}
void
(
<
> ,
parsing
::
,
bool
)
{
(
,
).
(
.
());
}
void
(
<
> ,
parsing
::
,
bool
)
{
(
,
).
(
.
());
}
class
ContextFreeDesugarVisitor
:
public
traverse_visitor
::
{
public
:
*
;
*
=
nullptr
;
*
=
nullptr
;
ContextFreeDesugarVisitor
(
*
)
:manager(
)
{
}
void
(
*
)
override
{
if
(
->
)
{
return
;
}
<
<
>>
;
const
wchar_t
*
=
->
.
.
();
const
wchar_t
*
=
reading
;
=
->
.
;
formatPos
.
+=
2
;
while
(*
reading
)
{
const
wchar_t
*
=
(
reading
,
L"$("
);
if
(
begin
)
{
<
>
=
new
;
expression
->
;
expression
.
(
reading
,
(
begin
-
reading
));
expressions
.
(
expression
);
}
else
{
break
;
}
const
wchar_t
*
=
begin
+
2
;
=
1
;
while
(
wchar_t
= *
end
++)
{
switch
(
c
)
{
case
L'('
:
counter
++;
break
;
case
L')'
:
counter
--;
break
;
}
if
(
counter
==
0
)
{
break
;
}
}
if
(
counter
!=
0
)
{
auto
=
::
(
);
error
+=
L" (Does not find matched close bracket.)"
;
->
.
(
error
);
return
;
}
else
{
(
begin
+
2
,
(
end
-
begin
-
3
));
<
<
>>
;
if
(
auto
=
(
input
,
->
,
errors
))
{
expressions
.
(
expression
);
while
(
textPosCounter
++ <
begin
+
2
)
{
switch
(
textPosCounter
[-
1
])
{
case
'\n'
:
formatPos
.
++;
formatPos
.
=
0
;
break
;
default
:
formatPos
.
++;
break
;
}
}
(
expression
, {
formatPos
,
formatPos
,
->
.
},
true
);
}
FOREACH(Ptr<ParsingError>, originalError, errors)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
errors
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
originalError
);)
{
auto
=
::
(
);
error
+=
L" ("
+
originalError
+
L")"
;
->
.
(
error
);
}
reading
=
end
;
}
}
if
(*
reading
||
expressions
.
() ==
0
)
{
<
>
=
new
;
expression
->
;
expression
.
=
reading
;
expressions
.
(
expression
);
}
if
(
expressions
.
() >
0
)
{
<
>
=
expressions
0
];
FOREACH(Ptr<WfExpression>, expression, From(expressions).Skip(1))
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
(
expressions
).Skip(
1
));
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
expression
);)
{
<
>
=
new
;
binary
->
;
binary
current
;
binary
expression
;
binary
=
::
;
current
binary
;
}
->
current
;
(
->
,
->
);
}
}
void
(
WfAutoPropertyDeclaration
*
)
override
{
if
(
->
.
() >
0
)
{
return
;
}
bool
=
false
;
bool
=
false
;
bool
=
false
;
bool
=
false
;
if
(
)
{
switch
(
->
)
{
case
::
:
{
needVariable
=
true
;
needVirtual
=
false
;
needEvent
=
->
==
::
;
needProperty
=
true
;
}
break
;
case
::
:
{
needVariable
=
false
;
needVirtual
=
true
;
needEvent
=
->
==
::
;
needProperty
=
true
;
}
break
;
}
}
else
if
(
)
{
needVariable
=
true
;
needVirtual
=
false
;
needEvent
=
false
;
needProperty
=
false
;
}
auto
=
L"<prop>"
+
->
.
;
auto
=
L"Get"
+
->
.
;
auto
=
L"Set"
+
->
.
;
auto
=
->
.
+
L"Changed"
;
if
(
needVariable
&&
->
)
{
auto
=
<
>();
->
.
(
decl
);
decl
.
=
varName
;
decl
(
->
);
decl
(
->
,
true
);
auto
=
<
>();
att
.
=
L"cpp"
;
att
.
=
L"Private"
;
decl
.
(
att
);
}
{
auto
=
<
>();
->
.
(
decl
);
decl
=
::
;
decl
.
=
getterName
;
decl
(
->
);
if
(!
needVirtual
)
{
auto
=
<
>();
refExpr
.
=
varName
;
auto
=
<
>();
returnStat
refExpr
;
auto
=
<
>();
block
.
(
returnStat
);
decl
block
;
}
}
if
(!
needVirtual
||
->
==
::
)
{
auto
=
<
>();
->
.
(
decl
);
decl
=
::
;
decl
.
=
setterName
;
if
(
->
==
::
)
{
auto
=
<
>();
att
.
=
L"cpp"
;
att
.
=
L"Protected"
;
decl
.
(
att
);
}
{
auto
=
<
>();
argument
.
=
L"<value>"
;
argument
(
->
);
decl
.
(
argument
);
}
{
auto
=
<
>();
voidType
=
::
;
decl
voidType
;
}
if
(!
needVirtual
)
{
auto
=
<
>();
decl
block
;
auto
= [&](
)
{
auto
=
<
>();
refArgument
.
=
L"<value>"
;
auto
=
<
>();
refVar
.
=
varName
;
auto
=
<
>();
binaryExpr
refVar
;
binaryExpr
refArgument
;
binaryExpr
=
op
;
return
binaryExpr
;
};
if
(
->
==
::
)
{
auto
=
<
>();
ifStat
=
createBinaryExpr
(
::
);
auto
=
<
>();
ifStat
trueBlock
;
{
auto
=
<
>();
stat
=
createBinaryExpr
(
::
);
trueBlock
.
(
stat
);
}
{
auto
=
<
>();
refEvent
.
=
eventName
;
auto
=
<
>();
callExpr
refEvent
;
auto
=
<
>();
stat
callExpr
;
trueBlock
.
(
stat
);
}
block
.
(
ifStat
);
}
else
{
auto
=
<
>();
stat
=
createBinaryExpr
(
::
);
block
.
(
stat
);
}
}
}
if
(
needEvent
)
{
auto
=
<
>();
->
.
(
decl
);
decl
.
=
eventName
;
}
if
(
needProperty
)
{
auto
=
<
>();
->
.
(
decl
);
decl
(
->
);
decl
.
->
.
;
decl
.
=
getterName
;
if
(
->
==
::
)
{
decl
.
=
setterName
;
}
if
(
->
==
::
)
{
decl
.
=
eventName
;
}
}
FOREACH(Ptr<WfDeclaration>, decl, node->expandedDeclarations)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
->
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
decl
);)
{
auto
=
<
>();
decl
classMember
;
classMember
=
::
;
if
(
)
{
if
(
decl
.
==
getterName
)
{
classMember
=
::
;
}
else
if
(
decl
.
==
setterName
)
{
if
(
->
==
::
)
{
classMember
=
::
;
}
}
}
(
decl
,
->
);
}
}
void
(
WfCastResultInterfaceDeclaration
*
)
override
{
if
(
->
.
() >
0
)
{
return
;
}
auto
=
<
>();
->
.
(
decl
);
decl
=
::
;
decl
=
::
;
decl
.
->
.
;
decl
.
(
(
->
));
{
auto
=
<
>();
decl
.
(
funcDecl
);
{
funcDecl
<
>();
funcDecl
=
::
;
}
funcDecl
=
::
;
funcDecl
.
=
L"CastResult"
;
funcDecl
(
->
);
{
auto
=
<
>();
funcDecl
.
(
argument
);
argument
.
=
L"value"
;
argument
(
<
>::
().
());
}
{
auto
=
<
>();
funcDecl
block
;
auto
=
<
>();
refValue
.
=
L"value"
;
auto
=
<
>();
castExpr
=
::
;
castExpr
(
->
);
castExpr
refValue
;
auto
=
<
>();
stat
castExpr
;
block
.
(
stat
);
}
}
{
auto
=
<
>();
decl
.
(
funcDecl
);
{
funcDecl
<
>();
funcDecl
=
::
;
}
funcDecl
=
::
;
funcDecl
.
=
L"StoreResult"
;
funcDecl
(
<
>::
().
());
{
auto
=
<
>();
funcDecl
.
(
argument
);
argument
.
=
L"value"
;
argument
(
->
);
}
{
auto
=
<
>();
funcDecl
block
;
auto
=
<
>();
refValue
.
=
L"value"
;
auto
=
<
>();
stat
refValue
;
block
.
(
stat
);
}
}
(
<
>(
decl
),
->
);
}
#define PUSH_SURROUNDING\
auto o1 = surroundingClassDecl;\
auto o2 = surroundingLambda;\
surroundingClassDecl = nullptr;\
surroundingLambda = nullptr;\
#define POP_SURROUNDING\
surroundingClassDecl = o1;\
surroundingLambda = o2;\
void
(
*
)
override
{
PUSH_SURROUNDING
auto
=
;
auto
=
;
=
nullptr
;
=
nullptr
;
=
;
traverse_visitor
::
::
(
);
}
void
(
*
)
override
{
PUSH_SURROUNDING
auto
=
;
auto
=
;
=
nullptr
;
=
nullptr
;
=
;
traverse_visitor
::
::
(
);
}
#undef PUSH_SURROUNDING
#undef POP_SURROUNDING
};
void
(
*
,
<
>
)
{
ContextFreeDesugarVisitor
(
).
(
.
());
}
void
ContextFreeDeclarationDesugar
(
*
,
<
>
)
{
ContextFreeDesugarVisitor
(
).
(
.
());
}
void
ContextFreeStatementDesugar
(
*
,
<
>
)
{
ContextFreeDesugarVisitor
(
).
(
.
());
}
void
ContextFreeExpressionDesugar
(
*
,
<
>
)
{
ContextFreeDesugarVisitor
(
).
(
.
());
}
}
}
}