From 95fae8efbb3b270c5e1458a288474c75fef9f4ca Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Wed, 16 Sep 2015 02:49:53 +0200 Subject: [PATCH] work on #39 for the linux platform --- cedast/build/cedast.coedit | 4 ++-- cedast/build/nux-postbuild.sh | 2 +- cedast/src/ast.d | 15 +++++++++------ cedast/src/cedast.d | 11 +++++++++-- cedast/src/common.d | 4 +++- lazproj/coedit.lpi | 1 - src/ce_dast.pas | 14 ++++++-------- src/ce_symlist.pas | 1 + src/ce_synmemo.pas | 1 + 9 files changed, 32 insertions(+), 21 deletions(-) diff --git a/cedast/build/cedast.coedit b/cedast/build/cedast.coedit index 78786834..c029f46c 100644 --- a/cedast/build/cedast.coedit +++ b/cedast/build/cedast.coedit @@ -13,6 +13,7 @@ object CurrentProject: TCENativeProject debugingOptions.debug = True debugingOptions.codeviewDexts = True messagesOptions.additionalWarnings = True + messagesOptions.tlsInformations = True outputOptions.binaryKind = obj pathsOptions.outputFilename = '../bin/cedast.o' otherOptions.customOptions.Strings = ( @@ -30,7 +31,6 @@ object CurrentProject: TCENativeProject ) ConfigurationIndex = 1 LibraryAliases.Strings = ( - 'libdparse' - 'iz' + '*' ) end diff --git a/cedast/build/nux-postbuild.sh b/cedast/build/nux-postbuild.sh index f52d1688..ee838ad9 100644 --- a/cedast/build/nux-postbuild.sh +++ b/cedast/build/nux-postbuild.sh @@ -1 +1 @@ -dmd ../bin/cedast.o -of../bin/cedast.so -shared -defaultlib=libphobos2.so +dmd ../bin/cedast.o /home/basile/Dev/dproj/Iz/lib/iz.a /home/basile/Dev/metad/libs/libdparse.a -of../bin/cedast.so -shared -defaultlib=libphobos2.so diff --git a/cedast/src/ast.d b/cedast/src/ast.d index a6a7dc79..e6017fd5 100644 --- a/cedast/src/ast.d +++ b/cedast/src/ast.d @@ -1,7 +1,7 @@ module ast; import std.d.lexer, std.d.parser, std.d.ast; -import std.json, std.array, std.conv, std.parallelism; +import std.json, std.array, std.conv, std.parallelism, std.concurrency; import iz.enumset, iz.memory; import common; @@ -323,7 +323,7 @@ private: ubyte[] todosJson; ubyte[] symsPas; ubyte[] symsJson; - static AstError*[] errors; + __gshared static AstError*[] errors; final static void parserError(string fname, size_t line, size_t col, string msg, bool isErr) { @@ -349,6 +349,7 @@ private: mod = parseModule(getTokensForParser(src, config, &strcache), fname, null, &parserError); if (notif) notif(notifparam); scanned = true; + } public: @@ -366,7 +367,8 @@ public: try src = cast(ubyte[]) read(fname, size_t.max); catch(Exception e){} scanned = false; - task(&taskScan).executeInNewThread; + version(Windows)task(&taskScan).executeInNewThread; + else taskScan; } final void scanBuffer(ubyte[] buffer) @@ -374,7 +376,8 @@ public: resetCachedInfo; src = buffer.dup; scanned = false; - task(&taskScan).executeInNewThread; + version(Windows) task(&taskScan).executeInNewThread; + else taskScan; } @property AstNotification notification(){return notif;} @@ -393,7 +396,7 @@ public: foreach(Token t; mod.moduleDeclaration.moduleName.identifiers) result ~= t.text ~ "."; if (result.length) - modName = result[0 .. $-1]; + modName = result[0 .. $-1].idup; } return modName; } @@ -421,7 +424,7 @@ public: cachedInfos += AstInfos.SymsPas; SymbolListBuilder slb = construct!SymbolListBuilder(mod); scope(exit) destruct(slb); - symsPas = cast(ubyte[]) slb.serializePas(); + symsPas = cast(ubyte[]) slb.serializePas().dup; } return symsPas; } diff --git a/cedast/src/cedast.d b/cedast/src/cedast.d index 876c8192..562a8dc6 100644 --- a/cedast/src/cedast.d +++ b/cedast/src/cedast.d @@ -4,11 +4,19 @@ import core.runtime, common, ast; import iz.memory; __gshared Ast[] modules; +__gshared bool init; +void tryInit() +{ + if (init) return; + Runtime.initialize; + init = true; +} extern(C) export AstHandle newAst(void* param, AstNotification clbck) { + version(linux) tryInit; AstHandle result; try { @@ -134,7 +142,7 @@ version(Windows) final switch (ulReason) { case DLL_PROCESS_ATTACH: - Runtime.initialize; + tryInit; g_hInst = hInstance; dll_process_attach( hInstance, true ); break; @@ -155,4 +163,3 @@ version(Windows) return true; } } - diff --git a/cedast/src/common.d b/cedast/src/common.d index 8c8a65ed..cdb171e3 100644 --- a/cedast/src/common.d +++ b/cedast/src/common.d @@ -1,8 +1,10 @@ module common; +extern(C): + alias AstHandle = ptrdiff_t; -alias AstNotification = extern(C) void function(void* param); +alias AstNotification = void function(void* param); __gshared immutable AstHandle invalidAstHandle = 0; diff --git a/lazproj/coedit.lpi b/lazproj/coedit.lpi index 82a73a3e..bd8c8abd 100644 --- a/lazproj/coedit.lpi +++ b/lazproj/coedit.lpi @@ -112,7 +112,6 @@ - diff --git a/src/ce_dast.pas b/src/ce_dast.pas index b0d42138..34354ba7 100644 --- a/src/ce_dast.pas +++ b/src/ce_dast.pas @@ -5,7 +5,7 @@ unit ce_dast; interface uses - dynlibs, forms; + dynlibs, sysutils, ce_common; type @@ -44,14 +44,14 @@ var implementation var - dastHdl: TLibHandle; + dastHdl: TLibHandle = 0; + fname: string; initialization - if application.GetOptionValue('cedast') = 'off' then - exit; - - dastHdl := LoadLibrary('cedast'); + fname := exeFullName('cedast' + dynExt); + if FileExists(fname) then + dastHdl := LoadLibrary(fname); if dastHdl <> NilHandle then begin newAST := TNewAst(GetProcAddress(dastHdl, 'newAst')); @@ -60,13 +60,11 @@ initialization scanBuffer := TScanBuffer(GetProcAddress(dastHdl, 'scanBuffer')); moduleName := TModuleName(GetProcAddress(dastHdl, 'moduleName')); symbolList := TSymbolList(GetProcAddress(dastHdl, 'symbolList')); - symbolList := TSymbolList(GetProcAddress(dastHdl, 'symbolList')); // dastAvailable := assigned(newAST) and assigned(deleteAST) and assigned(scanFile) and assigned(scanBuffer) and assigned(moduleName) and assigned(symbolList); end; - finalization {$IFDEF RELEASE} if dastHdl <> NilHandle then diff --git a/src/ce_symlist.pas b/src/ce_symlist.pas index 83e0a0dc..897f7dbb 100644 --- a/src/ce_symlist.pas +++ b/src/ce_symlist.pas @@ -712,6 +712,7 @@ begin if fDoc.ast = 0 then exit; // ptr := symbolList(fDoc.ast, len, TSerializationFormat.pas); + if len = 0 then exit; fSymStream.clear; fSymStream.Write(ptr^, len); fSymStream.Position:=0; diff --git a/src/ce_synmemo.pas b/src/ce_synmemo.pas index 5e56f6c3..24baecb7 100644 --- a/src/ce_synmemo.pas +++ b/src/ce_synmemo.pas @@ -377,6 +377,7 @@ begin fAstTimer.Interval:= 2000; fAstTimer.OnTimer:= @AstTimerEvent; fAstTimer.Enabled:=true; + fAstTimer.AutoEnabled:=true; end; // ShowHint := false;