Introduce a new expression untyped_constant that corresponds to constants::literal, which is removed. untyped_constant is rather ugly in that it won't exist post-prepare. We should probably instead replace it with typed constants that use the widest possible type (decimal and varint), and select a narrower type during the prepare phase when we perform type inference. The conversion itseld is straightforward.
60 lines
1.8 KiB
C++
60 lines
1.8 KiB
C++
/*
|
|
* Copyright (C) 2020-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* This file is part of Scylla.
|
|
*
|
|
* Scylla is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Scylla is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with Scylla. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "cql3/term.hh"
|
|
#include "expression.hh"
|
|
|
|
// A term::raw that is implemented using an expression
|
|
namespace cql3::expr {
|
|
|
|
class term_raw_expr final : public term::raw {
|
|
expression _expr;
|
|
public:
|
|
explicit term_raw_expr(expression expr) : _expr(std::move(expr)) {}
|
|
|
|
virtual ::shared_ptr<term> prepare(database& db, const sstring& keyspace, const column_specification_or_tuple& receiver) const override;
|
|
|
|
virtual sstring to_string() const override;
|
|
|
|
virtual test_result test_assignment(database& db, const sstring& keyspace, const column_specification& receiver) const override;
|
|
|
|
virtual sstring assignment_testable_source_context() const override;
|
|
|
|
const expression& as_expression() const {
|
|
return _expr;
|
|
}
|
|
};
|
|
|
|
|
|
// Temporary: if a term_raw_expr is an untyped_constant, return it
|
|
inline
|
|
const untyped_constant*
|
|
as_untyped_constant(::shared_ptr<term::raw> t) {
|
|
if (auto tre = dynamic_pointer_cast<term_raw_expr>(t)) {
|
|
return std::get_if<untyped_constant>(&tre->as_expression());
|
|
} else {
|
|
return nullptr;
|
|
}
|
|
}
|
|
|
|
} |