Beispiel #1
0
TEST(FirstPass, add_symbol) {
    sglib_hashed_Symbol_init(symbol_table);
    char s1[] = "START";
    char s2[] = "END";
    Symbol *result;
    add_symbol(s1, 0x144, false, true);
    add_symbol(s2, 0x164, true, false);
    result = get_symbol_by_name(symbol_table, "END");
    EXPECT_EQ(result -> address, 0x164);
    
}
krb5_error_code
_krb5_plugin_find(krb5_context context,
		  enum krb5_plugin_type type,
		  const char *name,
		  struct krb5_plugin **list)
{
    struct plugin *e;
    krb5_error_code ret;

    *list = NULL;

    HEIMDAL_MUTEX_lock(&plugin_mutex);

    load_plugins(context);

    for (ret = 0, e = registered; e != NULL; e = e->next) {
	switch(e->type) {
	case DSO: {
	    void *sym;
	    if (e->u.dso.dsohandle == NULL)
		continue;
	    sym = dlsym(e->u.dso.dsohandle, name);
	    if (sym)
		ret = add_symbol(context, list, sym);
	    break;
	}
	case SYMBOL:
	    if (strcmp(e->u.symbol.name, name) == 0 && e->u.symbol.type == type)
		ret = add_symbol(context, list, e->u.symbol.symbol);
	    break;
	}
	if (ret) {
	    _krb5_plugin_free(*list);
	    *list = NULL;
	}
    }

    HEIMDAL_MUTEX_unlock(&plugin_mutex);
    if (ret)
	return ret;

    if (*list == NULL) {
	krb5_set_error_message(context, ENOENT, "Did not find a plugin for %s", name);
	return ENOENT;
    }

    return 0;
}
Beispiel #3
0
int   lr1_token_action::lookup (short& t) // Look for Symbol.
{
		int sti;														// Symbol-table index.
		sti = add_symbol (t, token.start, token.end);	// Add to symbol table. 
		t   = symbol[sti].term;									//	Redefine terminal number (need this for typedef names). 
		return (sti); // Return symbol-table index. 
}
Beispiel #4
0
void setup_macro(struct macro_head *h, int arity, struct pnode *parms)
{
  if (enforce_arity(arity, list_length(h->parms))) {
    /* push table for the marco parms */
    state.stTopDefines = push_symbol_table(state.stTopDefines, 
                                        state.case_insensitive);

    /* Now add the macro's declared parameter list to the new 
       defines table. */
    if (arity > 0) {
      struct pnode *pFrom, *pFromH;
      struct pnode *pTo, *pToH;
      struct symbol *sym;

      pTo = parms;

      for (pFrom = h->parms; pFrom; pFrom = TAIL(pFrom)) {
	pToH = HEAD(pTo);
	pFromH = HEAD(pFrom);
	assert(pFromH->tag == symbol);
 
        arg_index = 0;
        arg_buffer[0] = '\0';
        node_to_string(pToH);
        sym = add_symbol(state.stTopDefines, pFromH->value.symbol);	
        annotate_symbol(sym, strdup(arg_buffer));
        pTo = TAIL(pTo);
      }
    }

    state.next_state = state_macro;  
    state.next_buffer.macro = h;
    state.lst.line.linetype = none;
  }
}
Beispiel #5
0
/*!
 * \param[in,out] tab    Symbol table to add the symbol to.
 * \param[in]     name   Name of the new symbol.
 * \param[in]     sel    Value of the variable.
 * \returns       Pointer to the created symbol record, or NULL if there was a
 *   symbol with the same name.
 */
gmx_sel_symrec_t *
_gmx_sel_add_var_symbol(gmx_sel_symtab_t *tab, const char *name,
                        struct t_selelem *sel)
{
    gmx_sel_symrec_t *sym;
    e_symbol_t        ctype;

    sym = add_symbol(tab, name, &ctype);
    if (!sym)
    {
        fprintf(stderr, "parse error: ");
        switch (ctype)
        {
            case SYMBOL_RESERVED:
            case SYMBOL_POS:
                fprintf(stderr, "variable name (%s) conflicts with a reserved keyword\n",
                        name);
                break;
            case SYMBOL_VARIABLE:
                fprintf(stderr, "duplicate variable name (%s)\n", name);
                break;
            case SYMBOL_METHOD:
                fprintf(stderr, "variable name (%s) conflicts with a selection keyword\n",
                        name);
                break;
        }
        return NULL;
    }

