Skip to content

Commit

Permalink
Merge pull request #6 from Hackerpilot/allocator_improvements
Browse files Browse the repository at this point in the history
Updated dparse compatability
  • Loading branch information
Hackerpilot committed Mar 3, 2016
2 parents f6aac6c + 81c824f commit 86cf39c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/dsymbol/conversion/first.d
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ final class FirstPass : ASTVisitor
rootSymbol = allocateSemanticSymbol(null, CompletionKind.moduleName,
symbolFile);
currentSymbol = rootSymbol;
moduleScope = make!Scope(semanticAllocator, 0, uint.max);
moduleScope = semanticAllocator.make!Scope(0, uint.max);
currentScope = moduleScope;
auto objectLocation = cache.resolveImportLocation("object");
if (objectLocation is null)
Expand Down Expand Up @@ -628,7 +628,7 @@ private:
{
assert (startLocation < uint.max);
assert (endLocation < uint.max || endLocation == ulong.max);
Scope* s = make!Scope(semanticAllocator, cast(uint) startLocation, cast(uint) endLocation);
Scope* s = semanticAllocator.make!Scope(cast(uint) startLocation, cast(uint) endLocation);
s.parent = currentScope;
currentScope.children.insert(s);
currentScope = s;
Expand All @@ -649,7 +649,7 @@ private:
functionBody.outStatement is null ? 0 : functionBody.outStatement.blockStatement.endLocation,
functionBody.blockStatement is null ? 0 : functionBody.blockStatement.endLocation,
functionBody.bodyStatement is null ? 0 : functionBody.bodyStatement.blockStatement.endLocation);
Scope* s = make!Scope(semanticAllocator, cast(uint) scopeBegin, cast(uint) scopeEnd);
Scope* s = semanticAllocator.make!Scope(cast(uint) scopeBegin, cast(uint) scopeEnd);
s.parent = currentScope;
currentScope.children.insert(s);
currentScope = s;
Expand Down
16 changes: 9 additions & 7 deletions src/dsymbol/conversion/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ import dsymbol.semantic;
import dparse.ast;
import dparse.lexer;
import dparse.parser;
import dparse.rollback_allocator;
import std.experimental.allocator;
import std.typecons;

/**
* Used by autocompletion.
*/
ScopeSymbolPair generateAutocompleteTrees(const(Token)[] tokens,
IAllocator symbolAllocator, size_t cursorPosition, ref ModuleCache cache)
IAllocator symbolAllocator, RollbackAllocator* parseAllocator,
size_t cursorPosition, ref ModuleCache cache)
{
Module m = parseModuleForAutocomplete(tokens, internString("stdin"),
symbolAllocator, cursorPosition);
parseAllocator, cursorPosition);

auto first = scoped!FirstPass(m, internString("stdin"), symbolAllocator,
symbolAllocator, true, &cache);
Expand Down Expand Up @@ -72,7 +74,7 @@ struct ScopeSymbolPair
* parseAllocator = the allocator to use for the AST
* Returns: the parsed module
*/
Module parseModuleSimple(const(Token)[] tokens, string fileName, IAllocator parseAllocator)
Module parseModuleSimple(const(Token)[] tokens, string fileName, RollbackAllocator* parseAllocator)
{
assert (parseAllocator !is null);
auto parser = scoped!SimpleParser();
Expand All @@ -86,7 +88,7 @@ Module parseModuleSimple(const(Token)[] tokens, string fileName, IAllocator pars
private:

Module parseModuleForAutocomplete(const(Token)[] tokens, string fileName,
IAllocator parseAllocator, size_t cursorPosition)
RollbackAllocator* parseAllocator, size_t cursorPosition)
{
auto parser = scoped!AutocompleteParser();
parser.fileName = fileName;
Expand All @@ -103,7 +105,7 @@ class AutocompleteParser : Parser
{
if (current.index > cursorPosition)
{
BlockStatement bs = allocate!(BlockStatement);
BlockStatement bs = allocator.make!(BlockStatement);
bs.startLocation = current.index;
skipBraces();
bs.endLocation = tokens[index - 1].index;
Expand All @@ -115,7 +117,7 @@ class AutocompleteParser : Parser
if (tokens[index - 1].index < cursorPosition)
{
abandonBookmark(b);
BlockStatement bs = allocate!BlockStatement();
BlockStatement bs = allocator.make!BlockStatement();
bs.startLocation = start;
bs.endLocation = tokens[index - 1].index;
return bs;
Expand Down Expand Up @@ -181,7 +183,7 @@ class SimpleParser : Parser
if (currentIs(tok!"{"))
skipBraces();
}
return allocate!FunctionBody();
return allocator.make!FunctionBody();
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dsymbol/modulecache.d
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ struct ModuleCache
CacheEntry* newEntry = Mallocator.instance.make!CacheEntry();

auto semanticAllocator = scoped!(ASTAllocator);
Module m = parseModuleSimple(tokens[], cachedLocation, semanticAllocator);
import dparse.rollback_allocator:RollbackAllocator;
RollbackAllocator parseAllocator;
Module m = parseModuleSimple(tokens[], cachedLocation, &parseAllocator);

assert (symbolAllocator);
auto first = scoped!FirstPass(m, cachedLocation, symbolAllocator,
Expand Down

0 comments on commit 86cf39c

Please sign in to comment.