Ejemplo n.º 1
0
END_TEST

START_TEST (test_types_equal)
{
	Type a, b;

	a = (Type){BOOL,0,0,0}; 
	b = (Type){BOOL,0,0,0};
	ck_assert_int_eq(1, types_equal(a,b,0));

	a = (Type){INT,0,0,0}; 
	b = (Type){REAL,0,0,0};
	ck_assert_int_eq(0, types_equal(a,b,0));

	a = (Type){AINT,0,30,0}; 
	b = (Type){AINT,0,10,0};
	ck_assert_int_eq(0, types_equal(a,b,0));

	a = (Type){AINT,0,30,0}; 
	b = (Type){AINT,0,30,0};
	ck_assert_int_eq(1, types_equal(a,b,0));

	a = (Type){AINT,0,30,1}; 
	b = (Type){AINT,0,30,0};
	ck_assert_int_eq(0, types_equal(a,b,1));
}
Ejemplo n.º 2
0
compile_scope
compile_cplus_instance::new_scope (const char *type_name, struct type *type)
{
  /* Break the type name into components.  If TYPE was defined in some
     superclass, we do not process TYPE but process the enclosing type
     instead.  */
  compile_scope scope = type_name_to_scope (type_name, block ());

  if (!scope.empty ())
    {
      /* Get the name of the last component, which should be the
	 unqualified name of the type to process.  */
      scope_component &comp = scope.back ();

      if (!types_equal (type, SYMBOL_TYPE (comp.bsymbol.symbol))
	  && (m_scopes.empty ()
	      || (m_scopes.back ().back ().bsymbol.symbol
		  != comp.bsymbol.symbol)))
	{
	  /* The type is defined inside another class(es).  Convert that
	     type instead of defining this type.  */
	  convert_type (SYMBOL_TYPE (comp.bsymbol.symbol));

	  /* If the original type (passed in to us) is defined in a nested
	     class, the previous call will give us that type's gcc_type.
	     Upper layers are expecting to get the original type's
	     gcc_type!  */
	  get_cached_type (type, &scope.m_nested_type);
	  return scope;
	}
    }
  else
    {
      if (TYPE_NAME (type) == nullptr)
	{
	  /* Anonymous type  */

	  /* We don't have a qualified name for this to look up, but
	     we need a scope.  We have to assume, then, that it is the same
	     as the current scope, if any.  */
	  if (!m_scopes.empty ())
	    {
	      scope = m_scopes.back ();
	      scope.m_pushed = false;
	    }
	  else
	    scope.push_back (scope_component ());
	}
      else
	{
	  scope_component comp
	    = {
	        decl_name (TYPE_NAME (type)).get (),
		lookup_symbol (TYPE_NAME (type), block (), VAR_DOMAIN, nullptr)
	      };
	  scope.push_back (comp);
	}
    }

  /* There must be at least one component in the compile_scope.  */
  gdb_assert (scope.size () > 0);
  return scope;
}