diff options
author | Josh Stone <jistone@redhat.com> | 2009-07-09 12:46:57 -0700 |
---|---|---|
committer | Josh Stone <jistone@redhat.com> | 2009-07-09 16:17:14 -0700 |
commit | 2203b03262e340b25fc26996cc2786c1c02041e3 (patch) | |
tree | ad6f6a37153f502d7fcdcee0842c8ec5ac460c83 | |
parent | 66c7d4c1a4147bc05abd1e69f41ec9d59685c433 (diff) | |
download | systemtap-steved-2203b03262e340b25fc26996cc2786c1c02041e3.tar.gz systemtap-steved-2203b03262e340b25fc26996cc2786c1c02041e3.tar.xz systemtap-steved-2203b03262e340b25fc26996cc2786c1c02041e3.zip |
Remove the filename copy from token->location
The location already has a pointer to a stapfile with the filename, so
there's no need to keep an extra copy.
-rw-r--r-- | coveragedb.h | 11 | ||||
-rw-r--r-- | elaborate.cxx | 24 | ||||
-rw-r--r-- | parse.cxx | 28 | ||||
-rw-r--r-- | parse.h | 4 |
4 files changed, 30 insertions, 37 deletions
diff --git a/coveragedb.h b/coveragedb.h index 3675e3b4..f0f071c4 100644 --- a/coveragedb.h +++ b/coveragedb.h @@ -10,6 +10,7 @@ #define COVERAGEDB_H #include "session.h" +#include "staptree.h" #include <string> @@ -62,12 +63,12 @@ public: int compiled; int executed; - coverage_element() { line = 0; col = 0; - compiled = 0; executed = 0; } + coverage_element(): + line(0), col(0), compiled(0), executed(0) {} - coverage_element(source_loc &place) { - file = place.file; line = place.line; col = place.column; - compiled = 0; executed = 0; } + coverage_element(source_loc &place): + file(place.file->name), line(place.line), col(place.column), + compiled(0), executed(0) {} }; diff --git a/elaborate.cxx b/elaborate.cxx index 30e9a775..fafc5e63 100644 --- a/elaborate.cxx +++ b/elaborate.cxx @@ -1491,9 +1491,9 @@ systemtap_session::print_token (ostream& o, const token* tok) tmpo << *tok; string ts = tmpo.str(); // search & replace the file name with nothing - size_t idx = ts.find (tok->location.file); + size_t idx = ts.find (tok->location.file->name); if (idx != string::npos) - ts.replace (idx, tok->location.file.size(), ""); + ts.replace (idx, tok->location.file->name.size(), ""); o << ts; } @@ -1560,16 +1560,16 @@ systemtap_session::print_error_source (std::ostream& message, std::string& align, const token* tok) { unsigned i = 0; - unsigned line = tok->location.line; - unsigned col = tok->location.column; - string file_contents; assert (tok); - if (tok->location.stap_file) - file_contents = tok->location.stap_file->file_contents; - else + if (!tok->location.file) //No source to print, silently exit return; + + unsigned line = tok->location.line; + unsigned col = tok->location.column; + const string &file_contents = tok->location.file->file_contents; + size_t start_pos = 0, end_pos = 0; //Navigate to the appropriate line while (i != line && end_pos != std::string::npos) @@ -1937,7 +1937,7 @@ void semantic_pass_opt1 (systemtap_session& s, bool& relaxed_p) functiondecl* fd = it->second; if (ftv.traversed.find(fd) == ftv.traversed.end()) { - if (fd->tok->location.file == s.user_file->name && // !tapset + if (fd->tok->location.file->name == s.user_file->name && // !tapset ! s.suppress_warnings) s.print_warning ("eliding unused function '" + fd->name + "'", fd->tok); else if (s.verbose>2) @@ -1993,7 +1993,7 @@ void semantic_pass_opt2 (systemtap_session& s, bool& relaxed_p, unsigned iterati if (vut.read.find (l) == vut.read.end() && vut.written.find (l) == vut.written.end()) { - if (l->tok->location.file == s.user_file->name && // !tapset + if (l->tok->location.file->name == s.user_file->name && // !tapset ! s.suppress_warnings) s.print_warning ("eliding unused variable '" + l->name + "'", l->tok); else if (s.verbose>2) @@ -2037,7 +2037,7 @@ void semantic_pass_opt2 (systemtap_session& s, bool& relaxed_p, unsigned iterati if (vut.read.find (l) == vut.read.end() && vut.written.find (l) == vut.written.end()) { - if (l->tok->location.file == s.user_file->name && // !tapset + if (l->tok->location.file->name == s.user_file->name && // !tapset ! s.suppress_warnings) s.print_warning ("eliding unused variable '" + l->name + "'", l->tok); else if (s.verbose>2) @@ -2083,7 +2083,7 @@ void semantic_pass_opt2 (systemtap_session& s, bool& relaxed_p, unsigned iterati if (vut.read.find (l) == vut.read.end() && vut.written.find (l) == vut.written.end()) { - if (l->tok->location.file == s.user_file->name && // !tapset + if (l->tok->location.file->name == s.user_file->name && // !tapset ! s.suppress_warnings) s.print_warning ("eliding unused variable '" + l->name + "'", l->tok); else if (s.verbose>2) @@ -584,11 +584,12 @@ parser::peek_kw (std::string const & kw) lexer::lexer (istream& input, const string& in, systemtap_session& s): - input_name (in), input_contents (""), input_pointer (0), + input_name (in), input_pointer (0), input_end (0), cursor_suspend_count(0), cursor_line (1), cursor_column (1), session(s), current_file (0) { getline(input, input_contents, '\0'); + input_pointer = input_contents.data(); input_end = input_contents.data() + input_contents.size(); @@ -616,16 +617,15 @@ lexer::lexer (istream& input, const string& in, systemtap_session& s): set<string> lexer::keywords; -std::string -lexer::get_input_contents () -{ - return input_contents; -} - void lexer::set_current_file (stapfile* f) { current_file = f; + if (f) + { + f->file_contents = input_contents; + f->name = input_name; + } } int @@ -682,9 +682,7 @@ token* lexer::scan (bool wildcard) { token* n = new token; - n->location.file = input_name; - if (current_file) - n->location.stap_file = current_file; + n->location.file = current_file; unsigned semiskipped_p = 0; @@ -952,8 +950,6 @@ parser::parse () { stapfile* f = new stapfile; input.set_current_file (f); - f->file_contents = input.get_input_contents (); - f->name = input_name; bool empty = true; @@ -1021,18 +1017,16 @@ parser::parse () { cerr << "Input file '" << input_name << "' is empty or missing." << endl; delete f; - input.set_current_file (0); - return 0; + f = 0; } else if (num_errors > 0) { cerr << num_errors << " parse error(s)." << endl; delete f; - input.set_current_file (0); - return 0; + f = 0; } - input.set_current_file (0); + input.set_current_file(0); return f; } @@ -23,10 +23,9 @@ struct stapfile; struct source_loc { - std::string file; + stapfile* file; unsigned line; unsigned column; - stapfile* stap_file; }; std::ostream& operator << (std::ostream& o, const source_loc& loc); @@ -75,7 +74,6 @@ class lexer public: token* scan (bool wildcard=false); lexer (std::istream&, const std::string&, systemtap_session&); - std::string get_input_contents (); void set_current_file (stapfile* f); private: |