Fix #161
This commit is contained in:
parent
c7952880eb
commit
a32086e066
|
@ -402,7 +402,7 @@ body
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto symbols = ModuleCache.getSymbolsInModule(ModuleCache.resolveImportLoctation(path));
|
auto symbols = ModuleCache.getModuleSymbol(ModuleCache.resolveImportLoctation(path));
|
||||||
import containers.hashset;
|
import containers.hashset;
|
||||||
HashSet!string h;
|
HashSet!string h;
|
||||||
|
|
||||||
|
|
|
@ -152,7 +152,7 @@ private:
|
||||||
foreach (importInfo; currentScope.importInformation[])
|
foreach (importInfo; currentScope.importInformation[])
|
||||||
{
|
{
|
||||||
string location = ModuleCache.resolveImportLoctation(importInfo.modulePath);
|
string location = ModuleCache.resolveImportLoctation(importInfo.modulePath);
|
||||||
ACSymbol* symbol = location is null ? null : ModuleCache.getSymbolsInModule(location);
|
ACSymbol* symbol = location is null ? null : ModuleCache.getModuleSymbol(location);
|
||||||
if (symbol is null)
|
if (symbol is null)
|
||||||
continue;
|
continue;
|
||||||
ACSymbol* moduleSymbol = createImportSymbols(importInfo, currentScope, symbol);
|
ACSymbol* moduleSymbol = createImportSymbols(importInfo, currentScope, symbol);
|
||||||
|
|
|
@ -113,7 +113,7 @@ struct ModuleCache
|
||||||
{
|
{
|
||||||
import std.path: baseName;
|
import std.path: baseName;
|
||||||
if(fileName.baseName.startsWith(".#")) continue;
|
if(fileName.baseName.startsWith(".#")) continue;
|
||||||
getSymbolsInModule(fileName);
|
getModuleSymbol(fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,79 +127,78 @@ struct ModuleCache
|
||||||
* Returns:
|
* Returns:
|
||||||
* The symbols defined in the given module
|
* The symbols defined in the given module
|
||||||
*/
|
*/
|
||||||
static ACSymbol* getSymbolsInModule(string location)
|
static ACSymbol* getModuleSymbol(string location)
|
||||||
{
|
{
|
||||||
import string_interning;
|
import string_interning;
|
||||||
|
import std.stdio;
|
||||||
|
import std.typecons;
|
||||||
|
|
||||||
assert (location !is null);
|
assert (location !is null);
|
||||||
if (!needsReparsing(location))
|
|
||||||
|
string cachedLocation = internString(location);
|
||||||
|
|
||||||
|
if (!needsReparsing(cachedLocation))
|
||||||
{
|
{
|
||||||
CacheEntry e;
|
CacheEntry e;
|
||||||
e.path = location;
|
e.path = cachedLocation;
|
||||||
auto r = cache.equalRange(&e);
|
auto r = cache.equalRange(&e);
|
||||||
if (!r.empty)
|
if (!r.empty)
|
||||||
return r.front.symbol;
|
return r.front.symbol;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
string cachedLocation = internString(location);
|
|
||||||
|
|
||||||
Log.info("Getting symbols for ", cachedLocation);
|
Log.info("Getting symbols for ", cachedLocation);
|
||||||
|
|
||||||
recursionGuard.insert(cachedLocation);
|
recursionGuard.insert(cachedLocation);
|
||||||
|
|
||||||
ACSymbol* symbol;
|
ACSymbol* symbol;
|
||||||
// try
|
File f = File(cachedLocation);
|
||||||
// {
|
immutable fileSize = cast(size_t) f.size;
|
||||||
import std.stdio;
|
if (fileSize == 0)
|
||||||
import std.typecons;
|
return null;
|
||||||
File f = File(cachedLocation);
|
ubyte[] source = cast(ubyte[]) Mallocator.it.allocate(fileSize);
|
||||||
immutable fileSize = cast(size_t)f.size;
|
f.rawRead(source);
|
||||||
if (fileSize == 0)
|
LexerConfig config;
|
||||||
return null;
|
config.fileName = cachedLocation;
|
||||||
ubyte[] source = cast(ubyte[]) Mallocator.it.allocate(fileSize);
|
auto parseStringCache = StringCache(StringCache.defaultBucketCount);
|
||||||
f.rawRead(source);
|
auto semanticAllocator = scoped!(CAllocatorImpl!(BlockAllocator!(1024 * 64)));
|
||||||
LexerConfig config;
|
const(Token)[] tokens = getTokensForParser(
|
||||||
config.fileName = cachedLocation;
|
(source.length >= 3 && source[0 .. 3] == "\xef\xbb\xbf"c) ? source[3 .. $] : source,
|
||||||
auto parseStringCache = StringCache(StringCache.defaultBucketCount);
|
config, &parseStringCache);
|
||||||
auto semanticAllocator = scoped!(CAllocatorImpl!(BlockAllocator!(1024 * 64)));
|
Mallocator.it.deallocate(source);
|
||||||
const(Token)[] tokens = getTokensForParser(
|
|
||||||
(source.length >= 3 && source[0 .. 3] == "\xef\xbb\xbf"c) ? source[3 .. $] : source,
|
|
||||||
config, &parseStringCache);
|
|
||||||
Mallocator.it.deallocate(source);
|
|
||||||
|
|
||||||
// StopWatch sw;
|
Module m = parseModuleSimple(tokens[], cachedLocation, semanticAllocator);
|
||||||
// sw.start();
|
|
||||||
Module m = parseModuleSimple(tokens[], cachedLocation, semanticAllocator);
|
|
||||||
|
|
||||||
assert (symbolAllocator);
|
assert (symbolAllocator);
|
||||||
auto first = scoped!FirstPass(m, cachedLocation, symbolAllocator,
|
auto first = scoped!FirstPass(m, cachedLocation, symbolAllocator,
|
||||||
semanticAllocator);
|
semanticAllocator);
|
||||||
first.run();
|
first.run();
|
||||||
|
|
||||||
// Log.trace(location, " finished in ", sw.peek.msecs, "msecs");
|
SecondPass second = SecondPass(first);
|
||||||
|
second.run();
|
||||||
|
|
||||||
SecondPass second = SecondPass(first);
|
ThirdPass third = ThirdPass(second, cachedLocation);
|
||||||
second.run();
|
third.run();
|
||||||
|
|
||||||
ThirdPass third = ThirdPass(second, cachedLocation);
|
symbol = third.rootSymbol.acSymbol;
|
||||||
third.run();
|
|
||||||
|
|
||||||
symbol = third.rootSymbol.acSymbol;
|
typeid(Scope).destroy(third.moduleScope);
|
||||||
|
symbolsAllocated += first.symbolsAllocated;
|
||||||
|
|
||||||
typeid(Scope).destroy(third.moduleScope);
|
|
||||||
symbolsAllocated += first.symbolsAllocated;
|
|
||||||
// }
|
|
||||||
// catch (Exception ex)
|
|
||||||
// {
|
|
||||||
// Log.error("Couln't parse ", location, " due to exception: ", ex.msg);
|
|
||||||
// return [];
|
|
||||||
// }
|
|
||||||
SysTime access;
|
SysTime access;
|
||||||
SysTime modification;
|
SysTime modification;
|
||||||
getTimes(cachedLocation, access, modification);
|
getTimes(cachedLocation, access, modification);
|
||||||
CacheEntry* c = allocate!CacheEntry(Mallocator.it, symbol,
|
|
||||||
modification, cachedLocation);
|
CacheEntry e;
|
||||||
cache.insert(c);
|
e.path = cachedLocation;
|
||||||
|
auto r = cache.equalRange(&e);
|
||||||
|
CacheEntry* c = r.empty ? allocate!CacheEntry(Mallocator.it)
|
||||||
|
: r.front;
|
||||||
|
c.symbol = symbol;
|
||||||
|
c.modificationTime = modification;
|
||||||
|
c.path = cachedLocation;
|
||||||
|
if (r.empty)
|
||||||
|
cache.insert(c);
|
||||||
recursionGuard.remove(cachedLocation);
|
recursionGuard.remove(cachedLocation);
|
||||||
return symbol;
|
return symbol;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue