Skip to content

Commit

Permalink
Merge pull request universal-ctags#3617 from masatake/various-prepara…
Browse files Browse the repository at this point in the history
…tions

Various preparations
  • Loading branch information
masatake authored Jan 4, 2023
2 parents 13d8e3f + 8be2171 commit 0435cac
Show file tree
Hide file tree
Showing 17 changed files with 159 additions and 28 deletions.
1 change: 0 additions & 1 deletion Units/parser-asm.r/gas-section.d/args.ctags
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--sort=no
--extras=+r
--fields=+r

22 changes: 17 additions & 5 deletions main/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -1738,17 +1738,24 @@ extern size_t countEntryInCorkQueue (void)
return ptrArrayCount (TagFile.corkQueue);
}

extern void markTagPlaceholder (tagEntryInfo *e, bool placeholder)
extern void markTagAsPlaceholder (tagEntryInfo *e, bool placeholder)
{
e->placeholder = placeholder;
}

extern void markCorkEntryAsPlaceholder (int index, bool placeholder)
{
tagEntryInfo *e = getEntryInCorkQueue(index);
if (e)
markTagAsPlaceholder(e, placeholder);
}

extern int makePlaceholder (const char *const name)
{
tagEntryInfo e;

initTagEntry (&e, name, KIND_GHOST_INDEX);
markTagPlaceholder(&e, true);
markTagAsPlaceholder(&e, true);

/*
* makePlaceholder may be called even before reading any bytes
Expand Down Expand Up @@ -2078,6 +2085,11 @@ extern void assignRole(tagEntryInfo *const e, int roleIndex)
assignRoleFull(e, roleIndex, true);
}

extern void unassignRole(tagEntryInfo *const e, int roleIndex)
{
assignRoleFull(e, roleIndex, false);
}

extern bool isRoleAssigned(const tagEntryInfo *const e, int roleIndex)
{
if (roleIndex == ROLE_DEFINITION_INDEX)
Expand Down Expand Up @@ -2151,14 +2163,14 @@ extern const char* getTagFileDirectory (void)
return TagFile.directory;
}

static bool markAsPlaceholder (int index, tagEntryInfo *e, void *data CTAGS_ATTR_UNUSED)
static bool markAsPlaceholderRecursively (int index, tagEntryInfo *e, void *data CTAGS_ATTR_UNUSED)
{
e->placeholder = 1;
markTagAsPlaceholder (e, true);
markAllEntriesInScopeAsPlaceholder (index);
return true;
}

extern void markAllEntriesInScopeAsPlaceholder (int index)
{
foreachEntriesInScope (index, NULL, markAsPlaceholder, NULL);
foreachEntriesInScope (index, NULL, markAsPlaceholderRecursively, NULL);
}
5 changes: 4 additions & 1 deletion main/entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ extern void initForeignRefTagEntry (tagEntryInfo *const e, const char *const nam
langType type,
int kindIndex, int roleIndex);
extern void assignRole(tagEntryInfo *const e, int roleIndex);
#define clearRoles(E) assignRole((E), ROLE_DEFINITION_INDEX)
extern void unassignRole(tagEntryInfo *const e, int roleIndex);
extern bool isRoleAssigned(const tagEntryInfo *const e, int roleIndex);

extern int makeQualifiedTagEntry (const tagEntryInfo *const e);
Expand Down Expand Up @@ -286,7 +288,8 @@ extern void attachParserFieldToCorkEntry (int index, fieldType ftype, const char
extern const char* getParserFieldValueForType (tagEntryInfo *const tag, fieldType ftype);

extern int makePlaceholder (const char *const name);
extern void markTagPlaceholder (tagEntryInfo *e, bool placeholder);
extern void markTagAsPlaceholder (tagEntryInfo *e, bool placeholder);
extern void markCorkEntryAsPlaceholder (int index, bool placeholder);

/* Marking all tag entries entries under the scope specified
* with index recursively.
Expand Down
73 changes: 69 additions & 4 deletions main/lregex.c
Original file line number Diff line number Diff line change
Expand Up @@ -1733,7 +1733,9 @@ static void matchTagPattern (struct lregexControlBlock *lcb,
scriptSetup (optvm, lcb, n, window);
EsObject *e = scriptEval (optvm, patbuf->optscript);
if (es_error_p (e))
error (WARNING, "error when evaluating: %s", patbuf->optscript_src);
error (WARNING, "error when evaluating: %s %% input: %s, line:%lu", patbuf->optscript_src,
getInputFileName (),
getInputLineNumberInRegPType(patbuf->regptype, offset));
es_object_unref (e);
scriptTeardown (optvm, lcb);
}
Expand Down Expand Up @@ -1886,7 +1888,8 @@ static bool matchRegexPattern (struct lregexControlBlock *lcb,
scriptSetup (optvm, lcb, CORK_NIL, &window);
EsObject *e = scriptEval (optvm, patbuf->optscript);
if (es_error_p (e))
error (WARNING, "error when evaluating: %s", patbuf->optscript_src);
error (WARNING, "error when evaluating: %s %% input: %s", patbuf->optscript_src,
getInputFileName ());
es_object_unref (e);
scriptTeardown (optvm, lcb);
}
Expand Down Expand Up @@ -1978,7 +1981,8 @@ static bool matchMultilineRegexPattern (struct lregexControlBlock *lcb,
scriptSetup (optvm, lcb, CORK_NIL, &window);
EsObject *e = scriptEval (optvm, patbuf->optscript);
if (es_error_p (e))
error (WARNING, "error when evaluating: %s", patbuf->optscript_src);
error (WARNING, "error when evaluating: %s %% input: %s", patbuf->optscript_src,
getInputFileName ());
es_object_unref (e);
scriptTeardown (optvm, lcb);
}
Expand Down Expand Up @@ -3333,6 +3337,55 @@ static EsObject* lrop_make_reftag (OptVM *vm, EsObject *name)
return es_false;
}

static EsObject* lrop_assign_role_common (OptVM *vm, EsObject *name, bool assign)
{
EsObject *tag = opt_vm_ostack_peek (vm, 1);
tagEntryInfo *e;
if (es_integer_p (tag))
{
int n = es_integer_get (tag);
if (! (CORK_NIL < n && n < countEntryInCorkQueue()))
return OPT_ERR_RANGECHECK;
e = getEntryInCorkQueue (n);
}
else if (es_object_get_type (tag) == OPT_TYPE_TAG)
e = es_pointer_get (tag);
else
return OPT_ERR_TYPECHECK;

if (e == NULL)
return OPTSCRIPT_ERR_NOTAGENTRY;

langType lang = e->langType;
int kind_index = e->kindIndex;
EsObject *role = opt_vm_ostack_top (vm);
if (es_object_get_type (role) != OPT_TYPE_NAME)
return OPT_ERR_TYPECHECK;
EsObject *role_sym = es_pointer_get (role);
const char *role_str = es_symbol_get (role_sym);
roleDefinition* role_def = getLanguageRoleForName (lang, kind_index, role_str);
if (!role_def)
return OPTSCRIPT_ERR_UNKNOWNROLE;
int role_index = role_def->id;

(assign? assignRole: unassignRole) (e, role_index);

opt_vm_ostack_pop (vm);
opt_vm_ostack_pop (vm);

return es_false;
}

static EsObject* lrop_assign_role (OptVM *vm, EsObject *name)
{
return lrop_assign_role_common (vm, name, true);
}

static EsObject* lrop_unassign_role (OptVM *vm, EsObject *name)
{
return lrop_assign_role_common (vm, name, false);
}

/* tag COMMIT int */
static EsObject* lrop_commit_tag (OptVM *vm, EsObject *name)
{
Expand Down Expand Up @@ -3947,7 +4000,7 @@ static EsObject *lrop_markplaceholder (OptVM *vm, EsObject *name)
if (e == NULL)
return OPTSCRIPT_ERR_NOTAGENTRY;

markTagPlaceholder (e, true);
markTagAsPlaceholder (e, true);

opt_vm_ostack_pop (vm);
return es_false;
Expand Down Expand Up @@ -4211,6 +4264,18 @@ static struct optscriptOperatorRegistration lropOperators [] = {
.help_str = "param:name _PARAM value:string true%"
"param:name _PARAM false",
},
{
.name = "_assignrole",
.fn = lrop_assign_role,
.arity = 2,
.help_str = "tag:int|tag:tag role:name _ASSIGNROLE -",
},
{
.name = "_unassignrole",
.fn = lrop_unassign_role,
.arity = 2,
.help_str = "tag:int|tag:tag role:name _UNASSIGNROLE -",
},
};

extern void initRegexOptscript (void)
Expand Down
4 changes: 3 additions & 1 deletion main/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ extern bool isLanguageEnabled (const langType language);
extern bool isLanguageKindEnabled (const langType language, int kindIndex);
extern bool isLanguageRoleEnabled (const langType language, int kindIndex, int roleIndex);

extern kindDefinition* getLanguageKindForLetter (const langType language, char kindLetter);
extern kindDefinition* getLanguageKindForName (const langType language, const char *kindName);
extern roleDefinition* getLanguageRoleForName (const langType language, int kindIndex,
const char *roleName);

extern void initializeParser (langType language);
extern unsigned int getLanguageCorkUsage (langType language);
Expand Down
4 changes: 1 addition & 3 deletions main/parse_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ extern bool doesLanguageRequestAutomaticFQTag (const langType language);
extern langType getNamedLanguageFull (const char *const name, size_t len, bool noPretending, bool include_aliases);

extern kindDefinition* getLanguageKind(const langType language, int kindIndex);
extern kindDefinition* getLanguageKindForName (const langType language, const char *kindName);
extern kindDefinition* getLanguageKindForLetter (const langType language, char kindLetter);
extern roleDefinition* getLanguageRole(const langType language, int kindIndex, int roleIndex);
extern roleDefinition* getLanguageRoleForName (const langType language, int kindIndex,
const char *roleName);
extern unsigned int getLanguageVersionCurrent (const langType language);
extern unsigned int getLanguageVersionAge (const langType language);

Expand Down
7 changes: 6 additions & 1 deletion misc/optlib2c
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,11 @@ EOF
if (defined $opts->{'selector'}) {
print <<EOF;
#include "selectors.h"
EOF
}
if ((scalar @{$opts->{'paramdefs'}}) > 0) {
print <<EOF;
#include "param.h"
EOF
}
print <<EOF;
Expand Down Expand Up @@ -968,7 +973,7 @@ EOF
print <<EOF;
{
.name = "$_->{'name'}",
.description = "$desc",
.desc = "$desc",
.handleParam = NULL,
},
EOF
Expand Down
28 changes: 27 additions & 1 deletion misc/review
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,43 @@ function tmain_inspect_run
make tmain UNITS=$(basename $t .d)
}


