slicc: work around improper initialization of a global in slicc.
authorNathan Binkert <nate@binkert.org>
Wed, 13 May 2009 05:33:05 +0000 (22:33 -0700)
committerNathan Binkert <nate@binkert.org>
Wed, 13 May 2009 05:33:05 +0000 (22:33 -0700)
src/mem/slicc/ast/Location.cc
src/mem/slicc/ast/Location.hh
src/mem/slicc/parser/parser.yy

index 6209ccdb736d0c89194ae6042e230fb94681bbf4..23d1dba0f40aab9fe48c69dbc89b91fffc8bedfb 100644 (file)
 #include "mem/slicc/ast/Location.hh"
 
 int g_line_number = 0;
-string g_file_name("");
+string &g_file_name()
+{
+    static string the_string;
+    return the_string;
+}
 
 Location::Location()
 {
-  m_file_name = g_file_name;
+  m_file_name = g_file_name();
   m_line_number = g_line_number;
 
   ostringstream sstr;
index f070efc4662e2439acf67ad290c59774d2b3b272..3233bdb3b496a18e4cfbe4cabeedcf1edac2a793 100644 (file)
@@ -42,7 +42,7 @@
 #include "mem/slicc/slicc_global.hh"
 
 extern int g_line_number;
-extern string g_file_name;
+extern string &g_file_name();
 
 class Location {
 public:
index 8090b88f79f4dd87df8e15a11c95ede6e7021b9a..724184665348d2f7abf9f8ad4552fae5023a79f5 100644 (file)
@@ -337,7 +337,7 @@ DeclListAST* parse(string filename)
     exit(1);
   }
   g_line_number = 1;
-  g_file_name = filename;
+  g_file_name() = filename;
   yyin = file;
   g_decl_list_ptr = NULL;
   yyparse();
@@ -346,7 +346,7 @@ DeclListAST* parse(string filename)
 
 extern "C" void yyerror(char* s)
 {
-  fprintf(stderr, "%s:%d: %s at %s\n", g_file_name.c_str(), g_line_number, s, yytext);
+  fprintf(stderr, "%s:%d: %s at %s\n", g_file_name().c_str(), g_line_number, s, yytext);
   exit(1);
 }