/*
Vczh Workflow Special Name:
__vwsn_not_exists__ : Represents all not supported code
__vwsn_temp_(#|_) : Temporary variable
__vwsn_CATEGORY : <CATEGORY>
__vwsn_CATEGORY_NAME : <CATEGORY>NAME
__vwsno#_ASSEMBLY_* : Ordered lambda class name
__vwsnf#_ASSEMBLY_* : Function expression class name
__vwsnc#_ASSEMBLY_* : Anonymous interface class name
__vwsnthis_# : Captured this pointer in fields
__vwsnctor_* : Captured symbol in constructor arguments, assigned to "this->*"
__vwsnctorthis_# : Captured this pointer in constructor arguments assigned to "this->__vwsnthis_#"?
__vwsnt_# : Temporary type
__vwsne_# : Temporary variable (not for lambda)
__vwsnb_# : Temporary block
__vwnsl_#_LABEL_NAME : Goto label
__vwsn_structs::NAME : Struct definition
__vwsn_enums::NAME : Struct definition
*/
class
WfCppConfig
:
public
Object
{
using
ITypeInfo
=
reflection
::
description
::
ITypeInfo
;
using
IMethodInfo
=
reflection
::
description
::
IMethodInfo
;
using
ITypeDescriptor
=
reflection
::
description
::
ITypeDescriptor
;
public
:
class
ClosureInfo
:
public
Object
{
using
SymbolMap
=
collections
::
Dictionary
<
WString
,
Ptr
<
analyzer
::
WfLexicalSymbol
>>;
public
:
WString
lambdaClassName
;
SymbolMap
symbols
;
SymbolMap
ctorArgumentSymbols
;
collections
::
List
<
ITypeDescriptor
*>
thisTypes
;
// nearer this pointer first
};
public
:
regex
::
Regex
regexSplitName
;
regex
::
Regex
regexSpecialName
;
regex
::
Regex
regexTemplate
;
protected
:
Ptr
<
ClosureInfo
>
CollectClosureInfo
(
Ptr
<
WfExpression
>
closure
);
void
Collect
();
struct
GlobalDep
{
collections
::
Dictionary
<
WString
,
ITypeDescriptor
*>
allTds
;
// Type name to type descriptor of class decls. Class index is the position in this map.
collections
::
Group
<
vint
,
vint
>
expandedClassDecls
;
// Class index (-1 means top level) to all direct and indirect internal classes
collections
::
Group
<
vint
,
vint
>
dependencies
;
// Class dependencies
collections
::
SortedList
<
vint
>
topLevelClasses
;
// Class index
collections
::
Group
<
vint
,
vint
>
topLevelClassDep
;
// Class dependencies for top level classes
};
struct
ClassLevelDep
{
Ptr
<
WfClassDeclaration
>
parentClass
;
vint
parentIndexKey
= -
1
;
collections
::
Group
<
vint
,
vint
>
depGroup
;
// A slice of GlobalDep::dependencies
collections
::
Dictionary
<
vint
,
vint
>
subClass
;
// Classes to their ancestor, which are direct internal classes of the selected parent class
};
void
ExpandClassDeclGroup
(
Ptr
<
WfClassDeclaration
>
parent
,
GlobalDep
&
globalDep
);
void
GenerateClassDependencies
(
GlobalDep
&
globalDep
);
void
GenerateGlobalDep
(
GlobalDep
&
globalDep
);
void
CollectExpandedDepGroup
(
vint
parentIndexKey
,
GlobalDep
&
globalDep
,
ClassLevelDep
&
classLevelDep
);
void
CollectExpandedSubClass
(
vint
subDeclIndexKey
,
GlobalDep
&
globalDep
,
ClassLevelDep
&
classLevelDep
);
void
GenerateClassLevelDep
(
Ptr
<
WfClassDeclaration
>
parent
,
GlobalDep
&
globalDep
,
ClassLevelDep
&
classLevelDep
);
void
SortClassDecls
(
GlobalDep
&
globalDep
);
void
GenerateFileClassMaps
(
GlobalDep
&
globalDep
);
void
SortFileClassMaps
(
GlobalDep
&
globalDep
);
void
AssignClassDeclsToFiles
();
template
<
typename
T
>
void
SortDeclsByName
(
collections
::
List
<
Ptr
<
T
>>&
decls
)
{
collections
::
Sort
<
Ptr
<
T
>>(&
decls
[
0
],
decls
.
Count
(), [=](
Ptr
<
T
>
a
,
Ptr
<
T
>
b
)
{
auto
tdA
=
manager
->
declarationTypes
[
a
.
Obj
()].
Obj
();
auto
tdB
=
manager
->
declarationTypes
[
b
.
Obj
()].
Obj
();
return
WString
::
Compare
(
tdA
->
GetTypeName
(),
tdB
->
GetTypeName
());
});
}
public
:
analyzer
::
WfLexicalScopeManager
*
manager
;
Ptr
<
emitter
::
WfAttributeEvaluator
>
attributeEvaluator
;
WString
assemblyNamespace
;
WString
assemblyName
;
collections
::
Dictionary
<
ITypeDescriptor
*,
Ptr
<
WfDeclaration
>>
tdDecls
;
// type descriptor to declaration
collections
::
Group
<
Ptr
<
WfClassDeclaration
>,
Ptr
<
WfEnumDeclaration
>>
enumDecls
;
// class (nullable) to direct internal enums
collections
::
Group
<
Ptr
<
WfClassDeclaration
>,
Ptr
<
WfStructDeclaration
>>
structDecls
;
// class (nullable) to direct internal structs
collections
::
Group
<
Ptr
<
WfClassDeclaration
>,
Ptr
<
WfClassDeclaration
>>
classDecls
;
// class (nullable) to direct internal classes
collections
::
List
<
Ptr
<
WfVariableDeclaration
>>
varDecls
;
// global variables
collections
::
List
<
Ptr
<
WfFunctionDeclaration
>>
funcDecls
;
// global functions
collections
::
Group
<
WString
,
Ptr
<
WfClassDeclaration
>>
customFilesClasses
;
// @cpp:File to top level classes, empty key means the default cpp
collections
::
Group
<
vint
,
Ptr
<
WfClassDeclaration
>>
headerFilesClasses
;
// non-@cpp:File header file to top level classes, 0 means the default header
collections
::
Group
<
vint
,
vint
>
headerIncludes
;
// 0:default header, positive:@cpp:File indexed in customFilesClasses, negative:non-@cpp:File headers