    sym->type  = SYMBOL_VARIABLE;
    sym->u.var = sel;
    sel->refcount++;
    return sym;
}
/* add a variable declaration or a function prototype
 * declaration to the symbol table
 */
symbol* declare_symbol(symbol_type_t symbol_type, char *name, YYLTYPE  loc, visibility_level_t  level, data_type_t data_type, int size) {

    symbol *s;
    MALLOC(s, symbol, 1);
    s->type = symbol_type;
    s->loc  = loc;
    strcpy(s->name, name);

    if ( symbol_type == FUNCTION ) {
        s->u.func.arity = size;
        s->u.func.return_type = data_type;
        s->u.func.defined = FALSE;
    } else { /* var*/
        s->u.var.size = size;
        s->u.var.data_type = data_type;
    }
    
    if ( check_duplicate(level, s) ) {
#ifndef NDEBUG
        fprintf(stderr, " Adding symbol `%s' with data type \t%s\n", s->name, data_type_names[(s->type == FUNCTION) ? s->u.func.return_type : s->u.var.data_type]);
#endif
        add_symbol(level, s);
        return s;
    } else {
        nberrs++;
        return NULL;
    }

}
/* TODO: obey static to declare a function to the file level */
symbol *define_function(char *name, YYLTYPE  loc, data_type_t  return_type, symbol* param_list) {
    
    symbol *s;
    MALLOC(s, symbol, 1);
    s->type = FUNCTION;
    s->loc  = loc;
    strcpy(s->name, name);

    //s->u.func.arity = size;
    s->u.func.return_type = return_type;
    s->u.func.defined = TRUE;
    s->u.func.plist = param_list;

    print_fn_signature(s);


    if ( check_duplicate(GLOBAL_LEVEL, s) ) {
        /* if a prototype exists, replace it by the definition */
        symbol *sym;
        if ( (sym = find_symbol(GLOBAL_LEVEL, s->name)) ) {
            delete_symbol(GLOBAL_LEVEL, sym);
        }
        add_symbol(GLOBAL_LEVEL, s);
        // add all params as vars to the current function symtable
        for ( sym = param_list; sym; sym = sym->u.param.next )
            if ( !declare_symbol(VARIABLE,  sym->name, sym->loc, FUNCTION_LEVEL, sym->u.param.data_type, sym->u.param.size) )
                return NULL;
        return s;
    } else {
        nberrs++;
        printf("errrrrr\n");
        return NULL;
    }
}
Beispiel #8
0
/*!
 * \param[in,out] tab    Symbol table to add the symbol to.
 * \param[in]     name   Name of the new symbol.
 * \param[in]     method Method that this symbol represents.
 * \returns       Pointer to the created symbol record, or NULL if there was a
 *   symbol with the same name.
 */
gmx_sel_symrec_t *
_gmx_sel_add_method_symbol(gmx_sel_symtab_t *tab, const char *name,
                           struct gmx_ana_selmethod_t *method)
{
    gmx_sel_symrec_t *sym;
    e_symbol_t        ctype;

    sym = add_symbol(tab, name, &ctype);
    if (!sym)
    {
        fprintf(stderr, "parse error: ");
        switch (ctype)
        {
            case SYMBOL_RESERVED:
            case SYMBOL_POS:
                fprintf(stderr, "method name (%s) conflicts with a reserved keyword\n",
                        name);
                break;
            case SYMBOL_VARIABLE:
                fprintf(stderr, "method name (%s) conflicts with a variable name\n",
                        name);
                break;
            case SYMBOL_METHOD:
                fprintf(stderr, "duplicate method name (%s)\n", name);
                break;
        }
        return NULL;
    }

    sym->type   = SYMBOL_METHOD;
    sym->u.meth = method;
    return sym;
}
Beispiel #9
0
static void
fake_up_certain_popular_kernel_symbols(void)
{
	kstat_ctl_t *kc;
	kstat_t *ksp;
	char *name;

	if ((kc = kstat_open()) == NULL)
		return;

	for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
		if (strcmp(ksp->ks_module, "cpu_info") == 0) {
			if ((name = malloc(20)) == NULL)
				break;
			/*
			 * For consistency, keep cpu[0] and toss cpu0
			 * or any other such symbols.
			 */
			if (ksp->ks_instance == 0)
				remove_symbol((uintptr_t)ksp->ks_private);
			(void) sprintf(name, "cpu[%d]", ksp->ks_instance);
			add_symbol(name, (uintptr_t)ksp->ks_private,
			    sizeof (struct cpu));
		}
	}
	(void) kstat_close(kc);
}
Beispiel #10
0
//------------------------------------------------------------------------------
    Elf_Word
    add_symbol( Elf_Word name, Elf64_Addr value, Elf_Xword size,
                unsigned char bind, unsigned char type, unsigned char other,
                Elf_Half shndx )
    {
        return add_symbol( name, value, size, ELF_ST_INFO( bind, type ), other, shndx );
    }
