Skip to content

Commit 3bf163d

Browse files
alessio-peruginicmaglie
authored andcommitted
add comments and make some plubic methods private
1 parent 7b5a030 commit 3bf163d

File tree

3 files changed

+64
-63
lines changed

3 files changed

+64
-63
lines changed

Diff for: arduino/builder/cpp/cpp.go

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ func ParseString(line string) (string, string, bool) {
107107
}
108108
}
109109

110+
// WrapWithHyphenI fixdoc
110111
func WrapWithHyphenI(value string) string {
111112
return "\"-I" + value + "\""
112113
}

Diff for: arduino/builder/detector/detector.go

+52-51
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,6 @@ func (l *SketchLibrariesDetector) AppendImportedLibraries(library *libraries.Lib
146146
l.importedLibraries = append(l.importedLibraries, library)
147147
}
148148

149-
// UseCachedLibrariesResolution todo
150-
func (l *SketchLibrariesDetector) UseCachedLibrariesResolution() bool {
151-
return l.useCachedLibrariesResolution
152-
}
153-
154149
// PrintUsedAndNotUsedLibraries todo
155150
func (l *SketchLibrariesDetector) PrintUsedAndNotUsedLibraries(sketchError bool) {
156151
// Print this message:
@@ -182,20 +177,21 @@ func (l *SketchLibrariesDetector) PrintUsedAndNotUsedLibraries(sketchError bool)
182177
time.Sleep(100 * time.Millisecond)
183178
}
184179

180+
// IncludeFolders fixdoc
185181
func (l *SketchLibrariesDetector) IncludeFolders() paths.PathList {
186182
// TODO should we do a deep copy?
187183
return l.includeFolders
188184
}
189185

