aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend/lex.cc
diff options
context:
space:
mode:
authorSanjoy Das <thedigitalangel@gmail.com>2011-11-29 19:10:50 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2011-11-29 19:10:50 +0000
commit8afa2bfbdc60088acd7f199245244890a6e7773e (patch)
treef79cf7c9d2d4e5b74c516201a60c5753fe79c93f /gcc/go/gofrontend/lex.cc
parent09ad58e618b0145ed98ee081ffc8117824390972 (diff)
downloadgcc-8afa2bfbdc60088acd7f199245244890a6e7773e.zip
gcc-8afa2bfbdc60088acd7f199245244890a6e7773e.tar.gz
gcc-8afa2bfbdc60088acd7f199245244890a6e7773e.tar.bz2
compiler: Define and use backend-independent Location class.
From Sanjoy Das. * go-location.h: New file. * go-linemap.cc: New file. * go-gcc.cc: Change all uses of source_location to Location. * Make-lang.in (GO_OBJS): Add go/go-linemap.o. (GO_LINEMAP_H): New variable. (GO_LEX_H): Use $(GO_LINEMAP_H). (GO_GOGO_H, GO_TYPES_H, GO_IMPORT_H): Likewise. (go/go-linemap.o): New target. Co-Authored-By: Ian Lance Taylor <iant@google.com> From-SVN: r181813
Diffstat (limited to 'gcc/go/gofrontend/lex.cc')
-rw-r--r--gcc/go/gofrontend/lex.cc42
1 files changed, 20 insertions, 22 deletions
diff --git a/gcc/go/gofrontend/lex.cc b/gcc/go/gofrontend/lex.cc
index 167c7dd..effa087 100644
--- a/gcc/go/gofrontend/lex.cc
+++ b/gcc/go/gofrontend/lex.cc
@@ -146,7 +146,7 @@ static Keywords keywords;
// Make a general token.
-Token::Token(Classification classification, source_location location)
+Token::Token(Classification classification, Location location)
: classification_(classification), location_(location)
{
}
@@ -432,19 +432,18 @@ Token::print(FILE* file) const
// Class Lex.
-Lex::Lex(const char* input_file_name, FILE* input_file)
+Lex::Lex(const char* input_file_name, FILE* input_file, Linemap* linemap)
: input_file_name_(input_file_name), input_file_(input_file),
- linebuf_(NULL), linebufsize_(120), linesize_(0), lineoff_(0),
- lineno_(0), add_semi_at_eol_(false)
+ linemap_(linemap), linebuf_(NULL), linebufsize_(120), linesize_(0),
+ lineoff_(0), lineno_(0), add_semi_at_eol_(false)
{
this->linebuf_ = new char[this->linebufsize_];
- linemap_add(line_table, LC_ENTER, 0, input_file_name, 1);
+ this->linemap_->start_file(input_file_name, 0);
}
Lex::~Lex()
{
delete[] this->linebuf_;
- linemap_add(line_table, LC_LEAVE, 0, NULL, 0);
}
// Read a new line from the file.
@@ -508,26 +507,26 @@ Lex::require_line()
this->linesize_= got;
this->lineoff_ = 0;
- linemap_line_start(line_table, this->lineno_, this->linesize_);
+ this->linemap_->start_line(this->lineno_, this->linesize_);
return true;
}
// Get the current location.
-source_location
+Location
Lex::location() const
{
- return linemap_position_for_column (line_table, this->lineoff_ + 1);
+ return this->linemap_->get_location(this->lineoff_ + 1);
}
// Get a location slightly before the current one. This is used for
// slightly more efficient handling of operator tokens.
-source_location
+Location
Lex::earlier_location(int chars) const
{
- return linemap_position_for_column (line_table, this->lineoff_ + 1 - chars);
+ return this->linemap_->get_location(this->lineoff_ + 1 - chars);
}
// Get the next token.
@@ -586,7 +585,7 @@ Lex::next_token()
else if (p[1] == '*')
{
this->lineoff_ = p - this->linebuf_;
- source_location location = this->location();
+ Location location = this->location();
if (!this->skip_c_comment())
return Token::make_invalid_token(location);
p = this->linebuf_ + this->lineoff_;
@@ -889,7 +888,7 @@ Lex::gather_identifier()
buf.append(ubuf);
}
}
- source_location location = this->location();
+ Location location = this->location();
this->add_semi_at_eol_ = true;
this->lineoff_ = p - this->linebuf_;
if (has_non_ascii_char)
@@ -956,7 +955,7 @@ Lex::gather_number()
const char* p = pstart;
const char* pend = this->linebuf_ + this->linesize_;
- source_location location = this->location();
+ Location location = this->location();
bool neg = false;
if (*p == '+')
@@ -1253,7 +1252,7 @@ Lex::advance_one_char(const char* p, bool is_single_quote, unsigned int* value,
void
Lex::append_char(unsigned int v, bool is_character, std::string* str,
- source_location location)
+ Location location)
{
char buf[4];
size_t len;
@@ -1319,7 +1318,7 @@ Lex::gather_character()
mpz_t val;
mpz_init_set_ui(val, value);
- source_location location = this->location();
+ Location location = this->location();
this->lineoff_ = p + 1 - this->linebuf_;
Token ret = Token::make_integer_token(val, location);
mpz_clear(val);
@@ -1338,7 +1337,7 @@ Lex::gather_string()
std::string value;
while (*p != '"')
{
- source_location loc = this->location();
+ Location loc = this->location();
unsigned int c;
bool is_character;
this->lineoff_ = p - this->linebuf_;
@@ -1352,7 +1351,7 @@ Lex::gather_string()
Lex::append_char(c, is_character, &value, loc);
}
- source_location location = this->location();
+ Location location = this->location();
this->lineoff_ = p + 1 - this->linebuf_;
return Token::make_string_token(value, location);
}
@@ -1364,7 +1363,7 @@ Lex::gather_raw_string()
{
const char* p = this->linebuf_ + this->lineoff_ + 1;
const char* pend = this->linebuf_ + this->linesize_;
- source_location location = this->location();
+ Location location = this->location();
std::string value;
while (true)
@@ -1376,7 +1375,7 @@ Lex::gather_raw_string()
this->lineoff_ = p + 1 - this->linebuf_;
return Token::make_string_token(value, location);
}
- source_location loc = this->location();
+ Location loc = this->location();
unsigned int c;
bool issued_error;
this->lineoff_ = p - this->linebuf_;
@@ -1630,8 +1629,7 @@ Lex::skip_cpp_comment()
memcpy(file, p, filelen);
file[filelen] = '\0';
- linemap_add(line_table, LC_LEAVE, 0, NULL, 0);
- linemap_add(line_table, LC_ENTER, 0, file, lineno);
+ this->linemap_->start_file(file, lineno);
this->lineno_ = lineno - 1;
p = plend;