@@ -28,25 +28,30 @@ public static class SemanticsHelpers
28
28
/// <param name="field">Field declaration</param>
29
29
/// <param name="sourceBuilder">Source builder</param>
30
30
/// <param name="coBuilder">Lateral builder signature</param>
31
+ /// <param name="warnMissingOrInconsistent">Issues warning when the type is eligible but not available.</param>
31
32
/// <returns>True when the member is eligible for generation.</returns>
32
- public static ( bool isEligible , ITypeDeclaration eligibleType ) IsMemberEligibleForTranspile ( this IFieldDeclaration field , ISourceBuilder sourceBuilder , string coBuilder = "" )
33
+ public static ( bool isEligible , ITypeDeclaration eligibleType ) IsMemberEligibleForTranspile ( this IFieldDeclaration field , ISourceBuilder sourceBuilder ,
34
+ string coBuilder = "" , bool warnMissingOrInconsistent = false )
33
35
{
34
- var eligibility = field . IsEligibleForTranspile ( sourceBuilder ) ;
36
+ var eligibility = field . IsEligibleForTranspile ( sourceBuilder , warnMissingOrInconsistent ) ;
35
37
var isEligible = ( field . AccessModifier == AccessModifier . Public
36
38
&& eligibility . isEligibe
37
39
&& ! IsToBeOmitted ( field , sourceBuilder , coBuilder ) ) ;
38
40
39
41
return ( isEligible , eligibility . eligibleType ) ;
40
42
}
41
-
43
+
42
44
43
45
/// <summary>
44
46
/// Finds type declaration.
45
47
/// </summary>
46
48
/// <param name="compilation">Compilation object</param>
47
49
/// <param name="typeAccess">Required type</param>
50
+ /// <param name="warnMissingOrInconsistent">Will report missing type.</param>
48
51
/// <returns>Required type if found.</returns>
49
- public static ITypeDeclaration FindTypeDeclaration ( this Compilation compilation , AX . ST . Semantic . Model . ISemanticTypeAccess ? typeAccess )
52
+ public static ITypeDeclaration FindTypeDeclaration
53
+ ( this Compilation compilation , AX . ST . Semantic . Model . ISemanticTypeAccess ? typeAccess ,
54
+ bool warnMissingOrInconsistent = false )
50
55
{
51
56
if ( typeAccess == null )
52
57
return null ;
@@ -82,14 +87,14 @@ public static ITypeDeclaration FindTypeDeclaration(this Compilation compilation,
82
87
var span = typeAccess ? . Location ? . GetLineSpan ( ) ;
83
88
var line = span . Value . StartLinePosition . Line ;
84
89
var character = span . Value . StartLinePosition . Character ;
85
- if ( candidates . Count ( ) == 0 )
90
+ if ( candidates . Count ( ) == 0 && warnMissingOrInconsistent )
86
91
{
87
- Log . Logger . Warning ( $ "{ span ? . Filename } ({ line } :{ character } ) : Type '{ typeAccess . TypeSymbol . Name } ' not found the type may not be eligible for transpile or meta information is not available because this type is not defined in AX# compliant project. ") ;
92
+ Log . Logger . Warning ( $ "{ span ? . Filename } ({ line } :{ character } ) : Type '{ typeAccess . TypeSymbol . Name } ' not found. The type may not be eligible for transpile or meta information is not available because this type is not defined in AX# compliant project.") ;
88
93
}
89
94
90
- if ( candidates . Count ( ) > 1 )
95
+ if ( candidates . Count ( ) > 1 && warnMissingOrInconsistent )
91
96
{
92
- Log . Logger . Warning ( $ "{ span ? . Filename } ({ line } :{ character } ) : Multiple types found for '{ typeAccess . TypeSymbol . Name } ' the declaration appears ambiguous. You may need to fully qualify the declaration.") ;
97
+ Log . Logger . Warning ( $ "{ span ? . Filename } ({ line } :{ character } ) : Multiple types found for '{ typeAccess . TypeSymbol . Name } '. The declaration appears ambiguous. You may need to fully qualify the declaration.") ;
93
98
}
94
99
}
95
100
catch
@@ -101,7 +106,8 @@ public static ITypeDeclaration FindTypeDeclaration(this Compilation compilation,
101
106
return null ;
102
107
}
103
108
104
- public static ITypeDeclaration FindTypeDeclaration ( this Compilation compilation , IDeclaration ? typeAccess )
109
+ private static ITypeDeclaration FindTypeDeclaration ( this Compilation compilation , IDeclaration ? typeAccess ,
110
+ bool warnMissingOrInconsistent = false )
105
111
{
106
112
// This is to resolve fully qualified type name when the type cannot be determined propeprly form the semantic tree.
107
113
// TODO: This workaround should be removed once we can properly use project dependencies in the stc.
@@ -123,20 +129,20 @@ public static ITypeDeclaration FindTypeDeclaration(this Compilation compilation,
123
129
return candidates . First ( ) ;
124
130
}
125
131
126
- if ( candidates . Count ( ) == 0 )
132
+ if ( candidates . Count ( ) == 0 && warnMissingOrInconsistent )
127
133
{
128
134
Log . Logger . Warning ( $ "Type '{ typeAccess ? . ToString ( ) } ' not found in the semantic tree. { typeAccess ? . Location } ") ;
129
135
}
130
136
131
- if ( candidates . Count ( ) > 1 )
137
+ if ( candidates . Count ( ) > 1 && warnMissingOrInconsistent )
132
138
{
133
139
Log . Logger . Warning ( $ "Multiple types found for '{ typeAccess ? . ToString ( ) } ' in the semantic tree. You may need to fully qualify the declaration.") ;
134
140
}
135
141
136
142
return null ;
137
143
}
138
144
139
- public static string ? DetermineFullyQualifiedName ( this AX . ST . Semantic . Model . ISemanticTypeAccess declaration , Compilation compilation )
145
+ private static string ? DetermineFullyQualifiedName ( this AX . ST . Semantic . Model . ISemanticTypeAccess declaration , Compilation compilation )
140
146
{
141
147
return compilation . FindTypeDeclaration ( declaration ) ? . FullyQualifiedName ;
142
148
}
@@ -184,7 +190,7 @@ public static void AddFullyQualifiedName(this IDeclaration declaration, Compilat
184
190
/// <param name="declaration">Field declaration</param>
185
191
/// <param name="compilation">Compilation object.</param>
186
192
/// <returns>Fully qualified name of the declaration.</returns>
187
- public static string ? DetermineFullyQualifiedName ( this IFieldDeclaration declaration , Compilation compilation )
193
+ private static string ? DetermineFullyQualifiedName ( this IFieldDeclaration declaration , Compilation compilation )
188
194
{
189
195
return compilation . FindTypeDeclaration ( declaration . TypeAccess ) ? . FullyQualifiedName ;
190
196
}
@@ -195,7 +201,7 @@ public static void AddFullyQualifiedName(this IDeclaration declaration, Compilat
195
201
/// <param name="declaration">Variable declaration</param>
196
202
/// <param name="compilation">Compilation object.</param>
197
203
/// <returns>Fully qualified name of the declaration.</returns>
198
- public static string ? DetermineFullyQualifiedName ( this IVariableDeclaration declaration , Compilation compilation )
204
+ private static string ? DetermineFullyQualifiedName ( this IVariableDeclaration declaration , Compilation compilation )
199
205
{
200
206
return compilation . FindTypeDeclaration ( declaration . TypeAccess ) ? . FullyQualifiedName ;
201
207
}
@@ -243,11 +249,12 @@ private static bool IsToBeOmitted(this IStorageDeclaration fieldDeclaration, ISo
243
249
/// </summary>
244
250
/// <param name="fieldDeclaration"></param>
245
251
/// <param name="sourceBuilder"></param>
252
+ /// <param name="warnMissingOrInconsistent">Issues warning when the type is eligible but not available.</param>
246
253
/// <returns>True when the type is eligible</returns>
247
- public static ( bool isEligibe , ITypeDeclaration eligibleType ) IsEligibleForTranspile ( this IFieldDeclaration fieldDeclaration , ISourceBuilder sourceBuilder )
254
+ private static ( bool isEligibe , ITypeDeclaration eligibleType ) IsEligibleForTranspile ( this IFieldDeclaration fieldDeclaration , ISourceBuilder sourceBuilder , bool warnMissingOrInconsistent = false )
248
255
{
249
256
var type = fieldDeclaration . Type ;
250
- var fullyQualified = sourceBuilder . Compilation . FindTypeDeclaration ( fieldDeclaration . TypeAccess ) ;
257
+ var fullyQualified = sourceBuilder . Compilation . FindTypeDeclaration ( fieldDeclaration . TypeAccess , warnMissingOrInconsistent ) ;
251
258
var isEligible = ! ( type is IReferenceTypeDeclaration )
252
259
&&
253
260
fieldDeclaration . IsAvailableForComm ( sourceBuilder )
@@ -271,11 +278,13 @@ type is INamedValueTypeDeclaration ||
271
278
/// </summary>
272
279
/// <param name="variableDeclaration"></param>
273
280
/// <param name="sourceBuilder"></param>
281
+ /// <param name="warnMissingOrInconsistent">Will issue warning when the type is eligible but not available.</param>
274
282
/// <returns>True when the type is eligible</returns>
275
- public static ( bool isEligibe , ITypeDeclaration ? eligibleType ) IsEligibleForTranspile ( this IVariableDeclaration variableDeclaration , ISourceBuilder sourceBuilder )
283
+ private static ( bool isEligibe , ITypeDeclaration ? eligibleType ) IsEligibleForTranspile ( this IVariableDeclaration variableDeclaration ,
284
+ ISourceBuilder sourceBuilder , bool warnMissingOrInconsistent = false )
276
285
{
277
286
var type = variableDeclaration . Type ;
278
- var declaration = sourceBuilder . Compilation . FindTypeDeclaration ( variableDeclaration . TypeAccess ) ;
287
+ var declaration = sourceBuilder . Compilation . FindTypeDeclaration ( variableDeclaration . TypeAccess , warnMissingOrInconsistent ) ;
279
288
var isEligible = ! ( type is IReferenceTypeDeclaration )
280
289
&&
281
290
variableDeclaration . IsAvailableForComm ( sourceBuilder )
@@ -300,11 +309,14 @@ type is INamedValueTypeDeclaration ||
300
309
/// </summary>
301
310
/// <param name="arrayTypeDeclaration"></param>
302
311
/// <param name="sourceBuilder">Source builder</param>
312
+ /// <param name="warnMissingOrInconsistent">Should issue warning if the type was not found though eligible.</param>
303
313
/// <returns></returns>
304
- public static ( bool isEligibe , ITypeDeclaration ? eligibleType ) IsEligibleForTranspile ( this IArrayTypeDeclaration arrayTypeDeclaration , ISourceBuilder sourceBuilder )
314
+ public static ( bool isEligibe , ITypeDeclaration ? eligibleType ) IsEligibleForTranspile ( this IArrayTypeDeclaration arrayTypeDeclaration ,
315
+ ISourceBuilder sourceBuilder ,
316
+ bool warnMissingOrInconsistent = false )
305
317
{
306
318
var singleDimensionalArray = arrayTypeDeclaration . Dimensions . Count == 1 ;
307
- var declaration = sourceBuilder . Compilation . FindTypeDeclaration ( arrayTypeDeclaration . ElementTypeAccess ) ;
319
+ var declaration = sourceBuilder . Compilation . FindTypeDeclaration ( arrayTypeDeclaration . ElementTypeAccess , warnMissingOrInconsistent ) ;
308
320
var isEligibleType = ! ( arrayTypeDeclaration . ElementTypeAccess . Type is IReferenceTypeDeclaration )
309
321
&&
310
322
arrayTypeDeclaration . IsAvailableForComm ( sourceBuilder )
@@ -326,10 +338,12 @@ arrayTypeDeclaration.ElementTypeAccess.Type is INamedValueTypeDeclaration ||
326
338
/// <param name="variable">Variable declaration</param>
327
339
/// <param name="sourceBuilder">Source builder</param>
328
340
/// <param name="coBuilder">Co-builder signature (e.g. POCO, Onliner, etc.)</param>
341
+ /// <param name="warnMissingOrInconsistent">Will issue warning when the type is eligible but not found</param>
329
342
/// <returns>True when the member is eligible for generation.</returns>
330
- public static ( bool isEligibe , ITypeDeclaration ? eligibleType ) IsMemberEligibleForTranspile ( this IVariableDeclaration variable , ISourceBuilder sourceBuilder , string coBuilder = "" )
343
+ public static ( bool isEligibe , ITypeDeclaration ? eligibleType ) IsMemberEligibleForTranspile ( this IVariableDeclaration variable ,
344
+ ISourceBuilder sourceBuilder , string coBuilder = "" , bool warnMissingOrInconsistent = false )
331
345
{
332
- var eligibility = variable . IsEligibleForTranspile ( sourceBuilder ) ;
346
+ var eligibility = variable . IsEligibleForTranspile ( sourceBuilder , warnMissingOrInconsistent ) ;
333
347
var eligible = variable . IsInGlobalMemory
334
348
&& eligibility . isEligibe
335
349
&& ! IsToBeOmitted ( variable , sourceBuilder , coBuilder ) ;
0 commit comments