Example #1
0
File: type.c Project: certik/nwcc
static int
compare_tfunc(struct ty_func *dest, struct ty_func *src) {
	struct sym_entry	*sd;
	struct sym_entry	*ss;
	int			i;

	if (dest->nargs == -1 || src->nargs == -1) {
		/* This is a mere declaration like void foo(); - assume equal */
		return 0;
	}
	if (dest->nargs != src->nargs) {
		return -1;
	}
	if (dest->ret && src->ret) {
		if (compare_types(dest->ret, src->ret, CMPTY_SIGN|CMPTY_CONST)
			== -1) {
			return -1;
		}
	}

	/* XXX this is a kludge ... use func data instead */
	sd = dest->scope->slist;
	ss = src->scope->slist;
	for (i = 0; i < dest->nargs; ++i) {
		struct decl		*d1;
		struct decl		*d2;
		struct type		*t1;
		struct type		*t2;
		static struct vreg	dummyvr;

		d1 = sd->dec;
		d2 = ss->dec;

		t1 = d1->dtype;
		t2 = d2->dtype;

		if (is_transparent_union(t1) && is_transparent_union(t2)) {
		} else if (is_transparent_union(t1)) {
			dummyvr.type = t2;
			t1 = get_transparent_union_type(d1->tok, t1, &dummyvr); 
			if (t1 == NULL) {
				return -1;
			}
		} else if (is_transparent_union(t2)) {
			dummyvr.type = t1;
			t2 = get_transparent_union_type(d2->tok, t2, &dummyvr); 
			if (t2 == NULL) {
				return -1;
			}
		}

		if (compare_types(t1, t2, CMPTY_SIGN|CMPTY_CONST) == -1) {
			return -1;
		}
		sd = sd->next;
		ss = ss->next;
	}
	
	return 0;
}
Example #2
0
char *redhttp_negotiate_choose(redhttp_negotiate_t ** server, redhttp_negotiate_t ** client)
{
  const char *best_type = NULL;
  redhttp_negotiate_t *s, *c;
  int best_score = -1;
  char *result = NULL;

  for (s = *server; s; s = s->next) {
    for (c = *client; c; c = c->next) {
      if (compare_types(s->type, c->type)) {
        int score = s->q * c->q;
        if (score > best_score) {
          best_score = score;
          best_type = s->type;
          break;
        }
      }
    }
  }

  // Copy best match into the result buffer
  if (best_type) {
    result = redhttp_strdup(best_type);
  }

  return result;
}
        virtual bool call_match(const std::vector<Boxed_Value> &vals, const Dynamic_Cast_Conversions &t_conversions) const
        {
          if (int(vals.size()) != get_arity()) 
          {
            return false;
          }

          return compare_types(m_types, vals) || detail::compare_types_cast(m_dummy_func, vals, t_conversions);
        }
   bool compare_decl(SgFunctionDeclaration* f_func_dec, SgFunctionDeclaration* c_func_dec)
   {
      // check for number of arguments
      if (f_func_dec->get_args().size() != c_func_dec->get_args().size()) {
         std::cout << "   compare_decl(): Different number of arguments, returning false" << std::endl;
         return false;
      }

      // check for matching return types
      SgType* f_return_type = f_func_dec->get_orig_return_type();
      SgType* c_return_type = c_func_dec->get_orig_return_type();

      if (f_return_type != c_return_type) {
         std::cout << "   compare_decl(): Different return types, returning false" << std::endl;
         return false;
      }
      else {
         std::cout << "   compare_decl(): Return types match" << std::endl;
      }

      const SgInitializedNamePtrList & f_name_list = f_func_dec->get_args();
      const SgInitializedNamePtrList & c_name_list = c_func_dec->get_args();
      bool found = false;

   // TODO - make sure same # of arguments
      // Is done at the top of the function
   //--------------------------
      int i = 0;
      BOOST_FOREACH(SgInitializedName* f_name, f_name_list)
      {
         if (compare_types(f_name, c_name_list[i])) {
            found = true;
         }
         else {
            std::cout << "   compare_decl(): returning false" << std::endl;
            return false;
         }
         i++;
      }

      std::cout << "   compare_decl(): returning true" << std::endl;
      return found;
   }
