Skip to content

Commit

Permalink
fix: use c_str() instead of char address
Browse files Browse the repository at this point in the history
  • Loading branch information
zeim839 committed May 12, 2023
1 parent fdd7dfa commit 88537d7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/frontend/expressions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Bexpression* Var_expression::do_get_backend(Backend* backend) {

if (!is_defined) {
rin_error_at(obj->location(), "'%s' is undeclared",
&obj->identifier()[0]);
obj->identifier().c_str());
return backend->invalid_expression();
}

Expand Down
6 changes: 3 additions & 3 deletions src/frontend/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ class Expression_node

// Returns the C-string pointer of the expression for debug.
char* str()
{ return &this->_str[0]; }
{ return this->_str.c_str(); }

// Adds a child to the node
void add_child(Expression_node* a, Expression_node* b = NULL) {
Expand Down Expand Up @@ -737,7 +737,7 @@ Expression* Parser::parse_expression(RIN_OPERATOR terminal)
prev_token = token;
rin_error_at(token.location(),
"Unresolved expression: reached EOF before expected %s",
&operator_name(terminal)[0]);
operator_name(terminal).c_str());
__abort_expr_parse(operators, output);
return NULL;

Expand All @@ -748,7 +748,7 @@ Expression* Parser::parse_expression(RIN_OPERATOR terminal)
prev_token = token;
rin_error_at(token.location(),
"Cannot use %s token as expression value (NOT IMPLEMENTED)",
&token.classification_as_string()[0]);
token.classification_as_string().c_str());
__abort_expr_parse(operators, output);
return NULL;

Expand Down
8 changes: 4 additions & 4 deletions src/frontend/scanner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Token::Token(const Token& tok)
{
if (tok._classification == TOKEN_INTEGER
|| tok._classification == TOKEN_FLOAT) {
mpfr_init_set_str(this->value.float_value, &tok.token_string[0], 10, MPFR_RNDN);
mpfr_init_set_str(this->value.float_value, tok.token_string.c_str(), 10, MPFR_RNDN);
} else if (tok._classification == TOKEN_IDENT)
this->value.id_name = new std::string(*tok.value.id_name);
else if (tok._classification == TOKEN_OPERATOR)
Expand Down Expand Up @@ -87,7 +87,7 @@ Token Token::make_operator_token(RIN_OPERATOR op, Location loc)
Token Token::make_float_token(const std::string& str, Location loc)
{
Token tok(TOKEN_FLOAT, str, loc);
mpfr_init_set_str(tok.value.float_value, &str[0], 10, MPFR_RNDN);
mpfr_init_set_str(tok.value.float_value, str.c_str(), 10, MPFR_RNDN);
return tok;
}

Expand Down Expand Up @@ -180,7 +180,7 @@ void Scanner::acknowledge(Token tok)
}
if (is_righthand_op(tok.op())) {
rin_error_at(tok.location(), "Unexpected %s",
&operator_name(tok.op())[0]);
operator_name(tok.op()).c_str());
}
}

Expand Down Expand Up @@ -336,7 +336,7 @@ Token Scanner::scan_token()
if (is_valid_identifier(tokenStr))
return Token::make_ident_token(tokenStr, Scanner::location());

rin_error_at(location(), "Unknown keyword %s", &tokenStr[0]);
rin_error_at(location(), "Unknown keyword %s", tokenStr.c_str());
return make_invalid_token(tokenStr);
}

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/statements.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Bstatement* Variable_declaration_statement::do_get_backend(Backend* backend)
RIN_ASSERT(backend->current_scope());
if (backend->current_scope()->is_defined(this->identifier())) {
rin_error_at(this->var()->location(), "Redefinition of '%s'",
&this->identifier()[0]);
this->identifier().c_str());
return backend->invalid_statement();
}

Expand Down

0 comments on commit 88537d7

Please sign in to comment.