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


C++ AST::set_use_for_templates方法代码示例

本文整理汇总了C++中AST::set_use_for_templates方法的典型用法代码示例。如果您正苦于以下问题:C++ AST::set_use_for_templates方法的具体用法?C++ AST::set_use_for_templates怎么用?C++ AST::set_use_for_templates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AST的用法示例。


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

示例1: handle_template

int context_parser::handle_template(definition_scope *scope, token_t& token, unsigned inherited_flags)
{
  token = read_next_token(scope);
  if (token.type != TT_LESSTHAN) {
    token.report_error(herr, "Expected opening triangle bracket following `template' token");
    return ERROR_CODE;
  }
  token = read_next_token(scope);
  
  definition_template* temp = new definition_template("", scope, DEF_TEMPLATE | inherited_flags);
  
  for (;;) {
    string pname; // The name given to this parameter
    unsigned dtpflags = DEF_TEMPPARAM | DEF_DEPENDENT;
    
    definition_tempparam* dtn;
    if (token.type == TT_TYPENAME || token.type == TT_CLASS || token.type == TT_STRUCT) {
      token = lex->get_token(herr);
      if (token.type == TT_IDENTIFIER) {
        pname = token.content.toString();
        token = read_next_token(temp);
      }
      dtpflags |= DEF_TYPENAME;
    }
    else if (token.type == TT_DECFLAG || token.type == TT_DECLARATOR || token.type == TT_DECLTYPE) {
      full_type fts = read_fulltype(token, temp);
      pname = fts.refs.name;
    }
    else {
      if (token.type == TT_GREATERTHAN) break;
      token.report_errorf(herr, "Expected '>' token here before %s");
      FATAL_RETURN((delete temp, 1));
      break;
    }
    
    AST *ast = NULL;
    if (token.type == TT_OPERATOR) {
      if (token.content.len != 1 or *token.content.str != '=') {
        token.report_error(herr, "Unexpected operator here; value must be denoted by '='");
        FATAL_RETURN((void(delete temp),1));
      }
      token = read_next_token(temp);
      ast = new AST();
      ast->set_use_for_templates(true);
      astbuilder->parse_expression(ast, token, temp, precedence::comma+1);
    }
    dtn = new definition_tempparam(pname, temp, ast, dtpflags);
    
    temp->params.push_back(dtn);
    if (pname.empty()) {
      char nname[32];
      sprintf(nname, "<templateParam%03u>", (unsigned)temp->params.size());
    }
    else
      temp->use_general(pname, dtn);
    if (token.type == TT_GREATERTHAN)
      break;
    if (token.type != TT_COMMA)
      token.report_errorf(herr, "Expected '>' or ',' before %s");
    token = read_next_token(temp);
  }
  
  token = read_next_token(temp);
  
  // ========================================================================================================================================
  // =====: Handle template class definitions :==============================================================================================
  // ========================================================================================================================================
  
  if (token.type == TT_CLASS || token.type == TT_STRUCT)
  {
    unsigned protection = token.type == TT_CLASS? DEF_PRIVATE : 0;
    token = read_next_token(scope);
    definition_class *tclass;
    
    if (token.type == TT_IDENTIFIER) {
      regular_identifier:
      temp->name = token.content.toString();
      tclass = new definition_class(temp->name, temp, DEF_CLASS | DEF_TYPENAME);
      temp->def = tclass;
    
      scope->declare(temp->name, temp);
      
      token = read_next_token(scope);
      regular_template_class:
      
      if (token.type == TT_COLON) {
        if (handle_class_inheritance(tclass, token, tclass, protection))
          return 1;
      }
      
      if (token.type != TT_LEFTBRACE) {
        if (token.type == TT_SEMICOLON) {
          tclass->flags |= DEF_INCOMPLETE;
          return 0;
        }
        token.report_errorf(herr, "Opening brace for class body expected before %s");
        return 1;
      }
      
      if (handle_scope(tclass, token, protection))
//.........这里部分代码省略.........
开发者ID:enigma-dev,项目名称:enigma-dev,代码行数:101,代码来源:handle_templates.cpp


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