mirror of https://gitlab.com/basile.b/dexed.git
use dastworx to detect main(), fixup #79
without the imports it was not possible to use DMD
This commit is contained in:
parent
44bf535c11
commit
c5e1cf513a
|
@ -11,6 +11,15 @@ object CurrentProject: TCENativeProject
|
||||||
)
|
)
|
||||||
pathsOptions.outputFilename = '../bin/dastworx'
|
pathsOptions.outputFilename = '../bin/dastworx'
|
||||||
runOptions.options = [poUsePipes, poStderrToOutPut]
|
runOptions.options = [poUsePipes, poStderrToOutPut]
|
||||||
|
end
|
||||||
|
item
|
||||||
|
name = 'release'
|
||||||
|
outputOptions.inlining = True
|
||||||
|
outputOptions.boundsCheck = offAlways
|
||||||
|
outputOptions.optimizations = True
|
||||||
|
outputOptions.release = True
|
||||||
|
pathsOptions.outputFilename = '../bin/dastworx'
|
||||||
|
runOptions.options = [poUsePipes, poStderrToOutPut]
|
||||||
end>
|
end>
|
||||||
Sources.Strings = (
|
Sources.Strings = (
|
||||||
'src/main.d'
|
'src/main.d'
|
||||||
|
@ -21,7 +30,7 @@ object CurrentProject: TCENativeProject
|
||||||
'src/common.d'
|
'src/common.d'
|
||||||
'src/runnableflags.d'
|
'src/runnableflags.d'
|
||||||
)
|
)
|
||||||
ConfigurationIndex = 0
|
ConfigurationIndex = 1
|
||||||
LibraryAliases.Strings = (
|
LibraryAliases.Strings = (
|
||||||
'iz'
|
'iz'
|
||||||
'libdparse'
|
'libdparse'
|
||||||
|
|
|
@ -9,5 +9,5 @@ object _1: TProjectGroup
|
||||||
item
|
item
|
||||||
filename = 'dastworx.ce'
|
filename = 'dastworx.ce'
|
||||||
end>
|
end>
|
||||||
index = 0
|
index = 2
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
module ceasttools;
|
module dastworx;
|
||||||
|
|
||||||
import
|
import
|
||||||
core.memory;
|
core.memory;
|
||||||
|
@ -18,6 +18,7 @@ private __gshared Module module_ = void;
|
||||||
private __gshared static Appender!(ubyte[]) source;
|
private __gshared static Appender!(ubyte[]) source;
|
||||||
private __gshared RollbackAllocator allocator;
|
private __gshared RollbackAllocator allocator;
|
||||||
private __gshared LexerConfig config;
|
private __gshared LexerConfig config;
|
||||||
|
private __gshared StringCache* cache;
|
||||||
private __gshared static Appender!(AstErrors) errors;
|
private __gshared static Appender!(AstErrors) errors;
|
||||||
private __gshared string[] files;
|
private __gshared string[] files;
|
||||||
|
|
||||||
|
@ -49,8 +50,7 @@ void main(string[] args)
|
||||||
files = args[1].splitter(pathSeparator).array;
|
files = args[1].splitter(pathSeparator).array;
|
||||||
|
|
||||||
config = LexerConfig("", StringBehavior.source, WhitespaceBehavior.skip);
|
config = LexerConfig("", StringBehavior.source, WhitespaceBehavior.skip);
|
||||||
StringCache cache = StringCache(StringCache.defaultBucketCount);
|
cache = construct!(StringCache)(StringCache.defaultBucketCount);
|
||||||
tokens = getTokensForParser(source.data, config, &cache);
|
|
||||||
|
|
||||||
getopt(args, std.getopt.config.passThrough,
|
getopt(args, std.getopt.config.passThrough,
|
||||||
"d", &deepSymList
|
"d", &deepSymList
|
||||||
|
@ -77,9 +77,10 @@ void handleSymListOption()
|
||||||
void handleTodosOption()
|
void handleTodosOption()
|
||||||
{
|
{
|
||||||
mixin(logCall);
|
mixin(logCall);
|
||||||
const(Token)[]*[] tokensArray;
|
lex!true;
|
||||||
|
const(Token)[][] tokensArray;
|
||||||
if (tokens.length)
|
if (tokens.length)
|
||||||
tokensArray ~= &tokens;
|
tokensArray ~= tokens;
|
||||||
|
|
||||||
import std.file: exists;
|
import std.file: exists;
|
||||||
if (files.length)
|
if (files.length)
|
||||||
|
@ -94,7 +95,7 @@ void handleTodosOption()
|
||||||
ubyte[] src;
|
ubyte[] src;
|
||||||
foreach(buffer; f.byChunk(4096))
|
foreach(buffer; f.byChunk(4096))
|
||||||
src ~= buffer;
|
src ~= buffer;
|
||||||
//tokensArray ~= getTokensForParser(src, config, &cache);
|
tokensArray ~= getTokensForParser(src, config, &cache);
|
||||||
f.close;
|
f.close;
|
||||||
}
|
}
|
||||||
catch (Exception e) continue;
|
catch (Exception e) continue;
|
||||||
|
@ -106,6 +107,7 @@ void handleTodosOption()
|
||||||
void handleRunnableFlags()
|
void handleRunnableFlags()
|
||||||
{
|
{
|
||||||
mixin(logCall);
|
mixin(logCall);
|
||||||
|
lex!true;
|
||||||
getRunnableFlags(tokens);
|
getRunnableFlags(tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +115,7 @@ void handleImportsOption()
|
||||||
{
|
{
|
||||||
mixin(logCall);
|
mixin(logCall);
|
||||||
storeAstErrors = false;
|
storeAstErrors = false;
|
||||||
|
lex!false;
|
||||||
parseTokens;
|
parseTokens;
|
||||||
listImports(module_);
|
listImports(module_);
|
||||||
}
|
}
|
||||||
|
@ -121,6 +124,7 @@ void handleMainfunOption()
|
||||||
{
|
{
|
||||||
mixin(logCall);
|
mixin(logCall);
|
||||||
storeAstErrors = false;
|
storeAstErrors = false;
|
||||||
|
lex!false;
|
||||||
parseTokens;
|
parseTokens;
|
||||||
detectMainFun(module_);
|
detectMainFun(module_);
|
||||||
}
|
}
|
||||||
|
@ -131,6 +135,17 @@ void handleErrors(string fname, size_t line, size_t col, string message, bool er
|
||||||
errors ~= construct!(AstError)(cast(ErrorType) err, message, line, col);
|
errors ~= construct!(AstError)(cast(ErrorType) err, message, line, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lex(bool keepComments = false)()
|
||||||
|
{
|
||||||
|
static if (keepComments)
|
||||||
|
{
|
||||||
|
DLexer dlx = DLexer(source.data, config, cache);
|
||||||
|
tokens = dlx.array;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
tokens = getTokensForParser(source.data, config, cache);
|
||||||
|
}
|
||||||
|
|
||||||
void parseTokens()
|
void parseTokens()
|
||||||
{
|
{
|
||||||
mixin(logCall);
|
mixin(logCall);
|
||||||
|
|
|
@ -10,18 +10,17 @@ import
|
||||||
|
|
||||||
private __gshared Appender!string stream;
|
private __gshared Appender!string stream;
|
||||||
|
|
||||||
void getTodos(const(Token)[]*[] tokensArray)
|
void getTodos(const(Token)[][] tokensArray)
|
||||||
{
|
{
|
||||||
mixin(logCall);
|
mixin(logCall);
|
||||||
stream.reserve(2^^16);
|
stream.reserve(2^^16);
|
||||||
stream.put("object TTodoItems\ritems = <");
|
stream.put("object TTodoItems\ritems = <");
|
||||||
assert(tokensArray.length);
|
assert(tokensArray.length);
|
||||||
|
assert(tokensArray[0].length);
|
||||||
foreach(tokens; tokensArray)
|
foreach(tokens; tokensArray)
|
||||||
//foreach(token; (*tokens).filter!((a) => a.type == tok!"comment")())
|
foreach(token; tokens.filter!((a) => a.type == tok!"comment"))
|
||||||
foreach(token; *tokens)
|
|
||||||
if (token.type == tok!"comment")
|
|
||||||
token.analyze;
|
token.analyze;
|
||||||
stream.put(">\rend\r\n");
|
stream.put(">\rend\r");
|
||||||
writeln(stream.data);
|
writeln(stream.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +110,7 @@ private void analyze(const(Token) token)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
stream.put("item\r");
|
stream.put("\ritem\r");
|
||||||
//stream.put(format("filename = '%s'\r", fname));
|
//stream.put(format("filename = '%s'\r", fname));
|
||||||
stream.put(format("line = '%d'\r", token.line));
|
stream.put(format("line = '%d'\r", token.line));
|
||||||
stream.put(format("text = '%s'\r", text));
|
stream.put(format("text = '%s'\r", text));
|
||||||
|
@ -123,5 +122,5 @@ private void analyze(const(Token) token)
|
||||||
stream.put(format("priority = '%s'\r", p));
|
stream.put(format("priority = '%s'\r", p));
|
||||||
if (s.length)
|
if (s.length)
|
||||||
stream.put(format("status = '%s'\r", s));
|
stream.put(format("status = '%s'\r", s));
|
||||||
stream.put("end\r");
|
stream.put("end");
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@ type
|
||||||
|
|
||||||
TIndentationMode = (imSpaces, imTabs);
|
TIndentationMode = (imSpaces, imTabs);
|
||||||
|
|
||||||
|
THasMain = (mainNo, mainYes, mainDefaultBehavior);
|
||||||
|
|
||||||
TCECompiler = (dmd, gdc, ldc);
|
TCECompiler = (dmd, gdc, ldc);
|
||||||
|
|
||||||
// aliased to get a custom prop inspector
|
// aliased to get a custom prop inspector
|
||||||
|
|
|
@ -2193,6 +2193,7 @@ var
|
||||||
lst: TStringList = nil;
|
lst: TStringList = nil;
|
||||||
firstLineFlags: string = '';
|
firstLineFlags: string = '';
|
||||||
asObj: boolean = false;
|
asObj: boolean = false;
|
||||||
|
hasMain: THasMain;
|
||||||
begin
|
begin
|
||||||
|
|
||||||
result := false;
|
result := false;
|
||||||
|
@ -2261,8 +2262,17 @@ begin
|
||||||
dmdproc.Parameters.AddText(fRunnableSw);
|
dmdproc.Parameters.AddText(fRunnableSw);
|
||||||
if lst.isNotNil and (lst.Count <> 0) then
|
if lst.isNotNil and (lst.Count <> 0) then
|
||||||
dmdproc.Parameters.AddStrings(lst);
|
dmdproc.Parameters.AddStrings(lst);
|
||||||
if fAppliOpts.detectMain and not fDoc.implementMain then
|
if fAppliOpts.detectMain then
|
||||||
|
begin
|
||||||
|
hasMain := fDoc.implementMain;
|
||||||
|
case hasMain of
|
||||||
|
mainNo:
|
||||||
dmdproc.Parameters.Add('-main');
|
dmdproc.Parameters.Add('-main');
|
||||||
|
mainDefaultBehavior:
|
||||||
|
if unittest then
|
||||||
|
dmdproc.Parameters.Add('-main');
|
||||||
|
end;
|
||||||
|
end;
|
||||||
if unittest then
|
if unittest then
|
||||||
begin
|
begin
|
||||||
if not fAppliOpts.detectMain then
|
if not fAppliOpts.detectMain then
|
||||||
|
|
|
@ -108,6 +108,7 @@ type
|
||||||
TCESynMemo = class(TSynEdit)
|
TCESynMemo = class(TSynEdit)
|
||||||
private
|
private
|
||||||
fFilename: string;
|
fFilename: string;
|
||||||
|
fDastWorxExename: string;
|
||||||
fModified: boolean;
|
fModified: boolean;
|
||||||
fFileDate: double;
|
fFileDate: double;
|
||||||
fCacheLoaded: boolean;
|
fCacheLoaded: boolean;
|
||||||
|
@ -216,7 +217,7 @@ type
|
||||||
procedure nextChangedArea;
|
procedure nextChangedArea;
|
||||||
procedure previousChangedArea;
|
procedure previousChangedArea;
|
||||||
procedure copy;
|
procedure copy;
|
||||||
function implementMain: boolean;
|
function implementMain: THasMain;
|
||||||
//
|
//
|
||||||
function breakPointsCount: integer;
|
function breakPointsCount: integer;
|
||||||
function breakPointLine(index: integer): integer;
|
function breakPointLine(index: integer): integer;
|
||||||
|
@ -579,6 +580,8 @@ begin
|
||||||
LineHighlightColor.Background := color - $080808;
|
LineHighlightColor.Background := color - $080808;
|
||||||
LineHighlightColor.Foreground := clNone;
|
LineHighlightColor.Foreground := clNone;
|
||||||
//
|
//
|
||||||
|
fDastWorxExename:= exeFullName('dastworx' + exeExt);
|
||||||
|
//
|
||||||
subjDocNew(TCEMultiDocSubject(fMultiDocSubject), self);
|
subjDocNew(TCEMultiDocSubject(fMultiDocSubject), self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -1300,74 +1303,33 @@ begin
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCESynMemo.implementMain: boolean;
|
function TCESynMemo.implementMain: THasMain;
|
||||||
function search(root: TJSONData): boolean;
|
|
||||||
var
|
|
||||||
i: integer;
|
|
||||||
p: TJSONData;
|
|
||||||
begin
|
|
||||||
if root.isNil then
|
|
||||||
exit(false);
|
|
||||||
root := root.FindPath('members');
|
|
||||||
if root.isNil then
|
|
||||||
exit(false);
|
|
||||||
for i := 0 to root.Count-1 do
|
|
||||||
begin
|
|
||||||
p := root.Items[i].FindPath('kind');
|
|
||||||
if p.isNotNil and (p.AsString = 'function') then
|
|
||||||
begin
|
|
||||||
p := root.Items[i].FindPath('name');
|
|
||||||
if p.isNotNil and (p.AsString = 'main') then
|
|
||||||
exit(true);
|
|
||||||
end;
|
|
||||||
if search(root.Items[i]) then
|
|
||||||
exit(true);
|
|
||||||
end;
|
|
||||||
exit(false);
|
|
||||||
end;
|
|
||||||
var
|
var
|
||||||
|
res: char = '0';
|
||||||
prc: TProcess;
|
prc: TProcess;
|
||||||
jfn: string;
|
src: string;
|
||||||
jdt: string;
|
|
||||||
begin
|
begin
|
||||||
if fileName.fileExists then
|
if fDastWorxExename.length = 0 then
|
||||||
save
|
exit(mainDefaultBehavior);
|
||||||
else
|
src := Lines.Text;
|
||||||
saveTempFile;
|
|
||||||
jfn := tempFilename + '.json';
|
|
||||||
prc := TProcess.Create(nil);
|
prc := TProcess.Create(nil);
|
||||||
try
|
try
|
||||||
//TODO-crunnables: the main() detector that uses DMD, libman entries must be passd to DMD.
|
prc.Executable:= fDastWorxExename;
|
||||||
prc.Executable:= 'dmd' + exeExt;
|
prc.Parameters.Add('-m');
|
||||||
prc.Parameters.Add(fileName);
|
prc.Options := [poUsePipes{$IFDEF WINDOWS}, poNewConsole{$ENDIF}];
|
||||||
prc.Parameters.Add('-c');
|
prc.ShowWindow := swoHIDE;
|
||||||
prc.Parameters.Add('-o-');
|
|
||||||
prc.Parameters.Add('-Xf' + jfn);
|
|
||||||
prc.Execute;
|
prc.Execute;
|
||||||
while prc.Running do Sleep(5);
|
prc.Input.Write(src[1], src.length);
|
||||||
|
prc.CloseInput;
|
||||||
|
while prc.Running do
|
||||||
|
sleep(1);
|
||||||
|
prc.Output.Read(res, 1);
|
||||||
finally
|
finally
|
||||||
prc.Free;
|
prc.Free;
|
||||||
end;
|
end;
|
||||||
if not jfn.fileExists then
|
case res = '1' of
|
||||||
exit(false);
|
false:result := mainNo;
|
||||||
with TMemoryStream.Create do
|
true: result := mainYes;
|
||||||
try
|
|
||||||
LoadFromFile(jfn);
|
|
||||||
setLength(jdt, size);
|
|
||||||
read(jdt[1], size);
|
|
||||||
finally
|
|
||||||
free;
|
|
||||||
DeleteFile(jfn);
|
|
||||||
end;
|
|
||||||
with TJSONParser.Create(jdt) do
|
|
||||||
try
|
|
||||||
try
|
|
||||||
result := search(Parse.Items[0]);
|
|
||||||
except
|
|
||||||
exit(false);
|
|
||||||
end;
|
|
||||||
finally
|
|
||||||
free;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
{$ENDREGION}
|
{$ENDREGION}
|
||||||
|
|
Loading…
Reference in New Issue