当前位置: 首页>>代码示例>>C++>>正文


C++ ASTPtr类代码示例

本文整理汇总了C++中ASTPtr的典型用法代码示例。如果您正苦于以下问题:C++ ASTPtr类的具体用法?C++ ASTPtr怎么用?C++ ASTPtr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ASTPtr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: visit

void ExecuteScalarSubqueriesMatcher::visit(ASTPtr & ast, Data & data)
{
    if (auto * t = typeid_cast<ASTSubquery *>(ast.get()))
        visit(*t, ast, data);
    if (auto * t = typeid_cast<ASTFunction *>(ast.get()))
        visit(*t, ast, data);
}
开发者ID:greck2908,项目名称:ClickHouse,代码行数:7,代码来源:ExecuteScalarSubqueriesVisitor.cpp

示例2: and

AnalyzeLambdas::LambdaParameters AnalyzeLambdas::extractLambdaParameters(ASTPtr & ast)
{
    /// Lambda parameters could be specified in AST in two forms:
    /// - just as single parameter: x -> x + 1
    /// - parameters in tuple: (x, y) -> x + 1

#define LAMBDA_ERROR_MESSAGE " There are two valid forms of lambda expressions: x -> ... and (x, y...) -> ..."

    if (!ast->tryGetAlias().empty())
        throw Exception("Lambda parameters cannot have aliases."
            LAMBDA_ERROR_MESSAGE, ErrorCodes::BAD_LAMBDA);

    if (const ASTIdentifier * identifier = typeid_cast<const ASTIdentifier *>(ast.get()))
    {
        return { identifier->name };
    }
    else if (const ASTFunction * function = typeid_cast<const ASTFunction *>(ast.get()))
    {
        if (function->name != "tuple")
            throw Exception("Left hand side of '->' or first argument of 'lambda' is a function, but this function is not tuple."
                LAMBDA_ERROR_MESSAGE " Found function '" + function->name + "' instead.", ErrorCodes::BAD_LAMBDA);

        if (!function->arguments || function->arguments->children.empty())
            throw Exception("Left hand side of '->' or first argument of 'lambda' is empty tuple."
                LAMBDA_ERROR_MESSAGE, ErrorCodes::BAD_LAMBDA);

        LambdaParameters res;
        res.reserve(function->arguments->children.size());

        for (const ASTPtr & arg : function->arguments->children)
        {
            const ASTIdentifier * arg_identifier = typeid_cast<const ASTIdentifier *>(arg.get());

            if (!arg_identifier)
                throw Exception("Left hand side of '->' or first argument of 'lambda' contains something that is not just identifier."
                    LAMBDA_ERROR_MESSAGE, ErrorCodes::BAD_LAMBDA);

            if (!arg_identifier->children.empty())
                throw Exception("Left hand side of '->' or first argument of 'lambda' contains compound identifier."
                    LAMBDA_ERROR_MESSAGE, ErrorCodes::BAD_LAMBDA);

            if (!arg_identifier->alias.empty())
                throw Exception("Lambda parameters cannot have aliases."
                    LAMBDA_ERROR_MESSAGE, ErrorCodes::BAD_LAMBDA);

            res.emplace_back(arg_identifier->name);
        }

        return res;

    }
    else
        throw Exception("Unexpected left hand side of '->' or first argument of 'lambda'."
            LAMBDA_ERROR_MESSAGE, ErrorCodes::BAD_LAMBDA);

#undef LAMBDA_ERROR_MESSAGE
}
开发者ID:bamx23,项目名称:ClickHouse,代码行数:57,代码来源:AnalyzeLambdas.cpp

示例3: extractValueFromNode

static Field extractValueFromNode(ASTPtr & node, const IDataType & type, const Context & context)
{
	if (ASTLiteral * lit = typeid_cast<ASTLiteral *>(node.get()))
		return convertFieldToType(lit->value, type);
	else if (typeid_cast<ASTFunction *>(node.get()))
		return convertFieldToType(evaluateConstantExpression(node, context), type);
	else
		throw Exception("Incorrect element of set. Must be literal or constant expression.", ErrorCodes::INCORRECT_ELEMENT_OF_SET);
}
开发者ID:DieHertz,项目名称:ClickHouse,代码行数:9,代码来源:Set.cpp