tmain_inspect_cmd_show_diff_generic()
{
local prefix=$1
local t=$2
local c=$3
cat $prefix/$t/$c-diff.txt | diff_post_processor
}

tmain_inspect_cmd_show_diff_all()
{
local prefix=$1
local t=$2
local c

for c in stdout stderr exit; do
if [[ -e "$prefix/$t/$c-diff.txt" ]]; then
echo '### ' "$c"
tmain_inspect_cmd_show_diff_generic "$prefix" "$t" "$c"
fi
done
}

do_tmain_inspect()
{
local next=0
local r
local t=$1

select r in '<n>ext' '<S>hell' '<R>un' '<q>uit'; do
select r in '<n>ext' '<d>iff' '<S>hell' '<R>un' '<q>uit'; do
case $r-$REPLY in
("<n>ext"-*|-n)
next=1
;;
("<d>iff"-*|-d)
tmain_inspect_cmd_show_diff_all Tmain "$t"
;;
("<S>hell"-*|-S)
inspect_cmd_shell Tmain "$t"
;;
Expand Down
1 change: 1 addition & 0 deletions optlib/pod.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static void initializePodParser (const langType language CTAGS_ATTR_UNUSED)
" 0 get ?1 sub\n"
" } def\n"
"\n"
" % cork:int DEPTHFORCORK depth:int\n"
" /depthForCork {\n"
" :kind kindTable exch _aindex pop\n"
" } def\n"
Expand Down
1 change: 1 addition & 0 deletions optlib/pod.ctags
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
0 get ?1 sub
} def

