Skip to content

Commit 492e75b

Browse files
committed
Output source location with all type checking errors
1 parent 4aaa315 commit 492e75b

File tree

1 file changed

+44
-36
lines changed

1 file changed

+44
-36
lines changed

src/ansi-c/c_typecheck_base.cpp

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ void c_typecheck_baset::move_symbol(symbolt &symbol, symbolt *&new_symbol)
7171
if(symbol_table.move(symbol, new_symbol))
7272
{
7373
err_location(symbol.location);
74-
str << "failed to move symbol `" << symbol.name
75-
<< "' into symbol table";
74+
error() << "failed to move symbol `" << symbol.name
75+
<< "' into symbol table" << eom;
7676
throw 0;
7777
}
7878
}
@@ -118,7 +118,7 @@ void c_typecheck_baset::typecheck_symbol(symbolt &symbol)
118118
else if(!is_function && symbol.value.id()==ID_code)
119119
{
120120
err_location(symbol.value);
121-
str << "only functions can have a function body";
121+
error() << "only functions can have a function body" << eom;
122122
throw 0;
123123
}
124124

@@ -162,8 +162,8 @@ void c_typecheck_baset::typecheck_symbol(symbolt &symbol)
162162
if(old_it->second.is_type!=symbol.is_type)
163163
{
164164
err_location(symbol.location);
165-
str << "redeclaration of `" << symbol.display_name()
166-
<< "' as a different kind of symbol";
165+
error() << "redeclaration of `" << symbol.display_name()
166+
<< "' as a different kind of symbol" << eom;
167167
throw 0;
168168
}
169169

@@ -275,9 +275,9 @@ void c_typecheck_baset::typecheck_redefinition_type(
275275
else
276276
{
277277
err_location(new_symbol.location);
278-
str << "error: conflicting definition of type symbol `"
279-
<< new_symbol.display_name()
280-
<< "'";
278+
error() << "error: conflicting definition of type symbol `"
279+
<< new_symbol.display_name()
280+
<< "'" << eom;
281281
throw 0;
282282
}
283283
}
@@ -296,9 +296,9 @@ void c_typecheck_baset::typecheck_redefinition_type(
296296
{
297297
// arg! new tag type
298298
err_location(new_symbol.location);
299-
str << "error: conflicting definition of tag symbol `"
300-
<< new_symbol.display_name()
301-
<< "'";
299+
error() << "error: conflicting definition of tag symbol `"
300+
<< new_symbol.display_name()
301+
<< "'" << eom;
302302
throw 0;
303303
}
304304
}
@@ -322,10 +322,10 @@ void c_typecheck_baset::typecheck_redefinition_type(
322322
if(follow(new_symbol.type)!=follow(old_symbol.type))
323323
{
324324
err_location(new_symbol.location);
325-
str << "error: type symbol `" << new_symbol.display_name()
326-
<< "' defined twice:" << "\n";
327-
str << "Original: " << to_string(old_symbol.type) << "\n";
328-
str << " New: " << to_string(new_symbol.type);
325+
error() << "error: type symbol `"
326+
<< new_symbol.display_name() << "' defined twice:\n"
327+
<< "Original: " << to_string(old_symbol.type) << "\n"
328+
<< " New: " << to_string(new_symbol.type) << eom;
329329
throw 0;
330330
}
331331
}
@@ -375,7 +375,8 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
375375
if(final_new.id()==ID_code)
376376
{
377377
err_location(new_symbol.location);
378-
str << "function type not allowed for K&R function parameter";
378+
error() << "function type not allowed for K&R function parameter"
379+
<< eom;
379380
throw 0;
380381
}
381382

@@ -393,10 +394,11 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
393394
if(final_old.id()!=ID_code)
394395
{
395396
err_location(new_symbol.location);
396-
str << "error: function symbol `" << new_symbol.display_name()
397-
<< "' redefined with a different type:" << "\n";
398-
str << "Original: " << to_string(old_symbol.type) << "\n";
399-
str << " New: " << to_string(new_symbol.type);
397+
error() << "error: function symbol `"
398+
<< new_symbol.display_name()
399+
<< "' redefined with a different type:\n"
400+
<< "Original: " << to_string(old_symbol.type) << "\n"
401+
<< " New: " << to_string(new_symbol.type) << eom;
400402
throw 0;
401403
}
402404

@@ -449,8 +451,8 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
449451
else
450452
{
451453
err_location(new_symbol.location);
452-
str << "function body `" << new_symbol.display_name()
453-
<< "' defined twice";
454+
error() << "function body `" << new_symbol.display_name()
455+
<< "' defined twice" << eom;
454456
throw 0;
455457
}
456458
}
@@ -504,8 +506,9 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
504506
if(s_it==symbol_table.symbols.end())
505507
{
506508
err_location(old_symbol.location);
507-
str << "typecheck_redefinition_non_type: "
508-
"failed to find symbol `" << identifier << "'";
509+
error() << "typecheck_redefinition_non_type: "
510+
<< "failed to find symbol `" << identifier << "'"
511+
<< eom;
509512
throw 0;
510513
}
511514

@@ -547,10 +550,10 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
547550
else
548551
{
549552
err_location(new_symbol.location);
550-
str << "error: symbol `" << new_symbol.display_name()
551-
<< "' redefined with a different type:" << "\n";
552-
str << "Original: " << to_string(old_symbol.type) << "\n";
553-
str << " New: " << to_string(new_symbol.type);
553+
error() << "error: symbol `" << new_symbol.display_name()
554+
<< "' redefined with a different type:\n"
555+
<< "Original: " << to_string(old_symbol.type) << "\n"
556+
<< " New: " << to_string(new_symbol.type) << eom;
554557
throw 0;
555558
}
556559
}
@@ -587,8 +590,8 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
587590
else
588591
{
589592
err_location(new_symbol.value);
590-
str << "symbol `" << new_symbol.display_name()
591-
<< "' already has an initial value";
593+
error() << "symbol `" << new_symbol.display_name()
594+
<< "' already has an initial value" << eom;
592595
warning_msg();
593596
}
594597
}
@@ -687,8 +690,8 @@ void c_typecheck_baset::typecheck_function_body(symbolt &symbol)
687690
if(labels_defined.find(it->first)==labels_defined.end())
688691
{
689692
err_location(it->second);
690-
str << "branching label `" << it->first
691-
<< "' is not defined in function";
693+
error() << "branching label `" << it->first
694+
<< "' is not defined in function" << eom;
692695
throw 0;
693696
}
694697
}
@@ -736,9 +739,9 @@ void c_typecheck_baset::apply_asm_label(
736739
}
737740
else
738741
{
739-
str << "replacing asm renaming "
740-
<< asm_label_map[orig_name] << " by "
741-
<< asm_label;
742+
error() << "replacing asm renaming "
743+
<< asm_label_map[orig_name] << " by "
744+
<< asm_label << eom;
742745
throw 0;
743746
}
744747
}
@@ -849,7 +852,12 @@ void c_typecheck_baset::typecheck_declaration(
849852
if(!full_spec.alias.empty())
850853
{
851854
if(symbol.value.is_not_nil())
852-
throw "alias attribute cannot be used with a body";
855+
{
856+
err_location(symbol.location);
857+
error() << "alias attribute cannot be used with a body"
858+
<< eom;
859+
throw 0;
860+
}
853861

854862
// alias function need not have been declared yet, thus
855863
// can't lookup

0 commit comments

Comments
 (0)