int main (int argc, char* argv[]) {

    int a = add_symbol("a", type_int);    
    printf("1 = %d\n", a);
    
    printf("1 = %d\n", add_symbol("b", type_double));

    printf("1 = %d\n", add_symbol("c", type_char));

    printf("0 = %d\n", add_symbol("a", type_char));     // ERRO: já declarada
    
    printf("0 = %d\n", add_symbol("b", type_double));   // ERRO: Já declarada

    printf("1 = %d\n", is_type("a", type_int));

    printf("1 = %d\n", is_type("b", type_int));
}
Beispiel #12
0
int add_table_name(int index, const char *name) {
  set_table_name(name, index);

  if (add_symbol(name, 10, 1, COM(TABTYPE, index)) < 0)
    return 1;

  return 0;
}
Beispiel #13
0
//------------------------------------------------------------------------------
    Elf_Word
    add_symbol( string_section_accessor& pStrWriter, const char* str,
                Elf64_Addr value, Elf_Xword size,
                unsigned char bind, unsigned char type, unsigned char other,
                Elf_Half shndx )
    {
        return add_symbol( pStrWriter, str, value, size, ELF_ST_INFO( bind, type ), other, shndx );
    }
Beispiel #14
0
void 
add_name(struct symbol_table *table, char *name)
{
  struct symbol *sym;

  sym = get_symbol(table, name);
  if (sym == NULL)
    sym = add_symbol(table, name);
}
Beispiel #15
0
/*
 * If the symbol is an inline symbol, add it to the list of symbols to parse
 */
void access_symbol(SCTX_ struct symbol *sym)
{
	if (sym->ctype.modifiers & MOD_INLINE) {
		if (!(sym->ctype.modifiers & MOD_ACCESSED)) {
			add_symbol(sctx_ &sctxp translation_unit_used_list, sym);
			sym->ctype.modifiers |= MOD_ACCESSED;
		}
	}
}
Beispiel #16
0
//------------------------------------------------------------------------------
    Elf_Word
    add_symbol( string_section_accessor& pStrWriter, const char* str,
                Elf64_Addr value, Elf_Xword size,
                unsigned char info, unsigned char other,
                Elf_Half shndx )
    {
        Elf_Word index = pStrWriter.add_string( str );
        return add_symbol( index, value, size, info, other, shndx );
    }
