Esempio n. 1
0
bool symtab_add(symtab_t* symtab, const char* name, ast_t* def,
  sym_status_t status)
{
  const char* no_case = name_without_case(name);

  if(no_case != name)
  {
    symbol_t s1 = {no_case, def, SYM_NOCASE, 0};
    size_t index = HASHMAP_UNKNOWN;
    symbol_t* s2 = symtab_get(symtab, &s1, &index);

    if(s2 != NULL)
      return false;

    // didn't find it in the map but index is where we can put the
    // new one without another search
    symtab_putindex(symtab, sym_dup(&s1), index);
  }

  symbol_t s1 = {name, def, status, 0};
  size_t index = HASHMAP_UNKNOWN;
  symbol_t* s2 = symtab_get(symtab, &s1, &index);

  if(s2 != NULL)
    return false;

  // didn't find it in the map but index is where we can put the
  // new one without another search
  symtab_putindex(symtab, sym_dup(&s1), index);
  return true;
}
Esempio n. 2
0
bool symtab_add(symtab_t* symtab, const char* name, ast_t* def,
  sym_status_t status)
{
  const char* no_case = name_without_case(name);

  if(no_case != name)
  {
    symbol_t s1 = {no_case, def, SYM_NOCASE, 0};
    symbol_t* s2 = symtab_get(symtab, &s1);

    if(s2 != NULL)
      return false;

    symtab_put(symtab, sym_dup(&s1));
  }

  symbol_t s1 = {name, def, status, 0};
  symbol_t* s2 = symtab_get(symtab, &s1);

  if(s2 != NULL)
    return false;

  symtab_put(symtab, sym_dup(&s1));
  return true;
}
Esempio n. 3
0
void symtab_inherit_status(symtab_t* dst, symtab_t* src)
{
  size_t i = HASHMAP_BEGIN;
  symbol_t* sym;
  size_t index = HASHMAP_UNKNOWN;

  while((sym = symtab_next(src, &i)) != NULL)
  {
    // Only inherit symbols that were declared in an outer scope.
    if(sym->def != NULL)
      continue;

    symbol_t* dsym = symtab_get(dst, sym, &index);

    if(dsym != NULL)
    {
      // Copy the source status the the destination.
      dsym->status = sym->status;
    } else {
      // Add this symbol to the destination.
      // didn't find it in the map but index is where we can put the
      // new one without another search
      symtab_putindex(dst, sym_dup(sym), index);
    }
  }
}
Esempio n. 4
0
void symtab_set_status(symtab_t* symtab, const char* name, sym_status_t status)
{
  symbol_t s1 = {name, NULL, status, 0};
  symbol_t* s2 = symtab_get(symtab, &s1);

  if(s2 != NULL)
    s2->status = status;
  else
    symtab_put(symtab, sym_dup(&s1));
}
Esempio n. 5
0
symtab_t* symtab_dup(symtab_t* symtab)
{
  symtab_t* n = POOL_ALLOC(symtab_t);
  symtab_init(n, symtab_size(symtab));

  size_t i = HASHMAP_BEGIN;
  symbol_t* sym;

  while((sym = symtab_next(symtab, &i)) != NULL)
    symtab_put(n, sym_dup(sym));

  return n;
}
Esempio n. 6
0
void symtab_set_status(symtab_t* symtab, const char* name, sym_status_t status)
{
  symbol_t s1 = {name, NULL, status, 0};
  size_t index = HASHMAP_UNKNOWN;
  symbol_t* s2 = symtab_get(symtab, &s1, &index);

  if(s2 != NULL)
    s2->status = status;
  else
  {
    // didn't find it in the map but index is where we can put the
    // new one without another search
    symtab_putindex(symtab, sym_dup(&s1), index);
  }
}
Esempio n. 7
0
void symtab_inherit_branch(symtab_t* dst, symtab_t* src)
{
  size_t i = HASHMAP_BEGIN;
  symbol_t* sym;
  size_t index = HASHMAP_UNKNOWN;

  while((sym = symtab_next(src, &i)) != NULL)
  {
    // Only inherit symbols that were declared in an outer scope.
    if(sym->def != NULL)
      continue;

    symbol_t* dsym = symtab_get(dst, sym, &index);

    if(dsym != NULL)
    {
      if(sym->status == SYM_DEFINED)
      {
        // Treat defined as adding one to the undefined branch count.
        if(dsym->status == SYM_UNDEFINED)
          dsym->branch_count++;
      } else if(sym->status == SYM_CONSUMED) {
        // Consumed overrides everything.
        dsym->status = SYM_CONSUMED;
        dsym->branch_count = 0;
      }
    } else {
      // Add this symbol to the destination.
      dsym = sym_dup(sym);

      if(dsym->status == SYM_DEFINED)
      {
        // Treat defined as undefined with a branch count of one.
        dsym->status = SYM_UNDEFINED;
        dsym->branch_count = 1;
      }

      // didn't find it in the map but index is where we can put the
      // new one without another search
      symtab_putindex(dst, dsym, index);
    }
  }
}
Esempio n. 8
0
void symtab_inherit_branch(symtab_t* dst, symtab_t* src)
{
  size_t i = HASHMAP_BEGIN;
  symbol_t* sym;

  while((sym = symtab_next(src, &i)) != NULL)
  {
    // Only inherit symbols that were declared in an outer scope.
    if(sym->value != NULL)
      continue;

    symbol_t* dsym = symtab_get(dst, sym);

    if(dsym != NULL)
    {
      if(sym->status == SYM_DEFINED)
      {
        // Treat defined as adding one to the undefined branch count.
        if(dsym->status == SYM_UNDEFINED)
          dsym->branch_count++;
      } else if(sym->status == SYM_CONSUMED) {
        // Consumed overrides everything.
        dsym->status = SYM_CONSUMED;
        dsym->branch_count = 0;
      }
    } else {
      // Add this symbol to the destination.
      dsym = sym_dup(sym);

      if(dsym->status == SYM_DEFINED)
      {
        // Treat defined as undefined with a branch count of one.
        dsym->status = SYM_UNDEFINED;
        dsym->branch_count = 1;
      }

      symtab_put(dst, dsym);
    }
  }
}
Esempio n. 9
0
void symtab_inherit_status(symtab_t* dst, symtab_t* src)
{
  size_t i = HASHMAP_BEGIN;
  symbol_t* sym;

  while((sym = symtab_next(src, &i)) != NULL)
  {
    // Only inherit symbols that were declared in an outer scope.
    if(sym->def != NULL)
      continue;

    symbol_t* dsym = symtab_get(dst, sym);

    if(dsym != NULL)
    {
      // Copy the source status the the destination.
      dsym->status = sym->status;
    } else {
      // Add this symbol to the destination.
      symtab_put(dst, sym_dup(sym));
    }
  }
}