@@ -572,34 +572,49 @@ void verilog_preprocessort::directive()
572
572
// skip whitespace
573
573
tokenizer ().skip_ws ();
574
574
575
- // We expect one of:
575
+ std::string argument;
576
+
577
+ // Read any tokens until end of line.
578
+ // 1800-2017 is silent on whether further directives are
579
+ // processed. We emit an error.
580
+ // 1800-2017 is silent wether file names in quotes are processed
581
+ // as string literals. We assume not so.
582
+ while (!tokenizer ().eof () && tokenizer ().peek () != ' \n ' )
583
+ {
584
+ auto token = tokenizer ().next_token ();
585
+
586
+ if (token == ' `' )
587
+ {
588
+ throw verilog_preprocessor_errort ()
589
+ << " preprocessor directive inside `include directive" ;
590
+ }
591
+
592
+ argument += token.text ;
593
+ }
594
+
595
+ // We expect the argument to be one of:
576
596
// <filename> -- include paths only
577
597
// "filename" -- relative path, then include paths.
578
598
std::string given_filename;
579
599
bool include_paths_only;
580
600
581
- if (tokenizer (). peek (). is_string_literal () )
601
+ if (!argument. empty () && argument[ 0 ] == ' " ' )
582
602
{
583
603
include_paths_only = false ;
584
- const auto file_token = tokenizer ().next_token ();
585
- CHECK_RETURN (file_token.is_string_literal ());
586
- // strip quotes off string literal, escaping, etc.
587
- given_filename = file_token.string_literal_value ();
604
+ auto quote_pos = argument.find (' "' , 1 );
605
+ if (quote_pos == std::string::npos)
606
+ throw verilog_preprocessor_errort ()
607
+ << " expected closing \" in include directive" ;
608
+ given_filename = std::string (argument, 1 , quote_pos - 1 );
588
609
}
589
- else if (tokenizer (). peek () == ' <' )
610
+ else if (!argument. empty () && argument[ 0 ] == ' <' )
590
611
{
591
- tokenizer ().next_token (); // <
592
612
include_paths_only = true ;
593
-
594
- while (tokenizer ().peek () != ' >' )
595
- {
596
- if (tokenizer ().peek ().is_eof ())
597
- throw verilog_preprocessor_errort () << " eof in include directive" ;
598
-
599
- given_filename += tokenizer ().next_token ().text ;
600
- }
601
-
602
- tokenizer ().next_token (); // >
613
+ auto quote_pos = argument.find (' >' , 1 );
614
+ if (quote_pos == std::string::npos)
615
+ throw verilog_preprocessor_errort ()
616
+ << " expected closing > in include directive" ;
617
+ given_filename = std::string (argument, 1 , quote_pos - 1 );
603
618
}
604
619
else
605
620
{
0 commit comments