@@ -307,7 +307,7 @@ func (cache *includeCache) WriteToFile() error {
307
307
return nil
308
308
}
309
309
310
- func (f * CppIncludesFinder ) findIncludesUntilDone (sourceFile SourceFile ) error {
310
+ func (f * CppIncludesFinder ) findIncludesUntilDone (sourceFile * SourceFile ) error {
311
311
sourcePath := sourceFile .SourcePath ()
312
312
targetFilePath := paths .NullPath ()
313
313
depPath := sourceFile .DepfilePath ()
@@ -440,23 +440,23 @@ type SourceFile struct {
440
440
RelativePath * paths.Path
441
441
}
442
442
443
- func (f SourceFile ) String () string {
443
+ func (f * SourceFile ) String () string {
444
444
return fmt .Sprintf ("Root: %s - Path: %s - BuildPath: %s" ,
445
445
f .SourceRoot , f .RelativePath , f .BuildRoot )
446
446
}
447
447
448
448
// MakeSourceFile creates a SourceFile containing the given source file path
449
449
// within the given sourceRoot. If srcPath is absolute it is transformed to
450
450
// relative to sourceRoot.
451
- func MakeSourceFile (sourceRoot , buildRoot , srcPath * paths.Path ) (SourceFile , error ) {
451
+ func MakeSourceFile (sourceRoot , buildRoot , srcPath * paths.Path ) (* SourceFile , error ) {
452
452
if srcPath .IsAbs () {
453
453
if relPath , err := sourceRoot .RelTo (srcPath ); err == nil {
454
454
srcPath = relPath
455
455
} else {
456
- return SourceFile {} , err
456
+ return nil , err
457
457
}
458
458
}
459
- return SourceFile {SourceRoot : sourceRoot , BuildRoot : buildRoot , RelativePath : srcPath }, nil
459
+ return & SourceFile {SourceRoot : sourceRoot , BuildRoot : buildRoot , RelativePath : srcPath }, nil
460
460
}
461
461
462
462
// SourcePath returns the path to the source file
@@ -474,22 +474,30 @@ func (f *SourceFile) DepfilePath() *paths.Path {
474
474
return f .BuildRoot .Join (f .RelativePath .String () + ".d" )
475
475
}
476
476
477
+ // Equals return true if the SourceFile equals to the SourceFile
478
+ // passed as parameter
479
+ func (f * SourceFile ) Equals (other * SourceFile ) bool {
480
+ return f .BuildRoot .EqualsTo (other .BuildRoot ) &&
481
+ f .SourceRoot .EqualsTo (other .SourceRoot ) &&
482
+ f .RelativePath .EqualsTo (other .RelativePath )
483
+ }
484
+
477
485
type UniqueSourceFileQueue struct {
478
- queue []SourceFile
486
+ queue []* SourceFile
479
487
curr int
480
488
}
481
489
482
490
func (q * UniqueSourceFileQueue ) Len () int {
483
491
return len (q .queue ) - q .curr
484
492
}
485
493
486
- func (q * UniqueSourceFileQueue ) Push (value SourceFile ) {
494
+ func (q * UniqueSourceFileQueue ) Push (value * SourceFile ) {
487
495
if ! q .Contains (value ) {
488
496
q .queue = append (q .queue , value )
489
497
}
490
498
}
491
499
492
- func (q * UniqueSourceFileQueue ) Pop () SourceFile {
500
+ func (q * UniqueSourceFileQueue ) Pop () * SourceFile {
493
501
res := q .queue [q .curr ]
494
502
q .curr ++
495
503
return res
@@ -499,11 +507,9 @@ func (q *UniqueSourceFileQueue) Empty() bool {
499
507
return q .Len () == 0
500
508
}
501
509
502
- func (q * UniqueSourceFileQueue ) Contains (target SourceFile ) bool {
510
+ func (q * UniqueSourceFileQueue ) Contains (target * SourceFile ) bool {
503
511
for _ , elem := range q .queue {
504
- if elem .BuildRoot .EqualsTo (target .BuildRoot ) &&
505
- elem .SourceRoot .EqualsTo (target .SourceRoot ) &&
506
- elem .RelativePath .EqualsTo (target .RelativePath ) {
512
+ if elem .Equals (target ) {
507
513
return true
508
514
}
509
515
}
0 commit comments