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


C++ symbolt::display_name方法代码示例

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


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

示例1: handle_initializer

void cpp_declarator_convertert::handle_initializer(
    symbolt &symbol,
    cpp_declaratort &declarator)
{
    exprt &value=declarator.value();

    // moves member initializers into 'value'
    cpp_typecheck.move_member_initializers(
        declarator.member_initializers(),
        symbol.type,
        value);

    // any initializer to be done?
    if(value.is_nil())
        return;

    if(symbol.is_extern)
    {
        // the symbol is really located here
        symbol.is_extern=false;
    }

    if(symbol.value.is_nil())
    {
        // no initial value yet
        symbol.value.swap(value);

        if(is_code && declarator.type().id()!=ID_template)
            cpp_typecheck.add_function_body(&symbol);

        if(!is_code)
            cpp_typecheck.convert_initializer(symbol);
    }
    else
    {
#if 0
        cpp_typecheck.err_location(declarator.name());

        if(is_code)
            cpp_typecheck.str << "body of function `"
                              << symbol.display_name()
                              << "' has already been defined";
        else
            cpp_typecheck.str << "symbol `"
                              << symbol.display_name()
                              << "' already has an initializer";

        throw 0;
#endif
    }
}
开发者ID:sarnold,项目名称:cbmc,代码行数:51,代码来源:cpp_declarator_converter.cpp

示例2: combine_types

void cpp_declarator_convertert::combine_types(
    const source_locationt &source_location,
    const typet &decl_type,
    symbolt &symbol)
{
    if(symbol.type.id()==decl_type.id() &&
            decl_type.id()==ID_code)
    {
        // functions need special treatment due
        // to argument names, default values, and inlined-ness
        const code_typet &decl_code_type=to_code_type(decl_type);
        code_typet &symbol_code_type=to_code_type(symbol.type);

        if(decl_code_type.get_inlined())
            symbol_code_type.set_inlined(true);

        if(decl_code_type.return_type()==symbol_code_type.return_type() &&
                decl_code_type.parameters().size()==symbol_code_type.parameters().size())
        {
            for(unsigned i=0; i<decl_code_type.parameters().size(); i++)
            {
                const code_typet::parametert &decl_parameter=decl_code_type.parameters()[i];
                code_typet::parametert &symbol_parameter=symbol_code_type.parameters()[i];

                // first check type
                if(decl_parameter.type()!=symbol_parameter.type())
                {
                    // The 'this' parameter of virtual functions mismatches
                    if(i!=0 || !symbol_code_type.get_bool("#is_virtual"))
                    {
                        cpp_typecheck.err_location(source_location);
                        cpp_typecheck.str << "symbol `" << symbol.display_name()
                                          << "': parameter " << (i+1) << " type mismatch"
                                          << std::endl;
                        cpp_typecheck.str << "previous type: "
                                          << cpp_typecheck.to_string(symbol_parameter.type()) << std::endl;
                        cpp_typecheck.str << "new type: "
                                          << cpp_typecheck.to_string(decl_parameter.type());
                        throw 0;
                    }
                }

                if(symbol.value.is_nil())
                {
                    symbol_parameter.set_base_name(decl_parameter.get_base_name());
                    symbol_parameter.set_identifier(decl_parameter.get_identifier());
                    symbol_parameter.add_source_location()=decl_parameter.source_location();
                }
            }

            // ok
            return;
        }
    }
    else if(symbol.type==decl_type)
        return; // ok
    else if(symbol.type.id()==ID_array &&
            symbol.type.find(ID_size).is_nil() &&
            decl_type.id()==ID_array &&
            symbol.type.subtype()==decl_type.subtype())
    {
        symbol.type = decl_type;
        return; // ok
    }

    cpp_typecheck.err_location(source_location);
    cpp_typecheck.str << "symbol `" << symbol.display_name()
                      << "' already declared with different type:"
                      << std::endl;
    cpp_typecheck.str << "original: "
                      << cpp_typecheck.to_string(symbol.type) << std::endl;
    cpp_typecheck.str << "     new: "
                      << cpp_typecheck.to_string(final_type);
    throw 0;
}
开发者ID:sarnold,项目名称:cbmc,代码行数:75,代码来源:cpp_declarator_converter.cpp

示例3: typecheck_symbol

