Skip to content

Commit

Permalink
main,refactor: don't access lineNumber member of tag entries directrl…
Browse files Browse the repository at this point in the history
…y when setting

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed May 9, 2023
1 parent 627bf65 commit 3a1949f
Show file tree
Hide file tree
Showing 47 changed files with 79 additions and 124 deletions.
13 changes: 10 additions & 3 deletions main/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,14 @@ static int queueTagEntry (const tagEntryInfo *const tag)
return corkIndex;
}

extern void updateTagLine (tagEntryInfo *tag, unsigned long lineNumber,
MIOPos filePosition)
{
tag->lineNumber = lineNumber;
tag->filePosition = filePosition;
tag->boundaryInfo = getNestedInputBoundaryInfo (lineNumber);
}

extern void setTagEndLine(tagEntryInfo *tag, unsigned long endLine)
{
if (endLine != 0 && endLine < tag->lineNumber)
Expand Down Expand Up @@ -1910,9 +1918,8 @@ extern int makeQualifiedTagEntry (const tagEntryInfo *const e)
extern void setTagPositionFromTag (tagEntryInfo *const dst,
const tagEntryInfo *const src)
{
dst->lineNumber = src->lineNumber;
dst->boundaryInfo = src->boundaryInfo;
dst->filePosition = src->filePosition;
updateTagLine (dst, src->lineNumber, src->filePosition);
dst->boundaryInfo = src->boundaryInfo;
}

static void initTagEntryFull (tagEntryInfo *const e, const char *const name,
Expand Down
4 changes: 3 additions & 1 deletion main/entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ struct sTagEntryInfo {
* Set in the cork queue; don't touch this.*/
unsigned int boundaryInfo: 2; /* info about nested input stream */

unsigned long lineNumber; /* line number of tag */
unsigned long lineNumber; /* line number of tag;
use updateTagLine() for updating this member. */
const char* pattern; /* pattern for locating input line
* (may be NULL if not present) *//* */
MIOPos filePosition; /* file position of line containing tag */
Expand Down Expand Up @@ -241,6 +242,7 @@ int anyKindsEntryInScopeRecursive (int corkIndex,
const int * kinds, int count,
bool onlyDefinitionTag);

extern void updateTagLine(tagEntryInfo *tag, unsigned long lineNumber, MIOPos filePosition);
extern void setTagEndLine (tagEntryInfo *tag, unsigned long endLine);
extern void setTagEndLineToCorkEntry (int corkIndex, unsigned long endLine);

Expand Down
5 changes: 1 addition & 4 deletions main/field.c
Original file line number Diff line number Diff line change
Expand Up @@ -1889,10 +1889,7 @@ static EsObject* setFieldValueForLineCommon (tagEntryInfo *tag, const fieldDefin
if (fdef->ftype == FIELD_END_LINE)
setTagEndLine(tag, (unsigned long)l);
else
{
tag->lineNumber = l;
tag->filePosition = getInputFilePositionForLine (l);
}
updateTagLine (tag, l, getInputFilePositionForLine (l));

return es_false;
}
Expand Down
5 changes: 1 addition & 4 deletions main/lregex.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,7 @@ static void initRegexTag (tagEntryInfo *e,
e->extensionFields.scopeIndex = scopeIndex;
markTagAsPlaceholder(e, placeholder);
if (line)
{
e->lineNumber = line;
e->filePosition = *pos;
}
updateTagLine(e, line, *pos);

if (xtag_type != XTAG_UNKNOWN)
markTagExtraBit (e, xtag_type);
Expand Down
4 changes: 2 additions & 2 deletions main/lxpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ static void simpleXpathMakeTag (xmlNode *node,
goto out;


tag.lineNumber = XML_GET_LINE (node);
tag.filePosition = getInputFilePositionForLine (tag.lineNumber);
unsigned long lineNumber = XML_GET_LINE (node);
updateTagLine(&tag, lineNumber, getInputFilePositionForLine (lineNumber));

path = (char *)xmlGetNodePath (node);
tag.extensionFields.xpath = path;
Expand Down
17 changes: 7 additions & 10 deletions parsers/ada.c
Original file line number Diff line number Diff line change
Expand Up @@ -1499,8 +1499,8 @@ static adaTokenInfo *adaParseVariables (adaTokenInfo *parent, adaKind kind)

/* now set the proper line and file position counts for this
* new token */
token->tag.lineNumber = lineNum + filePosIndex;
token->tag.filePosition = filePos[filePosIndex];
updateTagLine (&token->tag, lineNum + filePosIndex,
filePos[filePosIndex]);
}
tokenStart = -1;
}
Expand All @@ -1526,8 +1526,8 @@ static adaTokenInfo *adaParseVariables (adaTokenInfo *parent, adaKind kind)

/* now set the proper line and file position counts for this
* new token */
token->tag.lineNumber = lineNum + filePosIndex;
token->tag.filePosition = filePos[filePosIndex];
updateTagLine (&token->tag, lineNum + filePosIndex,
filePos[filePosIndex]);
}
}

Expand Down Expand Up @@ -1931,8 +1931,7 @@ static adaTokenInfo *adaParse (adaParseMode mode, adaTokenInfo *parent)
token = newAdaToken (NULL, 0, ADA_KIND_ANONYMOUS, false, parent);

/* save the correct starting line */
token->tag.lineNumber = matchLineNum;
token->tag.filePosition = matchFilePos;
updateTagLine (&token->tag, matchLineNum, matchFilePos);

adaParse (ADA_DECLARATIONS, token);
}
Expand All @@ -1947,8 +1946,7 @@ static adaTokenInfo *adaParse (adaParseMode mode, adaTokenInfo *parent)
token = newAdaToken (NULL, 0, ADA_KIND_ANONYMOUS, false, parent);

