From f9d8d0b219ade34ee6108463c00b68fa22ba59e1 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 27 Sep 2023 20:00:07 -0700 Subject: [PATCH] Avoid converting between sp::Atom and PoolString. This isn't necessary now that tokens atomize everything. --- compiler/parse-node.h | 14 +++++++------- compiler/parser.cpp | 14 +++++++------- compiler/semantics.cpp | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/compiler/parse-node.h b/compiler/parse-node.h index 6e571aa3f..3bea599d3 100644 --- a/compiler/parse-node.h +++ b/compiler/parse-node.h @@ -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) @@ -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 @@ -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 diff --git a/compiler/parser.cpp b/compiler/parser.cpp index c9575a513..bf0dcb342 100644 --- a/compiler/parser.cpp +++ b/compiler/parser.cpp @@ -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); @@ -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: @@ -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(')'); @@ -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. diff --git a/compiler/semantics.cpp b/compiler/semantics.cpp index 7607f625d..e0b94acd0 100644 --- a/compiler/semantics.cpp +++ b/compiler/semantics.cpp @@ -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())); }