55 "github.com/spf13/cobra"
66 "github.com/strict-lang/sdk/pkg/compiler"
77 "github.com/strict-lang/sdk/pkg/compiler/backend"
8+ "github.com/strict-lang/sdk/pkg/compiler/input/linemap"
89 "github.com/strict-lang/sdk/pkg/compiler/report"
910 "io/ioutil"
1011 "log"
@@ -40,18 +41,18 @@ func disableLogging() {
4041 }
4142}
4243
43- var reportFormats = map [string ] func (report.Report ) report.Output {
44+ var reportFormats = map [string ] func (report.Report , * linemap. LineMap ) report.Output {
4445 "text" : report .NewRenderingOutput ,
45- "json" : func (input report.Report ) report.Output {
46+ "json" : func (input report.Report , lineMap * linemap. LineMap ) report.Output {
4647 return report .NewSerializingOutput (report .NewJsonSerializationFormat (), input )
4748 },
48- "pretty-json" : func (input report.Report ) report.Output {
49+ "pretty-json" : func (input report.Report , lineMap * linemap. LineMap ) report.Output {
4950 return report .NewSerializingOutput (report .NewPrettyJsonSerializationFormat (), input )
5051 },
51- "xml" : func (input report.Report ) report.Output {
52+ "xml" : func (input report.Report , lineMap * linemap. LineMap ) report.Output {
5253 return report .NewSerializingOutput (report .NewXmlSerializationFormat (), input )
5354 },
54- "pretty-xml" : func (input report.Report ) report.Output {
55+ "pretty-xml" : func (input report.Report , lineMap * linemap. LineMap ) report.Output {
5556 return report .NewSerializingOutput (report .NewPrettyXmlSerializationFormat (), input )
5657 },
5758}
@@ -69,47 +70,56 @@ func createFailedReport(beginTime time.Time) report.Report {
6970
7071func RunCompile (command * cobra.Command , arguments []string ) error {
7172 disableLogging ()
72- compilationReport := compile (command , arguments )
73- output := createOutput (compilationReport )
73+ compilationReport , lineMap := compile (command , arguments )
74+ output := createOutput (compilationReport , lineMap )
7475 return output .Print (command .OutOrStdout ())
7576}
7677
77- func createOutput (compilationReport report.Report ) report.Output {
78+ func createOutput (
79+ compilationReport report.Report ,
80+ lineMap * linemap.LineMap ) report.Output {
81+
7882 if output , ok := reportFormats [buildOptions .reportFormat ]; ok {
79- return output (compilationReport )
83+ return output (compilationReport , lineMap )
8084 }
81- return report .NewRenderingOutput (compilationReport )
85+ return report .NewRenderingOutput (compilationReport , lineMap )
8286}
8387
84- func compile (command * cobra.Command , arguments []string ) report.Report {
88+ func compile (
89+ command * cobra.Command , arguments []string ) (report.Report , * linemap.LineMap ) {
90+
8591 beginTime := time .Now ()
8692 file , ok := findSourceFileInArguments (command , arguments )
8793 if ! ok {
88- return createFailedReport (beginTime )
94+ return createFailedReport (beginTime ), linemap . Empty ()
8995 }
9096 defer file .Close ()
9197 name , err := ParseUnitName (file .Name ())
9298 if err != nil {
9399 command .Printf ("Invalid filename: %s\n " , file .Name ())
94- return createFailedReport (beginTime )
100+ return createFailedReport (beginTime ), linemap . Empty ()
95101 }
96102 return runCompilation (command , name , file )
97103}
98104
99- func runCompilation (command * cobra.Command , unitName string , file * os.File ) report.Report {
105+ func runCompilation (
106+ command * cobra.Command ,
107+ unitName string ,
108+ file * os.File ) (report.Report , * linemap.LineMap ) {
109+
100110 compilation := & compiler.Compilation {
101111 Name : unitName ,
102112 Source : & compiler.FileSource {File : file },
103113 }
104114 result := compilation .Compile ()
105115 if result .Error != nil {
106- return result .Report
116+ return result .Report , result . LineMap
107117 }
108118 if err := writeGeneratedSources (result ); err != nil {
109119 command .PrintErrf ("failed to write generated sources %v\n " , err )
110120 result .Report .Success = false
111121 }
112- return result .Report
122+ return result .Report , result . LineMap
113123}
114124
115125func writeGeneratedSources (compilation compiler.Result ) (err error ) {
0 commit comments