diff --git a/cesyms/cesyms.d b/cesyms/cesyms.d index 63d54085..d3ebd8e9 100644 --- a/cesyms/cesyms.d +++ b/cesyms/cesyms.d @@ -2,36 +2,6 @@ module cesyms; import std.stdio, std.path, std.file, std.array, std.string; 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 { @@ -58,18 +28,18 @@ struct Symbol 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(" col = %d\r", col)); - lfmApp.put(format(" name = '%s'\r", name)); - lfmApp.put(format(" symType = %s\r", type)); + lfmApp.put(format("line = %d\r", line)); + lfmApp.put(format("col = %d\r", col)); + lfmApp.put(format("name = '%s'\r", name)); + lfmApp.put(format("symType = %s\r", type)); - lfmApp.put(" subs = <"); + lfmApp.put("subs = <"); if (subs.length) foreach(Symbol * sub; subs) sub.serialize(lfmApp); lfmApp.put(">\r"); - lfmApp.put(" end\r"); + lfmApp.put("end\r"); } } @@ -91,30 +61,27 @@ void main(string[] args) { slb.resetRoot; slb.visit(decl); - } - - - // 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("."); - level++; - write(s.name, '\r'); - foreach(ss; s.subs) - print(ss); - - level--; } - //print(&slb.root); + + version(none) + { + int level = -1; + void print(Symbol * s) + { + foreach(i; 0 .. level) write("."); + level++; + write(s.name, '\r'); + foreach(ss; s.subs) + print(ss); + + level--; + } + print(&slb.root); + } auto str = slb.serialize; - - //std.file.write(r"C:\too.txt",cast(ubyte[])str); - + //std.file.write(r"C:\tool.txt",cast(ubyte[])str); write(str); - stdout.flush; } class SymbolListBuilder : ASTVisitor @@ -134,12 +101,11 @@ class SymbolListBuilder : ASTVisitor Appender!string lfmApp; lfmApp.reserve(count * 64); - lfmApp.put("object TSymbolList\r symbols = <"); + lfmApp.put("object TSymbolList\rsymbols = <"); foreach(Symbol * sym; root.subs) sym.serialize(lfmApp); 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". @@ -161,7 +127,7 @@ class SymbolListBuilder : ASTVisitor { count++; auto result = new Symbol; - result.name = adt.name.text.idup; + result.name = adt.name.text; result.line = adt.name.line; result.col = adt.name.column; parent.subs ~= result; @@ -185,7 +151,7 @@ class SymbolListBuilder : ASTVisitor dt.accept(this); } } - + final override void visit(const AliasDeclaration decl) { // old alias syntax not supported by this. @@ -201,7 +167,7 @@ class SymbolListBuilder : ASTVisitor 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); } @@ -241,8 +207,8 @@ class SymbolListBuilder : ASTVisitor final override void visit(const MixinDeclaration decl) { - // 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. + // TODO-cfeature: MixinDeclaration, just display the name of the mixed template. + // the template might be implemented in another module so their cant be displayed. } final override void visit(const StructDeclaration decl) diff --git a/src/ce_symlist.pas b/src/ce_symlist.pas index a8f14d8f..b1f9b79e 100644 --- a/src/ce_symlist.pas +++ b/src/ce_symlist.pas @@ -94,6 +94,7 @@ type fAutoRefresh: boolean; fRefreshOnChange: boolean; fRefreshOnFocus: boolean; + fToolOutput: TMemoryStream; ndAlias, ndClass, ndEnum, ndFunc, ndUni: TTreeNode; ndImp, ndIntf, ndMix, ndStruct, ndTmp, ndVar: TTreeNode; procedure TreeDblClick(Sender: TObject); @@ -106,7 +107,8 @@ type procedure clearTree; // procedure callToolProc; - procedure symbolListProduced(sender: TObject); + procedure toolOutputData(sender: TObject); + procedure toolTerminated(sender: TObject); // procedure optget_AutoRefresh(aWriter: TWriter); procedure optset_AutoRefresh(aReader: TReader); @@ -239,6 +241,7 @@ begin inherited; // allow empty name if owner is nil fSyms := TSymbolList.create(nil); + fToolOutput := TMemoryStream.create; // ndAlias := Tree.Items[0]; ndClass := Tree.Items[1]; @@ -271,6 +274,7 @@ begin EntitiesConnector.removeObserver(self); // killProcess(fToolProc); + fToolOutput.free; fSyms.Free; inherited; end; @@ -517,8 +521,8 @@ begin fToolProc.ShowWindow := swoHIDE; fToolProc.Options := [poUsePipes]; fToolProc.Executable := 'cesyms'; - fToolProc.OnTerminate := @symbolListProduced; - fToolProc.OnReadData := @symbolListProduced; + fToolProc.OnTerminate := @toolTerminated; + fToolProc.OnReadData := @toolOutputData; fToolProc.CurrentDirectory := ExtractFileDir(Application.ExeName); // focused source @@ -531,13 +535,14 @@ begin fToolProc.Execute; end; -procedure TCESymbolListWidget.symbolListProduced(sender: TObject); +procedure TCESymbolListWidget.toolOutputData(sender: TObject); +begin + processOutputToStream(TProcess(sender), fToolOutput); +end; + +procedure TCESymbolListWidget.toolTerminated(sender: TObject); var - cnt, sum: Integer; - str: TmemoryStream; i: Integer; -const - buffSz = 1024; // procedure symbolToTreeNode(sym: TSymbol); var @@ -573,23 +578,12 @@ begin updateVisibleCat; if fDoc = nil then exit; // - sum := 0; - str := TMemoryStream.Create; - try - 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; + processOutputToStream(TProcess(sender), fToolOutput); + fToolOutput.Position := 0; + fSyms.LoadFromTool(fToolOutput); fToolProc.OnTerminate := nil; fToolProc.OnReadData := nil; + fToolOutput.Clear; // tree.BeginUpdate; for i := 0 to fSyms.symbols.Count-1 do