Skip to content

Commit

Permalink
Merge pull request #2940 from masatake/optscript-prep
Browse files Browse the repository at this point in the history
some fixes made during developing optscript
  • Loading branch information
masatake authored Apr 4, 2021
2 parents 3185b28 + a80686c commit 068a16f
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 24 deletions.
8 changes: 4 additions & 4 deletions main/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,7 @@ static int queueTagEntry(const tagEntryInfo *const tag)

corkIndex = (int)ptrArrayAdd (TagFile.corkQueue, entry);
entry->corkIndex = corkIndex;
entry->slot.inCorkQueue = 1;

return corkIndex;
}
Expand Down Expand Up @@ -1884,8 +1885,9 @@ static void markTagExtraBitFull (tagEntryInfo *const tag, xtagType extra,

int n = countXtags () - XTAG_COUNT;
tag->extraDynamic = xCalloc ((n / 8) + 1, uint8_t);
PARSER_TRASH_BOX(tag->extraDynamic, eFree);
markTagExtraBit (tag, extra);
if (!tag->inCorkQueue)
PARSER_TRASH_BOX(tag->extraDynamic, eFree);
markTagExtraBitFull (tag, extra, mark);
return;
}

Expand Down Expand Up @@ -1913,7 +1915,6 @@ extern bool isTagExtraBitMarked (const tagEntryInfo *const tag, xtagType extra)
index = (extra / 8);
offset = (extra % 8);
slot = tag->extra;

}
else if (!tag->extraDynamic)
return false;
Expand All @@ -1923,7 +1924,6 @@ extern bool isTagExtraBitMarked (const tagEntryInfo *const tag, xtagType extra)
index = ((extra - XTAG_COUNT) / 8);
offset = ((extra - XTAG_COUNT) % 8);
slot = tag->extraDynamic;

}
return !! ((slot [ index ]) & (1 << offset));
}
Expand Down
1 change: 1 addition & 0 deletions main/entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct sTagEntryInfo {
current tag by itself, set this. */
unsigned int isPseudoTag:1; /* Used only in xref output.
If a tag is a pseudo, set this. */
unsigned int inCorkQueue:1;

unsigned long lineNumber; /* line number of tag */
const char* pattern; /* pattern for locating input line
Expand Down
28 changes: 19 additions & 9 deletions main/htable.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ struct sHashTable {
hashTableEqualFunc equalfn;
hashTableDeleteFunc keyfreefn;
hashTableDeleteFunc valfreefn;
void *valForNotUnknownKey;
hashTableDeleteFunc valForNotUnknownKeyfreefn;
};

struct chainTracker {
Expand Down Expand Up @@ -100,15 +102,16 @@ static void entry_reclaim (hentry* entry,
entry = entry_destroy (entry, keyfreefn, valfreefn);
}

static void *entry_find (hentry* entry, const void* const key, hashTableEqualFunc equalfn)
static void *entry_find (hentry* entry, const void* const key, hashTableEqualFunc equalfn,
void *valForNotUnknownKey)
{
while (entry)
{
if (equalfn( key, entry->key))
return entry->value;
entry = entry->next;
}
return NULL;
return valForNotUnknownKey;
}

static bool entry_delete (hentry **entry, const void *key, hashTableEqualFunc equalfn,
Expand Down Expand Up @@ -168,16 +171,21 @@ extern hashTable *hashTableNew (unsigned int size,
htable->equalfn = equalfn;
htable->keyfreefn = keyfreefn;
htable->valfreefn = valfreefn;
htable->valForNotUnknownKey = NULL;
htable->valForNotUnknownKeyfreefn = NULL;

return htable;
}

extern hashTable* hashTableIntNew (unsigned int size,
hashTableHashFunc hashfn,
hashTableEqualFunc equalfn,
hashTableDeleteFunc keyfreefn)
extern void hashTableSetValueForUnknownKey (hashTable *htable,
void *val,
hashTableDeleteFunc valfreefn)
{
return hashTableNew (size, hashfn, equalfn, keyfreefn, NULL);
if (htable->valfreefn)
htable->valfreefn (htable->valForNotUnknownKey);

htable->valForNotUnknownKey = val;
htable->valForNotUnknownKeyfreefn = valfreefn;
}

extern void hashTableDelete (hashTable *htable)
Expand All @@ -187,6 +195,8 @@ extern void hashTableDelete (hashTable *htable)

hashTableClear (htable);

if (htable->valForNotUnknownKeyfreefn)
htable->valForNotUnknownKeyfreefn (htable->valForNotUnknownKey);
eFree (htable->table);
eFree (htable);
}
Expand Down Expand Up @@ -220,7 +230,7 @@ extern void* hashTableGetItem (hashTable *htable, const void * key)
unsigned int i;

i = htable->hashfn (key) % htable->size;
return entry_find(htable->table[i], key, htable->equalfn);
return entry_find(htable->table[i], key, htable->equalfn, htable->valForNotUnknownKey);
}

extern bool hashTableDeleteItem (hashTable *htable, const void *key)
Expand All @@ -246,7 +256,7 @@ extern bool hashTableUpdateItem (hashTable *htable, void *key, void *value)

extern bool hashTableHasItem (hashTable *htable, const void *key)
{
return hashTableGetItem (htable, key)? true: false;
return hashTableGetItem (htable, key) == htable->valForNotUnknownKey? false: true;
}

extern bool hashTableForeachItem (hashTable *htable, hashTableForeachFunc proc, void *user_data)
Expand Down
14 changes: 10 additions & 4 deletions main/htable.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ extern hashTable* hashTableNew (unsigned int size,
hashTableDeleteFunc keyfreefn,
hashTableDeleteFunc valfreefn);

/* By default, hashTableGetItem() returns NULL for a unknown key.
* It means you cannot store NULL as a value for a key.
* With hashTableSetValueForUnknownKey(), you can specific
* an alternative address representing the value for for unknown
* keys.
*/
extern void hashTableSetValueForUnknownKey (hashTable *htable,
void *val,
hashTableDeleteFunc valfreefn);

extern void hashTableDelete (hashTable *htable);
extern void hashTableClear (hashTable *htable);
extern void hashTablePutItem (hashTable *htable, void *key, void *value);
Expand All @@ -77,10 +87,6 @@ extern bool hashTableForeachItemOnChain (hashTable *htable, const void *ke

extern unsigned int hashTableCountItem (hashTable *htable);

extern hashTable* hashTableIntNew (unsigned int size,
hashTableHashFunc hashfn,
hashTableEqualFunc equalfn,
hashTableDeleteFunc keyfreefn);
#define HT_PTR_TO_INT(P) ((int)(intptr_t)(P))
#define HT_INT_TO_PTR(P) ((void*)(intptr_t)(P))
#define HT_PTR_TO_UINT(P) ((unsigned int)(uintptr_t)(P))
Expand Down
6 changes: 3 additions & 3 deletions main/xtag.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,12 @@ extern bool isCommonXtag (xtagType type)
return (type < XTAG_COUNT)? true: false;
}

extern int getXtagOwner (xtagType type)
extern langType getXtagOwner (xtagType type)
{
return getXtagObject (type)->language;
}

const char* getXtagName (xtagType type)
extern const char* getXtagName (xtagType type)
{
xtagDefinition* def = getXtagDefinition (type);
if (def)
Expand All @@ -296,7 +296,7 @@ const char* getXtagName (xtagType type)
return NULL;
}

const char* getXtagDescription (xtagType type)
extern const char* getXtagDescription (xtagType type)
{
xtagDefinition* def = getXtagDefinition (type);
if (def)
Expand Down
8 changes: 5 additions & 3 deletions main/xtag_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ extern xtagType getXtagTypeForNameAndLanguage (const char *name, langType langu
extern bool enableXtag (xtagType type, bool state);
extern bool isXtagFixed (xtagType type);
extern bool isCommonXtag (xtagType type);
extern int getXtagOwner (xtagType type);

const char* getXtagName (xtagType type);
const char* getXtagDescription (xtagType type);
/* Return LANG_IGNORE for common fields. */
extern langType getXtagOwner (xtagType type);

extern const char* getXtagName (xtagType type);
extern const char* getXtagDescription (xtagType type);

extern void initXtagObjects (void);
extern int countXtags (void);
Expand Down
3 changes: 3 additions & 0 deletions source.mak
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,9 @@ ALL_OBJS = \
$(ALL_SRCS:.c=.$(OBJEXT)) \
$(LIBOBJS)

ALL_LIB_OBJS = \
$(ALL_LIB_SRCS:.c=.$(OBJEXT)) \
$(LIBOBJS)

READTAGS_SRCS = \
libreadtags/readtags.c \
Expand Down
2 changes: 1 addition & 1 deletion win32/ctags_vs2013.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<ClCompile Include="..\optlib\qemuhx.c" />
<ClCompile Include="..\optlib\scss.c" />
<ClCompile Include="..\optlib\systemtap.c" />
<ClCompile Include="..\parsers\abaqus.c" />
<ClCompile Include="..\parsers\abaqus.c" />
<ClCompile Include="..\parsers\abc.c" />
<ClCompile Include="..\parsers\ada.c" />
<ClCompile Include="..\parsers\ant.c" />
Expand Down

0 comments on commit 068a16f

Please sign in to comment.