This commit is contained in:
Hackerpilot 2014-09-12 14:32:58 -07:00
parent c7952880eb
commit a32086e066
3 changed files with 49 additions and 50 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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,31 +127,31 @@ 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
// {
import std.stdio;
import std.typecons;
File f = File(cachedLocation); File f = File(cachedLocation);
immutable fileSize = cast(size_t) f.size; immutable fileSize = cast(size_t) f.size;
if (fileSize == 0) if (fileSize == 0)
@ -167,8 +167,6 @@ struct ModuleCache
config, &parseStringCache); config, &parseStringCache);
Mallocator.it.deallocate(source); Mallocator.it.deallocate(source);
// StopWatch sw;
// sw.start();
Module m = parseModuleSimple(tokens[], cachedLocation, semanticAllocator); Module m = parseModuleSimple(tokens[], cachedLocation, semanticAllocator);
assert (symbolAllocator); assert (symbolAllocator);
@ -176,8 +174,6 @@ struct ModuleCache
semanticAllocator); semanticAllocator);
first.run(); first.run();
// Log.trace(location, " finished in ", sw.peek.msecs, "msecs");
SecondPass second = SecondPass(first); SecondPass second = SecondPass(first);
second.run(); second.run();
@ -188,17 +184,20 @@ struct ModuleCache
typeid(Scope).destroy(third.moduleScope); typeid(Scope).destroy(third.moduleScope);
symbolsAllocated += first.symbolsAllocated; 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;
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); cache.insert(c);
recursionGuard.remove(cachedLocation); recursionGuard.remove(cachedLocation);
return symbol; return symbol;