This commit is contained in:
Hackerpilot 2013-10-29 23:10:01 -07:00
parent 13ef990fa9
commit 506573b493
3 changed files with 112 additions and 100 deletions

View File

@ -77,41 +77,41 @@ final class FirstPass : ASTVisitor
currentSymbol = s.parent; currentSymbol = s.parent;
} }
override void visit(Constructor con) override void visit(Constructor con)
{ {
// Log.trace(__FUNCTION__, " ", typeof(con).stringof); // Log.trace(__FUNCTION__, " ", typeof(con).stringof);
visitConstructor(con.location, con.parameters, con.functionBody); visitConstructor(con.location, con.parameters, con.functionBody);
} }
override void visit(SharedStaticConstructor con) override void visit(SharedStaticConstructor con)
{ {
// Log.trace(__FUNCTION__, " ", typeof(con).stringof); // Log.trace(__FUNCTION__, " ", typeof(con).stringof);
visitConstructor(con.location, null, con.functionBody); visitConstructor(con.location, null, con.functionBody);
} }
override void visit(StaticConstructor con) override void visit(StaticConstructor con)
{ {
// Log.trace(__FUNCTION__, " ", typeof(con).stringof); // Log.trace(__FUNCTION__, " ", typeof(con).stringof);
visitConstructor(con.location, null, con.functionBody); visitConstructor(con.location, null, con.functionBody);
} }
override void visit(Destructor des) override void visit(Destructor des)
{ {
// Log.trace(__FUNCTION__, " ", typeof(des).stringof); // Log.trace(__FUNCTION__, " ", typeof(des).stringof);
visitDestructor(des.location, des.functionBody); visitDestructor(des.location, des.functionBody);
} }
override void visit(SharedStaticDestructor des) override void visit(SharedStaticDestructor des)
{ {
// Log.trace(__FUNCTION__, " ", typeof(des).stringof); // Log.trace(__FUNCTION__, " ", typeof(des).stringof);
visitDestructor(des.location, des.functionBody); visitDestructor(des.location, des.functionBody);
} }
override void visit(StaticDestructor des) override void visit(StaticDestructor des)
{ {
// Log.trace(__FUNCTION__, " ", typeof(des).stringof); // Log.trace(__FUNCTION__, " ", typeof(des).stringof);
visitDestructor(des.location, des.functionBody); visitDestructor(des.location, des.functionBody);
} }
override void visit(FunctionDeclaration dec) override void visit(FunctionDeclaration dec)
{ {
@ -199,7 +199,7 @@ final class FirstPass : ASTVisitor
foreach (Attribute attr; dec.attributes) foreach (Attribute attr; dec.attributes)
{ {
if (isProtection(attr.attribute)) if (isProtection(attr.attribute))
p = attr.attribute; protection = attr.attribute;
} }
dec.accept(this); dec.accept(this);
protection = p; protection = p;
@ -221,30 +221,30 @@ final class FirstPass : ASTVisitor
mod.accept(this); mod.accept(this);
} }
override void visit(EnumDeclaration dec) override void visit(EnumDeclaration dec)
{ {
assert (currentSymbol); assert (currentSymbol);
// Log.trace(__FUNCTION__, " ", typeof(dec).stringof); // Log.trace(__FUNCTION__, " ", typeof(dec).stringof);
SemanticSymbol* symbol = new SemanticSymbol(dec.name.value.dup, SemanticSymbol* symbol = new SemanticSymbol(dec.name.value.dup,
CompletionKind.enumName, symbolFile, dec.name.startIndex); CompletionKind.enumName, symbolFile, dec.name.startIndex);
symbol.type = dec.type; symbol.type = dec.type;
symbol.parent = currentSymbol; symbol.parent = currentSymbol;
currentSymbol = symbol; currentSymbol = symbol;
if (dec.enumBody !is null) if (dec.enumBody !is null)
dec.enumBody.accept(this); dec.enumBody.accept(this);
currentSymbol = symbol.parent; currentSymbol = symbol.parent;
currentSymbol.addChild(symbol); currentSymbol.addChild(symbol);
} }
override void visit(EnumMember member) override void visit(EnumMember member)
{ {
// Log.trace(__FUNCTION__, " ", typeof(member).stringof); // Log.trace(__FUNCTION__, " ", typeof(member).stringof);
SemanticSymbol* symbol = new SemanticSymbol(member.name.value.dup, SemanticSymbol* symbol = new SemanticSymbol(member.name.value.dup,
CompletionKind.enumMember, symbolFile, member.name.startIndex); CompletionKind.enumMember, symbolFile, member.name.startIndex);
symbol.type = member.type; symbol.type = member.type;
symbol.parent = currentSymbol; symbol.parent = currentSymbol;
currentSymbol.addChild(symbol); currentSymbol.addChild(symbol);
} }
override void visit(ModuleDeclaration dec) override void visit(ModuleDeclaration dec)
{ {
@ -284,6 +284,7 @@ final class FirstPass : ASTVisitor
{ {
ImportInformation info; ImportInformation info;
info.modulePath = convertChainToImportPath(single.identifierChain); info.modulePath = convertChainToImportPath(single.identifierChain);
info.isPublic = protection == TokenType.public_;
currentScope.importInformation ~= info; currentScope.importInformation ~= info;
} }
if (importDeclaration.importBindings is null) return; if (importDeclaration.importBindings is null) return;
@ -298,6 +299,7 @@ final class FirstPass : ASTVisitor
bindTuple[1] = bind.right == TokenType.invalid ? null : bind.right.value.dup; bindTuple[1] = bind.right == TokenType.invalid ? null : bind.right.value.dup;
info.importedSymbols ~= bindTuple; info.importedSymbols ~= bindTuple;
} }
info.isPublic = protection == TokenType.public_;
currentScope.importInformation ~= info; currentScope.importInformation ~= info;
} }
@ -339,7 +341,6 @@ private:
void visitAggregateDeclaration(AggType)(AggType dec, CompletionKind kind) void visitAggregateDeclaration(AggType)(AggType dec, CompletionKind kind)
{ {
// Log.trace("visiting aggregate declaration ", dec.name.value); // Log.trace("visiting aggregate declaration ", dec.name.value);
SemanticSymbol* symbol = new SemanticSymbol(dec.name.value.dup, SemanticSymbol* symbol = new SemanticSymbol(dec.name.value.dup,
kind, symbolFile, dec.name.startIndex); kind, symbolFile, dec.name.startIndex);
@ -449,8 +450,8 @@ private:
/// Package and module name /// Package and module name
string[] moduleName; string[] moduleName;
/// Current scope /// Current scope
Scope* currentScope; Scope* currentScope;
/// Module scope /// Module scope
Scope* moduleScope; Scope* moduleScope;
@ -502,6 +503,11 @@ private:
if (importInfo.importedSymbols.length == 0) if (importInfo.importedSymbols.length == 0)
{ {
currentScope.symbols ~= symbols; currentScope.symbols ~= symbols;
if (importInfo.isPublic && currentScope.parent is null)
{
Log.trace("Public import");
rootSymbol.acSymbol.parts ~= symbols;
}
continue; continue;
} }
symbolLoop: foreach (symbol; symbols) symbolLoop: foreach (symbol; symbols)
@ -522,9 +528,15 @@ private:
s.location = symbol.location; s.location = symbol.location;
s.symbolFile = symbol.symbolFile; s.symbolFile = symbol.symbolFile;
currentScope.symbols ~= s; currentScope.symbols ~= s;
if (importInfo.isPublic && currentScope.parent is null)
rootSymbol.acSymbol.parts ~= s;
} }
else else
{
currentScope.symbols ~= symbol; currentScope.symbols ~= symbol;
if (importInfo.isPublic && currentScope.parent is null)
rootSymbol.acSymbol.parts ~= symbol;
}
} }
} }
} }
@ -717,18 +729,18 @@ private:
const(ACSymbol)*[] convertAstToSymbols(const(Token)[] tokens, string symbolFile) const(ACSymbol)*[] convertAstToSymbols(const(Token)[] tokens, string symbolFile)
{ {
Module m = parseModuleSimple(tokens, null); Module m = parseModuleSimple(tokens, symbolFile);
FirstPass first = new FirstPass(m, symbolFile); FirstPass first = new FirstPass(m, symbolFile);
first.run(); first.run();
SecondPass second = SecondPass(first.rootSymbol, first.moduleScope); SecondPass second = SecondPass(first.rootSymbol, first.moduleScope);
second.run(); second.run();
ThirdPass third = ThirdPass(second.rootSymbol, second.moduleScope); ThirdPass third = ThirdPass(second.rootSymbol, second.moduleScope);
third.run(); third.run();
return cast(typeof(return)) third.rootSymbol.acSymbol.parts; return cast(typeof(return)) third.rootSymbol.acSymbol.parts;
} }
const(Scope)* generateAutocompleteTrees(const(Token)[] tokens, string symbolFile) const(Scope)* generateAutocompleteTrees(const(Token)[] tokens, string symbolFile)
@ -751,60 +763,60 @@ private:
Module parseModuleSimple(const(Token)[] tokens, string fileName) Module parseModuleSimple(const(Token)[] tokens, string fileName)
{ {
auto parser = new SimpleParser(); auto parser = new SimpleParser();
parser.fileName = fileName; parser.fileName = fileName;
parser.tokens = tokens; parser.tokens = tokens;
parser.messageFunction = &doesNothing; parser.messageFunction = &doesNothing;
auto mod = parser.parseModule(); auto mod = parser.parseModule();
return mod; return mod;
} }
class SimpleParser : Parser class SimpleParser : Parser
{ {
override Unittest parseUnittest() override Unittest parseUnittest()
{ {
expect(TokenType.unittest_); expect(TokenType.unittest_);
skipBraces(); skipBraces();
return null; return null;
} }
override FunctionBody parseFunctionBody() override FunctionBody parseFunctionBody()
{ {
if (currentIs(TokenType.semicolon)) if (currentIs(TokenType.semicolon))
advance(); advance();
else if (currentIs(TokenType.lBrace)) else if (currentIs(TokenType.lBrace))
skipBraces(); skipBraces();
else else
{ {
if (currentIs(TokenType.in_)) if (currentIs(TokenType.in_))
{ {
advance(); advance();
skipBraces(); skipBraces();
if (currentIs(TokenType.out_)) if (currentIs(TokenType.out_))
{ {
advance(); advance();
if (currentIs(TokenType.lParen)) if (currentIs(TokenType.lParen))
skipParens(); skipParens();
skipBraces(); skipBraces();
} }
} }
else if (currentIs(TokenType.out_)) else if (currentIs(TokenType.out_))
{ {
advance(); advance();
if (currentIs(TokenType.lParen)) if (currentIs(TokenType.lParen))
skipParens(); skipParens();
skipBraces(); skipBraces();
if (currentIs(TokenType.in_)) if (currentIs(TokenType.in_))
{ {
advance(); advance();
skipBraces(); skipBraces();
} }
} }
expect(TokenType.body_); expect(TokenType.body_);
skipBraces(); skipBraces();
} }
return null; return null;
} }
} }
string[] iotcToStringArray(const IdentifierOrTemplateChain iotc) string[] iotcToStringArray(const IdentifierOrTemplateChain iotc)

@ -1 +1 @@
Subproject commit 1c057260d5541f2ebd4d5b1780bacf45e482df39 Subproject commit e3819643bbec121e16abda6f980cc096d2e7f4f1

View File

@ -69,7 +69,7 @@ struct ModuleCache
estimate = symbol.estimateMemory(estimate); estimate = symbol.estimateMemory(estimate);
} }
double megabytes = estimate / (1024.0F * 1024.0F); double megabytes = estimate / (1024.0F * 1024.0F);
Log.info("Memory use estimated at ", megabytes, " megabytes"); Log.trace("Memory use estimated at ", megabytes, " megabytes");
} }
/** /**