@@ -22,31 +22,21 @@ import (
22
22
23
23
"github.com/arduino/arduino-cli/legacy/builder/constants"
24
24
"github.com/arduino/arduino-cli/legacy/builder/ctags"
25
- "github.com/arduino/arduino-cli/legacy/builder/types"
26
25
"github.com/arduino/arduino-cli/legacy/builder/utils"
27
26
)
28
27
29
- type PrototypesAdder struct {}
30
-
31
- func (s * PrototypesAdder ) Run (ctx * types.Context ) error {
32
- debugOutput := ctx .DebugPreprocessor
33
-
34
- source := ctx .SketchSourceMerged
28
+ func PrototypesAdder (source string , firstFunctionLine , lineOffset int , prototypes []* ctags.Prototype , debugOutput bool ) (preprocessedSource , prototypeSection string ) {
35
29
source = strings .Replace (source , "\r \n " , "\n " , - 1 )
36
30
source = strings .Replace (source , "\r " , "\n " , - 1 )
37
-
38
31
sourceRows := strings .Split (source , "\n " )
39
-
40
- firstFunctionLine := ctx .PrototypesLineWhereToInsert
41
32
if isFirstFunctionOutsideOfSource (firstFunctionLine , sourceRows ) {
42
- return nil
33
+ return
43
34
}
44
35
45
- insertionLine := firstFunctionLine + ctx . LineOffset - 1
36
+ insertionLine := firstFunctionLine + lineOffset - 1
46
37
firstFunctionChar := len (strings .Join (sourceRows [:insertionLine ], "\n " )) + 1
47
- prototypeSection := composePrototypeSection (firstFunctionLine , ctx .Prototypes )
48
- ctx .PrototypesSection = prototypeSection
49
- source = source [:firstFunctionChar ] + prototypeSection + source [firstFunctionChar :]
38
+ prototypeSection = composePrototypeSection (firstFunctionLine , prototypes )
39
+ preprocessedSource = source [:firstFunctionChar ] + prototypeSection + source [firstFunctionChar :]
50
40
51
41
if debugOutput {
52
42
fmt .Println ("#PREPROCESSED SOURCE" )
@@ -63,9 +53,7 @@ func (s *PrototypesAdder) Run(ctx *types.Context) error {
63
53
}
64
54
fmt .Println ("#END OF PREPROCESSED SOURCE" )
65
55
}
66
- ctx .SketchSourceAfterArduinoPreprocessing = source
67
-
68
- return nil
56
+ return
69
57
}
70
58
71
59
func composePrototypeSection (line int , prototypes []* ctags.Prototype ) string {
0 commit comments