<commit_before>#include <string.h>
#include <assert.h>
#include "ops.h"
#include "expr_identifier.h"
#include "../out/asm.h"
#include "../sue.h"
#include "expr_addr.h"
#include "../type_is.h"
#include "../type_nav.h"

const char *str_expr_identifier()
{
	return "identifier";
}

static void fold_const_expr_identifier(expr *e, consty *k)
{
	/*
	 * if we are an array identifier, we are constant:
	 * int x[];
	 */
	k->type = CONST_NO;

	/* may not have e->sym if we're the struct-member-identifier */
	switch(e->bits.ident.type){
		case IDENT_NORM:
		{
			sym *sym = e->bits.ident.bits.ident.sym;

			if(sym && sym->decl){
				decl *const d = sym->decl;

				/* only a constant if global/static/extern */
				if(decl_store_duration_is_static(d) && !attribute_present(d, attr_weak)){
					CONST_FOLD_LEAF(k);

					k->type = CONST_ADDR_OR_NEED(d);

					k->bits.addr.bits.lbl = decl_asm_spel(sym->decl);

					k->bits.addr.is_lbl = 1;
					k->offset = 0;
				}
			}
			break;
		}
		case IDENT_ENUM:
			const_fold(e->bits.ident.bits.enum_mem->val, k);
			break;
	}
}

static const out_val *gen_expr_identifier_lea(expr *e, out_ctx *octx)
{
	assert(e->bits.ident.type == IDENT_NORM);
	return out_new_sym(octx, e->bits.ident.bits.ident.sym);
}

void fold_expr_identifier(expr *e, symtable *stab)
{
	char *sp = e->bits.ident.bits.ident.spel;
	sym *sym = e->bits.ident.bits.ident.sym;
	decl *in_fn = symtab_func(stab);

	if(sp && !sym)
		e->bits.ident.bits.ident.sym = sym = symtab_search(stab, sp);<commit_msg>Handle incomplete enum member const_fold<commit_after>#include <string.h>
#include <assert.h>
#include "ops.h"
#include "expr_identifier.h"
#include "../out/asm.h"
#include "../sue.h"
#include "expr_addr.h"
#include "../type_is.h"
#include "../type_nav.h"

const char *str_expr_identifier()
{
	return "identifier";
}

static void fold_const_expr_identifier(expr *e, consty *k)
{
	/*
	 * if we are an array identifier, we are constant:
	 * int x[];
	 */
	k->type = CONST_NO;

	/* may not have e->sym if we're the struct-member-identifier */
	switch(e->bits.ident.type){
		case IDENT_NORM:
		{
			sym *sym = e->bits.ident.bits.ident.sym;

			if(sym && sym->decl){
				decl *const d = sym->decl;

				/* only a constant if global/static/extern */
				if(decl_store_duration_is_static(d) && !attribute_present(d, attr_weak)){
					CONST_FOLD_LEAF(k);

					k->type = CONST_ADDR_OR_NEED(d);

					k->bits.addr.bits.lbl = decl_asm_spel(sym->decl);

					k->bits.addr.is_lbl = 1;
					k->offset = 0;
				}
			}
			break;
		}
		case IDENT_ENUM:
			if(e->bits.ident.bits.enum_mem->val == (void *)-1){
				/* part-way through processing an enum, we reference one in the
				 * future that hasn't had its value set. invalid, error caught later
				 */
				return;
			}

			const_fold(e->bits.ident.bits.enum_mem->val, k);
			break;
	}
}

static const out_val *gen_expr_identifier_lea(expr *e, out_ctx *octx)
{
	assert(e->bits.ident.type == IDENT_NORM);
	return out_new_sym(octx, e->bits.ident.bits.ident.sym);
}

void fold_expr_identifier(expr *e, symtable *stab)
{
	char *sp = e->bits.ident.bits.ident.spel;
	sym *sym = e->bits.ident.bits.ident.sym;
	decl *in_fn = symtab_func(stab);

	if(sp && !sym)
		e->bits.ident.bits.ident.sym = sym = symtab_search(stab, sp);
{'fraction_non_alphanumeric': 0.1675360540042958, 'fraction_numerical': 0.0015342129487572874, 'mean_word_length': 3.44141689373297, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 45, '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': '791491', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1275, 'n_words': 262}