/* save the correct starting line */
token->tag.lineNumber = matchLineNum;
token->tag.filePosition = matchFilePos;
updateTagLine (&token->tag, matchLineNum, matchFilePos);

adaParse (ADA_CODE, token);
}
Expand Down Expand Up @@ -2029,8 +2027,7 @@ static adaTokenInfo *adaParse (adaParseMode mode, adaTokenInfo *parent)
ADA_KIND_ANONYMOUS, false, parent);

/* save the correct starting line */
token->tag.lineNumber = matchLineNum;
token->tag.filePosition = matchFilePos;
updateTagLine (&token->tag, matchLineNum, matchFilePos);

/* parse the loop body */
skipWhiteSpace ();
Expand Down
4 changes: 2 additions & 2 deletions parsers/asciidoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ static int makeAsciidocTag (const vString* const name, const int kind, const boo
if (e.lineNumber > 1)
{
unsigned long lineNumber = e.lineNumber - 1;
e.lineNumber = lineNumber;
e.filePosition = getInputFilePositionForLine(lineNumber);
updateTagLine (&e, lineNumber,
getInputFilePositionForLine(lineNumber));
}
}

Expand Down
3 changes: 1 addition & 2 deletions parsers/bibtex.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ static void makeBibTag (tokenInfo *const token, bibKind kind)
tagEntryInfo e;
initTagEntry (&e, name, kind);

e.lineNumber = token->lineNumber;
e.filePosition = token->filePosition;
updateTagLine (&e, token->lineNumber, token->filePosition);

makeTagEntry (&e);
}
Expand Down
3 changes: 1 addition & 2 deletions parsers/c-based.c
Original file line number Diff line number Diff line change
Expand Up @@ -1239,8 +1239,7 @@ static int makeTag (const tokenInfo *const token,
else
initRefTagEntry (&e, vStringValue (token->name), kind, role);

e.lineNumber = token->lineNumber;
e.filePosition = token->filePosition;
updateTagLine (&e, token->lineNumber, token->filePosition);
e.isFileScope = isFileScope;
if (e.isFileScope)
markTagExtraBit (&e, XTAG_FILE_SCOPE);
Expand Down
3 changes: 1 addition & 2 deletions parsers/c.c
Original file line number Diff line number Diff line change
Expand Up @@ -1480,8 +1480,7 @@ static int makeTag (const tokenInfo *const token,
else
initRefTagEntry (&e, vStringValue (token->name), kind, role);

e.lineNumber = token->lineNumber;
e.filePosition = token->filePosition;
updateTagLine (&e, token->lineNumber, token->filePosition);
e.isFileScope = isFileScope;
if (e.isFileScope)
markTagExtraBit (&e, XTAG_FILE_SCOPE);
Expand Down
3 changes: 1 addition & 2 deletions parsers/cobol.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,7 @@ static void initCOBOLRefTagEntry (tagEntryInfo *e, const char *name,
const cobolKind kind, const int role)
{
initRefTagEntry (e, name, kind, role);
e->lineNumber = CblInputState.lineNumber;
e->filePosition = CblInputState.filePosition;
updateTagLine (e, CblInputState.lineNumber, CblInputState.filePosition);
}

static void initCOBOLTagEntry (tagEntryInfo *e, const char *name, const cobolKind kind)
Expand Down
3 changes: 1 addition & 2 deletions parsers/cpreprocessor.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,8 +980,7 @@ static int directiveDefine (const int c, bool undef)
tagEntryInfo *e = getEntryInCorkQueue (r);
if (e)
{
e->lineNumber = lineNumber;
e->filePosition = filePosition;
updateTagLine (e, lineNumber, filePosition);
patchScopeFieldOfParameters (param_start, param_end, r);
}
}
Expand Down
3 changes: 1 addition & 2 deletions parsers/css.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ static void findCssTags (void)
tagEntryInfo e;
initTagEntry (&e, vStringValue (selector), kind);

e.lineNumber = lineNumber;
e.filePosition = filePosition;
updateTagLine (&e, lineNumber, filePosition);

makeTagEntry (&e);
}
Expand Down
3 changes: 1 addition & 2 deletions parsers/cxx/cxx_qtmoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ static void qtMocMakeTagForProperty (CXXToken * pToken, const char *pszType)
initTagEntry(&tag,
vStringValue(pToken->pszWord),
K_PROPERTY);
tag.lineNumber = pToken->iLineNumber;
tag.filePosition = pToken->oFilePosition;
updateTagLine (&tag, pToken->iLineNumber, pToken->oFilePosition);
tag.isFileScope = false;