% cork:int DEPTHFORCORK depth:int
/depthForCork {
:kind kindTable exch _aindex pop
} def
Expand Down
15 changes: 8 additions & 7 deletions parsers/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ static int makeAsmTag (
const bool labelCandidate,
const bool nameFollows,
const bool directive,
int *scope)
int *macroScope)
{
int r = CORK_NIL;

Expand Down Expand Up @@ -258,17 +258,17 @@ static int makeAsmTag (
macro_tag = getEntryInCorkQueue (r);
if (macro_tag)
{
macro_tag->extensionFields.scopeIndex = *scope;
macro_tag->extensionFields.scopeIndex = *macroScope;
registerEntry (r);
*scope = r;
*macroScope = r;
}
break;
case K_PSUEDO_MACRO_END:
macro_tag = getEntryInCorkQueue (*scope);
macro_tag = getEntryInCorkQueue (*macroScope);
if (macro_tag)
{
macro_tag->extensionFields.endLine = getInputLineNumber ();
*scope = macro_tag->extensionFields.scopeIndex;
*macroScope = macro_tag->extensionFields.scopeIndex;
}
break;
case K_SECTION:
Expand All @@ -278,6 +278,7 @@ static int makeAsmTag (
break;
default:
r = makeSimpleTag (operator, kind_for_directive);
break;
}
}
}
Expand Down Expand Up @@ -655,7 +656,7 @@ static void findAsmTagsCommon (bool useCpp)
KIND_GHOST_INDEX, 0, 0, KIND_GHOST_INDEX, KIND_GHOST_INDEX, 0, 0,
FIELD_UNKNOWN);