示例4: extractFunctions

/// Extract all subfunctions of the main conjunction, but depending only on the specified columns
static void extractFunctions(const ASTPtr & expression, const NameSet & columns, std::vector<ASTPtr> & result)
{
    const ASTFunction * function = typeid_cast<const ASTFunction *>(expression.get());
    if (function && function->name == "and")
    {
        for (size_t i = 0; i < function->arguments->children.size(); ++i)
            extractFunctions(function->arguments->children[i], columns, result);
    }
    else if (isValidFunction(expression, columns))
    {
        result.push_back(expression->clone());
    }
}
开发者ID:kellylg,项目名称:ClickHouse,代码行数:14,代码来源:VirtualColumnUtils.cpp

示例5: parseRepeatedCharFL

static ASTPtr parseRepeatedCharFL(const char** fptr, const LengthFunc** lengthFuncsPtr) {
  assert(**fptr == '#');
  const char* f_at = *fptr;
  ASTPtr ast;
  FunctionLength length = parseFunctionLength(fptr, lengthFuncsPtr);
  if (**fptr == '\'') {
    char c = parseCharLiteral(fptr);
    ast.reset(new RepeatedCharFL(f_at, length, c));
  } else {
    throw DSLException(*fptr, "Expected char literal after function length.");
  }
  return ast;
}
开发者ID:wangyix,项目名称:CS448H,代码行数:13,代码来源:text.cpp

示例6: mayBenefitFromIndexForIn

bool MergeTreeMinMaxIndex::mayBenefitFromIndexForIn(const ASTPtr & node) const
{
    const String column_name = node->getColumnName();

    for (const auto & name : columns)
        if (column_name == name)
            return true;

    if (const auto * func = typeid_cast<const ASTFunction *>(node.get()))
        if (func->arguments->children.size() == 1)
            return mayBenefitFromIndexForIn(func->arguments->children.front());

    return false;
}
开发者ID:shenqsdev,项目名称:ClickHouse,代码行数:14,代码来源:MergeTreeMinMaxIndex.cpp

示例7:

bool ParserWithOptionalAliasImpl<ParserAlias>::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
	ParserWhiteSpaceOrComments ws;

	if (!elem_parser->parse(pos, end, node, max_parsed_pos, expected))
		return false;

	/** Маленький хак.
	  *
	  * В секции SELECT мы разрешаем парсить алиасы без указания ключевого слова AS.
	  * Эти алиасы не могут совпадать с ключевыми словами запроса.
	  * А само выражение может быть идентификатором, совпадающем с ключевым словом.
	  * Например, столбец может называться where. И в запросе может быть написано SELECT where AS x FROM table или даже SELECT where x FROM table.
	  * Даже может быть написано SELECT where AS from FROM table, но не может быть написано SELECT where from FROM table.
	  * Смотрите подробнее в реализации ParserAlias.
	  *
	  * Но возникает небольшая проблема - неудобное сообщение об ошибке, если в секции SELECT в конце есть лишняя запятая.
	  * Хотя такая ошибка очень распространена. Пример: SELECT x, y, z, FROM tbl
	  * Если ничего не предпринять, то это парсится как выбор столбца с именем FROM и алиасом tbl.
	  * Чтобы избежать такой ситуации, мы не разрешаем парсить алиас без ключевого слова AS для идентификатора с именем FROM.
	  *
	  * Замечание: это также фильтрует случай, когда идентификатор квотирован.
	  * Пример: SELECT x, y, z, `FROM` tbl. Но такой случай можно было бы разрешить.
	  *
	  * В дальнейшем было бы проще запретить неквотированные идентификаторы, совпадающие с ключевыми словами.
	  */
	bool allow_alias_without_as_keyword_now = allow_alias_without_as_keyword;
	if (allow_alias_without_as_keyword)
		if (const ASTIdentifier * id = typeid_cast<const ASTIdentifier *>(node.get()))
			if (0 == strcasecmp(id->name.data(), "FROM"))
				allow_alias_without_as_keyword_now = false;

	ws.ignore(pos, end);

	ASTPtr alias_node;
	if (ParserAlias(allow_alias_without_as_keyword_now).parse(pos, end, alias_node, max_parsed_pos, expected))
	{
		String alias_name = typeid_cast<ASTIdentifier &>(*alias_node).name;

		if (ASTWithAlias * ast_with_alias = dynamic_cast<ASTWithAlias *>(node.get()))
			ast_with_alias->alias = alias_name;
		else
		{
			expected = "alias cannot be here";
			return false;
		}
	}

	return true;
}
开发者ID:allookin,项目名称:ClickHouse,代码行数:50,代码来源:ExpressionElementParsers.cpp

