#include "WfCpp.h"
namespace
{
namespace
{
namespace
{
using
namespace
analyzer
;
using
namespace
collections
;
#define ASSIGN_INDEX_KEY(INDEX_DECL, INDEX_KEY, STRING_KEY) \
INDEX_DECL INDEX_KEY = globalDep.allTds.Keys().IndexOf(STRING_KEY); \
CHECK_ERROR(INDEX_KEY != -1, L"WfCppConfig::AssignClassDeclsToFiles()#Internal error.") \
void
::
(
<
>
,
&
)
{
=
.
().
(
.
());
if
(
index
== -
1
)
return
;
FOREACH(Ptr<WfClassDeclaration>, subDecl, classDecls.GetByIndex(index))
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
.
(
index
));
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
subDecl
);)
{
(
subDecl
,
);
}
auto
=
(
.
(
index
))
.
([&](
<
>
)
{
auto
=
->
decl
.
()]
();
ASSIGN_INDEX_KEY(auto, indexKey, stringKey);
auto
=
.
.
().
(
stringKey
);
do
{
if
(!(
indexKey
!= -
1
))
throw
(
L"WfCppConfig::AssignClassDeclsToFiles()#Internal error."
);}
while
(
0
);
return
indexKey
;
});
auto
=
(
.
(
index
))
.
([&](
<
>
)
{
auto
=
->
subDecl
.
()]
();
ASSIGN_INDEX_KEY(auto, indexKey, stringKey);
auto
=
.
.
().
(
stringKey
);
do
{
if
(!(
indexKey
!= -
1
))
throw
(
L"WfCppConfig::AssignClassDeclsToFiles()#Internal error."
);}
while
(
0
);
return
.
.
().
(
indexKey
);
})
.
([](
)
{
return
index
!= -
1
;
})
.
([&](
)
{
return
(
.
.
(
index
));
});
= -
1
;
if
(
)
{
auto
=
->
.
()]
();
ASSIGN_INDEX_KEY(, indexKey, stringKey);
indexKey
=
.
.
().
(
stringKey
);
do
{
if
(!(
indexKey
!= -
1
))
throw
(
L"WfCppConfig::AssignClassDeclsToFiles()#Internal error."
);}
while
(
0
);
}
FOREACH(vint, subDecl, directChildren.Concat(indirectChildren))
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
>&
= ::
vl
::
collections
::
(
directChildren
.
(
indirectChildren
));
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
;
__foreach_iterator__
.
(
subDecl
);)
{
.
.
(
indexKey
,
subDecl
);
}
}
void
::
GenerateClassDependencies
(
&
)
{
FOREACH_INDEXER(ITypeDescriptor*, td, tdIndex, globalDep.allTds.Values())
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
*>&
= ::
vl
::
collections
::
(
.
.
());
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
if
(
bool
=
true
)
for
(
=
0
;
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
*
;
__foreach_iterator__
.
(
td
);
tdIndex
++)
{
=
td
->
GetBaseTypeDescriptorCount
();
for
(
=
0
;
i
<
count
;
i
++)
{
auto
=
td
->
(
i
);
=
.
.
().
(
baseTd
->
());
if
(
baseTdIndex
!= -
1
)
{
.
.
(
tdIndex
,
baseTdIndex
);
}
}
}
}
void
::
(
&
)
{
FOREACH_INDEXER(ITypeDescriptor*, td, index, tdDecls.Keys())
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
*>&
= ::
vl
::
collections
::
(
.
());
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
if
(
bool
=
true
)
for
(
=
0
;
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
*
;
__foreach_iterator__
.
(
td
);
index
++)
{
if
(
.
()
index
].
<
>())
{
.
.
(
td
->
(),
td
);
}
}
(
nullptr
,
);
GenerateClassDependencies
(
);
}
void
::
(
,
&
,
&
)
{
const
auto
&
=
.
];
FOREACH(vint, subDecl, items)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
>&
= ::
vl
::
collections
::
(
items
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
;
__foreach_iterator__
.
(
subDecl
);)
{
=
.
.
().
(
subDecl
);
if
(
index
!= -
1
)
{
FOREACH(vint, dep, globalDep.dependencies.GetByIndex(index))
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
>&
= ::
vl
::
collections
::
(
.
.
(
index
));
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
;
__foreach_iterator__
.
(
dep
);)
{
if
(
items
.
(
dep
))
{
.
.
(
subDecl
,
dep
);
}
}
}
}
}
void
::
(
,
&
,
&
)
{
.
.
(
,
);
=
.
.
().
(
);
if
(
index
!= -
1
)
{
FOREACH(vint, expandDecl, globalDep.expandedClassDecls.GetByIndex(index))
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
>&
= ::
vl
::
collections
::
(
.
.
(
index
));
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
;
__foreach_iterator__
.
(
expandDecl
);)
{
.
.
(
expandDecl
,
);
}
}
}
void
::
(
<
>
,
&
,
&
)
{
.
;
if
(
)
{
auto
=
->
.
()]
();
ASSIGN_INDEX_KEY(, classLevelDep.parentIndexKey, parentStringKey);
.
=
.
.
().
(
parentStringKey
);
do
{
if
(!(
.
!= -
1
))
throw
(
L"WfCppConfig::AssignClassDeclsToFiles()#Internal error."
);}
while
(
0
);
}
const
auto
&
=
.
.
];
(
.
,
,
);
FOREACH(Ptr<WfClassDeclaration>, subDecl, classDecls.Get(parent.Obj()))
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
.
(
.
()));
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
subDecl
);)
{
auto
=
->
subDecl
.
()]
();
ASSIGN_INDEX_KEY(auto, subDeclIndexKey, subDeclStringKey);
auto
=
.
.
().
(
subDeclStringKey
);
do
{
if
(!(
subDeclIndexKey
!= -
1
))
throw
(
L"WfCppConfig::AssignClassDeclsToFiles()#Internal error."
);}
while
(
0
);
(
subDeclIndexKey
,
,
);
}
}
void
::
(
&
)
{
for
(
=
.
() -
1
;
i
>=
0
;
i
--)
{
auto
=
.
()
i
];
;
(
parent
,
,
classLevelDep
);
;
const
auto
&
=
.
classLevelDep
.
];
pop
.
(
items
,
classLevelDep
.
,
classLevelDep
.
);
pop
.
();
{
auto
&
=
const_cast
<
<
<
>>&>(
.
(
i
));
for
(
=
0
;
j
<
pop
.
.
();
j
++)
{
auto
&
=
pop
.
j
];
if
(
component
.
>
1
)
{
<
*>
;
for
(
=
0
;
k
<
component
.
;
k
++)
{
auto
&
=
pop
.
component
.
[
k
]];
auto
=
classLevelDep
.
items
node
.
[
0
]]];
tds
.
(
.
.
()
indexKey
]);
}
<
*>(&
tds
0
],
tds
.
(), [](
*
,
*
)
{
return
::
(
a
->
(),
b
->
());
});
->
.
(
::
CppUnableToDecideClassOrder
(
tds
0
]].
<
>().
(),
tds
));
}
auto
&
=
pop
.
component
.
[
0
]];
auto
=
classLevelDep
.
items
node
.
[
0
]]];
auto
=
.
.
()
subDeclIndexKey
]].
<
>();
values
j
]
subDecl
;
}
}
if
(!
parent
&&
->
.
() ==
0
)
{
for
(
=
0
;
i
<
classLevelDep
.
.
();
i
++)
{
=
classLevelDep
.
.
()
i
];
if
(!
.
.
(
index
))
{
.
.
(
index
);
}
}
for
(
=
0
;
i
<
pop
.
.
();
i
++)
{
auto
&
=
pop
.
i
];
=
classLevelDep
.
items
keyNode
.
[
0
]]];
for
(
=
0
;
j
<
keyNode
.
->
();
j
++)
{
auto
&
=
pop
.
keyNode
.
->
(
j
)];
=
classLevelDep
.
items
valueNode
.
[
0
]]];
if
(!
.
.
(
keyIndex
,
valueIndex
))
{
.
.
(
keyIndex
,
valueIndex
);
}
}
}
}
}
}
void
::
(
&
)
{
if
(
.
().
(
nullptr
))
{
;
<
>
;
<
>
;
<
bool
>
;
<
,
>
;
{
<
,
>
;
for
(
=
0
;
i
<
.
();
i
++)
{
=
.
()
i
];
if
(
key
!=
L""
)
{
FOREACH(Ptr<WfClassDeclaration>, decl, customFilesClasses.GetByIndex(i))
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
.
(
i
));
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
decl
);)
{
auto
=
->
decl
.
()]
();
ASSIGN_INDEX_KEY(auto, indexKey, stringKey);
auto
=
.
.
().
(
stringKey
);
do
{
if
(!(
indexKey
!= -
1
))
throw
(
L"WfCppConfig::AssignClassDeclsToFiles()#Internal error."
);}
while
(
0
);
subClass
.
(
indexKey
,
key
);
}
}
}
popSubClass
.
(
.
,
.
,
subClass
);
popSubClass
.
();
for
(
=
0
;
i
<
popSubClass
.
.
();
i
++)
{
auto
&
=
popSubClass
.
i
];
if
(
component
.
>
1
)
{
<
*>
;
for
(
=
0
;
j
<
component
.
;
j
++)
{
auto
&
=
popSubClass
.
component
.
[
j
]];
for
(
=
0
;
k
<
node
.
;
k
++)
{
auto
=
.
node
.
[
k
]];
tds
.
(
.
.
()
indexKey
]);
}
}
<
*>(&
tds
0
],
tds
.
(), [](
*
,
*
)
{
return
::
(
a
->
(),
b
->
());
});
->
.
(
::
CppUnableToSeparateCustomFile
(
tds
0
]].
<
>().
(),
tds
));
}
}
if
(
->
.
() !=
0
)
{
return
;
}
{
<
>
;
<
>
;
for
(
=
0
;
i
<
popSubClass
.
.
();
i
++)
{
auto
&
=
popSubClass
.
i
];
if
(
subClass
.
().
(
.
node
.
[
0
]]))
{
customItems
.
(
i
);
}
else
{
nonCustomItems
.
(
i
);
}
}
auto
= [&](
<
>&
)
{
if
(
items
.
() >
0
)
{
<
>(&
items
0
],
items
.
(), [&](
,
)
{
auto
&
=
popSubClass
.
a
];
auto
&
=
popSubClass
.
b
];
=
(
nodeA
.
,
nodeA
.
+
nodeA
.
)
.
([&](
) {
return
.
index
]; })
.
();
=
(
nodeB
.
,
nodeB
.
+
nodeB
.
)
.
([&](
) {
return
.
index
]; })
.
();
return
indexA
-
indexB
;
});
}
};
SortNodes
(
customItems
);
SortNodes
(
nonCustomItems
);
isCustomItems
.
(
customItems
.
() +
nonCustomItems
.
());
for
(
=
0
;
i
<
customItems
.
();
i
++)
{
isCustomItems
customItems
i
]] =
true
;
}
for
(
=
0
;
i
<
nonCustomItems
.
();
i
++)
{
isCustomItems
nonCustomItems
i
]] =
false
;
}
(
customFirstItems
,
customItems
);
(
nonCustomFirstItems
,
nonCustomItems
);
(
nonCustomFirstItems
,
customItems
,
true
);
(
customFirstItems
,
nonCustomItems
,
true
);
}
}
for
(
=
0
;
i
<
popSubClass
.
.
();
i
++)
{
auto
&
=
popSubClass
.
i
];
for
(
=
0
;
j
<
node
.
->
();
j
++)
{
subClassDepGroup
.
(
i
,
node
.
->
(
j
));
}
}
;
popCustomFirst
.
(
customFirstItems
,
subClassDepGroup
);
popCustomFirst
.
();
;
popNonCustomFirst
.
(
nonCustomFirstItems
,
subClassDepGroup
);
popNonCustomFirst
.
();
CHECK_ERROR(popCustomFirst.components.Count() == customFirstItems.Count(), L"WfCppConfig::AssignClassDeclsToFiles()#Internal error: Unexpected circle dependency found, this should have been caught by code above.");
do
{
if
(!(
popCustomFirst
.
.
() ==
customFirstItems
.
()))
throw
(
L"WfCppConfig::AssignClassDeclsToFiles()#Internal error: Unexpected circle dependency found, this should have been caught by code above."
);}
while
(
0
);
CHECK_ERROR(popNonCustomFirst.components.Count() == nonCustomFirstItems.Count(), L"WfCppConfig::AssignClassDeclsToFiles()#Future error: Unexpected circle dependency found, this should have been caught by code above.");
do
{
if
(!(
popNonCustomFirst
.
.
() ==
nonCustomFirstItems
.
()))
throw
(
L"WfCppConfig::AssignClassDeclsToFiles()#Future error: Unexpected circle dependency found, this should have been caught by code above."
);}
while
(
0
);
CHECK_ERROR(popCustomFirst.components.Count() == popNonCustomFirst.components.Count(), L"WfCppConfig::AssignClassDeclsToFiles()#Future error: Unexpected circle dependency found, this should have been caught by code above.");
do
{
if
(!(
popCustomFirst
.
.
() ==
popNonCustomFirst
.
.
()))
throw
(
L"WfCppConfig::AssignClassDeclsToFiles()#Future error: Unexpected circle dependency found, this should have been caught by code above."
);}
while
(
0
);
<
>
(
popCustomFirst
.
.
());
for
(
=
0
;
i
<
popCustomFirst
.
.
();
i
++)
{
auto
&
=
popCustomFirst
.
i
];
customFirstOrder
i
] =
customFirstItems
component
.
[
0
]];
}
<
>
(
popNonCustomFirst
.
.
());
for
(
=
0
;
i
<
popNonCustomFirst
.
.
();
i
++)
{
auto
&
=
popNonCustomFirst
.
i
];
nonCustomFirstOrder
i
] =
nonCustomFirstItems
component
.
[
0
]];
}
=
0
;
nonCustomFirstOrderPicked
=
0
;
=
0
;
<
bool
>
(
customFirstOrder
.
());
for
(
=
0
;
i
<
visited
.
();
i
++)
{
visited
i
] =
false
;
}
auto
= [&](
<
>&
,
&
,
bool
)
{
while
(
picked
<
order
.
())
{
=
order
picked
];
if
(
visited
item
])
{
picked
++;
}
else
if
(
isCustomItems
item
] ==
customItem
)
{
visited
item
] =
true
;
picked
++;
if
(!
customItem
)
{
auto
&
=
popSubClass
.
item
];
for
(
=
0
;
i
<
node
.
;
i
++)
{
auto
=
.
node
.
[
i
]];
auto
=
.
.
()
indexKey
];
.
(
currentHeaderIndex
,
td
].
<
>());
}
}
}
else
{
break
;
}
}
};
while
(
nonCustomFirstOrderPicked
<
nonCustomFirstOrder
.
() ||
customFirstOrderPicked
<
customFirstOrder
.
())
{
pickItems
(
nonCustomFirstOrder
,
nonCustomFirstOrderPicked
,
false
);
pickItems
(
customFirstOrder
,
customFirstOrderPicked
,
false
);
pickItems
(
nonCustomFirstOrder
,
nonCustomFirstOrderPicked
,
true
);
pickItems
(
customFirstOrder
,
customFirstOrderPicked
,
true
);
currentHeaderIndex
++;
}
<
,
> ;
auto
= [&](
const
<
<
>>& ,
)
{
FOREACH(Ptr<WfClassDeclaration>, decl, decls)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>& = ::
vl
::
collections
::
(
decls
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
> ;
__foreach_iterator__
.
(
decl
);)
{
auto
=
->
decl
.
()]
();
ASSIGN_INDEX_KEY(auto, indexKey, stringKey);
auto
=
.
.
().
(
stringKey
);
do
{
if
(!(
indexKey
!= -
1
))
throw
(
L"WfCppConfig::AssignClassDeclsToFiles()#Internal error."
);}
while
(
0
);
headers
.
(
indexKey
,
headerIndex
);
}
};
auto
= [&](
const
<
<
>>&
,
<
>&
)
{
FOREACH(Ptr<WfClassDeclaration>, decl, decls)
if
(
bool
=
true
)
for
(
const
::
vl
::
collections
::
<
<
>>&
= ::
vl
::
collections
::
(
decls
);
__scope_variable_flag__
;
__scope_variable_flag__
=
false
)
for
(
<
>
;
__foreach_iterator__
.
(
decl
);)
{
auto
=
->
decl
.
()]
();
ASSIGN_INDEX_KEY(auto, indexKey, stringKey);
auto
=
.
.
().
(
stringKey
);
do
{
if
(!(
indexKey
!= -
1
))
throw
(
L"WfCppConfig::AssignClassDeclsToFiles()#Internal error."
);}
while
(
0
);
=
.
.
().
(
indexKey
);
if
(
index
!= -
1
)
{
const
auto
&
=
.
.
(
index
);
for
(
=
0
;
i
<
values
.
();
i
++)
{
=
headers
values
i
]];
if
(
header
!=
0
&& !
includes
.
(
header
))
{
includes
.
(
header
);
}
}
}
}
};
for
(
=
0
;
i
<
.
();
i
++)
{
if
(
.
()
i
]
L""
)
{
addToHeaders
(
.
(
i
),
i
);
}
}
for
(
=
0
;
i
<
.
();
i
++)
{
addToHeaders
(
.
(
i
), -
.
()
i
]);
}
for
(
=
0
;
i
<
.
();
i
++)
{
if
(
.
()
i
]
L""
)
{
<
>
;
calculateIncludes
(
.
(
i
),
includes
);
for
(
=
0
;
j
<
includes
.
();
j
++)
{
.
(
i
,
includes
j
]);
}
}
}
for
(
=
0
;
i
<
.
();
i
++)
{
if
(
.
()
i
] !=
0
)
{
<
>
;
calculateIncludes
(
.
(
i
),
includes
);
for
(
=
0
;
j
<
includes
.
();
j
++)
{
.
(-
.
()
i
],
includes
j
]);
}
}
}
}
}
void
::
(
&
)
{
if
(
.
().
(
nullptr
))
{
<
<
>>
;
(
ordered
,
nullptr
]);
for
(
=
0
;
i
<
.
();
i
++)
{
auto
&
=
const_cast
<
<
<
>>&>(
.
(
i
));
<
<
>>(&
values
0
],
values
.
(), [&](
<
>
,
<
>
)
{
=
ordered
.
(
a
.
());
=
ordered
.
(
b
.
());
return
aIndex
-
bIndex
;
});
}
for
(
=
0
;
i
<
.
();
i
++)
{
auto
&
=
const_cast
<
<
<
>>&>(
.
(
i
));
<
<
>>(&
values
0
],
values
.
(), [&](
<
>
,
<
>
)
{
=
ordered
.
(
a
.
());
=
ordered
.
(
b
.
());
return
aIndex
-
bIndex
;
});
}
}
}
void
::
()
{
;
(
globalDep
);
if
(
->
.
() ==
0
)
(
globalDep
);
if
(
->
.
() ==
0
)
(
globalDep
);
if
(
->
.
() ==
0
)
(
globalDep
);
}
#undef ASSIGN_INDEX_KEY
}
}
}