@@ -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
4041type PrototypesAdder struct {}
4142
4243func (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