ClickHouse/dbms/include/DB/Parsers/ASTNameTypePair.h

50 lines
1.1 KiB
C
Raw Normal View History

2011-08-18 18:48:00 +00:00
#pragma once
#include <DB/Parsers/IAST.h>
#include <DB/Parsers/ASTFunction.h>
namespace DB
{
/** Пара из имени и типа. Например, browser FixedString(2).
*/
class ASTNameTypePair : public IAST
{
public:
/// имя
String name;
/// тип
ASTPtr type;
2014-12-17 15:26:24 +00:00
ASTNameTypePair() = default;
ASTNameTypePair(const StringRange range_) : IAST(range_) {}
2011-08-18 18:48:00 +00:00
/** Получить текст, который идентифицирует этот элемент. */
2014-12-17 15:26:24 +00:00
String getID() const override { return "NameTypePair_" + name; }
2011-12-12 06:15:34 +00:00
2014-12-17 15:26:24 +00:00
ASTPtr clone() const override
2011-12-12 06:15:34 +00:00
{
ASTNameTypePair * res = new ASTNameTypePair(*this);
2014-12-17 15:26:24 +00:00
ASTPtr ptr{res};
2011-12-12 06:15:34 +00:00
res->children.clear();
if (type) { res->type = type->clone(); res->children.push_back(res->type); }
2014-12-17 15:26:24 +00:00
return ptr;
2011-12-12 06:15:34 +00:00
}
protected:
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
{
std::string indent_str = settings.one_line ? "" : std::string(4 * frame.indent, ' ');
settings.ostr << settings.nl_or_ws << indent_str << backQuoteIfNeed(name) << " ";
type->formatImpl(settings, state, frame);
}
2011-08-18 18:48:00 +00:00
};
}