@@ -71,8 +71,7 @@ reverse(ASTNode::ref list)
7171ASTNode::ASTNode (NodeType nodetype, OSLCompilerImpl* compiler)
7272 : m_nodetype(nodetype)
7373 , m_compiler(compiler)
74- , m_sourcefile(compiler->filename ())
75- , m_sourceline(compiler->lineno ())
74+ , m_srcloc(compiler->srcloc ())
7675 , m_op(0 )
7776 , m_is_lvalue(false )
7877{
@@ -88,8 +87,7 @@ ASTNode::ASTNode(NodeType nodetype, OSLCompilerImpl* compiler, int op,
8887 ASTNode* a)
8988 : m_nodetype(nodetype)
9089 , m_compiler(compiler)
91- , m_sourcefile(compiler->filename ())
92- , m_sourceline(compiler->lineno ())
90+ , m_srcloc(compiler->srcloc ())
9391 , m_op(op)
9492 , m_is_lvalue(false )
9593{
@@ -105,8 +103,7 @@ ASTNode::ASTNode(NodeType nodetype, OSLCompilerImpl* compiler, int op,
105103ASTNode::ASTNode (NodeType nodetype, OSLCompilerImpl* compiler, int op)
106104 : m_nodetype(nodetype)
107105 , m_compiler(compiler)
108- , m_sourcefile(compiler->filename ())
109- , m_sourceline(compiler->lineno ())
106+ , m_srcloc(compiler->srcloc ())
110107 , m_op(op)
111108 , m_is_lvalue(false )
112109{
@@ -122,8 +119,7 @@ ASTNode::ASTNode(NodeType nodetype, OSLCompilerImpl* compiler, int op,
122119 ASTNode* a, ASTNode* b)
123120 : m_nodetype(nodetype)
124121 , m_compiler(compiler)
125- , m_sourcefile(compiler->filename ())
126- , m_sourceline(compiler->lineno ())
122+ , m_srcloc(compiler->srcloc ())
127123 , m_op(op)
128124 , m_is_lvalue(false )
129125{
@@ -141,8 +137,7 @@ ASTNode::ASTNode(NodeType nodetype, OSLCompilerImpl* compiler, int op,
141137 ASTNode* a, ASTNode* b, ASTNode* c)
142138 : m_nodetype(nodetype)
143139 , m_compiler(compiler)
144- , m_sourcefile(compiler->filename ())
145- , m_sourceline(compiler->lineno ())
140+ , m_srcloc(compiler->srcloc ())
146141 , m_op(op)
147142 , m_is_lvalue(false )
148143{
@@ -161,8 +156,7 @@ ASTNode::ASTNode(NodeType nodetype, OSLCompilerImpl* compiler, int op,
161156 ASTNode* a, ASTNode* b, ASTNode* c, ASTNode* d)
162157 : m_nodetype(nodetype)
163158 , m_compiler(compiler)
164- , m_sourcefile(compiler->filename ())
165- , m_sourceline(compiler->lineno ())
159+ , m_srcloc(compiler->srcloc ())
166160 , m_op(op)
167161 , m_is_lvalue(false )
168162{
@@ -213,31 +207,31 @@ ASTNode::~ASTNode()
213207void
214208ASTNode::error_impl (string_view msg) const
215209{
216- m_compiler->errorfmt (sourcefile (), sourceline (), " {}" , msg);
210+ m_compiler->errorfmt (sourceloc (), " {}" , msg);
217211}
218212
219213
220214
221215void
222216ASTNode::warning_impl (string_view msg) const
223217{
224- m_compiler->warningfmt (sourcefile (), sourceline (), " {}" , msg);
218+ m_compiler->warningfmt (sourceloc (), " {}" , msg);
225219}
226220
227221
228222
229223void
230224ASTNode::info_impl (string_view msg) const
231225{
232- m_compiler->infofmt (sourcefile (), sourceline (), " {}" , msg);
226+ m_compiler->infofmt (sourceloc (), " {}" , msg);
233227}
234228
235229
236230
237231void
238232ASTNode::message_impl (string_view msg) const
239233{
240- m_compiler->messagefmt (sourcefile (), sourceline (), " {}" , msg);
234+ m_compiler->messagefmt (sourceloc (), " {}" , msg);
241235}
242236
243237
@@ -366,7 +360,7 @@ ASTfunction_declaration::ASTfunction_declaration(OSLCompilerImpl* comp,
366360 TypeSpec type, ustring name,
367361 ASTNode* form, ASTNode* stmts,
368362 ASTNode* meta,
369- int sourceline_start )
363+ const SrcLoc& srcloc_start )
370364 : ASTNode(function_declaration_node, comp, 0 , meta, form, stmts)
371365 , m_name(name)
372366 , m_sym(NULL )
@@ -375,8 +369,12 @@ ASTfunction_declaration::ASTfunction_declaration(OSLCompilerImpl* comp,
375369 // Some trickery -- the compiler's idea of the "current" source line
376370 // is the END of the function body, so if a hint was passed about the
377371 // start of the declaration, substitute that.
378- if (sourceline_start >= 0 )
379- m_sourceline = sourceline_start;
372+ // FIXME: [lfascione] Maybe with the move from int sourceline to SrcLoc this
373+ // is the right thing to do here
374+ if (srcloc_start) {
375+ m_srcloc.line_start = srcloc_start.line_start ;
376+ m_srcloc.column_begin = srcloc_start.column_begin ;
377+ }
380378
381379 if (Strutil::starts_with (name, " ___" ))
382380 errorfmt (" \" {}\" : sorry, can't start with three underscores" , name);
@@ -386,7 +384,9 @@ ASTfunction_declaration::ASTfunction_declaration(OSLCompilerImpl* comp,
386384 if (existing_syms && existing_syms->symtype () != SymTypeFunction) {
387385 errorfmt (" \" {}\" already declared in this scope as a {}" , name,
388386 existing_syms->typespec ());
389- // FIXME -- print the file and line of the other definition
387+ // print the file and line of the other definition when available
388+ if (existing_syms->node ())
389+ comp->message_srcloc (existing_syms->node ()->sourceloc ());
390390 existing_syms = NULL ;
391391 }
392392
@@ -429,13 +429,9 @@ ASTfunction_declaration::ASTfunction_declaration(OSLCompilerImpl* comp,
429429 }
430430 err += " \n " ;
431431 if (other) {
432- err += Strutil::fmt::format (
433- " {}:{}" ,
434- OIIO::Filesystem::filename (
435- other->sourcefile ().string ()),
436- other->sourceline ());
432+ err += Strutil::fmt::format (" {}" , other->sourceloc ());
437433 } else
438- err += " built-in" ;
434+ err += " ( built-in) " ;
439435 }
440436 }
441437 }
@@ -519,7 +515,7 @@ ASTvariable_declaration::ASTvariable_declaration(OSLCompilerImpl* comp,
519515 ustring name, ASTNode* init,
520516 bool isparam, bool ismeta,
521517 bool isoutput, bool initlist,
522- int sourceline_start )
518+ const SrcLoc& srcloc_start )
523519 : ASTNode(variable_declaration_node, comp, 0 , init, NULL /* meta */ )
524520 , m_name(name)
525521 , m_sym(NULL )
@@ -531,8 +527,10 @@ ASTvariable_declaration::ASTvariable_declaration(OSLCompilerImpl* comp,
531527 // Some trickery -- the compiler's idea of the "current" source line
532528 // is the END of the declaration, so if a hint was passed about the
533529 // start of the declaration, substitute that.
534- if (sourceline_start >= 0 )
535- m_sourceline = sourceline_start;
530+ if (srcloc_start) {
531+ m_srcloc.line_start = srcloc_start.line_start ;
532+ m_srcloc.column_begin = srcloc_start.column_begin ;
533+ }
536534
537535 if (m_initlist && init) {
538536 // Typecheck the init list early.
@@ -547,10 +545,8 @@ ASTvariable_declaration::ASTvariable_declaration(OSLCompilerImpl* comp,
547545 = Strutil::fmt::format (" \" {}\" already declared in this scope" ,
548546 name);
549547 if (f->node ()) {
550- std::string filename = OIIO::Filesystem::filename (
551- f->node ()->sourcefile ().string ());
552- e += Strutil::fmt::format (" \n\t\t previous declaration was at {}:{}" ,
553- filename, f->node ()->sourceline ());
548+ e += Strutil::fmt::format (" \n\t\t previous declaration was at {}" ,
549+ f->node ()->sourceloc ());
554550 }
555551 if (f->scope () == 0 && f->symtype () == SymTypeFunction && isparam) {
556552 // special case: only a warning for param to mask global function
0 commit comments