Beispiel #17
0
int add_kernel(const char *name, double mu, const char *expr) {
  int ki = volterra2_add_kernel(expr, mu);
  if (ki < 0)
    return 1;

  if (add_symbol(name, 10, 0, COM(KERTYPE, ki)) < 0) {
    volterra2_remove_kernel(ki);
    return 1;
  }

  return 0;
}
void add_arg(node_ptr var, node_ptr qstring, int isbool)
{
    if (!var || !qstring) {
	yyerror("Null node");
	return;
    }
    add_symbol(var, qstring);
    if (isbool) {
	set_bool(var);
	set_bool(qstring);
    }
}
Beispiel #19
0
int add_var(const char *name, double value) {
  double *p = parser_doubles_append(&variables);

  if (!p) return 1;

  *p = value;

  if (add_symbol(name, 10, 0, COM(VARTYPE, variables.len - 1)) < 0) {
    parser_doubles_remove(&variables, variables.len - 1, 1);
    return 1;
  }

  return 0;
}
Beispiel #20
0
int add_con(const char *name, double value) {
  double *p = parser_doubles_append(&constants);

  if (!p) return 1;

  *p = value;

  if (add_symbol(name, 10, 0, COM(CONTYPE, constants.len - 1)) < 0) {
    parser_doubles_remove(&constants, constants.len - 1, 1);
    return 1;
  }

  return 0;
}
Beispiel #21
0
void setup_macro(struct macro_head *h, int arity, struct pnode *parms)
{
  if (enforce_arity(arity, list_length(h->parms))) {
    /* push table for the marco parms */
    state.stTopDefines = push_symbol_table(state.stTopDefines, 
                                        state.case_insensitive);

    /* Now add the macro's declared parameter list to the new 
       defines table. */
    if (arity > 0) {
      struct pnode *pFrom, *pFromH;
      struct pnode *pTo, *pToH;
      struct symbol *sym;
      char buffer[BUFSIZ];

      pTo = parms;

      for (pFrom = h->parms; pFrom; pFrom = TAIL(pFrom)) {
	pToH = HEAD(pTo);
	pFromH = HEAD(pFrom);
	assert(pFromH->tag == symbol);
 
        sym = add_symbol(state.stTopDefines, pFromH->value.symbol);	

        /* must convert the parm to a plain string, this will allow
           subsitutions of labels and strings */
        if (pToH->tag == symbol) {
          annotate_symbol(sym, strdup(pToH->value.symbol));
        } else if (pToH->tag == string) {
          sprintf(buffer, "\"%s\"", pToH->value.string);
          annotate_symbol(sym, strdup(buffer));
        } else {
          int value = maybe_evaluate(pToH);

	  if (value < 0)
	    sprintf(buffer, "-%#x", -value);
          else
	    sprintf(buffer, "%#x", value);	  
	  annotate_symbol(sym, strdup(buffer));
        }
    
        pTo = TAIL(pTo);
      }
    }

    state.next_state = _macro;  
    state.next_buffer.macro = h;
    state.lst.line.linetype = none;
  }
}
Beispiel #22
0
	void symbol_table::add_label(const label &label, uint16_t offset) {
		string name = full_name(label.name, offset);

		symbol::symbol_type type = symbol::symbol_type::GLOBAL_LABEL;
		if (label.type == label_type::LOCAL) {
			type = symbol::symbol_type::LOCAL_LABEL;
		}

		auto existing_symbol = lookup_table.find(name);
		if (existing_symbol != lookup_table.end()) {
			throw duplicate_symbol_error(name, existing_symbol->second.location);
		}

		add_symbol(symbol(label.location, type, name, offset));
	}
