@@ -36,36 +36,27 @@ export enum ContractFunctionVisibility {
36
36
}
37
37
38
38
export class SourceFile {
39
- public readonly contracts : Contract [ ] = [ ] ;
40
- public readonly functions : ContractFunction [ ] = [ ] ;
39
+ private readonly _functions : ContractFunction [ ] = [ ] ;
41
40
42
41
constructor (
43
42
public readonly sourceName : string ,
44
43
public readonly content : string
45
44
) { }
46
45
47
- public addContract ( contract : Contract ) {
48
- if ( contract . location . file !== this ) {
49
- throw new Error ( "Trying to add a contract from another file" ) ;
50
- }
51
-
52
- this . contracts . push ( contract ) ;
53
- }
54
-
55
46
public addFunction ( func : ContractFunction ) {
56
47
if ( func . location . file !== this ) {
57
48
throw new Error ( "Trying to add a function from another file" ) ;
58
49
}
59
50
60
- this . functions . push ( func ) ;
51
+ this . _functions . push ( func ) ;
61
52
}
62
53
63
54
public getContainingFunction (
64
55
location : SourceLocation
65
56
) : ContractFunction | undefined {
66
57
// TODO: Optimize this with a binary search or an internal tree
67
58
68
- for ( const func of this . functions ) {
59
+ for ( const func of this . _functions ) {
69
60
if ( func . location . contains ( location ) ) {
70
61
return func ;
71
62
}
@@ -124,12 +115,12 @@ export class SourceLocation {
124
115
}
125
116
126
117
export class Contract {
127
- public readonly localFunctions : ContractFunction [ ] = [ ] ;
128
118
public readonly customErrors : CustomError [ ] = [ ] ;
129
119
130
120
private _constructor : ContractFunction | undefined ;
131
121
private _fallback : ContractFunction | undefined ;
132
122
private _receive : ContractFunction | undefined ;
123
+ private readonly _localFunctions : ContractFunction [ ] = [ ] ;
133
124
private readonly _selectorHexToFunction : Map < string , ContractFunction > =
134
125
new Map ( ) ;
135
126
@@ -174,7 +165,7 @@ export class Contract {
174
165
}
175
166
}
176
167
177
- this . localFunctions . push ( func ) ;
168
+ this . _localFunctions . push ( func ) ;
178
169
}
179
170
180
171
public addCustomError ( customError : CustomError ) {
@@ -189,7 +180,7 @@ export class Contract {
189
180
this . _receive = baseContract . _receive ;
190
181
}
191
182
192
- for ( const baseContractFunction of baseContract . localFunctions ) {
183
+ for ( const baseContractFunction of baseContract . _localFunctions ) {
193
184
if (
194
185
baseContractFunction . type !== ContractFunctionType . GETTER &&
195
186
baseContractFunction . type !== ContractFunctionType . FUNCTION
@@ -305,52 +296,10 @@ export class Instruction {
305
296
public readonly pc : number ,
306
297
public readonly opcode : Opcode ,
307
298
public readonly jumpType : JumpType ,
299
+ // Used only for debugging
308
300
public readonly pushData ?: Buffer ,
309
301
public readonly location ?: SourceLocation
310
302
) { }
311
-
312
- /**
313
- * Checks equality with another Instruction.
314
- */
315
- public equals ( other : Instruction ) : boolean {
316
- if ( this . pc !== other . pc ) {
317
- return false ;
318
- }
319
-
320
- if ( this . opcode !== other . opcode ) {
321
- return false ;
322
- }
323
-
324
- if ( this . jumpType !== other . jumpType ) {
325
- return false ;
326
- }
327
-
328
- if ( this . pushData !== undefined ) {
329
- if ( other . pushData === undefined ) {
330
- return false ;
331
- }
332
-
333
- if ( ! this . pushData . equals ( other . pushData ) ) {
334
- return false ;
335
- }
336
- } else if ( other . pushData !== undefined ) {
337
- return false ;
338
- }
339
-
340
- if ( this . location !== undefined ) {
341
- if ( other . location === undefined ) {
342
- return false ;
343
- }
344
-
345
- if ( ! this . location . equals ( other . location ) ) {
346
- return false ;
347
- }
348
- } else if ( other . location !== undefined ) {
349
- return false ;
350
- }
351
-
352
- return true ;
353
- }
354
303
}
355
304
356
305
interface ImmutableReference {
@@ -365,7 +314,7 @@ export class Bytecode {
365
314
public readonly contract : Contract ,
366
315
public readonly isDeployment : boolean ,
367
316
public readonly normalizedCode : Buffer ,
368
- public readonly instructions : Instruction [ ] ,
317
+ instructions : Instruction [ ] ,
369
318
public readonly libraryAddressPositions : number [ ] ,
370
319
public readonly immutableReferences : ImmutableReference [ ] ,
371
320
public readonly compilerVersion : string
@@ -388,22 +337,4 @@ export class Bytecode {
388
337
public hasInstruction ( pc : number ) : boolean {
389
338
return this . _pcToInstruction . has ( pc ) ;
390
339
}
391
-
392
- /**
393
- * Checks equality with another Bytecode.
394
- */
395
- public equals ( other : Bytecode ) : boolean {
396
- if ( this . _pcToInstruction . size !== other . _pcToInstruction . size ) {
397
- return false ;
398
- }
399
-
400
- for ( const [ key , val ] of this . _pcToInstruction ) {
401
- const otherVal = other . _pcToInstruction . get ( key ) ;
402
- if ( otherVal === undefined || ! val . equals ( otherVal ) ) {
403
- return false ;
404
- }
405
- }
406
-
407
- return true ;
408
- }
409
340
}
0 commit comments