提交 ad6648af 编写于 作者: A Alexey Milovidov

Moved more code to .cpp

上级 25ab402d
#include <Parsers/ASTColumnDeclaration.h>
namespace DB
{
ASTPtr ASTColumnDeclaration::clone() const
{
const auto res = std::make_shared<ASTColumnDeclaration>(*this);
res->children.clear();
if (type)
{
res->type = type;
res->children.push_back(res->type);
}
if (default_expression)
{
res->default_expression = default_expression->clone();
res->children.push_back(res->default_expression);
}
if (codec)
{
res->codec = codec->clone();
res->children.push_back(res->codec);
}
if (comment)
{
res->comment = comment->clone();
res->children.push_back(res->comment);
}
return res;
}
void ASTColumnDeclaration::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
{
frame.need_parens = false;
std::string indent_str = settings.one_line ? "" : std::string(4 * frame.indent, ' ');
settings.ostr << settings.nl_or_ws << indent_str << backQuoteIfNeed(name);
if (type)
{
settings.ostr << ' ';
type->formatImpl(settings, state, frame);
}
if (default_expression)
{
settings.ostr << ' ' << (settings.hilite ? hilite_keyword : "") << default_specifier << (settings.hilite ? hilite_none : "") << ' ';
default_expression->formatImpl(settings, state, frame);
}
if (comment)
{
settings.ostr << ' ' << (settings.hilite ? hilite_keyword : "") << "COMMENT" << (settings.hilite ? hilite_none : "") << ' ';
comment->formatImpl(settings, state, frame);
}
if (codec)
{
settings.ostr << ' ';
codec->formatImpl(settings, state, frame);
}
}
}
...@@ -20,68 +20,8 @@ public: ...@@ -20,68 +20,8 @@ public:
String getID(char delim) const override { return "ColumnDeclaration" + (delim + name); } String getID(char delim) const override { return "ColumnDeclaration" + (delim + name); }
ASTPtr clone() const override ASTPtr clone() const override;
{ void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
const auto res = std::make_shared<ASTColumnDeclaration>(*this);
res->children.clear();
if (type)
{
res->type = type;
res->children.push_back(res->type);
}
if (default_expression)
{
res->default_expression = default_expression->clone();
res->children.push_back(res->default_expression);
}
if (codec)
{
res->codec = codec->clone();
res->children.push_back(res->codec);
}
if (comment)
{
res->comment = comment->clone();
res->children.push_back(res->comment);
}
return res;
}
void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override
{
frame.need_parens = false;
std::string indent_str = settings.one_line ? "" : std::string(4 * frame.indent, ' ');
settings.ostr << settings.nl_or_ws << indent_str << backQuoteIfNeed(name);
if (type)
{
settings.ostr << ' ';
type->formatImpl(settings, state, frame);
}
if (default_expression)
{
settings.ostr << ' ' << (settings.hilite ? hilite_keyword : "") << default_specifier << (settings.hilite ? hilite_none : "") << ' ';
default_expression->formatImpl(settings, state, frame);
}
if (comment)
{
settings.ostr << ' ' << (settings.hilite ? hilite_keyword : "") << "COMMENT" << (settings.hilite ? hilite_none : "") << ' ';
comment->formatImpl(settings, state, frame);
}
if (codec)
{
settings.ostr << ' ';
codec->formatImpl(settings, state, frame);
}
}
}; };
} }
...@@ -66,6 +66,19 @@ void ASTStorage::formatImpl(const FormatSettings & s, FormatState & state, Forma ...@@ -66,6 +66,19 @@ void ASTStorage::formatImpl(const FormatSettings & s, FormatState & state, Forma
} }
class ASTColumnsElement : public IAST
{
public:
String prefix;
IAST * elem;
String getID(char c) const override { return "ASTColumnsElement for " + elem->getID(c); }
ASTPtr clone() const override;
void formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const override;
};
ASTPtr ASTColumnsElement::clone() const ASTPtr ASTColumnsElement::clone() const
{ {
auto res = std::make_shared<ASTColumnsElement>(); auto res = std::make_shared<ASTColumnsElement>();
...@@ -117,6 +130,7 @@ void ASTColumns::formatImpl(const FormatSettings & s, FormatState & state, Forma ...@@ -117,6 +130,7 @@ void ASTColumns::formatImpl(const FormatSettings & s, FormatState & state, Forma
ASTExpressionList list; ASTExpressionList list;
if (columns) if (columns)
{
for (const auto & column : columns->children) for (const auto & column : columns->children)
{ {
auto elem = std::make_shared<ASTColumnsElement>(); auto elem = std::make_shared<ASTColumnsElement>();
...@@ -124,7 +138,9 @@ void ASTColumns::formatImpl(const FormatSettings & s, FormatState & state, Forma ...@@ -124,7 +138,9 @@ void ASTColumns::formatImpl(const FormatSettings & s, FormatState & state, Forma
elem->set(elem->elem, column->clone()); elem->set(elem->elem, column->clone());
list.children.push_back(elem); list.children.push_back(elem);
} }
}
if (indices) if (indices)
{
for (const auto & index : indices->children) for (const auto & index : indices->children)
{ {
auto elem = std::make_shared<ASTColumnsElement>(); auto elem = std::make_shared<ASTColumnsElement>();
...@@ -132,6 +148,7 @@ void ASTColumns::formatImpl(const FormatSettings & s, FormatState & state, Forma ...@@ -132,6 +148,7 @@ void ASTColumns::formatImpl(const FormatSettings & s, FormatState & state, Forma
elem->set(elem->elem, index->clone()); elem->set(elem->elem, index->clone());
list.children.push_back(elem); list.children.push_back(elem);
} }
}
if (!list.children.empty()) if (!list.children.empty())
list.formatImpl(s, state, frame); list.formatImpl(s, state, frame);
......
...@@ -28,20 +28,6 @@ public: ...@@ -28,20 +28,6 @@ public:
}; };
class ASTColumnsElement : public IAST
{
public:
String prefix;
IAST * elem;
String getID(char c) const override { return "ASTColumnsElement for " + elem->getID(c); }
ASTPtr clone() const override;
void formatImpl(const FormatSettings & s, FormatState & state, FormatStateStacked frame) const override;
};
class ASTExpressionList; class ASTExpressionList;
class ASTColumns : public IAST class ASTColumns : public IAST
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册