int scope = CORK_NIL;
int macroScope = CORK_NIL;

while ((line = asmReadLineFromInputFile (commentCharsInMOL, useCpp)) != NULL)
{
Expand Down Expand Up @@ -719,7 +720,7 @@ static void findAsmTagsCommon (bool useCpp)
cp = readSymbol (cp, name);
nameFollows = true;
}
int r = makeAsmTag (name, operator, labelCandidate, nameFollows, directive, &scope);
int r = makeAsmTag (name, operator, labelCandidate, nameFollows, directive, &macroScope);
tagEntryInfo *e = getEntryInCorkQueue (r);
if (e && e->kindIndex == K_MACRO && isRoleAssigned(e, ROLE_DEFINITION_INDEX))
readMacroParameters (r, e, cp);
Expand Down
15 changes: 15 additions & 0 deletions parsers/cxx/cxx_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ bool cxxTagKindEnabled(unsigned int uKind)
return g_cxx.pKindDefinitions[uKind].enabled;
}

bool cxxTagRoleEnabled(unsigned int uKind, int iRole)
{
if(!cxxTagKindEnabled(uKind))
return true;
if(iRole == ROLE_DEFINITION_INDEX)
return true;

CXX_DEBUG_ASSERT(
(ROLE_DEFINITION_INDEX < iRole
&& iRole < g_cxx.pKindDefinitions[uKind].nRoles),
"The role must be associated to the kind (%u)", uKind
);
return g_cxx.pKindDefinitions[uKind].roles[iRole].enabled;
}

fieldDefinition * cxxTagGetCPPFieldDefinitionifiers(void)
{
return g_aCXXCPPFields;
Expand Down
3 changes: 3 additions & 0 deletions parsers/cxx/cxx_tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ int cxxTagGetCPPKindDefinitionCount(void);
// Returns true if the specified tag kind is enabled in the current language
bool cxxTagKindEnabled(unsigned int uTagKind);

// Returns true if the specified tag role is enabled in the current language
bool cxxTagRoleEnabled(unsigned int uTagKind, int iTagRole);

// Begin composing a tag. The tag kind must correspond to the current language.
// Returns NULL if the tag should *not* be included in the output
// or the tag entry info that can be filled up with extension fields.
Expand Down
2 changes: 1 addition & 1 deletion parsers/cxx/cxx_token.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ typedef struct _CXXToken
vString * pszWord;
CXXKeyword eKeyword;
CXXTokenChain * pChain; // this is NOT the parent chain!
bool bFollowedBySpace;
unsigned int bFollowedBySpace: 1;

int iLineNumber;
MIOPos oFilePosition;
Expand Down
Loading

0 comments on commit 0435cac

Please sign in to comment.