Remove bad has-minus flag which should be contained within AST::Literal

This commit is contained in:
Philip Herron 2022-04-20 17:52:59 +01:00
parent 14dbac9a8b
commit 03ec66cf11
3 changed files with 11 additions and 22 deletions

View File

@ -2819,12 +2819,7 @@ StructPattern::as_string () const
std::string
LiteralPattern::as_string () const
{
std::string str;
if (has_minus)
str += "-";
return str + lit.as_string ();
return lit.as_string ();
}
std::string

View File

@ -27,14 +27,6 @@ namespace AST {
class LiteralPattern : public Pattern
{
Literal lit;
/* make literal have a type given by enum, etc. rustc uses an extended form of
* its literal token implementation */
// TODO: literal representation - use LiteralExpr? or another thing?
// Minus prefixed to literal (if integer or floating-point)
bool has_minus;
// Actually, this might be a good place to use a template.
Location locus;
NodeId node_id;
@ -42,16 +34,14 @@ public:
std::string as_string () const override;
// Constructor for a literal pattern
LiteralPattern (Literal lit, Location locus, bool has_minus = false)
: lit (std::move (lit)), has_minus (has_minus), locus (locus),
LiteralPattern (Literal lit, Location locus)
: lit (std::move (lit)), locus (locus),
node_id (Analysis::Mappings::get ()->get_next_node_id ())
{}
LiteralPattern (std::string val, Literal::LitType type, Location locus,
bool has_minus = false)
LiteralPattern (std::string val, Literal::LitType type, Location locus)
: lit (Literal (std::move (val), type, PrimitiveCoreType::CORETYPE_STR)),
has_minus (has_minus), locus (locus),
node_id (Analysis::Mappings::get ()->get_next_node_id ())
locus (locus), node_id (Analysis::Mappings::get ()->get_next_node_id ())
{}
Location get_locus () const override final { return locus; }
@ -62,6 +52,10 @@ public:
NodeId get_pattern_node_id () const override final { return node_id; }
Literal &get_literal () { return lit; }
const Literal &get_literal () const { return lit; }
protected:
/* Use covariance to implement clone function as returning this object rather
* than base */
@ -1110,7 +1104,7 @@ public:
TupleStructPattern (TupleStructPattern &&other) = default;
TupleStructPattern &operator= (TupleStructPattern &&other) = default;
Location get_locus () const { return path.get_locus (); }
Location get_locus () const override { return path.get_locus (); }
void accept_vis (ASTVisitor &vis) override;

View File

@ -10400,7 +10400,7 @@ Parser<ManagedTokenSource>::parse_literal_or_range_pattern ()
// literal pattern
return std::unique_ptr<AST::LiteralPattern> (
new AST::LiteralPattern (range_lower->get_str (), type,
range_lower->get_locus (), has_minus));
range_lower->get_locus ()));
}
}