2011-08-09 19:19:00 +00:00
|
|
|
|
#pragma once
|
2010-06-24 19:12:10 +00:00
|
|
|
|
|
|
|
|
|
#include <list>
|
2011-08-09 19:19:00 +00:00
|
|
|
|
#include <sstream>
|
|
|
|
|
|
2010-06-24 19:12:10 +00:00
|
|
|
|
#include <Poco/SharedPtr.h>
|
|
|
|
|
|
|
|
|
|
#include <DB/Core/Types.h>
|
|
|
|
|
#include <DB/Parsers/StringRange.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
using Poco::SharedPtr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Элемент синтаксического дерева (в дальнейшем - направленного ациклического графа с элементами семантики)
|
|
|
|
|
*/
|
|
|
|
|
class IAST
|
2011-08-13 21:05:18 +00:00
|
|
|
|
{
|
2010-06-24 19:12:10 +00:00
|
|
|
|
public:
|
2011-08-09 19:19:00 +00:00
|
|
|
|
typedef std::list<SharedPtr<IAST> > ASTs;
|
2011-08-13 21:05:18 +00:00
|
|
|
|
ASTs children;
|
|
|
|
|
StringRange range;
|
|
|
|
|
/// Было ли соответствующее выражение вычислено.
|
|
|
|
|
bool calculated;
|
2011-08-09 19:19:00 +00:00
|
|
|
|
|
|
|
|
|
|
2011-08-13 21:05:18 +00:00
|
|
|
|
IAST() : range(NULL, NULL), calculated(false) {}
|
|
|
|
|
IAST(StringRange range_) : range(range_), calculated(false) {}
|
|
|
|
|
virtual ~IAST() {}
|
|
|
|
|
|
2011-08-09 19:19:00 +00:00
|
|
|
|
/** Получить текст, который идентифицирует этот элемент. */
|
|
|
|
|
virtual String getID() = 0;
|
|
|
|
|
|
|
|
|
|
/** Получить текст, который идентифицирует этот элемент и всё поддерево.
|
|
|
|
|
* Обычно он содержит идентификатор элемента и getTreeID от всех детей.
|
|
|
|
|
*/
|
2011-08-13 21:05:18 +00:00
|
|
|
|
String getTreeID()
|
2011-08-09 19:19:00 +00:00
|
|
|
|
{
|
|
|
|
|
std::stringstream s;
|
|
|
|
|
s << getID();
|
|
|
|
|
|
|
|
|
|
if (!children.empty())
|
|
|
|
|
{
|
|
|
|
|
s << "(";
|
|
|
|
|
for (ASTs::iterator it = children.begin(); it != children.end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if (it != children.begin())
|
|
|
|
|
s << ", ";
|
|
|
|
|
s << (*it)->getTreeID();
|
|
|
|
|
}
|
|
|
|
|
s << ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return s.str();
|
|
|
|
|
}
|
2010-06-24 19:12:10 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2011-08-09 19:19:00 +00:00
|
|
|
|
typedef SharedPtr<IAST> ASTPtr;
|
2010-06-24 19:12:10 +00:00
|
|
|
|
typedef std::list<ASTPtr> ASTs;
|
|
|
|
|
|
|
|
|
|
}
|