#include "WfMergeCpp.h"
#include <VlppRegex.h>
namespace
{
namespace
{
namespace
{
using
namespace
collections
;
using
namespace
stream
;
using
namespace
regex
;
(
const
&
)
{
for
(
=
0
;
i
<
.
();
i
++)
{
if
(
i
] !=
L' '
&&
i
] !=
L'\t'
)
{
return
.
(
i
,
.
() -
i
);
}
}
return
::
;
}
const
=
0
;
const
=
1
;
const
=
2
;
const
=
3
;
const
=
4
;
const
=
5
;
template
<
typename
>
void
(
const
&
,
const
&
)
{
(
L"/.*?(?/{)?///* USER_CONTENT_BEGIN/((<name>[^)]*?)/) /*//"
);
=
NORMAL
;
=
0
;
;
(
);
while
(!
reader
.
())
{
auto
=
reader
.
();
if
(
reader
.
() &&
line
==
L""
)
{
break
;
}
if
(
line
==
L"// UNUSED_USER_CONTENT:"
)
{
state
=
UNUSED_USER_CONTENT
;
}
if
(
state
==
UNUSED_USER_CONTENT
)
{
(
state
,
state
,
line
,
line
);
}
else
{
auto
=
(
line
);
auto
=
state
;
switch
(
state
)
{
case
NORMAL
:
if
(
auto
=
regexUserContentBegin
.
(
content
))
{
content
=
L"USERIMPL(/* "
+
match
()[
L"name"
][
0
].
() +
L" */)"
;
if
(
match
().
() >
0
)
{
content
previousContent
;
}
state
=
USER_CONTENT
;
}
else if (INVLOC.StartsWith(content, L"USERIMPL(",Locale::None))
else
if
(
vl
::
::
().
(
content
,
L"USERIMPL("
,
::
))
{
state
=
WAIT_HEADER
;
}
break
;
case
WAIT_HEADER
:
state
=
WAIT_OPEN
;
break
;
case
WAIT_OPEN
:
if (INVLOC.StartsWith(content, L"{", Locale::None))
if
(
vl
::
::
().
(
content
,
L"{"
,
::
))
{
state
=
WAIT_CLOSE
;
}
break
;
case
WAIT_CLOSE
:
if (INVLOC.StartsWith(content, L"{", Locale::None))
if
(
vl
::
::
().
(
content
,
L"{"
,
::
))
{
counter
++;
}
else if (INVLOC.StartsWith(content, L"}", Locale::None))
else
if
(
vl
::
::
().
(
content
,
L"}"
,
::
))
{
if
(
counter
==
0
)
{
state
=
NORMAL
;
}
else
{
counter
--;
}
}
break
;
case
USER_CONTENT
:
if (INVLOC.EndsWith(content, L"/* USER_CONTENT_END() */", Locale::None))
if
(
vl
::
::
().
(
content
,
L"/* USER_CONTENT_END() */"
,
::
))
{
state
=
NORMAL
;
}
break
;
}
(
previousState
,
state
,
line
,
content
);
}
previousContent
(
line
);
}
}
template
<
typename
>
void
(
const
&
,
<
,
>&
,
<
,
>&
,
const
&
)
{
;
;
;
(
, [&](
,
,
const
&
,
const
&
)
{
if
(
state
==
UNUSED_USER_CONTENT
)
{
(
line
);
}
else
{
switch
(
previousState
)
{
case
NORMAL
:
switch
(
state
)
{
case
WAIT_HEADER
:
case
USER_CONTENT
:
name
content
;
userImpl
=
L""
;
userImplFull
=
L""
;
break
;
}
break
;
case
WAIT_HEADER
:
name
content
;
break
;
case
WAIT_CLOSE
:
case
USER_CONTENT
:
switch
(
state
)
{
case
WAIT_CLOSE
:
case
USER_CONTENT
:
userImpl
+=
line
+
L"\r\n"
;
break
;
case
NORMAL
:
userImplFull
+=
L"//"
+
line
+
L"\r\n"
;
.
(
name
,
userImpl
);
.
(
name
,
userImplFull
);
name
=
L""
;
break
;
}
break
;
}
if
(
name
!=
L""
)
{
userImplFull
+=
L"//"
+
line
+
L"\r\n"
;
}
}
});
}
MergeCppMultiPlatformException
::
(
,
,
,
)
:
(
L"The difference at "
L"x86 file(row:"
+
(
+
1
) +
L", column:"
+
(
+
1
) +
L") and "
L"x64 file(row:"
+
(
+
1
) +
L", column:"
+
(
+
1
) +
L") are not "
L"\"vint32_t\" and \"vint64_t\", "
L"\"vuint32_t\" and \"vuint64_t\", "
L"\"<number>\" and \"<number>L\", "
L"\"<number>\" and \"<number>UL\"."
)
, row32(
)
, column32(
)
, row64(
)
, column64(
)
{
}
void
(
const
wchar_t
*
,
const
wchar_t
*
,
&
,
&
)
{
=
0
;
=
0
;
while
(
<
)
{
if
(*
++ ==
L'\n'
)
{
++;
=
0
;
}
else
{
++;
}
}
}
(
const
&
,
const
&
)
{
static
wchar_t
[] =
L"static_cast<::vl::vint32_t>("
;
const
=
sizeof
(
stringCast32
) /
sizeof
(*
stringCast32
) -
1
;
static
wchar_t
[] =
L"static_cast<::vl::vint64_t>("
;
const
=
sizeof
(
stringCast64
) /
sizeof
(*
stringCast64
) -
1
;
return
([&](
&
)
{
const
wchar_t
*
=
.
();
const
wchar_t
*
=
.
();
const
wchar_t
*
=
reading32
;
const
wchar_t
*
=
reading64
;
while
(
true
)
{
=
0
;
while
(
reading32
[
length
] &&
reading64
[
length
])
{
if
(
reading32
[
length
] ==
reading64
[
length
])
{
length
++;
}
else
{
break
;
}
}
writer
.
(
reading32
,
length
);
reading32
+=
length
;
reading64
+=
length
;
if
(*
reading32
==
0
&& *
reading64
==
0
)
{
break
;
}
#define IS_DIGIT(C) (L'0' <= C && C <= L'9')
if
(
reading32
[
0
] ==
L'3'
&&
reading32
[
1
] ==
L'2'
&&
reading64
[
0
] ==
L'6'
&&
reading64
[
1
] ==
L'4'
)
{
if
(
length
>=
4
)
{
if
(
(
reading32
-
4
,
L"vint32_t"
,
8
) ==
0
&&
(
reading64
-
4
,
L"vint64_t"
,
8
) ==
0
)
{
reading32
+=
4
;
reading64
+=
4
;
goto
NEXT_ROUND;
}
}
if
(
length
>=
5
)
{
if
(
(
reading32
-
5
,
L"vuint32_t"
,
9
) ==
0
&&
(
reading64
-
5
,
L"vuint64_t"
,
9
) ==
0
)
{
reading32
+=
4
;
reading64
+=
4
;
goto
NEXT_ROUND;
}
}
}
else
if
(
reading64
[
0
] ==
L'L'
)
{
if
(
reading32
[
0
] ==
reading64
[
1
] &&
length
>=
1
)
{
if (IS_DIGIT(reading32[-1]) && !IS_DIGIT(reading32[0]))
if
((
L'0'
<=
reading32
[-
1
] &&
reading32
[-
1
] <=
L'9'
) && !(
L'0'
<=
reading32
[
0
] &&
reading32
[
0
] <=
L'9'
))
{
if (IS_DIGIT(reading64[-1]) && !IS_DIGIT(reading64[1]))
if
((
L'0'
<=
reading64
[-
1
] &&
reading64
[-
1
] <=
L'9'
) && !(
L'0'
<=
reading64
[
1
] &&
reading64
[
1
] <=
L'9'
))
{
reading64
+=
1
;
goto
NEXT_ROUND;
}
}
}
}
else
if
(
reading64
[
0
] ==
L'U'
&&
reading64
[
1
] ==
L'L'
)
{
if
(
reading32
[
0
] ==
reading64
[
2
] &&
length
>=
1
)
{
if (IS_DIGIT(reading32[-1]) && !IS_DIGIT(reading32[0]))
if
((
L'0'
<=
reading32
[-
1
] &&
reading32
[-
1
] <=
L'9'
) && !(
L'0'
<=
reading32
[
0
] &&
reading32
[
0
] <=
L'9'
))
{
if (IS_DIGIT(reading64[-1]) && !IS_DIGIT(reading64[2]))
if
((
L'0'
<=
reading64
[-
1
] &&
reading64
[-
1
] <=
L'9'
) && !(
L'0'
<=
reading64
[
2
] &&
reading64
[
2
] <=
L'9'
))
{
reading64
+=
2
;
goto
NEXT_ROUND;
}
}
}
}
else if (wcsncmp(reading32, stringCast32, lengthCast32) == 0 && IS_DIGIT(reading32[lengthCast32]) && IS_DIGIT(reading64[0]))
else
if
(
(
reading32
,
stringCast32
,
lengthCast32
) ==
0
&& (
L'0'
<=
reading32
[
lengthCast32
] &&
reading32
[
lengthCast32
] <=
L'9'
) && (
L'0'
<=
reading64
[
0
] &&
reading64
[
0
] <=
L'9'
))
{
reading32
+=
lengthCast32
;
=
0
;
while (IS_DIGIT(reading32[digitCount])) digitCount++;
while
((
L'0'
<=
reading32
[
digitCount
] &&
reading32
[
digitCount
] <=
L'9'
))
digitCount
++;
if
(
(
reading32
,
reading64
,
digitCount
) ==
0
&&
reading64
[
digitCount
] ==
L'L'
&&
reading32
[
digitCount
] ==
L')'
)
{
writer
.
(
L"static_cast<::vl::vint>("
);
writer
.
(
(
reading32
,
digitCount
));
writer
.
(
L')'
);
reading64
+=
digitCount
+
1
;
reading32
+=
digitCount
+
1
;
goto
NEXT_ROUND;
}
}
else if (wcsncmp(reading64, stringCast64, lengthCast64) == 0 && IS_DIGIT(reading64[lengthCast64]) && IS_DIGIT(reading32[0]))
else
if
(
(
reading64
,
stringCast64
,
lengthCast64
) ==
0
&& (
L'0'
<=
reading64
[
lengthCast64
] &&
reading64
[
lengthCast64
] <=
L'9'
) && (
L'0'
<=
reading32
[
0
] &&
reading32
[
0
] <=
L'9'
))
{
reading64
+=
lengthCast64
;
=
0
;
while (IS_DIGIT(reading64[digitCount])) digitCount++;
while
((
L'0'
<=
reading64
[
digitCount
] &&
reading64
[
digitCount
] <=
L'9'
))
digitCount
++;
if
(
(
reading64
,
reading32
,
digitCount
) ==
0
&&
reading64
[
digitCount
] ==
L'L'
&&
reading64
[
digitCount
+
1
] ==
L')'
)
{
writer
.
(
L"static_cast<::vl::vint>("
);
writer
.
(
(
reading64
,
digitCount
));
writer
.
(
L')'
);
reading64
+=
digitCount
+
2
;
reading32
+=
digitCount
;
goto
NEXT_ROUND;
}
}
{
=
0
;
=
0
;
=
0
;
=
0
;
(
start32
,
reading32
,
row32
,
column32
);
(
start64
,
reading64
,
row64
,
column64
);
throw
MergeCppMultiPlatformException
(
row32
,
column32
,
row64
,
column64
);
}
NEXT_ROUND:;
#undef IS_DIGIT
}
});
}
(
const
&
,
const
&
)
{
<
,
>
,
;
=
([&](
&
)
{
(
,
userContents
,
userContentsFull
, [&](
const
&
)
{
writer
.
(
line
);
});
});
processedUnusedUserContent
=
([&](
&
)
{
(
unusedUserContent
);
while
(!
reader
.
())
{
auto
=
reader
.
();
if
(
line
!=
L"// UNUSED_USER_CONTENT:"
)
{
if (INVLOC.StartsWith(line, L"//", Locale::None))
if
(
vl
::
::
().
(
line
,
L"//"
,
::
))
{
line
line
.
(
line
.
() -
2
);
}
writer
.
(
line
);
}
}
});
(
processedUnusedUserContent
,
userContents
,
userContentsFull
, [&](
const
&
) {});
return
([&](
&
)
{
;
;
(
, [&](
,
,
const
&
,
const
&
)
{
switch
(
previousState
)
{
case
NORMAL
:
switch
(
state
)
{
case
WAIT_HEADER
:
case
USER_CONTENT
:
name
content
;
userImpl
=
L""
;
break
;
}
break
;
case
WAIT_HEADER
:
name
content
;
break
;
case
WAIT_CLOSE
:
case
USER_CONTENT
:
switch
(
state
)
{
case
WAIT_CLOSE
:
case
USER_CONTENT
:
userImpl
+=
line
+
L"\r\n"
;
return
;
case
NORMAL
:
{
=
userContents
.
().
(
name
);
if
(
index
== -
1
)
{
writer
.
(
userImpl
);
}
else
{
writer
.
(
userContents
.
()
index
]);
userContentsFull
.
(
name
);
}
}
break
;
}
break
;
}
writer
.
(
line
);
});
if
(
userContentsFull
.
() >
0
)
{
writer
.
(
L"// UNUSED_USER_CONTENT:"
);
FOREACH(WString, content, userContentsFull.Values())
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
>&
= ::
vl
::
collections
::
(
userContentsFull
.
());
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
;
__foreach_iterator__
.
(
content
);)
{
writer
.
(
content
);
}
}
});
}
}
}
}