void c_typecheck_baset::typecheck_symbol(symbolt &symbol)
{
  current_symbol_id=symbol.name;

  bool is_function=symbol.type.id()==ID_code;

  const typet &final_type=follow(symbol.type);
  
  // set a few flags
  symbol.is_lvalue=!symbol.is_type && !symbol.is_macro;
  
  irep_idt root_name=symbol.base_name;
  irep_idt new_name=symbol.name;

  if(symbol.is_file_local)
  {
    // file-local stuff -- stays as is
    // collisions are resolved during linking
  }
  else if(symbol.is_extern && !is_function)
  {
    // variables marked as "extern" go into the global namespace
    // and have static lifetime
    new_name=root_name;
    symbol.is_static_lifetime=true;
  }
  else if(!is_function && symbol.value.id()==ID_code)
  {
    err_location(symbol.value);
    throw "only functions can have a function body";
  }
  
  // set the pretty name
  if(symbol.is_type &&
     (final_type.id()==ID_struct ||
      final_type.id()==ID_incomplete_struct))
  {
    symbol.pretty_name="struct "+id2string(symbol.base_name);
  }
  else if(symbol.is_type &&
          (final_type.id()==ID_union ||
           final_type.id()==ID_incomplete_union))
  {
    symbol.pretty_name="union "+id2string(symbol.base_name);
  }
  else if(symbol.is_type &&
          (final_type.id()==ID_c_enum ||
           final_type.id()==ID_incomplete_c_enum))
  {
    symbol.pretty_name="enum "+id2string(symbol.base_name);
  }
  else
  {
    symbol.pretty_name=new_name;
  }
  
  // see if we have it already
  symbol_tablet::symbolst::iterator old_it=symbol_table.symbols.find(symbol.name);
  
  if(old_it==symbol_table.symbols.end())
  {
    // just put into symbol_table
    symbolt *new_symbol;
    move_symbol(symbol, new_symbol);
    
    typecheck_new_symbol(*new_symbol);
  }    
  else
  {
    if(old_it->second.is_type!=symbol.is_type)
    {
      err_location(symbol.location);
      str << "redeclaration of `" << symbol.display_name()
          << "' as a different kind of symbol";
      throw 0;
    }

    if(symbol.is_type)
      typecheck_redefinition_type(old_it->second, symbol);
    else
      typecheck_redefinition_non_type(old_it->second, symbol);
  }
}
开发者ID:Dthird,项目名称:CBMC,代码行数:83,代码来源:c_typecheck_base.cpp

示例4: typecheck_redefinition_non_type