190-
// AppendIncludeFolder todo should rename this, probably after refactoring the
186+
// appendIncludeFolder todo should rename this, probably after refactoring the
191187
// container_find_includes command.
192188
// Original comment:
193189
// Append the given folder to the include path and match or append it to
194190
// the cache. sourceFilePath and include indicate the source of this
195191
// include (e.g. what #include line in what file it was resolved from)
196192
// and should be the empty string for the default include folders, like
197193
// the core or variant.
198-
func (l *SketchLibrariesDetector) AppendIncludeFolder(
194+
func (l *SketchLibrariesDetector) appendIncludeFolder(
199195
cache *includeCache,
200196
sourceFilePath *paths.Path,
201197
include string,
@@ -242,13 +238,13 @@ func (l *SketchLibrariesDetector) findIncludes(
242238
) error {
243239
librariesResolutionCache := buildPath.Join("libraries.cache")
244240
if l.useCachedLibrariesResolution && librariesResolutionCache.Exist() {
245-
if d, err := librariesResolutionCache.ReadFile(); err != nil {
241+
d, err := librariesResolutionCache.ReadFile()
242+
if err != nil {
243+
return err
244+
}
245+
includeFolders := l.includeFolders
246+
if err := json.Unmarshal(d, &includeFolders); err != nil {
246247
return err
247-
} else {
248-
includeFolders := l.includeFolders
249-
if err := json.Unmarshal(d, &includeFolders); err != nil {
250-
return err
251-
}
252248
}
253249
if l.verbose {
254250
l.verboseInfoFn("Using cached library discovery: " + librariesResolutionCache.String())
@@ -259,28 +255,28 @@ func (l *SketchLibrariesDetector) findIncludes(
259255
cachePath := buildPath.Join("includes.cache")
260256
cache := readCache(cachePath)
261257

262-
l.AppendIncludeFolder(cache, nil, "", buildCorePath)
258+
l.appendIncludeFolder(cache, nil, "", buildCorePath)
263259
if buildVariantPath != nil {
264-
l.AppendIncludeFolder(cache, nil, "", buildVariantPath)
260+
l.appendIncludeFolder(cache, nil, "", buildVariantPath)
265261
}
266262

267-
sourceFileQueue := &UniqueSourceFileQueue{}
263+
sourceFileQueue := &uniqueSourceFileQueue{}
268264

269265
if !l.useCachedLibrariesResolution {
270266
sketch := sketch
271-
mergedfile, err := MakeSourceFile(sketchBuildPath, librariesBuildPath, sketch, paths.New(sketch.MainFile.Base()+".cpp"))
267+
mergedfile, err := makeSourceFile(sketchBuildPath, librariesBuildPath, sketch, paths.New(sketch.MainFile.Base()+".cpp"))
272268
if err != nil {
273269
return errors.WithStack(err)
274270
}
275-
sourceFileQueue.Push(mergedfile)
271+
sourceFileQueue.push(mergedfile)
276272

277273
l.queueSourceFilesFromFolder(sketchBuildPath, librariesBuildPath, sourceFileQueue, sketch, sketchBuildPath, false /* recurse */)
278274
srcSubfolderPath := sketchBuildPath.Join("src")
279275
if srcSubfolderPath.IsDir() {
280276
l.queueSourceFilesFromFolder(sketchBuildPath, librariesBuildPath, sourceFileQueue, sketch, srcSubfolderPath, true /* recurse */)
281277
}
282278

283-
for !sourceFileQueue.Empty() {
279+
for !sourceFileQueue.empty() {
284280
err := l.findIncludesUntilDone(cache, sourceFileQueue, buildProperties, sketchBuildPath, librariesBuildPath, platformArch)
285281
if err != nil {
286282
cachePath.Remove()
@@ -310,13 +306,13 @@ func (l *SketchLibrariesDetector) findIncludes(
310306

311307
func (l *SketchLibrariesDetector) findIncludesUntilDone(
312308
cache *includeCache,
313-
sourceFileQueue *UniqueSourceFileQueue,
309+
sourceFileQueue *uniqueSourceFileQueue,
314310
buildProperties *properties.Map,
315311
sketchBuildPath *paths.Path,
316312
librariesBuildPath *paths.Path,
317313
platformArch string,
318314
) error {
319-
sourceFile := sourceFileQueue.Pop()
315+
sourceFile := sourceFileQueue.pop()
320316
sourcePath := sourceFile.SourcePath()
321317
targetFilePath := paths.NullPath()
322318
depPath := sourceFile.DepfilePath()
@@ -414,7 +410,7 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
414410
// include path and queue its source files for further
415411
// include scanning
416412
l.AppendImportedLibraries(library)
417-
l.AppendIncludeFolder(cache, sourcePath, missingIncludeH, library.SourceDir)
413+
l.appendIncludeFolder(cache, sourcePath, missingIncludeH, library.SourceDir)
418414

419415
if library.Precompiled && library.PrecompiledWithSources {
420416
// Fully precompiled libraries should have no dependencies to avoid ABI breakage
@@ -433,7 +429,7 @@ func (l *SketchLibrariesDetector) findIncludesUntilDone(
433429
func (l *SketchLibrariesDetector) queueSourceFilesFromFolder(
434430
sketchBuildPath *paths.Path,
435431
librariesBuildPath *paths.Path,
436-
sourceFileQueue *UniqueSourceFileQueue,
432+
sourceFileQueue *uniqueSourceFileQueue,
437433
origin interface{},
438434
folder *paths.Path,
439435
recurse bool,
@@ -448,11 +444,11 @@ func (l *SketchLibrariesDetector) queueSourceFilesFromFolder(
448444
}
449445

450446
for _, filePath := range filePaths {
451-
sourceFile, err := MakeSourceFile(sketchBuildPath, librariesBuildPath, origin, filePath)
447+
sourceFile, err := makeSourceFile(sketchBuildPath, librariesBuildPath, origin, filePath)
452448
if err != nil {
453449
return errors.WithStack(err)
454450
}
455-
sourceFileQueue.Push(sourceFile)
451+
sourceFileQueue.push(sourceFile)
456452
}
457453

458454
return nil
@@ -484,10 +480,12 @@ func (l *SketchLibrariesDetector) failIfImportedLibraryIsWrong() error {
484480
return nil
485481
}
486482

487-
var INCLUDE_REGEXP = regexp.MustCompile("(?ms)^\\s*#[ \t]*include\\s*[<\"](\\S+)[\">]")
483+
// includeRegexp fixdoc
484+
var includeRegexp = regexp.MustCompile("(?ms)^\\s*#[ \t]*include\\s*[<\"](\\S+)[\">]")
488485

486+
// IncludesFinderWithRegExp fixdoc
489487
func IncludesFinderWithRegExp(source string) string {
490-
match := INCLUDE_REGEXP.FindStringSubmatch(source)
488+
match := includeRegexp.FindStringSubmatch(source)
491489
if match != nil {
492490
return strings.TrimSpace(match[1])
493491
}
@@ -507,7 +505,7 @@ func findIncludeForOldCompilers(source string) string {
507505
return ""
508506
}
509507

510-
type SourceFile struct {
508+
type sourceFile struct {
511509
// Path to the source file within the sketch/library root folder
512510
relativePath *paths.Path
513511

@@ -528,22 +526,23 @@ type SourceFile struct {
528526
buildRoot *paths.Path
529527
}
530528

531-
func (f *SourceFile) Equals(g *SourceFile) bool {
529+
// Equals fixdoc
530+
func (f *sourceFile) Equals(g *sourceFile) bool {
532531
return f.relativePath.EqualsTo(g.relativePath) &&
533532
f.buildRoot.EqualsTo(g.buildRoot) &&
534533
f.sourceRoot.EqualsTo(g.sourceRoot)
535534
}
536535

537-
// Create a SourceFile containing the given source file path within the
536+
// makeSourceFile containing the given source file path within the
538537
// given origin. The given path can be absolute, or relative within the
539538
// origin's root source folder
540-
func MakeSourceFile(
539+
func makeSourceFile(
541540
sketchBuildPath *paths.Path,
542541
librariesBuildPath *paths.Path,
543542
origin interface{},
544543
path *paths.Path,
545-
) (*SourceFile, error) {
546-
res := &SourceFile{}
544+
) (*sourceFile, error) {
545+
res := &sourceFile{}
547546

548547
switch o := origin.(type) {
549548
case *sketch.Sketch:
@@ -568,19 +567,23 @@ func MakeSourceFile(
568567
return res, nil
569568
}
570569

571-
func (f *SourceFile) ExtraIncludePath() *paths.Path {
570+
// ExtraIncludePath fixdoc
571+
func (f *sourceFile) ExtraIncludePath() *paths.Path {
572572
return f.extraIncludePath
573573
}
574574

575-
func (f *SourceFile) SourcePath() *paths.Path {
575+
// SourcePath fixdoc
576+
func (f *sourceFile) SourcePath() *paths.Path {
576577
return f.sourceRoot.JoinPath(f.relativePath)
577578
}
578579

579-
func (f *SourceFile) ObjectPath() *paths.Path {
580+
// ObjectPath fixdoc
581+
func (f *sourceFile) ObjectPath() *paths.Path {
580582
return f.buildRoot.Join(f.relativePath.String() + ".o")
581583
}
582584

583-
func (f *SourceFile) DepfilePath() *paths.Path {
585+
// DepfilePath fixdoc
586+
func (f *sourceFile) DepfilePath() *paths.Path {
584587
return f.buildRoot.Join(f.relativePath.String() + ".d")
585588
}
586589

@@ -658,21 +661,19 @@ func LibrariesLoader(
658661
return lm, resolver, verboseOut.Bytes(), nil
659662
}
660663

661-
func (l *SketchLibrariesDetector) OnlyUpdateCompilationDatabase() bool {
662-
return l.onlyUpdateCompilationDatabase
663-
}
664-
665664
type includeCacheEntry struct {
666665
Sourcefile *paths.Path
667666
Include string
668667
Includepath *paths.Path
669668
}
670669

670+
// String fixdoc
671671
func (entry *includeCacheEntry) String() string {
672672
return fmt.Sprintf("SourceFile: %s; Include: %s; IncludePath: %s",
673673
entry.Sourcefile, entry.Include, entry.Includepath)
674674
}
675675

676+
// Equals fixdoc
676677
func (entry *includeCacheEntry) Equals(other *includeCacheEntry) bool {
677678
return entry.String() == other.String()
678679
}
@@ -686,14 +687,14 @@ type includeCache struct {
686687
entries []*includeCacheEntry
687688
}
688689

689-
// Return the next cache entry. Should only be called when the cache is
690+
// Next Return the next cache entry. Should only be called when the cache is
690691
// valid and a next entry is available (the latter can be checked with
691692
// ExpectFile). Does not advance the cache.
692693
func (cache *includeCache) Next() *includeCacheEntry {
693694
return cache.entries[cache.next]
694695
}
695696

696-
// Check that the next cache entry is about the given file. If it is
697+
// ExpectFile check that the next cache entry is about the given file. If it is
697698
// not, or no entry is available, the cache is invalidated. Does not
698699
// advance the cache.
699700
func (cache *includeCache) ExpectFile(sourcefile *paths.Path) {
@@ -703,7 +704,7 @@ func (cache *includeCache) ExpectFile(sourcefile *paths.Path) {
703704
}
704705
}
705706

706-
// Check that the next entry matches the given values. If so, advance
707+
// ExpectEntry check that the next entry matches the given values. If so, advance
707708
// the cache. If not, the cache is invalidated. If the cache is
708709
// invalidated, or was already invalid, an entry with the given values
709710
// is appended.
@@ -723,7 +724,7 @@ func (cache *includeCache) ExpectEntry(sourcefile *paths.Path, include string, l
723724
}
724725
}
725726

726-
// Check that the cache is completely consumed. If not, the cache is
727+
// ExpectEnd check that the cache is completely consumed. If not, the cache is
727728
// invalidated.
728729
func (cache *includeCache) ExpectEnd() {
729730
if cache.valid && cache.next < len(cache.entries) {
@@ -771,25 +772,25 @@ func writeCache(cache *includeCache, path *paths.Path) error {
771772
return nil
772773
}
773774

774-
type UniqueSourceFileQueue []*SourceFile
775+
type uniqueSourceFileQueue []*sourceFile
775776

776-
func (queue *UniqueSourceFileQueue) Push(value *SourceFile) {
777-
if !queue.Contains(value) {
777+
func (queue *uniqueSourceFileQueue) push(value *sourceFile) {
778+
if !queue.contains(value) {
778779
*queue = append(*queue, value)
779780
}
780781
}
781782

782-
func (queue UniqueSourceFileQueue) Contains(target *SourceFile) bool {
783+
func (queue uniqueSourceFileQueue) contains(target *sourceFile) bool {
783784
return slices.ContainsFunc(queue, target.Equals)
784785
}
785786

786-
func (queue *UniqueSourceFileQueue) Pop() *SourceFile {
787+
func (queue *uniqueSourceFileQueue) pop() *sourceFile {
787788
old := *queue
788789
x := old[0]
789790
*queue = old[1:]
790791
return x
791792
}
792793

793-
func (queue UniqueSourceFileQueue) Empty() bool {
794+
func (queue uniqueSourceFileQueue) empty() bool {
794795
return len(queue) == 0
795796
}

0 commit comments

Comments
 (0)