Alien-LibJIT

 view release on metacpan or  search on metacpan

libjit/dpas/dpas-scope.c  view on Meta::CPAN

		item = scope->first;
		while(item != 0)
		{
			next = item->next;
			if(item->name)
			{
				jit_free(item->name);
			}
			if(item->filename)
			{
				jit_free(item->filename);
			}
			if(item->free_info)
			{
				(*(item->free_info))(item->info);
			}
			jit_type_free(item->type);
			jit_free(item);
			item = next;
		}
		item = scope->first_with;
		while(item != 0)
		{
			next = item->next;
			if(item->name)
			{
				jit_free(item->name);
			}
			if(item->filename)
			{
				jit_free(item->filename);
			}
			if(item->free_info)
			{
				(*(item->free_info))(item->info);
			}
			jit_type_free(item->type);
			jit_free(item);
			item = next;
		}
		jit_free(scope);
	}
}

dpas_scope_item_t dpas_scope_lookup(dpas_scope_t scope,
									const char *name, int up)
{
	dpas_scope_item_t item;
	int check_with = 1;
	while(scope != 0)
	{
		/* Search through the "with" items for a field match */
		if(check_with)
		{
			item = scope->first_with;
			if(!item)
			{
				/* We are exiting from the top-most "with" scope
				   in the current procedure.  Ignore the rest of
				   the "with" scopes on the stack because we only
				   care about local/global variables from now on */
				check_with = 0;
			}
			while(item != 0)
			{
				if(dpas_type_find_name(item->type, name) != JIT_INVALID_NAME)
				{
					return item;
				}
				item = item->next;
			}
		}

		/* Search the regular items for a match */
		item = scope->first;
		while(item != 0)
		{
			if(!jit_stricmp(item->name, name))
			{
				return item;
			}
			item = item->next;
		}

		/* Move up to the parent scope if necessary */
		if(!up)
		{
			break;
		}
		scope = scope->parent;
	}
	return 0;
}

/*
 * Add an item to a scope list.
 */
static void scope_add(dpas_scope_item_t *first, dpas_scope_item_t *last,
					  const char *name, jit_type_t type, int kind,
					  void *info, jit_meta_free_func free_info,
					  char *filename, long linenum)
{
	dpas_scope_item_t item;
	item = jit_new(struct dpas_scope_item);
	if(!item)
	{
		dpas_out_of_memory();
	}
	if(name)
	{
		item->name = jit_strdup(name);
		if(!(item->name))
		{
			dpas_out_of_memory();
		}
	}
	else
	{
		item->name = 0;
	}
	item->type = jit_type_copy(type);

libjit/dpas/dpas-scope.c  view on Meta::CPAN

			if(jit_type_get_tagged_kind(type) == DPAS_TAG_NAME &&
			   jit_type_get_tagged_type(type) == 0)
			{
				dpas_error_on_line
					(item->filename, item->linenum,
					 "forward-referenced record type `%s' was not "
					 "declared", item->name);
				new_type = jit_type_create_struct(0, 0, 0);
				if(!new_type)
				{
					dpas_out_of_memory();
				}
				jit_type_set_tagged_type(type, new_type, 0);
			}
		}
		item = item->next;
	}
}

const char *dpas_scope_item_name(dpas_scope_item_t item)
{
	return item->name;
}

int dpas_scope_item_kind(dpas_scope_item_t item)
{
	return item->kind;
}

jit_type_t dpas_scope_item_type(dpas_scope_item_t item)
{
	return item->type;
}

void *dpas_scope_item_info(dpas_scope_item_t item)
{
	return item->info;
}

void dpas_scope_item_set_info(dpas_scope_item_t item, void *info)
{
	item->info = info;
}

const char *dpas_scope_item_filename(dpas_scope_item_t item)
{
	return item->filename;
}

long dpas_scope_item_linenum(dpas_scope_item_t item)
{
	return item->linenum;
}

int dpas_scope_level(dpas_scope_t scope)
{
	return scope->level;
}

/*
 * The global and current scopes.
 */
static dpas_scope_t global_scope = 0;
static dpas_scope_t current_scope = 0;

dpas_scope_t dpas_scope_current(void)
{
	if(!current_scope)
	{
		/* Create the global scope for the first time */
		global_scope = dpas_scope_create(0);

		/* Create a wrapper around the global scope to contain
		   the program-private definitions.  This allows the
		   program to override the global scope if it wants to */
		current_scope = dpas_scope_create(global_scope);
	}
	return current_scope;
}

dpas_scope_t dpas_scope_global(void)
{
	if(!current_scope)
	{
		dpas_scope_current();
	}
	return global_scope;
}

dpas_scope_t dpas_scope_push(void)
{
	current_scope = dpas_scope_create(dpas_scope_current());
	return current_scope;
}

void dpas_scope_pop(void)
{
	dpas_scope_t scope = dpas_scope_current();
	if(scope->parent && scope->parent != global_scope)
	{
		current_scope = scope->parent;
		dpas_scope_destroy(scope);
	}
}

int dpas_scope_is_module(void)
{
	return (dpas_scope_current()->parent == dpas_scope_global());
}



( run in 0.461 second using v1.01-cache-2.11-cpan-f0fbb3f571b )