@@ -84,7 +84,6 @@ internal void DumpModel()
8484 PropertyNamingPolicy = JsonNamingPolicy . CamelCase ,
8585 DictionaryKeyPolicy = null , // leave unchanged
8686 } ;
87-
8887 public string ToJson ( )
8988 {
9089 // always writes the "compact" format, see data_descriptor.md
@@ -96,19 +95,15 @@ public class Builder
9695 private string _baseline ;
9796 private readonly string _baselinesDir ;
9897 private bool _baselineParsed ;
99- private readonly string ? _overrideBaselineName ;
10098 private readonly Dictionary < string , TypeModelBuilder > _types = new ( ) ;
10199 private readonly Dictionary < string , GlobalBuilder > _globals = new ( ) ;
102100 private readonly Dictionary < string , GlobalBuilder > _subDescriptors = new ( ) ;
103101 private readonly Dictionary < string , ContractBuilder > _contracts = new ( ) ;
104- private DataDescriptorModel ? _baselineModel ;
105-
106- public Builder ( string baselinesDir , string ? overrideBaselineName = null )
102+ public Builder ( string baselinesDir )
107103 {
108104 _baseline = string . Empty ;
109105 _baselineParsed = false ;
110106 _baselinesDir = baselinesDir ;
111- _overrideBaselineName = overrideBaselineName ;
112107 }
113108
114109 public uint PlatformFlags { get ; set ; }
@@ -172,12 +167,6 @@ public void AddOrUpdateContract(string name, int version)
172167
173168 public void SetBaseline ( string baseline )
174169 {
175- // If an override baseline name was provided via command line, use it instead
176- if ( _overrideBaselineName is not null )
177- {
178- baseline = _overrideBaselineName ;
179- }
180-
181170 if ( _baseline != string . Empty && _baseline != baseline )
182171 {
183172 throw new InvalidOperationException ( $ "Baseline already set to { _baseline } cannot set to { baseline } ") ;
@@ -201,54 +190,20 @@ public void SetBaseline(string baseline)
201190
202191 private void ParseBaseline ( )
203192 {
204- // Load the baseline file to check if it's empty
205- var baselinePath = Path . Combine ( _baselinesDir , _baseline + ".jsonc" ) ;
206- if ( ! File . Exists ( baselinePath ) )
207- {
208- baselinePath = Path . Combine ( _baselinesDir , _baseline + ".json" ) ;
209- if ( ! File . Exists ( baselinePath ) )
210- {
211- throw new InvalidOperationException ( $ "Baseline file not found: { _baseline } .json or { _baseline } .jsonc in { _baselinesDir } ") ;
212- }
213- }
214-
215- var json = File . ReadAllText ( baselinePath ) ;
216-
217- // Check if this is an empty baseline (version 0 with no data)
218- using var doc = JsonDocument . Parse ( json , new JsonDocumentOptions
193+ if ( _baseline != "empty" )
219194 {
220- CommentHandling = JsonCommentHandling . Skip ,
221- AllowTrailingCommas = true
222- } ) ;
223-
224- if ( doc . RootElement . TryGetProperty ( "version" , out var versionProp ) &&
225- versionProp . GetInt32 ( ) == 0 )
226- {
227- // Empty baseline - no types, globals, or contracts to load
228- _baselineModel = null ;
229- return ;
195+ throw new InvalidOperationException ( "TODO: [cdac] - implement baseline parsing" ) ;
230196 }
231-
232- // TODO: [cdac] - implement non-empty baseline parsing
233- // For now, we only support empty baselines (version 0) which contain no data
234- // Future work: Add proper JSON deserialization for non-empty baselines
235- // This would require custom JsonConverters for the compact array format used
236- // in baseline files (e.g., "Field1": [0, "uint32"] instead of expanded objects)
237- throw new InvalidOperationException ( $ "Non-empty baseline parsing is not yet implemented for baseline '{ _baseline } '. Only empty baselines (version 0) are currently supported.") ;
238197 }
239198
240199 public DataDescriptorModel Build ( )
241200 {
242201 var types = new Dictionary < string , TypeModel > ( ) ;
243- var globals = new Dictionary < string , GlobalModel > ( ) ;
244- var subDescriptors = new Dictionary < string , GlobalModel > ( ) ;
245- var contracts = new Dictionary < string , int > ( ) ;
246-
247- // Build current model
248202 foreach ( var ( typeName , typeBuilder ) in _types )
249203 {
250204 types [ typeName ] = typeBuilder . Build ( typeName ) ;
251205 }
206+ var globals = new Dictionary < string , GlobalModel > ( ) ;
252207 foreach ( var ( globalName , globalBuilder ) in _globals )
253208 {
254209 GlobalValue ? v = globalBuilder . Value ;
@@ -258,6 +213,7 @@ public DataDescriptorModel Build()
258213 }
259214 globals [ globalName ] = new GlobalModel { Type = globalBuilder . Type , Value = v . Value } ;
260215 }
216+ var subDescriptors = new Dictionary < string , GlobalModel > ( ) ;
261217 foreach ( var ( subDescriptorName , subDescriptorBuilder ) in _subDescriptors )
262218 {
263219 GlobalValue ? v = subDescriptorBuilder . Value ;
@@ -267,118 +223,13 @@ public DataDescriptorModel Build()
267223 }
268224 subDescriptors [ subDescriptorName ] = new GlobalModel { Type = subDescriptorBuilder . Type , Value = v . Value } ;
269225 }
226+ var contracts = new Dictionary < string , int > ( ) ;
270227 foreach ( var ( contractName , contractBuilder ) in _contracts )
271228 {
272229 contracts [ contractName ] = contractBuilder . Build ( ) ;
273230 }
274-
275- // If we have a baseline model loaded, only include differences
276- // Note: Empty baselines (version 0) set _baselineModel to null, so they result in full model output
277- if ( _baselineModel is not null )
278- {
279- types = ComputeTypeDifferences ( types , _baselineModel . Types ) ;
280- globals = ComputeGlobalDifferences ( globals , _baselineModel . Globals ) ;
281- subDescriptors = ComputeGlobalDifferences ( subDescriptors , _baselineModel . SubDescriptors ) ;
282- contracts = ComputeContractDifferences ( contracts , _baselineModel . Contracts ) ;
283- }
284-
285231 return new DataDescriptorModel ( _baseline , types , globals , subDescriptors , contracts , PlatformFlags ) ;
286232 }
287-
288- private static Dictionary < string , TypeModel > ComputeTypeDifferences (
289- IReadOnlyDictionary < string , TypeModel > current ,
290- IReadOnlyDictionary < string , TypeModel > baseline )
291- {
292- var differences = new Dictionary < string , TypeModel > ( ) ;
293-
294- foreach ( var ( typeName , currentType ) in current )
295- {
296- if ( ! baseline . TryGetValue ( typeName , out var baselineType ) )
297- {
298- // New type not in baseline
299- differences [ typeName ] = currentType ;
300- continue ;
301- }
302-
303- // Check if type has differences
304- if ( ! TypesEqual ( currentType , baselineType ) )
305- {
306- differences [ typeName ] = currentType ;
307- }
308- }
309-
310- return differences ;
311- }
312-
313- private static bool TypesEqual ( TypeModel a , TypeModel b )
314- {
315- if ( a . Size != b . Size )
316- return false ;
317-
318- if ( a . Fields . Count != b . Fields . Count )
319- return false ;
320-
321- foreach ( var ( fieldName , fieldA ) in a . Fields )
322- {
323- if ( ! b . Fields . TryGetValue ( fieldName , out var fieldB ) )
324- return false ;
325-
326- if ( fieldA . Type != fieldB . Type || fieldA . Offset != fieldB . Offset )
327- return false ;
328- }
329-
330- return true ;
331- }
332-
333- private static Dictionary < string , GlobalModel > ComputeGlobalDifferences (
334- IReadOnlyDictionary < string , GlobalModel > current ,
335- IReadOnlyDictionary < string , GlobalModel > baseline )
336- {
337- var differences = new Dictionary < string , GlobalModel > ( ) ;
338-
339- foreach ( var ( globalName , currentGlobal ) in current )
340- {
341- if ( ! baseline . TryGetValue ( globalName , out var baselineGlobal ) )
342- {
343- // New global not in baseline
344- differences [ globalName ] = currentGlobal ;
345- continue ;
346- }
347-
348- // Check if global has differences
349- if ( currentGlobal . Type != baselineGlobal . Type || currentGlobal . Value != baselineGlobal . Value )
350- {
351- differences [ globalName ] = currentGlobal ;
352- }
353- }
354-
355- return differences ;
356- }
357-
358- private static Dictionary < string , int > ComputeContractDifferences (
359- IReadOnlyDictionary < string , int > current ,
360- IReadOnlyDictionary < string , int > baseline )
361- {
362- var differences = new Dictionary < string , int > ( ) ;
363-
364- foreach ( var ( contractName , currentVersion ) in current )
365- {
366- if ( ! baseline . TryGetValue ( contractName , out var baselineVersion ) )
367- {
368- // New contract not in baseline
369- differences [ contractName ] = currentVersion ;
370- continue ;
371- }
372-
373- // Check if version has changed
374- if ( currentVersion != baselineVersion )
375- {
376- differences [ contractName ] = currentVersion ;
377- }
378- }
379-
380- return differences ;
381- }
382233 }
383234
384235 public class TypeModelBuilder
0 commit comments