Example #5
0
    void
    compare_files(const unity_file &base, const unity_file &other, delta_store &store) {
        // Those modification objects can be applied to another unity_file if they have the right related elements
        // Two modifications with disjoint list of related elements will be applicable together,
        // this will be the basis of conflict resolution in three-way merges.

        bool layout_modified = false;

        if (base.unity_version != other.unity_version)
            store.modify_unity_version(base.unity_version, other.unity_version);

        if (base.magic_int_1 != other.magic_int_1)
            store.modify_file_magic(1, base.magic_int_1, other.magic_int_1);
        if (base.magic_int_2 != other.magic_int_2)
            store.modify_file_magic(2, base.magic_int_2, other.magic_int_2);
        if (base.magic_int_3 != other.magic_int_3)
            store.modify_file_magic(3, base.magic_int_3, other.magic_int_3);

        if (base.file_layout.metadata_size != other.file_layout.metadata_size)
            layout_modified = true;
        if (base.file_layout.assets_start != other.file_layout.assets_start)
            layout_modified = true;
        if (base.file_layout.previews_start != other.file_layout.previews_start)
            layout_modified = true;
        if (base.file_layout.file_endianness != other.file_layout.file_endianness)
            layout_modified = true;

        { // types
            std::vector<identified_type> base_identified_types(identify_types(base));
            std::vector<identified_type> other_identified_types(identify_types(other));

            for (const identified_type &base_identified_type : base_identified_types) {
                bool match_found = false;
                for (const identified_type &other_identified_type : other_identified_types)
                    if (base_identified_type.identity == other_identified_type.identity) {
                        match_found = true;
                        store.set_current_type(base_identified_type.identity);
                        compare_types(base_identified_type.type, other_identified_type.type, store);
                        break;
                    }
                if (!match_found)
                    store.remove_type(base_identified_type.identity, base_identified_type.type);
            }
            for (const identified_type &other_identified_type : other_identified_types) {
                bool match_found = false;
                for (const identified_type &base_identified_type : base_identified_types)
                    if (base_identified_type.identity == other_identified_type.identity) {
                        match_found = true;
                        break;
                    }
                if (!match_found)
                    store.add_type(other_identified_type.identity, other_identified_type.type);
            }
        }

        { // assets
            for (std::size_t base_asset_index = 0; base_asset_index < base.assets.size(); ++base_asset_index) {
                const int base_asset_id(base.assets.get_id_at(base_asset_index));
                const unity_asset &base_asset(base.assets.at(base_asset_index));
                if (other.assets.has_id(base_asset_id)) {
                    const unity_asset &other_asset(other.assets.get_by_id(base_asset_id));
                    const type_identity &base_asset_identity(get_type_identity(base, base_asset.type_id));
                    const type_identity &other_asset_identity(get_type_identity(other, other_asset.type_id));
                    store.set_current_asset(base_asset_id);
                    if (base_asset_identity != other_asset_identity)
                        store.modify_asset_type(base_asset_id, base_asset_identity, other_asset_identity);
                    if (base_asset.type_id_2 != other_asset.type_id_2)
                        store.modify_asset_type_2(base_asset_id, base_asset.type_id_2, other_asset.type_id_2);
                    base_asset.value->compare(*other_asset.value, store);
                    if (
                            base_asset.file_layout.offset != other_asset.file_layout.offset
                                    || base_asset.file_layout.size != other_asset.file_layout.size) {
                        layout_modified = true;
                    }
                } else {
                    store.remove_asset(base_asset_id, get_type_identity(base, base_asset.type_id), *base_asset.value);
                }
            }

            for (std::size_t other_asset_index = 0; other_asset_index < other.assets.size(); ++other_asset_index) {
                const int other_asset_id(other.assets.get_id_at(other_asset_index));
                const unity_asset &other_asset(other.assets.at(other_asset_index));
                if (!base.assets.has_id(other_asset_id))
                    store.add_asset(other_asset_id, get_type_identity(other, other_asset.type_id), *other_asset.value);
            }
        }

        { // file-references
            for (const unity_file_reference &base_file_reference : base.file_references) {
                bool match_found = false;
                for (const unity_file_reference &other_file_reference : other.file_references)
                    if (base_file_reference.file_guid == other_file_reference.file_guid) {
                        match_found = true;
                        if (base_file_reference.properties != other_file_reference.properties)
                            store.modify_file_reference(base_file_reference.file_guid, base_file_reference.properties, other_file_reference.properties);
                        break;
                    }
                if (!match_found)
                    store.remove_file_reference(base_file_reference);
            }

            for (const unity_file_reference &other_file_reference : other.file_references) {
                bool match_found = false;
                for (const unity_file_reference &base_file_reference : base.file_references)
                    if (base_file_reference.file_guid == other_file_reference.file_guid) {
                        match_found = true;
                        break;
                    }
                if (!match_found)
                    store.add_file_reference(other_file_reference);;
            }
        }

        { // previews
            for (const unity_preview &base_preview : base.previews) {
                bool match_found = false;
                for (const unity_preview &other_preview : other.previews)
                    if (base_preview.asset_id == other_preview.asset_id) {
                        match_found = true;
                        if (!are_previews_equal(base_preview, other_preview))
                            store.modify_preview(base_preview, other_preview);
                        if (
                                base_preview.file_layout.offset != other_preview.file_layout.offset
                                        || base_preview.file_layout.size != other_preview.file_layout.size) {
                            layout_modified = true;
                        }
                        break;
                    }
                if (!match_found)
                    store.remove_preview(base_preview);
            }

            for (const unity_preview &other_preview : other.previews) {
                bool match_found = false;
                for (const unity_preview &base_preview : base.previews)
                    if (base_preview.asset_id == other_preview.asset_id) {
                        match_found = true;
                        break;
                    }
                if (!match_found)
                    store.add_preview(other_preview);
            }
        }

        if (layout_modified)
            store.mark_modified_layout();
    }