if(!cxxScopeIsGlobal())
Expand Down
3 changes: 1 addition & 2 deletions parsers/cxx/cxx_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,7 @@ tagEntryInfo * cxxTagBegin(unsigned int uKind,CXXToken * pToken)
uKind
);

g_oCXXTag.lineNumber = pToken->iLineNumber;
g_oCXXTag.filePosition = pToken->oFilePosition;
updateTagLine (&g_oCXXTag, pToken->iLineNumber, pToken->oFilePosition);
g_oCXXTag.isFileScope = false;

if(!cxxScopeIsGlobal())
Expand Down
3 changes: 1 addition & 2 deletions parsers/dtd.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ static int makeDtdTagMaybe (tagEntryInfo *const e, tokenInfo *const token,
initRefTagEntry (e, tokenString (token),
kind,
role);
e->lineNumber = token->lineNumber;
e->filePosition = token->filePosition;
updateTagLine (e, token->lineNumber, token->filePosition);
e->extensionFields.scopeIndex = DTD (token)->scopeIndex;

return makeTagEntry (e);
Expand Down
3 changes: 1 addition & 2 deletions parsers/flex.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,7 @@ static void makeConstTag (tokenInfo *const token, const flexKind kind)

initRefTagEntry (&e, name, kind, role);

e.lineNumber = token->lineNumber;
e.filePosition = token->filePosition;
updateTagLine (&e, token->lineNumber, token->filePosition);

if ( vStringLength(token->scope) > 0 )
{
Expand Down
3 changes: 1 addition & 2 deletions parsers/fortran.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,7 @@ static void makeFortranTag (tokenInfo *const token, tagType tag)
if (token->anonymous)
markTagExtraBit (&e, XTAG_ANONYMOUS);

e.lineNumber = token->lineNumber;
e.filePosition = token->filePosition;
updateTagLine (&e, token->lineNumber, token->filePosition);
e.isFileScope = isFileScope (token->tag);
if (e.isFileScope)
markTagExtraBit (&e, XTAG_FILE_SCOPE);
Expand Down
8 changes: 2 additions & 6 deletions parsers/gdscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@ static void initGDScriptEntry (tagEntryInfo *const e, const tokenInfo *const tok
NestingLevel *nl;

initTagEntry (e, vStringValue (token->string), kind);

e->lineNumber = token->lineNumber;
e->filePosition = token->filePosition;
updateTagLine (e, token->lineNumber, token->filePosition);

nl = nestingLevelsGetCurrent (GDScriptNestingLevels);
if (nl)
Expand Down Expand Up @@ -322,9 +320,7 @@ static int makeSimpleGDScriptRefTag (const tokenInfo *const token,

initRefTagEntry (&e, vStringValue (token->string),
kind, roleIndex);

e.lineNumber = token->lineNumber;
e.filePosition = token->filePosition;
updateTagLine (&e, token->lineNumber, token->filePosition);

if (xtag != XTAG_UNKNOWN)
markTagExtraBit (&e, xtag);
Expand Down
3 changes: 1 addition & 2 deletions parsers/go.c
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,7 @@ static int makeTagFull (tokenInfo *const token, const goKind kind,

initRefTagEntry (&e, name, kind, role);

e.lineNumber = token->lineNumber;
e.filePosition = token->filePosition;
updateTagLine (&e, token->lineNumber, token->filePosition);
if (argList)
e.extensionFields.signature = argList;
if (typeref)
Expand Down
6 changes: 2 additions & 4 deletions parsers/jscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,7 @@ static int makeJsRefTagsForNameChain (char *name_chain, const tokenInfo *token,
}

initRefTagEntry (&e, name, kind, role);
e.lineNumber = token->lineNumber;
e.filePosition = token->filePosition;
updateTagLine (&e, token->lineNumber, token->filePosition);
e.extensionFields.scopeIndex = scope;

index = makeTagEntry (&e);
Expand Down Expand Up @@ -525,8 +524,7 @@ static int makeJsTagCommon (const tokenInfo *const token, const jsKind kind,

tagEntryInfo e;
initTagEntry (&e, name, kind);
e.lineNumber = token->lineNumber;
e.filePosition = token->filePosition;
updateTagLine (&e, token->lineNumber, token->filePosition);
e.extensionFields.scopeIndex = scope;

#ifdef DO_TRACING
Expand Down
3 changes: 1 addition & 2 deletions parsers/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ static void makeJsonTag (tokenInfo *const token, const jsonKind kind)

initTagEntry (&e, vStringValue (token->string), kind);

e.lineNumber = token->lineNumber;
e.filePosition = token->filePosition;
updateTagLine (&e, token->lineNumber, token->filePosition);

if (vStringLength (token->scope) > 0)
{
Expand Down
6 changes: 2 additions & 4 deletions parsers/julia.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,8 +874,7 @@ static void addTag (vString* ident, const char* type, const char* arg_list, int
tagEntryInfo tag;
initTagEntry(&tag, vStringValue(ident), kind);

tag.lineNumber = line;
tag.filePosition = pos;
updateTagLine(&tag, line, pos);
tag.sourceFileName = getInputFileName();

tag.extensionFields.signature = arg_list;
Expand All @@ -896,8 +895,7 @@ static void addReferenceTag (vString* ident, int kind, int role, unsigned long l
}
tagEntryInfo tag;
initRefTagEntry(&tag, vStringValue(ident), kind, role);
tag.lineNumber = line;
tag.filePosition = pos;
updateTagLine(&tag, line, pos);
if (parent_kind != K_NONE)
{
tag.extensionFields.scopeKindIndex = parent_kind;
Expand Down
3 changes: 1 addition & 2 deletions parsers/ldscript.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ static int makeLdScriptTagMaybe (tagEntryInfo *const e, tokenInfo *const token,
initRefTagEntry (e, tokenString (token),
kind,
role);
e->lineNumber = token->lineNumber;
e->filePosition = token->filePosition;
updateTagLine (e, token->lineNumber, token->filePosition);
e->extensionFields.scopeIndex = LDSCRIPT (token)->scopeIndex;

/* TODO: implement file: field. */
Expand Down
3 changes: 1 addition & 2 deletions parsers/markdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ static int makeMarkdownTag (const vString* const name, const int kind, const boo
if (e.lineNumber > 1)
{
unsigned long lineNumber = e.lineNumber - 1;
e.lineNumber = lineNumber;
e.filePosition = getInputFilePositionForLine (lineNumber);
updateTagLine (&e, lineNumber, getInputFilePositionForLine (lineNumber));
}
}

Expand Down
5 changes: 3 additions & 2 deletions parsers/maven2.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ static void makeTagForProperties (xmlNode *node,

str = node->name;
initTagEntry (&tag, (char *)str, K_PROPERTY);
tag.lineNumber = xmlGetLineNo (node);
tag.filePosition = getInputFilePositionForLine (tag.lineNumber);

unsigned long lineNumber = xmlGetLineNo (node);
updateTagLine (&tag, lineNumber, getInputFilePositionForLine (lineNumber));

makeTagEntry (&tag);
}
Expand Down
3 changes: 1 addition & 2 deletions parsers/ocaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,7 @@ static void prepareTag (tagEntryInfo * tag, vString const *name, int kind)
/* Ripped out of read.h initTagEntry, because of line number
* shenanigans.
* Ugh. Lookahead is harder than I expected. */
tag->lineNumber = ocaLineNumber;
tag->filePosition = ocaFilePosition;
updateTagLine(tag, ocaLineNumber, ocaFilePosition);

parentIndex = getLastNamedIndex ();
if (parentIndex >= 0)
Expand Down
3 changes: 1 addition & 2 deletions parsers/perl-moose.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ static void enterMoose (struct mooseSubparser *moose, bool role)

tagEntryInfo moose_e;
initTagEntry (&moose_e, perl_e->name, role? K_ROLE: K_CLASS);
moose_e.lineNumber = perl_e->lineNumber;
moose_e.filePosition = perl_e->filePosition;
updateTagLine(&moose_e, perl_e->lineNumber, perl_e->filePosition);
moose->classCork = makeTagEntry (&moose_e);
vStringClear (moose->supersOrRoles);

Expand Down
Loading

0 comments on commit 3a1949f

Please sign in to comment.