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


C++ symbolt类代码示例

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


在下文中一共展示了symbolt类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: convert

void xml_symbol_convertt::convert(const symbolt& sym, xmlt &root)
{
  xmlt &xmlsym = root.new_element("symbol");
  irepcache.push_back(irept());
  sym.to_irep(irepcache.back());  
  irepconverter.reference_convert(irepcache.back(), xmlsym);
}
开发者ID:Dthird,项目名称:CBMC,代码行数:7,代码来源:xml_symbol_hashing.cpp

示例3: 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

示例4: if

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

示例5: to_array_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

示例6: 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

示例7: to_symbol

void ansi_c_declarationt::to_symbol(
  const ansi_c_declaratort &declarator,
  symbolt &symbol) const
{
  symbol.clear();    
  symbol.value=declarator.value();
  symbol.type=full_type(declarator);
  symbol.name=declarator.get_name();
  symbol.base_name=declarator.get_base_name();
  symbol.is_type=get_is_typedef();
  symbol.location=declarator.source_location();
  symbol.is_extern=get_is_extern();
  symbol.is_macro=get_is_typedef() || get_is_enum_constant();
  symbol.is_parameter=get_is_parameter();
  
  // is it a function?
  
  if(symbol.type.id()==ID_code && !symbol.is_type)
  {
    symbol.is_static_lifetime=false;
    symbol.is_thread_local=false;

    symbol.is_file_local=get_is_static();
    
    if(get_is_inline())
      symbol.type.set(ID_C_inlined, true);

    if(config.ansi_c.mode==configt::ansi_ct::flavourt::MODE_GCC_C ||
       config.ansi_c.mode==configt::ansi_ct::flavourt::MODE_ARM_C_CPP)
    {
      // GCC extern inline cleanup, to enable remove_internal_symbols
      // do its full job
      // https://gcc.gnu.org/ml/gcc/2006-11/msg00006.html
      // __attribute__((__gnu_inline__))
      if(get_is_inline())
      {
        if(get_is_static()) // C99 and above
          symbol.is_extern=false;
        else  if(get_is_extern()) // traditional GCC
          symbol.is_file_local=true;
      }
    }
  }
  else // non-function
  {
    symbol.is_static_lifetime=
      !symbol.is_macro &&
      !symbol.is_type &&
      (get_is_global() || get_is_static());
      
    symbol.is_thread_local=
      (!symbol.is_static_lifetime && !get_is_extern()) ||
      get_is_thread_local();
       
    symbol.is_file_local=
      symbol.is_macro || 
      (!get_is_global() && !get_is_extern()) ||
      (get_is_global() && get_is_static()) ||
      symbol.is_parameter;
  }
}
开发者ID:Dthird,项目名称:CBMC,代码行数:61,代码来源:ansi_c_declaration.cpp

示例8: convert

void symbol_serializationt::convert(const symbolt& sym, std::ostream &out)
{
  irepcache.push_back(irept());
  sym.to_irep(irepcache.back());  
  irepconverter.reference_convert(irepcache.back(), out);
}
开发者ID:ashokkelur,项目名称:CBMC-With-DSP-C,代码行数:6,代码来源:symbol_serialization.cpp

示例9: java_record_outputs

void java_record_outputs(
  const symbolt &function,
  const exprt::operandst &main_arguments,
  code_blockt &init_code,
  symbol_tablet &symbol_table)
{
  const code_typet::parameterst &parameters=
    to_code_type(function.type).parameters();

  exprt::operandst result;
  result.reserve(parameters.size()+1);

  bool has_return_value=
    to_code_type(function.type).return_type()!=empty_typet();

  if(has_return_value)
  {
    // record return value
    codet output(ID_output);
    output.operands().resize(2);

    const symbolt &return_symbol=symbol_table.lookup("return'");

    output.op0()=
      address_of_exprt(
        index_exprt(
          string_constantt(return_symbol.base_name),
          from_integer(0, index_type())));
    output.op1()=return_symbol.symbol_expr();
    output.add_source_location()=function.location;

    init_code.move_to_operands(output);
  }

  for(std::size_t param_number=0;
      param_number<parameters.size();
      param_number++)
  {
    const symbolt &p_symbol=
      symbol_table.lookup(parameters[param_number].get_identifier());

    if(p_symbol.type.id()==ID_pointer)
    {
      // record as an output
      codet output(ID_output);
      output.operands().resize(2);
      output.op0()=
        address_of_exprt(
          index_exprt(
            string_constantt(p_symbol.base_name),
            from_integer(0, index_type())));
      output.op1()=main_arguments[param_number];
      output.add_source_location()=function.location;

      init_code.move_to_operands(output);
    }
  }

  // record exceptional return variable as output
  codet output(ID_output);
  output.operands().resize(2);

  assert(symbol_table.has_symbol(id2string(function.name)+EXC_SUFFIX));

  // retrieve the exception variable
  const symbolt exc_symbol=symbol_table.lookup(
    id2string(function.name)+EXC_SUFFIX);

  output.op0()=address_of_exprt(
    index_exprt(string_constantt(exc_symbol.base_name),
                from_integer(0, index_type())));
  output.op1()=exc_symbol.symbol_expr();
  output.add_source_location()=function.location;

  init_code.move_to_operands(output);
}
开发者ID:danpoe,项目名称:cbmc,代码行数:76,代码来源:java_entry_point.cpp


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