void c_typecheck_baset::typecheck_redefinition_non_type(
  symbolt &old_symbol,
  symbolt &new_symbol)
{
  const typet &final_old=follow(old_symbol.type);
  const typet &initial_new=follow(new_symbol.type);

  if(final_old.id()==ID_array &&
     to_array_type(final_old).size().is_not_nil() &&
     initial_new.id()==ID_array &&
     to_array_type(initial_new).size().is_nil() &&
     final_old.subtype()==initial_new.subtype())
  {
    // this is ok, just use old type
    new_symbol.type=old_symbol.type;
  }

  // do initializer, this may change the type
  if(follow(new_symbol.type).id()!=ID_code)
    do_initializer(new_symbol);
  
  const typet &final_new=follow(new_symbol.type);
  
  // K&R stuff?
  if(old_symbol.type.id()==ID_KnR)
  {
    // check the type
    if(final_new.id()==ID_code)
    {
      err_location(new_symbol.location);
      throw "function type not allowed for K&R function parameter";
    }
    
    // fix up old symbol -- we now got the type
    old_symbol.type=new_symbol.type;
    return;
  }
  
  if(final_new.id()==ID_code)
  {
    bool inlined=
       (new_symbol.type.get_bool(ID_C_inlined) ||
        old_symbol.type.get_bool(ID_C_inlined));
        
    if(final_old.id()!=ID_code)
    {
      err_location(new_symbol.location);
      str << "error: function symbol `" << new_symbol.display_name()
          << "' redefined with a different type:" << "\n";
      str << "Original: " << to_string(old_symbol.type) << "\n";
      str << "     New: " << to_string(new_symbol.type);
      throw 0;
    }

    code_typet &old_ct=to_code_type(old_symbol.type);
    code_typet &new_ct=to_code_type(new_symbol.type);
    
    if(old_ct.has_ellipsis() && !new_ct.has_ellipsis())
      old_ct=new_ct;
    else if(!old_ct.has_ellipsis() && new_ct.has_ellipsis())
      new_ct=old_ct;

    if(inlined)
    {
      old_symbol.type.set(ID_C_inlined, true);
      new_symbol.type.set(ID_C_inlined, true);
    }

    // do body
    
    if(new_symbol.value.is_not_nil())
    {  
      if(old_symbol.value.is_not_nil())
      {
        // gcc allows re-definition if the first
        // definition is marked as "extern inline"
        
        if(old_symbol.type.get_bool(ID_C_inlined) &&
           (config.ansi_c.mode==configt::ansi_ct::flavourt::MODE_GCC_C ||
            config.ansi_c.mode==configt::ansi_ct::flavourt::MODE_ARM_C_CPP))
        {
          // overwrite "extern inline" properties
          old_symbol.is_extern=new_symbol.is_extern;
          old_symbol.is_file_local=new_symbol.is_file_local;

          // remove parameter declarations to avoid conflicts
          const code_typet::parameterst &old_p=old_ct.parameters();
          for(code_typet::parameterst::const_iterator
              p_it=old_p.begin();
              p_it!=old_p.end();
              p_it++)
          {
            const irep_idt &identifier=p_it->get_identifier();

            symbol_tablet::symbolst::iterator p_s_it=
              symbol_table.symbols.find(identifier);
            if(p_s_it!=symbol_table.symbols.end())
              symbol_table.symbols.erase(p_s_it);
          }
        }
//.........这里部分代码省略.........
开发者ID:Dthird,项目名称:CBMC,代码行数:101,代码来源:c_typecheck_base.cpp

示例5: typecheck_redefinition_type

void c_typecheck_baset::typecheck_redefinition_type(
  symbolt &old_symbol,
  symbolt &new_symbol)
{
  const typet &final_old=follow(old_symbol.type);
  const typet &final_new=follow(new_symbol.type);

  // see if we had s.th. incomplete before
  if(final_old.id()==ID_incomplete_struct ||
     final_old.id()==ID_incomplete_union ||
     final_old.id()==ID_incomplete_c_enum)
  {
    // new one complete?
    if("incomplete_"+final_new.id_string()==final_old.id_string())
    {
      // overwrite location
      old_symbol.location=new_symbol.location;
      
      // move body
      old_symbol.type.swap(new_symbol.type);
    }
    else if(new_symbol.type.id()==old_symbol.type.id())
      return;
    else
    {
      err_location(new_symbol.location);
      str << "error: conflicting definition of type symbol `"
          << new_symbol.display_name()
          << "'";
      throw 0;
    }
  }
  else
  {
    // see if new one is just a tag
    if(final_new.id()==ID_incomplete_struct ||
       final_new.id()==ID_incomplete_union ||
       final_new.id()==ID_incomplete_c_enum)
    {
      if("incomplete_"+final_old.id_string()==final_new.id_string())
      {
        // just ignore silently  
      }
      else
      {
        // arg! new tag type
        err_location(new_symbol.location);
        str << "error: conflicting definition of tag symbol `"
            << new_symbol.display_name()
            << "'";
        throw 0;
      }
    }
    else if(config.ansi_c.os==configt::ansi_ct::ost::OS_WIN &&
            final_new.id()==ID_c_enum && final_old.id()==ID_c_enum)              
    {        
      // under Windows, ignore this silently;
      // MSC doesn't think this is a problem, but GCC complains.
    }
    else if(config.ansi_c.os==configt::ansi_ct::ost::OS_WIN &&
            final_new.id()==ID_pointer && final_old.id()==ID_pointer &&
            follow(final_new.subtype()).id()==ID_c_enum &&
            follow(final_old.subtype()).id()==ID_c_enum)
    {
      // under Windows, ignore this silently;
      // MSC doesn't think this is a problem, but GCC complains.
    }
    else
    {
      // see if it changed
      if(follow(new_symbol.type)!=follow(old_symbol.type))
      {
        err_location(new_symbol.location);
        str << "error: type symbol `" << new_symbol.display_name()
            << "' defined twice:" << "\n";
        str << "Original: " << to_string(old_symbol.type) << "\n";
        str << "     New: " << to_string(new_symbol.type);
        throw 0;
      }
    }
  }
}
开发者ID:Dthird,项目名称:CBMC,代码行数:82,代码来源:c_typecheck_base.cpp


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