Skip to content

Commit 0ccee37

Browse files
committed
Added some debugging facility in prototypes_adder
Signed-off-by: Cristian Maglie <[email protected]>
1 parent b04288f commit 0ccee37

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/arduino.cc/builder/constants/constants.go

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const CTX_CTAGS_OUTPUT = "ctagsOutput"
9292
const CTX_CTAGS_TEMP_FILE_PATH = "ctagsTempFilePath"
9393
const CTX_CUSTOM_BUILD_PROPERTIES = "customBuildProperties"
9494
const CTX_DEBUG_LEVEL = "debugLevel"
95+
const CTX_DEBUG_PREPROCESSOR = "debugPreprocessor"
9596
const CTX_FILE_PATH_TO_READ = "filePathToRead"
9697
const CTX_FOLDERS_WITH_SOURCES_QUEUE = "foldersWithSourcesQueue"
9798
const CTX_FQBN = "fqbn"

src/arduino.cc/builder/prototypes_adder.go

+17
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ import (
3333
"arduino.cc/builder/constants"
3434
"arduino.cc/builder/types"
3535
"arduino.cc/builder/utils"
36+
"fmt"
3637
"strconv"
3738
"strings"
3839
)
3940

4041
type PrototypesAdder struct{}
4142

4243
func (s *PrototypesAdder) Run(context map[string]interface{}) error {
44+
debugOutput := context[constants.CTX_DEBUG_PREPROCESSOR] != nil
4345
source := context[constants.CTX_SOURCE].(string)
4446
sourceRows := strings.Split(source, "\n")
4547

@@ -58,6 +60,21 @@ func (s *PrototypesAdder) Run(context map[string]interface{}) error {
5860
context[constants.CTX_PROTOTYPE_SECTION] = prototypeSection
5961
source = source[:firstFunctionChar] + prototypeSection + source[firstFunctionChar:]
6062

63+
if debugOutput {
64+
fmt.Println("#PREPROCESSED SOURCE")
65+
prototypesRows := strings.Split(prototypeSection, "\n")
66+
prototypesRows = prototypesRows[:len(prototypesRows)-1]
67+
for i := 0; i < len(sourceRows)+len(prototypesRows); i++ {
68+
if i < insertionLine {
69+
fmt.Printf(" |%s\n", sourceRows[i])
70+
} else if i < insertionLine+len(prototypesRows) {
71+
fmt.Printf("PRO|%s\n", prototypesRows[i-insertionLine])
72+
} else {
73+
fmt.Printf(" |%s\n", sourceRows[i-len(prototypesRows)])
74+
}
75+
}
76+
fmt.Println("#END OF PREPROCESSED SOURCE")
77+
}
6178
context[constants.CTX_SOURCE] = source
6279

6380
return nil

0 commit comments

Comments
 (0)