Example #6
0
static void
check_main(struct token *t, struct type *ty) {
	static struct type 	*maindef = NULL;
	struct ty_func		*tfunc = ty->tlist->tfunc;
	struct sym_entry	*se;
	struct type		*tytmp;

	if (maindef != NULL) return;
	if (ty->name[0] != 'm' || strcmp(ty->name + 1, "ain") != 0) {
		return;
	}
	maindef = ty;

	/* XXX why is it always null??? */
	if (ty->code != TY_INT
		|| ty->tlist->next != NULL) {
		warningfl(t,
	"Illegal return type for main(). ISO C says it must be `int'!");
		return;
	} else if (ty->storage == TOK_KEY_STATIC) {
		warningfl(t, "Static (file scope) declaration of main()");
		return;
	}	

	switch (tfunc->nargs) {
	case 0:
	case -1:
		/* int main(void) or int main() */
		break;
	case 1:
		warningfl(t,
			"main() should take no, two or three arguments");
		break;
	case 2:
	case 3:
		/* XXX check arg1 + 2 = int,char** */

		se = tfunc->scope->slist;
		tytmp = make_basic_type(TY_INT);

		if (compare_types(se->dec->dtype, tytmp,
			CMPTY_SIGN|CMPTY_CONST) != 0) {
			warningfl(t, "First argument of main is not \
`int' as it should be");
		}

		tytmp = n_xmemdup(make_basic_type(TY_CHAR), sizeof *tytmp);
		append_typelist(tytmp, TN_POINTER_TO, 0, NULL, NULL);
		append_typelist(tytmp, TN_POINTER_TO, 0, NULL, NULL);

		if (compare_types(se->next->dec->dtype, tytmp,
			CMPTY_SIGN|CMPTY_CONST) != 0) {
			warningfl(t, "Second argument of main is not \
`char **' as it should be");
		}
		free(tytmp);

		if (tfunc->nargs == 3) {
			/* XXX check arg3 = char** */
		}
	}
Example #7
0
bool ME_runner_qq_Spin1_ZZ_4l::is_my_type(const process_description &in)
{
    return compare_types(in, me);
}
Example #8
0
bool ME_runner_no_Spin1_2f_4lA::is_my_type(const process_description &in)
{
    return compare_types(in, me);
}
Example #9
0
bool ME_runner_all_bkg_2f_ttbb_2::is_my_type(const process_description &in)
{
    return compare_types(in, me);
}