read: add lineFposMap
This commit is contained in:
parent
ed03c2042d
commit
53f83e7cee
@ -151,10 +151,8 @@ extern MIOPos getInputFilePosition (void)
|
|||||||
|
|
||||||
extern MIOPos getInputFilePositionForLine (int line)
|
extern MIOPos getInputFilePositionForLine (int line)
|
||||||
{
|
{
|
||||||
MIOPos pos;
|
return File.lineFposMap.pos[(((File.lineFposMap.count > (line - 1)) \
|
||||||
return pos;
|
&& (line > 0))? (line - 1): 0)];
|
||||||
/* return File.lineFposMap.pos[(((File.lineFposMap.count > (line - 1)) \
|
|
||||||
&& (line > 0))? (line - 1): 0)];*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern langType getInputLanguage (void)
|
extern langType getInputLanguage (void)
|
||||||
@ -244,6 +242,41 @@ extern void freeInputFileResources (void)
|
|||||||
freeInputFileInfo (&File.source);
|
freeInputFileInfo (&File.source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* inputLineFposMap related functions
|
||||||
|
*/
|
||||||
|
static void freeLineFposMap (inputLineFposMap *lineFposMap)
|
||||||
|
{
|
||||||
|
if (lineFposMap->pos)
|
||||||
|
{
|
||||||
|
free (lineFposMap->pos);
|
||||||
|
lineFposMap->pos = NULL;
|
||||||
|
lineFposMap->count = 0;
|
||||||
|
lineFposMap->size = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void allocLineFposMap (inputLineFposMap *lineFposMap)
|
||||||
|
{
|
||||||
|
#define INITIAL_lineFposMap_LEN 256
|
||||||
|
lineFposMap->pos = xCalloc (INITIAL_lineFposMap_LEN, MIOPos);
|
||||||
|
lineFposMap->size = INITIAL_lineFposMap_LEN;
|
||||||
|
lineFposMap->count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void appendLineFposMap (inputLineFposMap *lineFposMap, MIOPos pos)
|
||||||
|
{
|
||||||
|
if (lineFposMap->size == lineFposMap->count)
|
||||||
|
{
|
||||||
|
lineFposMap->size *= 2;
|
||||||
|
lineFposMap->pos = xRealloc (lineFposMap->pos,
|
||||||
|
lineFposMap->size,
|
||||||
|
MIOPos);
|
||||||
|
}
|
||||||
|
lineFposMap->pos [lineFposMap->count] = pos;
|
||||||
|
lineFposMap->count++;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Input file access functions
|
* Input file access functions
|
||||||
*/
|
*/
|
||||||
@ -540,6 +573,7 @@ extern bool openInputFile (const char *const fileName, const langType language,
|
|||||||
setSourceFileParameters (vStringNewInit (fileName), language);
|
setSourceFileParameters (vStringNewInit (fileName), language);
|
||||||
File.source.lineNumberOrigin = 0L;
|
File.source.lineNumberOrigin = 0L;
|
||||||
File.source.lineNumber = File.source.lineNumberOrigin;
|
File.source.lineNumber = File.source.lineNumberOrigin;
|
||||||
|
allocLineFposMap (&File.lineFposMap);
|
||||||
|
|
||||||
verbose ("OPENING %s as %s language %sfile\n", fileName,
|
verbose ("OPENING %s as %s language %sfile\n", fileName,
|
||||||
getLanguageName (language),
|
getLanguageName (language),
|
||||||
@ -580,6 +614,7 @@ extern void closeInputFile (void)
|
|||||||
}
|
}
|
||||||
mio_free (File.mio);
|
mio_free (File.mio);
|
||||||
File.mio = NULL;
|
File.mio = NULL;
|
||||||
|
freeLineFposMap (&File.lineFposMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user