Beispiel #23
0
int add_ufun_name(char *name, int narg) {
  UserFunction *p = parser_ufuns_append(&ufuns);

  if (!p) return 1;

  strncpy(p->name, name, sizeof(p->name));
  p->name[sizeof(p->name) - 1] = '\0';

  if (add_symbol(name, 10, narg, COM(UFUNTYPE, ufuns.len - 1)) < 0) {
    parser_ufuns_remove(&ufuns, ufuns.len - 1, 1);
    return 1;
  }

  return 0;
}
Beispiel #24
0
int   calc_parser::init (char* Inputname, FILE* Outputdesc, int max_symb, int max_node)
{
		inputname  = Inputname;										// Move name into parser object.
		outputdesc = Outputdesc;									// Move desc into parser object.

		if (!init_symtab (max_symb)) return (0);           // Initialize the symbol table.
		if (!init_ast (max_node)) return (0);              // Initialize the AST. 
		token.start = "";                                  // Make a blank symbol.
		token.end   = token.start + 1;
		add_symbol (0, token.start, token.end);				// Add it to the symbol table.

      n_errors = 0;							                  // Set number of errors.    
      max_errs = 10;							                  // Set max number of errors.
		return (1); // Return OK.
}
void add_symbol(char *sym_name, int sym_len, char *sym_val, int sym_val_len,
                option_block *opts, int i)
{
    sym_t *pSym;
    char buf[8192]= {0};
    char buf2[8192] = {0};

    if((sym_len >= 8192) ||
       (sym_val_len >= 8192))
    {
        file_error("too large symbol!", opts);
    }

    opts->syms_array = realloc(opts->syms_array, 
                               sizeof(sym_t) * (opts->sym_count + 1));
    
    if(opts->syms_array == NULL)
    {
        file_error("out of memory adding symbol.", opts);
    }

    if(i == 0)
    {
	buf[0] = '%';
	memcpy(buf+1, sym_name, sym_len);
	
	snprintf(buf2, 8192, "%u", (unsigned int)strlen(sym_val));
	add_symbol(buf, strlen(buf), buf2, strlen(buf2), opts, 1);
	opts->syms_array = realloc(opts->syms_array, 
				   sizeof(sym_t) * (opts->sym_count + 1));
    
	if(opts->syms_array == NULL)
	{
	    file_error("out of memory adding symbol.", opts);
	}
    }
    opts->sym_count += 1;

    pSym = &(opts->syms_array[opts->sym_count - 1]);

    memset(pSym->sym_name, 0, 8192);
    memset(pSym->sym_val, 0, 8192);
    memcpy(pSym->sym_name, sym_name, sym_len);
    memcpy(pSym->sym_val,  sym_val,  sym_val_len);
    pSym->is_len = 0;
    if(i == 1)
        pSym->is_len = 1;
}
Beispiel #26
0
int add_ufun(const char *name, const char *expr, int narg) {
  int i, l;
  int end;
  UserFunction *p = parser_ufuns_append(&ufuns);

  if (!p) return 1;

  if ((p->rpn = malloc(1024)) == NULL) {
    plintf("not enough memory!!\n");
    return 1;
  }
  if ((p->def = malloc(MAXEXPLEN)) == NULL) {
    free(p->rpn);
    parser_ufuns_remove(&ufuns, ufuns.len - 1, 1);
    plintf("not enough memory!!\n");
    return 1;
  }

  strcpy(p->def, expr);
  l = strlen(p->def);
  p->def[l - 1] = '\0';
  strcpy(p->name, name);
  p->narg = narg;
  for (i = 0; i < narg; i++) {
    sprintf(p->args[i], "ARG%d", i + 1);
  }

  if (parse_expr(expr, p->rpn, &end)) {
    free(p->def);
    free(p->rpn);
    parser_ufuns_remove(&ufuns, ufuns.len - 1, 1);
    plintf("ERROR IN FUNCTION DEFINITION\n");
    return 1;
  }

  fixup_endfun(p->rpn, end, narg);

  if (add_symbol(name, 10, narg, COM(UFUNTYPE, ufuns.len - 1)) < 0) {
    free(p->def);
    free(p->rpn);
    parser_ufuns_remove(&ufuns, ufuns.len - 1, 1);
    return 1;
  }

  return 0;
}
Beispiel #27
0
static void	load_symtab(sym_strtab **list, Elf_Scn *sym_scn)
{
  Elf_Data	*data;
  size_t	nb_symbols;

  sym_shdr = elf64_getshdr(sym_scn);
  data = elf_getdata(sym_scn, NULL);

  symtab = (Elf64_Sym*)data->d_buf;
  nb_symbols = sym_shdr->sh_size / sym_shdr->sh_entsize;

  for (size_t i = 0; i < nb_symbols; ++i)
    if (ELF64_ST_TYPE(symtab[i].st_info) == STT_FUNC
	|| ELF64_ST_TYPE(symtab[i].st_info) == STT_NOTYPE)
      add_symbol(list, symtab[i].st_value,
		 elf_strptr(e, sym_shdr->sh_link, symtab[i].st_name));
}
Beispiel #28
0
static code_block *generate_let(code_block *parent, let_statement *let) {
  code_system *system = parent->system;

  define_clause *clause = let->clause;

  do {
    parent = generate_expression(parent, clause->value);
    symbol_entry *entry = add_symbol(parent, clause->symbol_entry,
      last_instruction(parent));
    entry->type = resolve_type(system, copy_type(clause->value->type));
    entry->exists = true;

    clause = clause->next;
  } while (clause);

  return parent;
}
Beispiel #29
0
void storage(char *varname) {

	int address;

	if (address = symtab_lookup(varname) == -1) {

		// assigns symtab_next_entry to address and add symtab_next_entry
		address = symtab_next_entry++;

		if (add_symbol(varname, address)) {

			memory[address] = stack[top];

		}

	}

}
Beispiel #30
0
/* Da de alta una nueva variable en la tabla de simbolos y la retorna */
Element *new_variable() {
	Element *e = (Element *)malloc(sizeof(Element));
	static int numero_va = 0;
	char *first_part = "$aux";
	char aux_num[6];
	numero_va++;
	sprintf(aux_num, "%d", numero_va);
	char *name = (char *)calloc(strlen(aux_num) + strlen(first_part) + 1, sizeof(char));
	strcat(name, first_part);
	strcat(name, aux_num);
	Symbol *s = create_symbol(name);
	s->type = INT;
	add_symbol(s);
	e->code = IDENTIFICADOR;
	e->name = name;
	
	return e;
}