2017-06-18 05:44:09 +00:00
|
|
|
#include <Parsers/ASTExpressionList.h>
|
2020-11-09 16:05:40 +00:00
|
|
|
#include <IO/Operators.h>
|
2017-06-18 05:44:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
ASTPtr ASTExpressionList::clone() const
|
|
|
|
{
|
2018-05-17 13:33:28 +00:00
|
|
|
auto clone = std::make_shared<ASTExpressionList>(*this);
|
|
|
|
clone->cloneChildren();
|
Get rid of useless std::move to get NRVO
http://eel.is/c++draft/class.copy.elision#:constructor,copy,elision
Some quote:
> Speaking of RVO, return std::move(w); prohibits it. It means "use move constructor or fail to compile", whereas return w; means "use RVO, and if you can't, use move constructor, and if you can't, use copy constructor, and if you can't, fail to compile."
There is one exception to this rule:
```cpp
Block FilterBlockInputStream::removeFilterIfNeed(Block && block)
{
if (block && remove_filter)
block.erase(static_cast<size_t>(filter_column));
return std::move(block);
}
```
because references are not eligible for NRVO, which is another rule "always move rvalue references and forward universal references" that takes precedence.
2018-08-27 14:04:22 +00:00
|
|
|
return clone;
|
2017-06-18 05:44:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ASTExpressionList::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
|
|
|
{
|
2020-09-08 20:34:10 +00:00
|
|
|
if (frame.expression_list_prepend_whitespace)
|
|
|
|
settings.ostr << ' ';
|
|
|
|
|
2017-06-18 05:44:09 +00:00
|
|
|
for (ASTs::const_iterator it = children.begin(); it != children.end(); ++it)
|
|
|
|
{
|
|
|
|
if (it != children.begin())
|
2019-10-07 16:23:16 +00:00
|
|
|
{
|
|
|
|
if (separator)
|
|
|
|
settings.ostr << separator;
|
|
|
|
settings.ostr << ' ';
|
|
|
|
}
|
2017-06-18 05:44:09 +00:00
|
|
|
|
|
|
|
(*it)->formatImpl(settings, state, frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ASTExpressionList::formatImplMultiline(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const
|
|
|
|
{
|
|
|
|
std::string indent_str = "\n" + std::string(4 * (frame.indent + 1), ' ');
|
|
|
|
|
2020-09-08 20:34:10 +00:00
|
|
|
if (frame.expression_list_prepend_whitespace)
|
|
|
|
{
|
|
|
|
if (!(children.size() > 1 || frame.expression_list_always_start_on_new_line))
|
|
|
|
settings.ostr << ' ';
|
|
|
|
}
|
|
|
|
|
2017-06-18 05:44:09 +00:00
|
|
|
++frame.indent;
|
|
|
|
for (ASTs::const_iterator it = children.begin(); it != children.end(); ++it)
|
|
|
|
{
|
|
|
|
if (it != children.begin())
|
2019-10-07 16:23:16 +00:00
|
|
|
{
|
|
|
|
if (separator)
|
|
|
|
settings.ostr << separator;
|
|
|
|
}
|
|
|
|
|
2020-06-15 04:27:33 +00:00
|
|
|
if (children.size() > 1 || frame.expression_list_always_start_on_new_line)
|
2017-06-18 05:44:09 +00:00
|
|
|
settings.ostr << indent_str;
|
|
|
|
|
2020-06-15 04:27:33 +00:00
|
|
|
FormatStateStacked frame_nested = frame;
|
|
|
|
frame_nested.expression_list_always_start_on_new_line = false;
|
|
|
|
(*it)->formatImpl(settings, state, frame_nested);
|
2017-06-18 05:44:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|