示例8: getTableDefinitionFromCreateQuery

String getTableDefinitionFromCreateQuery(const ASTPtr & query)
{
    ASTPtr query_clone = query->clone();
    ASTCreateQuery & create = typeid_cast<ASTCreateQuery &>(*query_clone.get());

    /// We remove everything that is not needed for ATTACH from the query.
    create.attach = true;
    create.database.clear();
    create.as_database.clear();
    create.as_table.clear();
    create.if_not_exists = false;
    create.is_populate = false;

    /// For views it is necessary to save the SELECT query itself, for the rest - on the contrary
    if (!create.is_view && !create.is_materialized_view)
        create.select = nullptr;

    create.format = nullptr;
    create.out_file = nullptr;

    std::ostringstream statement_stream;
    formatAST(create, statement_stream, false);
    statement_stream << '\n';
    return statement_stream.str();
}
开发者ID:chipitsine,项目名称:ClickHouse,代码行数:25,代码来源:DatabasesCommon.cpp

示例9: s_as

bool ParserAliasImpl<ParserIdentifier>::parseImpl(Pos & pos, Pos end, ASTPtr & node, Pos & max_parsed_pos, Expected & expected)
{
	ParserWhiteSpaceOrComments ws;
	ParserString s_as("AS", true, true);
	ParserIdentifier id_p;

	bool has_as_word = s_as.parse(pos, end, node, max_parsed_pos, expected);
	if (!allow_alias_without_as_keyword && !has_as_word)
		return false;

	ws.ignore(pos, end);

	if (!id_p.parse(pos, end, node, max_parsed_pos, expected))
		return false;

	if (!has_as_word)
	{
		/** В этом случае алиас не может совпадать с ключевым словом - для того,
		  *  чтобы в запросе "SELECT x FROM t", слово FROM не считалось алиасом,
		  *  а в запросе "SELECT x FRO FROM t", слово FRO считалось алиасом.
		  */

		const String & name = static_cast<const ASTIdentifier &>(*node.get()).name;

		for (const char ** keyword = restricted_keywords; *keyword != nullptr; ++keyword)
			if (0 == strcasecmp(name.data(), *keyword))
				return false;
	}

	return true;
}
开发者ID:allookin,项目名称:ClickHouse,代码行数:31,代码来源:ExpressionElementParsers.cpp

示例10: parseSpecifiedLengthContent

