<commit_before>#include "instanciate.h"
#include "instanciate-atom.h"
#include "libnanyc-traces.h"

using namespace Yuni;




namespace Nany
{
namespace Pass
{
namespace Instanciate
{

	namespace // anonymous
	{

		static bool tryFindProperties(const IR::ISA::Operand<IR::ISA::Op::identify>& operands,
			std::vector<std::reference_wrapper<Atom>>& multipleResults,
			Atom& atom, const AnyString& name)
		{
			// 'identifyset' is strictly identical to 'identify', but it indicates
			// that we should resolve a setter and not a getter
			bool setter = (operands.opcode == static_cast<uint32_t>(IR::ISA::Op::identifyset));

			if (not setter)
			{
				return atom.propertyLookupOnChildren(multipleResults, "^propget^", name);
			}
			else
			{
				bool success = true;
				success &= atom.propertyLookupOnChildren(multipleResults, "^propset^", name);
				return success;
			}
		}

	} // anonymous namespace




	Atom& SequenceBuilder::resolveTypeAlias(Atom& original, const Classdef*& resultcdef)
	{
		assert(original.isTypeAlias());
		assert(resultcdef == nullptr); // a null value will indicate a fail

		// trying a direct resolution
		auto cdef = std::cref(cdeftable.classdef(original.returnType.clid));

		// set of all atomid encountered so far, to detect circular references
		// (and avoid an infinite loop in the same time)
		// example:
		//    typedef A: B;
		//    typedef B: A;
		std::unordered_set<uint32_t> encountered;
		// temporary atom, as potential candidate
		Atom* alias = nullptr;
		do
		{
			if (cdef.get().isBuiltin()) // the typedef has been solved
			{
				resultcdef = &(cdef.get());
				return original;
			}

			// current atom to check
			alias = cdeftable.findClassdefAtom(cdef.get());
			if (unlikely(!alias))
			{
				warning() << "failed to retrieve atom from " << cdef.get().clid;
				break;
			}

			if ((alias->parent == original.parent) and alias->atomid > original.atomid)
			{
				// same parent but declared after (the atomid is likely to be greater
				// than the first one since registered after)
				complainTypedefDeclaredAfter(original, *alias);
				return original;
			}

			if (not alias->isTypeAlias()) // the typedef has been solved
			{<commit_msg>identify typedef: an invalid atom should produce an ICE<commit_after>#include "instanciate.h"
#include "instanciate-atom.h"
#include "libnanyc-traces.h"

using namespace Yuni;




namespace Nany
{
namespace Pass
{
namespace Instanciate
{

	namespace // anonymous
	{

		static bool tryFindProperties(const IR::ISA::Operand<IR::ISA::Op::identify>& operands,
			std::vector<std::reference_wrapper<Atom>>& multipleResults,
			Atom& atom, const AnyString& name)
		{
			// 'identifyset' is strictly identical to 'identify', but it indicates
			// that we should resolve a setter and not a getter
			bool setter = (operands.opcode == static_cast<uint32_t>(IR::ISA::Op::identifyset));

			if (not setter)
			{
				return atom.propertyLookupOnChildren(multipleResults, "^propget^", name);
			}
			else
			{
				bool success = true;
				success &= atom.propertyLookupOnChildren(multipleResults, "^propset^", name);
				return success;
			}
		}

	} // anonymous namespace




	Atom& SequenceBuilder::resolveTypeAlias(Atom& original, const Classdef*& resultcdef)
	{
		assert(original.isTypeAlias());
		assert(resultcdef == nullptr); // a null value will indicate a fail

		// trying a direct resolution
		auto cdef = std::cref(cdeftable.classdef(original.returnType.clid));

		// set of all atomid encountered so far, to detect circular references
		// (and avoid an infinite loop in the same time)
		// example:
		//    typedef A: B;
		//    typedef B: A;
		std::unordered_set<uint32_t> encountered;
		// temporary atom, as potential candidate
		Atom* alias = nullptr;
		do
		{
			if (cdef.get().isBuiltin()) // the typedef has been solved
			{
				resultcdef = &(cdef.get());
				return original;
			}

			// current atom to check
			alias = cdeftable.findClassdefAtom(cdef.get());
			if (unlikely(!alias))
			{
				ice() << "identify typedef: failed to retrieve atom from " << cdef.get().clid;
				break;
			}

			if ((alias->parent == original.parent) and alias->atomid > original.atomid)
			{
				// same parent but declared after (the atomid is likely to be greater
				// than the first one since registered after)
				complainTypedefDeclaredAfter(original, *alias);
				return original;
			}

			if (not alias->isTypeAlias()) // the typedef has been solved
			{
{'fraction_non_alphanumeric': 0.12113055181695828, 'fraction_numerical': 0.001794526693584567, 'mean_word_length': 3.5269035532994923, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1796129', 'n_tokens_mistral': 1620, 'n_tokens_neox': 1378, 'n_words': 402}