mirror of https://gitlab.com/basile.b/dexed.git
fix, in asyncprocess, output has to be accumulated in the two events
This commit is contained in:
parent
ac5c8e1ad4
commit
2c8182223f
|
@ -2,36 +2,6 @@ module cesyms;
|
||||||
|
|
||||||
import std.stdio, std.path, std.file, std.array, std.string;
|
import std.stdio, std.path, std.file, std.array, std.string;
|
||||||
import std.d.lexer, std.d.ast, std.d.parser;
|
import std.d.lexer, std.d.ast, std.d.parser;
|
||||||
static import std.conv;
|
|
||||||
|
|
||||||
interface I{}
|
|
||||||
|
|
||||||
alias Int32 = int;
|
|
||||||
//alias long Int64;
|
|
||||||
|
|
||||||
enum E
|
|
||||||
{
|
|
||||||
e1,
|
|
||||||
e2,
|
|
||||||
e3,
|
|
||||||
}
|
|
||||||
|
|
||||||
enum {opt1,opt2}
|
|
||||||
|
|
||||||
class A
|
|
||||||
{
|
|
||||||
class AA
|
|
||||||
{
|
|
||||||
class AA1{}
|
|
||||||
class AA2{}
|
|
||||||
}
|
|
||||||
|
|
||||||
class BB
|
|
||||||
{
|
|
||||||
class BB1{}
|
|
||||||
class BB2{}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum SymbolType
|
enum SymbolType
|
||||||
{
|
{
|
||||||
|
@ -58,18 +28,18 @@ struct Symbol
|
||||||
|
|
||||||
void serialize(ref Appender!string lfmApp)
|
void serialize(ref Appender!string lfmApp)
|
||||||
{
|
{
|
||||||
lfmApp.put(" \r item\r");
|
lfmApp.put("\ritem\r");
|
||||||
|
|
||||||
lfmApp.put(format(" line = %d\r", line));
|
lfmApp.put(format("line = %d\r", line));
|
||||||
lfmApp.put(format(" col = %d\r", col));
|
lfmApp.put(format("col = %d\r", col));
|
||||||
lfmApp.put(format(" name = '%s'\r", name));
|
lfmApp.put(format("name = '%s'\r", name));
|
||||||
lfmApp.put(format(" symType = %s\r", type));
|
lfmApp.put(format("symType = %s\r", type));
|
||||||
|
|
||||||
lfmApp.put(" subs = <");
|
lfmApp.put("subs = <");
|
||||||
if (subs.length) foreach(Symbol * sub; subs)
|
if (subs.length) foreach(Symbol * sub; subs)
|
||||||
sub.serialize(lfmApp);
|
sub.serialize(lfmApp);
|
||||||
lfmApp.put(">\r");
|
lfmApp.put(">\r");
|
||||||
lfmApp.put(" end\r");
|
lfmApp.put("end\r");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,28 +63,25 @@ void main(string[] args)
|
||||||
slb.visit(decl);
|
slb.visit(decl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
version(none)
|
||||||
// TODO-cfeature: Outputs the symbol tree in a format handlable by a Coedit widget
|
|
||||||
|
|
||||||
int level = -1;
|
|
||||||
void print(Symbol * s)
|
|
||||||
{
|
{
|
||||||
foreach(i; 0 .. level) write(".");
|
int level = -1;
|
||||||
level++;
|
void print(Symbol * s)
|
||||||
write(s.name, '\r');
|
{
|
||||||
foreach(ss; s.subs)
|
foreach(i; 0 .. level) write(".");
|
||||||
print(ss);
|
level++;
|
||||||
|
write(s.name, '\r');
|
||||||
|
foreach(ss; s.subs)
|
||||||
|
print(ss);
|
||||||
|
|
||||||
level--;
|
level--;
|
||||||
|
}
|
||||||
|
print(&slb.root);
|
||||||
}
|
}
|
||||||
//print(&slb.root);
|
|
||||||
|
|
||||||
auto str = slb.serialize;
|
auto str = slb.serialize;
|
||||||
|
//std.file.write(r"C:\tool.txt",cast(ubyte[])str);
|
||||||
//std.file.write(r"C:\too.txt",cast(ubyte[])str);
|
|
||||||
|
|
||||||
write(str);
|
write(str);
|
||||||
stdout.flush;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class SymbolListBuilder : ASTVisitor
|
class SymbolListBuilder : ASTVisitor
|
||||||
|
@ -134,12 +101,11 @@ class SymbolListBuilder : ASTVisitor
|
||||||
Appender!string lfmApp;
|
Appender!string lfmApp;
|
||||||
lfmApp.reserve(count * 64);
|
lfmApp.reserve(count * 64);
|
||||||
|
|
||||||
lfmApp.put("object TSymbolList\r symbols = <");
|
lfmApp.put("object TSymbolList\rsymbols = <");
|
||||||
foreach(Symbol * sym; root.subs) sym.serialize(lfmApp);
|
foreach(Symbol * sym; root.subs) sym.serialize(lfmApp);
|
||||||
lfmApp.put(">\rend\r\n");
|
lfmApp.put(">\rend\r\n");
|
||||||
|
|
||||||
return lfmApp.data;
|
return lfmApp.data;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// returns a new symbol if the declarator is based on a Token named "name".
|
/// returns a new symbol if the declarator is based on a Token named "name".
|
||||||
|
@ -161,7 +127,7 @@ class SymbolListBuilder : ASTVisitor
|
||||||
{
|
{
|
||||||
count++;
|
count++;
|
||||||
auto result = new Symbol;
|
auto result = new Symbol;
|
||||||
result.name = adt.name.text.idup;
|
result.name = adt.name.text;
|
||||||
result.line = adt.name.line;
|
result.line = adt.name.line;
|
||||||
result.col = adt.name.column;
|
result.col = adt.name.column;
|
||||||
parent.subs ~= result;
|
parent.subs ~= result;
|
||||||
|
@ -201,7 +167,7 @@ class SymbolListBuilder : ASTVisitor
|
||||||
|
|
||||||
final override void visit(const EnumDeclaration decl)
|
final override void visit(const EnumDeclaration decl)
|
||||||
{
|
{
|
||||||
// TODO-ctest: try to see if what dmd outputs as , "enum member" is handled.
|
//TODO-ctest: try to see if what dmd outputs as , "enum member" is handled.
|
||||||
namedVisitorImpl!(EnumDeclaration, SymbolType._class)(decl);
|
namedVisitorImpl!(EnumDeclaration, SymbolType._class)(decl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,7 +208,7 @@ class SymbolListBuilder : ASTVisitor
|
||||||
final override void visit(const MixinDeclaration decl)
|
final override void visit(const MixinDeclaration decl)
|
||||||
{
|
{
|
||||||
// TODO-cfeature: MixinDeclaration, just display the name of the mixed template.
|
// TODO-cfeature: MixinDeclaration, just display the name of the mixed template.
|
||||||
// the template might be implemented in another module so their ùeùbrs cant be displayed.
|
// the template might be implemented in another module so their cant be displayed.
|
||||||
}
|
}
|
||||||
|
|
||||||
final override void visit(const StructDeclaration decl)
|
final override void visit(const StructDeclaration decl)
|
||||||
|
|
|
@ -94,6 +94,7 @@ type
|
||||||
fAutoRefresh: boolean;
|
fAutoRefresh: boolean;
|
||||||
fRefreshOnChange: boolean;
|
fRefreshOnChange: boolean;
|
||||||
fRefreshOnFocus: boolean;
|
fRefreshOnFocus: boolean;
|
||||||
|
fToolOutput: TMemoryStream;
|
||||||
ndAlias, ndClass, ndEnum, ndFunc, ndUni: TTreeNode;
|
ndAlias, ndClass, ndEnum, ndFunc, ndUni: TTreeNode;
|
||||||
ndImp, ndIntf, ndMix, ndStruct, ndTmp, ndVar: TTreeNode;
|
ndImp, ndIntf, ndMix, ndStruct, ndTmp, ndVar: TTreeNode;
|
||||||
procedure TreeDblClick(Sender: TObject);
|
procedure TreeDblClick(Sender: TObject);
|
||||||
|
@ -106,7 +107,8 @@ type
|
||||||
procedure clearTree;
|
procedure clearTree;
|
||||||
//
|
//
|
||||||
procedure callToolProc;
|
procedure callToolProc;
|
||||||
procedure symbolListProduced(sender: TObject);
|
procedure toolOutputData(sender: TObject);
|
||||||
|
procedure toolTerminated(sender: TObject);
|
||||||
//
|
//
|
||||||
procedure optget_AutoRefresh(aWriter: TWriter);
|
procedure optget_AutoRefresh(aWriter: TWriter);
|
||||||
procedure optset_AutoRefresh(aReader: TReader);
|
procedure optset_AutoRefresh(aReader: TReader);
|
||||||
|
@ -239,6 +241,7 @@ begin
|
||||||
inherited;
|
inherited;
|
||||||
// allow empty name if owner is nil
|
// allow empty name if owner is nil
|
||||||
fSyms := TSymbolList.create(nil);
|
fSyms := TSymbolList.create(nil);
|
||||||
|
fToolOutput := TMemoryStream.create;
|
||||||
//
|
//
|
||||||
ndAlias := Tree.Items[0];
|
ndAlias := Tree.Items[0];
|
||||||
ndClass := Tree.Items[1];
|
ndClass := Tree.Items[1];
|
||||||
|
@ -271,6 +274,7 @@ begin
|
||||||
EntitiesConnector.removeObserver(self);
|
EntitiesConnector.removeObserver(self);
|
||||||
//
|
//
|
||||||
killProcess(fToolProc);
|
killProcess(fToolProc);
|
||||||
|
fToolOutput.free;
|
||||||
fSyms.Free;
|
fSyms.Free;
|
||||||
inherited;
|
inherited;
|
||||||
end;
|
end;
|
||||||
|
@ -517,8 +521,8 @@ begin
|
||||||
fToolProc.ShowWindow := swoHIDE;
|
fToolProc.ShowWindow := swoHIDE;
|
||||||
fToolProc.Options := [poUsePipes];
|
fToolProc.Options := [poUsePipes];
|
||||||
fToolProc.Executable := 'cesyms';
|
fToolProc.Executable := 'cesyms';
|
||||||
fToolProc.OnTerminate := @symbolListProduced;
|
fToolProc.OnTerminate := @toolTerminated;
|
||||||
fToolProc.OnReadData := @symbolListProduced;
|
fToolProc.OnReadData := @toolOutputData;
|
||||||
fToolProc.CurrentDirectory := ExtractFileDir(Application.ExeName);
|
fToolProc.CurrentDirectory := ExtractFileDir(Application.ExeName);
|
||||||
|
|
||||||
// focused source
|
// focused source
|
||||||
|
@ -531,13 +535,14 @@ begin
|
||||||
fToolProc.Execute;
|
fToolProc.Execute;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCESymbolListWidget.symbolListProduced(sender: TObject);
|
procedure TCESymbolListWidget.toolOutputData(sender: TObject);
|
||||||
|
begin
|
||||||
|
processOutputToStream(TProcess(sender), fToolOutput);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TCESymbolListWidget.toolTerminated(sender: TObject);
|
||||||
var
|
var
|
||||||
cnt, sum: Integer;
|
|
||||||
str: TmemoryStream;
|
|
||||||
i: Integer;
|
i: Integer;
|
||||||
const
|
|
||||||
buffSz = 1024;
|
|
||||||
//
|
//
|
||||||
procedure symbolToTreeNode(sym: TSymbol);
|
procedure symbolToTreeNode(sym: TSymbol);
|
||||||
var
|
var
|
||||||
|
@ -573,23 +578,12 @@ begin
|
||||||
updateVisibleCat;
|
updateVisibleCat;
|
||||||
if fDoc = nil then exit;
|
if fDoc = nil then exit;
|
||||||
//
|
//
|
||||||
sum := 0;
|
processOutputToStream(TProcess(sender), fToolOutput);
|
||||||
str := TMemoryStream.Create;
|
fToolOutput.Position := 0;
|
||||||
try
|
fSyms.LoadFromTool(fToolOutput);
|
||||||
while fToolProc.Output.NumBytesAvailable <> 0 do begin
|
|
||||||
str.SetSize(sum + buffSz);
|
|
||||||
cnt := fToolProc.Output.Read((str.Memory + sum)^, buffSz);
|
|
||||||
sum += cnt;
|
|
||||||
end;
|
|
||||||
str.SetSize(sum);
|
|
||||||
str.Position := 0;
|
|
||||||
//str.SaveToFile('C:\symlist.txt');
|
|
||||||
fSyms.LoadFromTool(str);
|
|
||||||
finally
|
|
||||||
str.Free;
|
|
||||||
end;
|
|
||||||
fToolProc.OnTerminate := nil;
|
fToolProc.OnTerminate := nil;
|
||||||
fToolProc.OnReadData := nil;
|
fToolProc.OnReadData := nil;
|
||||||
|
fToolOutput.Clear;
|
||||||
//
|
//
|
||||||
tree.BeginUpdate;
|
tree.BeginUpdate;
|
||||||
for i := 0 to fSyms.symbols.Count-1 do
|
for i := 0 to fSyms.symbols.Count-1 do
|
||||||
|
|
Loading…
Reference in New Issue