static ASTPtr parseSpecifiedLengthContent(const char** fptr, const char*** wordSourcesPtr, const LengthFunc** lengthFuncsPtr) {
  assert(**fptr == '\'' || std::isdigit(**fptr) || **fptr == '#');
  ASTPtr slc;
  if (**fptr == '\'') {
    slc = parseStringLiteral(fptr);
  } else if (**fptr == '#') {
    slc = parseRepeatedCharFL(fptr, lengthFuncsPtr);
  } else {
    const char* f_at = *fptr;
    LiteralLength length = parseLiteralLength(fptr);
    if (**fptr == '\'') {
      slc.reset(new RepeatedCharLL(f_at, length, parseCharLiteral(fptr)));
    } else if (**fptr == '[') {
      Block* block = new Block(f_at, length);
      slc.reset(block);
      ++*fptr;
      parseWhitespaces(fptr); // [ is a token
      while (**fptr != ']') {
        if (**fptr == '\'' || std::isdigit(**fptr) || **fptr == '#') {
          block->addChild(parseSpecifiedLengthContent(fptr, wordSourcesPtr, lengthFuncsPtr));
        } else if (**fptr == '{') {
          block->addWords(parseWords(fptr, wordSourcesPtr));
        } else {
          throw DSLException(*fptr, "Expected ', digit, or # to begin specified-length content, "
            "or { to begin greedy-length content.");
        }
      }
      ++*fptr;
      parseWhitespaces(fptr); // ] is a token
      if (**fptr == '^') {
        parseTopOrBottomFiller(fptr, &block->topFillers, true);
        if (**fptr == 'v') {
          parseTopOrBottomFiller(fptr, &block->bottomFillers, false);
        }
      } else if (**fptr == 'v') {
        parseTopOrBottomFiller(fptr, &block->bottomFillers, false);
        if (**fptr == '^') {
          parseTopOrBottomFiller(fptr, &block->topFillers, true);
        }
      }
    } else {
      throw DSLException(*fptr, "Expected ' or [ after length specifier.");
    }
  }
  return slc;
}
开发者ID:wangyix,项目名称:CS448H,代码行数:46,代码来源:text.cpp

示例11: processImpl

static void processImpl(const ASTPtr & ast, CollectAliases::Aliases & aliases, CollectAliases::Kind kind, size_t keep_kind_for_depth)
{
	String alias = ast->tryGetAlias();
	if (!alias.empty())
	{
		auto it_inserted = aliases.emplace(alias, CollectAliases::AliasInfo(ast, kind));

		if (!it_inserted.second && ast->getTreeHash() != it_inserted.first->second.node->getTreeHash())
		{
			std::stringstream message;
			message << "Different expressions with the same alias " << backQuoteIfNeed(alias) << ":\n";
			formatAST(*it_inserted.first->second.node, message, 0, false, true);
			message << "\nand\n";
			formatAST(*ast, message, 0, false, true);
			message << "\n";

			throw Exception(message.str(), ErrorCodes::MULTIPLE_EXPRESSIONS_FOR_ALIAS);
		}
	}

	for (auto & child : ast->children)
	{
		if (typeid_cast<const ASTSelectQuery *>(child.get()))
		{
			/// Don't go into subqueries.
		}
		else if (typeid_cast<const ASTTableExpression *>(child.get()))
		{
			processImpl(child, aliases, CollectAliases::Kind::Table, 1);
		}
		else if (typeid_cast<const ASTArrayJoin *>(child.get()))
		{
			/// ASTArrayJoin -> ASTExpressionList -> element of expression AS alias
			processImpl(child, aliases, CollectAliases::Kind::ArrayJoin, 3);
		}
		else if (keep_kind_for_depth > 0)
		{
			processImpl(child, aliases, kind, keep_kind_for_depth - 1);
		}
		else
		{
			processImpl(child, aliases, CollectAliases::Kind::Expression, 0);
		}
	}
}
开发者ID:jacktang,项目名称:ClickHouse,代码行数:45,代码来源:CollectAliases.cpp

示例12: parseFormat

static ASTPtr parseFormat(const char** fptr, const char*** wordSourcesPtr, const LengthFunc** lengthFuncsPtr) {
  parseWhitespaces(fptr);
  // Will insert all root content as children into a super-root Block.
  Block* rootsParentBlock = new Block(*fptr, LiteralLength(0, false));
  ASTPtr rootsParent(rootsParentBlock);
  while (**fptr != '\0') {
    if (**fptr == '\'' || std::isdigit(**fptr)) {
      ASTPtr root = parseSpecifiedLengthContent(fptr, wordSourcesPtr, lengthFuncsPtr);
      int rootLength = root->getFixedLength();
      if (rootLength == UNKNOWN_COL) {
        throw DSLException(root->f_at, "Root content must be fixed-length.");
      }
      rootsParentBlock->addChild(std::move(root));
      rootsParentBlock->length.value += rootLength;
    } else {
      throw DSLException(*fptr, "Expected ' or digit.");
    }
  }
  return rootsParent;
}
开发者ID:wangyix,项目名称:CS448H,代码行数:20,代码来源:text.cpp

示例13: needChildVisit

bool ExecuteScalarSubqueriesMatcher::needChildVisit(ASTPtr & node, const ASTPtr & child)
{
    /// Processed
    if (typeid_cast<ASTSubquery *>(node.get()) ||
        typeid_cast<ASTFunction *>(node.get()))
        return false;

    /// Don't descend into subqueries in FROM section
    if (typeid_cast<ASTTableExpression *>(node.get()))
        return false;

    if (typeid_cast<ASTSelectQuery *>(node.get()))
    {
        /// Do not go to FROM, JOIN, UNION.
        if (typeid_cast<ASTTableExpression *>(child.get()) ||
            typeid_cast<ASTSelectQuery *>(child.get()))
            return false;
    }

    return true;
}
开发者ID:greck2908,项目名称:ClickHouse,代码行数:21,代码来源:ExecuteScalarSubqueriesVisitor.cpp

示例14: generateCCs

static ASTPtr generateCCs(std::vector<ConsistentContent>* ccs, const char* format, const char*** wordSourcesPtr, const LengthFunc** lengthFuncsPtr, va_list args) {
  ccs->clear();
  std::string evaluatedFormat;
  vsprintf(&evaluatedFormat, format, args);
  const char* f_begin = evaluatedFormat.c_str();
  const char* f_at = f_begin;
  ASTPtr root;
  try {
    //printf("\n\n%s\n", format);

    root = parseFormat(&f_at, wordSourcesPtr, lengthFuncsPtr);
    root->convertLLSharesToLength();
    root->computeStartEndCols(0, root->getFixedLength());

    std::vector<FillerPtr> topFillersStack, bottomFillersStack;
    root->flatten(root, root, ccs, true, &topFillersStack, &bottomFillersStack);
    //root->print();
    //printf("\n");

    for (ConsistentContent& cc : *ccs) {
      cc.generateCCLines();
    }

    root->computeNumContentLines();
    root->computeNumTotalLines(true);
    root->computeBlockVerticalFillersShares();

    //printf("\n");
    for (ConsistentContent& cc : *ccs) {
      /*printf("\n");
      cc.print();
      printf("\n");
      printf("content: %d  fixed: %d  total: %d\n", cc.srcAst->numContentLines, cc.srcAst->numFixedLines, cc.srcAst->numTotalLines);*/
      cc.generateLinesChars(root->numTotalLines);
    }
    //printf("\n\n");

  } catch (DSLException& e) {
    fprintf(stderr, "%s\n", f_begin);
    for (int i = 0; i < e.f_at - f_begin; ++i) {
      fputc(' ', stderr);
    }
    fprintf(stderr, "^\n");
    fprintf(stderr, "Error at %d: %s\n", e.f_at - f_begin, e.what());
    
    return ASTPtr();
  }

  return root;
}
开发者ID:wangyix,项目名称:CS448H,代码行数:50,代码来源:text.cpp

示例15: process

void AnalyzeColumns::process(ASTPtr & ast, const CollectAliases & aliases, const CollectTables & tables)
{
    /// If this is SELECT query, don't go into FORMAT and SETTINGS clauses
    /// - they contain identifiers that are not columns.
    const ASTSelectQuery * select = typeid_cast<const ASTSelectQuery *>(ast.get());

    for (auto & child : ast->children)
    {
        if (select && (child.get() == select->format.get() || child.get() == select->settings.get()))
            continue;

        processImpl(child, columns, aliases, tables);
    }
}
开发者ID:bamx23,项目名称:ClickHouse,代码行数:14,代码来源:AnalyzeColumns.cpp


注:本文中的ASTPtr类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。