@@ -71,8 +71,7 @@ reverse(ASTNode::ref list)
71
71
ASTNode::ASTNode (NodeType nodetype, OSLCompilerImpl* compiler)
72
72
: m_nodetype(nodetype)
73
73
, m_compiler(compiler)
74
- , m_sourcefile(compiler->filename ())
75
- , m_sourceline(compiler->lineno ())
74
+ , m_srcloc(compiler->srcloc ())
76
75
, m_op(0 )
77
76
, m_is_lvalue(false )
78
77
{
@@ -88,8 +87,7 @@ ASTNode::ASTNode(NodeType nodetype, OSLCompilerImpl* compiler, int op,
88
87
ASTNode* a)
89
88
: m_nodetype(nodetype)
90
89
, m_compiler(compiler)
91
- , m_sourcefile(compiler->filename ())
92
- , m_sourceline(compiler->lineno ())
90
+ , m_srcloc(compiler->srcloc ())
93
91
, m_op(op)
94
92
, m_is_lvalue(false )
95
93
{
@@ -105,8 +103,7 @@ ASTNode::ASTNode(NodeType nodetype, OSLCompilerImpl* compiler, int op,
105
103
ASTNode::ASTNode (NodeType nodetype, OSLCompilerImpl* compiler, int op)
106
104
: m_nodetype(nodetype)
107
105
, m_compiler(compiler)
108
- , m_sourcefile(compiler->filename ())
109
- , m_sourceline(compiler->lineno ())
106
+ , m_srcloc(compiler->srcloc ())
110
107
, m_op(op)
111
108
, m_is_lvalue(false )
112
109
{
@@ -122,8 +119,7 @@ ASTNode::ASTNode(NodeType nodetype, OSLCompilerImpl* compiler, int op,
122
119
ASTNode* a, ASTNode* b)
123
120
: m_nodetype(nodetype)
124
121
, m_compiler(compiler)
125
- , m_sourcefile(compiler->filename ())
126
- , m_sourceline(compiler->lineno ())
122
+ , m_srcloc(compiler->srcloc ())
127
123
, m_op(op)
128
124
, m_is_lvalue(false )
129
125
{
@@ -141,8 +137,7 @@ ASTNode::ASTNode(NodeType nodetype, OSLCompilerImpl* compiler, int op,
141
137
ASTNode* a, ASTNode* b, ASTNode* c)
142
138
: m_nodetype(nodetype)
143
139
, m_compiler(compiler)
144
- , m_sourcefile(compiler->filename ())
145
- , m_sourceline(compiler->lineno ())
140
+ , m_srcloc(compiler->srcloc ())
146
141
, m_op(op)
147
142
, m_is_lvalue(false )
148
143
{
@@ -161,8 +156,7 @@ ASTNode::ASTNode(NodeType nodetype, OSLCompilerImpl* compiler, int op,
161
156
ASTNode* a, ASTNode* b, ASTNode* c, ASTNode* d)
162
157
: m_nodetype(nodetype)
163
158
, m_compiler(compiler)
164
- , m_sourcefile(compiler->filename ())
165
- , m_sourceline(compiler->lineno ())
159
+ , m_srcloc(compiler->srcloc ())
166
160
, m_op(op)
167
161
, m_is_lvalue(false )
168
162
{
@@ -213,31 +207,31 @@ ASTNode::~ASTNode()
213
207
void
214
208
ASTNode::error_impl (string_view msg) const
215
209
{
216
- m_compiler->errorfmt (sourcefile (), sourceline (), " {}" , msg);
210
+ m_compiler->errorfmt (sourceloc (), " {}" , msg);
217
211
}
218
212
219
213
220
214
221
215
void
222
216
ASTNode::warning_impl (string_view msg) const
223
217
{
224
- m_compiler->warningfmt (sourcefile (), sourceline (), " {}" , msg);
218
+ m_compiler->warningfmt (sourceloc (), " {}" , msg);
225
219
}
226
220
227
221
228
222
229
223
void
230
224
ASTNode::info_impl (string_view msg) const
231
225
{
232
- m_compiler->infofmt (sourcefile (), sourceline (), " {}" , msg);
226
+ m_compiler->infofmt (sourceloc (), " {}" , msg);
233
227
}
234
228
235
229
236
230
237
231
void
238
232
ASTNode::message_impl (string_view msg) const
239
233
{
240
- m_compiler->messagefmt (sourcefile (), sourceline (), " {}" , msg);
234
+ m_compiler->messagefmt (sourceloc (), " {}" , msg);
241
235
}
242
236
243
237
@@ -366,7 +360,7 @@ ASTfunction_declaration::ASTfunction_declaration(OSLCompilerImpl* comp,
366
360
TypeSpec type, ustring name,
367
361
ASTNode* form, ASTNode* stmts,
368
362
ASTNode* meta,
369
- int sourceline_start )
363
+ const SrcLoc& srcloc_start )
370
364
: ASTNode(function_declaration_node, comp, 0 , meta, form, stmts)
371
365
, m_name(name)
372
366
, m_sym(NULL )
@@ -375,8 +369,12 @@ ASTfunction_declaration::ASTfunction_declaration(OSLCompilerImpl* comp,
375
369
// Some trickery -- the compiler's idea of the "current" source line
376
370
// is the END of the function body, so if a hint was passed about the
377
371
// 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
+ }
380
378
381
379
if (Strutil::starts_with (name, " ___" ))
382
380
errorfmt (" \" {}\" : sorry, can't start with three underscores" , name);
@@ -386,7 +384,9 @@ ASTfunction_declaration::ASTfunction_declaration(OSLCompilerImpl* comp,
386
384
if (existing_syms && existing_syms->symtype () != SymTypeFunction) {
387
385
errorfmt (" \" {}\" already declared in this scope as a {}" , name,
388
386
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 ());
390
390
existing_syms = NULL ;
391
391
}
392
392
@@ -429,13 +429,9 @@ ASTfunction_declaration::ASTfunction_declaration(OSLCompilerImpl* comp,
429
429
}
430
430
err += " \n " ;
431
431
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 ());
437
433
} else
438
- err += " built-in" ;
434
+ err += " ( built-in) " ;
439
435
}
440
436
}
441
437
}
@@ -519,7 +515,7 @@ ASTvariable_declaration::ASTvariable_declaration(OSLCompilerImpl* comp,
519
515
ustring name, ASTNode* init,
520
516
bool isparam, bool ismeta,
521
517
bool isoutput, bool initlist,
522
- int sourceline_start )
518
+ const SrcLoc& srcloc_start )
523
519
: ASTNode(variable_declaration_node, comp, 0 , init, NULL /* meta */ )
524
520
, m_name(name)
525
521
, m_sym(NULL )
@@ -531,8 +527,10 @@ ASTvariable_declaration::ASTvariable_declaration(OSLCompilerImpl* comp,
531
527
// Some trickery -- the compiler's idea of the "current" source line
532
528
// is the END of the declaration, so if a hint was passed about the
533
529
// 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
+ }
536
534
537
535
if (m_initlist && init) {
538
536
// Typecheck the init list early.
@@ -547,10 +545,8 @@ ASTvariable_declaration::ASTvariable_declaration(OSLCompilerImpl* comp,
547
545
= Strutil::fmt::format (" \" {}\" already declared in this scope" ,
548
546
name);
549
547
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 ());
554
550
}
555
551
if (f->scope () == 0 && f->symtype () == SymTypeFunction && isparam) {
556
552
// special case: only a warning for param to mask global function
0 commit comments