Home | History | Annotate | Download | only in preprocessor

Lines Matching refs:atable

310 AtomTable *atable = &latable;
312 static int AddAtomFixed(AtomTable *atable, const char *s, int atom);
319 static int GrowAtomTable(AtomTable *atable, int size)
323 if (atable->size < size) {
324 if (atable->amap) {
325 newmap = realloc(atable->amap, sizeof(int)*size);
326 newrev = realloc(atable->arev, sizeof(int)*size);
330 atable->size = 0;
335 atable->amap = newmap;
337 atable->amap = newrev;
340 memset(&newmap[atable->size], 0, (size - atable->size) * sizeof(int));
341 memset(&newrev[atable->size], 0, (size - atable->size) * sizeof(int));
342 atable->amap = newmap;
343 atable->arev = newrev;
344 atable->size = size;
379 static int AllocateAtom(AtomTable *atable)
381 if (atable->nextFree >= atable->size)
382 GrowAtomTable(atable, atable->nextFree*2);
383 atable->amap[atable->nextFree] = -1;
384 atable->arev[atable->nextFree] = lReverse(atable->nextFree);
385 atable->nextFree++;
386 return atable->nextFree - 1;
394 static void SetAtomValue(AtomTable *atable, int atomnumber, int hashindex)
396 atable->amap[atomnumber] = atable->htable.entry[hashindex].index;
397 atable->htable.entry[hashindex].value = atomnumber;
405 static int FindHashLoc(AtomTable *atable, const char *s)
411 hashloc = HashString(s) % atable->htable.size;
412 if (!Empty(&atable->htable, hashloc)) {
413 if (Match(&atable->htable, &atable->stable, s, hashloc))
419 hashloc = ((hashloc + hashdelta) & 0x7fffffff) % atable->htable.size;
420 if (!Empty(&atable->htable, hashloc)) {
421 if (Match(&atable->htable, &atable->stable, s, hashloc)) {
444 ii + 1, collision[ii], GetAtomString(atable, atable->htable.entry[collision[ii]].value));
450 atable->htable.counts[count]++;
461 static int IncreaseHashTableSize(AtomTable *atable)
469 oldtable = *atable;
471 if (!InitAtomTable(atable, size))
476 for (ii = atable->nextFree; ii < oldtable.nextFree; ii++) {
482 AddAtomFixed(atable, s, value);
493 static int LookUpAddStringHash(AtomTable *atable, const char *s)
498 hashloc = FindHashLoc(atable, s);
501 IncreaseHashTableSize(atable);
504 if (Empty(&atable->htable, hashloc)) {
505 atable->htable.entries++;
506 strloc = AddString(&atable->stable, s);
507 atable->htable.entry[hashloc].index = strloc;
508 atable->htable.entry[hashloc].value = 0;
519 int LookUpAddString(AtomTable *atable, const char *s)
523 hashindex = LookUpAddStringHash(atable, s);
524 atom = atable->htable.entry[hashindex].value;
526 atom = AllocateAtom(atable);
527 SetAtomValue(atable, atom, hashindex);
537 const char *GetAtomString(AtomTable *atable, int atom)
541 if (atom > 0 && atom < atable->nextFree) {
542 soffset = atable->amap[atom];
543 atable->stable.nextFree) {
544 return &atable->stable.strings[soffset];
566 int GetReversedAtom(AtomTable *atable, int atom)
568 if (atom > 0 && atom < atable->nextFree) {
569 return atable->arev[atom];
580 int AddAtom(AtomTable *atable, const char *s)
584 atom = LookUpAddString(atable, s);
593 static int AddAtomFixed(AtomTable *atable, const char *s, int atom)
597 hashindex = LookUpAddStringHash(atable, s);
598 if (atable->nextFree >= atable->size || atom >= atable->size) {
599 lsize = atable->size*2;
602 GrowAtomTable(atable, lsize);
604 atable->amap[atom] = atable->htable.entry[hashindex].index;
605 atable->htable.entry[hashindex].value = atom;
606 //if (atom >= atable->nextFree)
607 // atable->nextFree = atom + 1;
608 while (atom >= atable->nextFree) {
609 atable->arev[atable->nextFree] = lReverse(atable->nextFree);
610 atable->nextFree++;
620 int InitAtomTable(AtomTable *atable, int htsize)
625 if (!InitStringTable(&atable->stable))
627 if (!InitHashTable(&atable->htable, htsize))
630 atable->nextFree = 0;
631 atable->amap = NULL;
632 atable->size = 0;
633 GrowAtomTable(atable, INIT_ATOM_TABLE_SIZE);
634 if (!atable->amap)
639 AddAtomFixed(atable, "<undefined>", 0);
641 atable->amap[ii] = atable->amap[0];
652 AddAtomFixed(atable, t, s[0]);
660 AddAtomFixed(atable, tokens[ii].str, tokens[ii].val);
665 AddAtomFixed(atable, "error", ERROR_SY);
667 AddAtom(atable, "<*** end fixed atoms ***>");
681 void PrintAtomTable(AtomTable *atable)
686 for (ii = 0; ii < atable->nextFree; ii++) {
687 sprintf(str, "%d: \"%s\"", ii, &atable->stable.strings[atable->amap[ii]]);
691 atable->htable.size, atable->htable.entries);
694 sprintf(str, " %d", atable->htable.counts[ii]);
706 char* GetStringOfAtom(AtomTable *atable, int atom)
709 chr_str=&atable->stable.strings[atable->amap[atom]];
718 void FreeAtomTable(AtomTable *atable)
720 FreeStringTable(&atable->stable);
721 FreeHashTable(&atable->htable);
722 if (atable->amap)
723 free(atable->amap);
724 if (atable->arev)
725 free(atable->arev);
726 atable->amap = NULL;
727 atable->arev = NULL;
728 atable->nextFree = 0;
729 atable->size = 0;