Skip to content

Commit

Permalink
Avoid converting between sp::Atom and PoolString.
Browse files Browse the repository at this point in the history
This isn't necessary now that tokens atomize everything.
  • Loading branch information
dvander committed Sep 28, 2023
1 parent 49de1c4 commit fc20591
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions compiler/parse-node.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class ContinueStmt : public Stmt
class StaticAssertStmt : public Stmt
{
public:
explicit StaticAssertStmt(const token_pos_t& pos, Expr* expr, PoolString* text)
explicit StaticAssertStmt(const token_pos_t& pos, Expr* expr, sp::Atom* text)
: Stmt(StmtKind::StaticAssertStmt, pos),
expr_(expr),
text_(text)
Expand All @@ -270,11 +270,11 @@ class StaticAssertStmt : public Stmt
static bool is_a(Stmt* node) { return node->kind() == StmtKind::StaticAssertStmt; }

Expr* expr() const { return expr_; }
PoolString* text() const { return text_; }
sp::Atom* text() const { return text_; }

private:
Expr* expr_;
PoolString* text_;
sp::Atom* text_;
};

class Decl : public Stmt
Expand Down Expand Up @@ -1161,21 +1161,21 @@ class FloatExpr final : public TaggedValueExpr
class StringExpr final : public Expr
{
public:
StringExpr(const token_pos_t& pos, const char* str, size_t len)
StringExpr(const token_pos_t& pos, sp::Atom* atom)
: Expr(ExprKind::StringExpr, pos),
text_(new PoolString(str, len))
text_(atom)
{}

void ProcessUses(SemaContext&) override {}

static bool is_a(Expr* node) { return node->kind() == ExprKind::StringExpr; }

PoolString* text() const {
sp::Atom* text() const {
return text_;
}

private:
PoolString* text_;
sp::Atom* text_;
};

class NewArrayExpr final : public Expr
Expand Down
14 changes: 7 additions & 7 deletions compiler/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,8 +1061,8 @@ Parser::constant()
case tRATIONAL:
return new FloatExpr(cc_, pos, lexer_->current_token()->value);
case tSTRING: {
const auto& str = lexer_->current_token()->data();
return new StringExpr(pos, str.c_str(), str.size());
const auto& atom = lexer_->current_token()->atom;
return new StringExpr(pos, atom);
}
case tTRUE:
return new TaggedValueExpr(lexer_->pos(), cc_.types()->tag_bool(), 1);
Expand Down Expand Up @@ -1177,8 +1177,8 @@ Parser::struct_init()
Expr* expr = nullptr;
switch (lexer_->lex()) {
case tSTRING: {
const auto& str = lexer_->current_token()->data();
expr = new StringExpr(pos, str.c_str(), str.size());
const auto& atom = lexer_->current_token()->atom;
expr = new StringExpr(pos, atom);
break;
}
case tCHAR_LITERAL:
Expand Down Expand Up @@ -1215,10 +1215,10 @@ Parser::parse_static_assert()
if (!expr)
return nullptr;

PoolString * text = nullptr;
sp::Atom* text = nullptr;
if (lexer_->match(',') && lexer_->need(tSTRING)) {
auto tok = lexer_->current_token();
text = new PoolString(tok->data().c_str(), tok->data().size());
text = tok->atom;
}

lexer_->need(')');
Expand Down Expand Up @@ -1261,7 +1261,7 @@ Parser::var_init(int vclass)

if (lexer_->match(tSTRING)) {
auto tok = lexer_->current_token();
return new StringExpr(tok->start, tok->data().c_str(), tok->data().size());
return new StringExpr(tok->start, tok->atom);
}

// We'll check const or symbol-ness for non-sLOCALs in the semantic pass.
Expand Down
2 changes: 1 addition & 1 deletion compiler/semantics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ bool Semantics::CheckPstructDecl(VarDeclBase* decl) {
if (ps->args[i]->type.ident == iREFARRAY) {
assert(ps->args[i]->type.tag() == types_->tag_string());

auto expr = new StringExpr(decl->pos(), "", 0);
auto expr = new StringExpr(decl->pos(), cc_.atom(""));
init->fields().push_back(new StructInitFieldExpr(ps->args[i]->name, expr,
decl->pos()));
}
Expand Down

0 comments on commit fc20591

Please sign in to comment.