pastojs: added option -vv, -va includes -vd

git-svn-id: trunk@38965 -
This commit is contained in:
Mattias Gaertner 2018-05-10 09:27:40 +00:00
parent e9843bccf0
commit 69d6e8ac90
3 changed files with 93 additions and 50 deletions

View File

@ -92,8 +92,8 @@ type
coShowTriedUsedFiles, coShowTriedUsedFiles,
coShowConditionals, coShowConditionals,
coShowUsedTools, coShowUsedTools,
coShowDebug,
coShowMessageNumbers, // not in "show all" coShowMessageNumbers, // not in "show all"
coShowDebug, // not in "show all"
// checks // checks
coOverflowChecks, coOverflowChecks,
coRangeChecks, coRangeChecks,
@ -104,6 +104,7 @@ type
// output // output
coLowerCase, coLowerCase,
coUseStrict, coUseStrict,
coWriteDebugLog,
coWriteMsgToStdErr, coWriteMsgToStdErr,
// optimizations // optimizations
coEnumValuesAsNumbers, coEnumValuesAsNumbers,
@ -118,7 +119,7 @@ type
TP2jsOptimization = coEnumValuesAsNumbers..coKeepNotUsedDeclarationsWPO; TP2jsOptimization = coEnumValuesAsNumbers..coKeepNotUsedDeclarationsWPO;
const const
DefaultP2jsCompilerOptions = [coShowErrors,coSourceMapXSSIHeader,coUseStrict]; DefaultP2jsCompilerOptions = [coShowErrors,coSourceMapXSSIHeader,coUseStrict];
coShowAll = [coShowErrors..coShowUsedTools]; coShowAll = [coShowErrors..coShowDebug];
coO1Enable = [coEnumValuesAsNumbers]; coO1Enable = [coEnumValuesAsNumbers];
coO1Disable = [coKeepNotUsedPrivates,coKeepNotUsedDeclarationsWPO]; coO1Disable = [coKeepNotUsedPrivates,coKeepNotUsedDeclarationsWPO];
@ -136,8 +137,8 @@ const
'Show tried/used files', 'Show tried/used files',
'Show conditionals', 'Show conditionals',
'Show used tools', 'Show used tools',
'Show message numbers',
'Show debug', 'Show debug',
'Show message numbers',
'Overflow checking', 'Overflow checking',
'Range checking', 'Range checking',
'Method call checking', 'Method call checking',
@ -145,6 +146,7 @@ const
'Allow C assignments', 'Allow C assignments',
'Lowercase identifiers', 'Lowercase identifiers',
'Use strict', 'Use strict',
'Write pas2jsdebug.log',
'Write messages to StdErr', 'Write messages to StdErr',
'Enum values as numbers', 'Enum values as numbers',
'Keep not used private declarations', 'Keep not used private declarations',
@ -388,6 +390,7 @@ type
function GetSrcMapEnable: boolean; function GetSrcMapEnable: boolean;
function GetSrcMapInclude: boolean; function GetSrcMapInclude: boolean;
function GetSrcMapXSSIHeader: boolean; function GetSrcMapXSSIHeader: boolean;
function GetWriteDebugLog: boolean;
function GetWriteMsgToStdErr: boolean; function GetWriteMsgToStdErr: boolean;
function OnMacroCfgDir(Sender: TObject; var Params: string; Lvl: integer function OnMacroCfgDir(Sender: TObject; var Params: string; Lvl: integer
): boolean; ): boolean;
@ -409,6 +412,7 @@ type
procedure SetSrcMapXSSIHeader(const AValue: boolean); procedure SetSrcMapXSSIHeader(const AValue: boolean);
procedure SetTargetPlatform(const AValue: TPasToJsPlatform); procedure SetTargetPlatform(const AValue: TPasToJsPlatform);
procedure SetTargetProcessor(const AValue: TPasToJsProcessor); procedure SetTargetProcessor(const AValue: TPasToJsProcessor);
procedure SetWriteDebugLog(const AValue: boolean);
procedure SetWriteMsgToStdErr(const AValue: boolean); procedure SetWriteMsgToStdErr(const AValue: boolean);
private private
FInterfaceType: TPasClassInterfaceType; FInterfaceType: TPasClassInterfaceType;
@ -514,6 +518,7 @@ type
property TargetPlatform: TPasToJsPlatform read FTargetPlatform write SetTargetPlatform; property TargetPlatform: TPasToJsPlatform read FTargetPlatform write SetTargetPlatform;
property TargetProcessor: TPasToJsProcessor read FTargetProcessor write SetTargetProcessor; property TargetProcessor: TPasToJsProcessor read FTargetProcessor write SetTargetProcessor;
property WPOAnalyzer: TPas2JSWPOptimizer read FWPOAnalyzer; // Whole Program Optimization property WPOAnalyzer: TPas2JSWPOptimizer read FWPOAnalyzer; // Whole Program Optimization
property WriteDebugLog: boolean read GetWriteDebugLog write SetWriteDebugLog;
property WriteMsgToStdErr: boolean read GetWriteMsgToStdErr write SetWriteMsgToStdErr; property WriteMsgToStdErr: boolean read GetWriteMsgToStdErr write SetWriteMsgToStdErr;
property ExitCode: longint read GetExitCode write SetExitCode; property ExitCode: longint read GetExitCode write SetExitCode;
end; end;
@ -1172,10 +1177,10 @@ begin
try try
Compiler.RemoveReadingModule(Self); Compiler.RemoveReadingModule(Self);
if ShowDebug then if coWriteDebugLog in Compiler.Options then
begin begin
Log.LogPlain('Pas-Module:'); Log.DebugLogWriteLn('Pas-Module:');
Log.LogPlain(PasModule.GetDeclaration(true)); Log.DebugLogWriteLn(PasModule.GetDeclaration(true));
end; end;
if PCUReader=nil then if PCUReader=nil then
@ -2565,6 +2570,11 @@ begin
Result:=coSourceMapXSSIHeader in FOptions; Result:=coSourceMapXSSIHeader in FOptions;
end; end;
function TPas2jsCompiler.GetWriteDebugLog: boolean;
begin
Result:=coWriteDebugLog in FOptions;
end;
function TPas2jsCompiler.GetWriteMsgToStdErr: boolean; function TPas2jsCompiler.GetWriteMsgToStdErr: boolean;
begin begin
Result:=coWriteMsgToStdErr in FOptions; Result:=coWriteMsgToStdErr in FOptions;
@ -2669,6 +2679,11 @@ begin
AddDefinesForTargetProcessor; AddDefinesForTargetProcessor;
end; end;
procedure TPas2jsCompiler.SetWriteDebugLog(const AValue: boolean);
begin
SetOption(coWriteDebugLog,AValue);
end;
procedure TPas2jsCompiler.SetWriteMsgToStdErr(const AValue: boolean); procedure TPas2jsCompiler.SetWriteMsgToStdErr(const AValue: boolean);
begin begin
SetOption(coWriteMsgToStdErr,AValue); SetOption(coWriteMsgToStdErr,AValue);
@ -3517,7 +3532,7 @@ begin
end; end;
// read other flags // read other flags
ReadSingleLetterOptions(Param,p,'ewnhila0bctdqxz',Enabled,Disabled); ReadSingleLetterOptions(Param,p,'ewnhila0bctdqxvz',Enabled,Disabled);
for i:=1 to length(Enabled) do begin for i:=1 to length(Enabled) do begin
case Enabled[i] of case Enabled[i] of
'e': Options:=Options+[coShowErrors]; 'e': Options:=Options+[coShowErrors];
@ -3534,6 +3549,7 @@ begin
'd': ShowDebug:=true; 'd': ShowDebug:=true;
'q': Options:=Options+[coShowMessageNumbers]; 'q': Options:=Options+[coShowMessageNumbers];
'x': Options:=Options+[coShowUsedTools]; 'x': Options:=Options+[coShowUsedTools];
'v': Options:=Options+[coWriteDebugLog];
'z': WriteMsgToStdErr:=true; 'z': WriteMsgToStdErr:=true;
end; end;
end; end;
@ -3553,6 +3569,7 @@ begin
'd': ShowDebug:=false; 'd': ShowDebug:=false;
'q': Options:=Options-[coShowMessageNumbers]; 'q': Options:=Options-[coShowMessageNumbers];
'x': Options:=Options-[coShowUsedTools]; 'x': Options:=Options-[coShowUsedTools];
'v': Options:=Options+[coWriteDebugLog];
'z': WriteMsgToStdErr:=false; 'z': WriteMsgToStdErr:=false;
end; end;
end; end;
@ -3813,6 +3830,8 @@ begin
// quick check command line params // quick check command line params
for i:=0 to ParamList.Count-1 do for i:=0 to ParamList.Count-1 do
ReadParam(ParamList[i],true,true); ReadParam(ParamList[i],true,true);
if WriteDebugLog then
Log.OpenDebugLog;
if ShowLogo then if ShowLogo then
WriteLogo; WriteLogo;
@ -4010,21 +4029,22 @@ begin
l(' -Tnodejs : add pas.run(), includes -Jc'); l(' -Tnodejs : add pas.run(), includes -Jc');
l(' -u<x> : Undefines the symbol <x>'); l(' -u<x> : Undefines the symbol <x>');
l(' -v<x> : Be verbose. <x> is a combination of the following letters:'); l(' -v<x> : Be verbose. <x> is a combination of the following letters:');
l(' e : show errors (default)'); l(' e : Show errors (default)');
l(' w : show warnings'); l(' w : Show warnings');
l(' n : show notes'); l(' n : Show notes');
l(' h : show hints'); l(' h : Show hints');
l(' i : show info'); l(' i : Show info');
l(' l : show line numbers'); l(' l : Show line numbers');
l(' a : show everything'); l(' a : Show everything');
l(' 0 : show nothing (except errors)'); l(' 0 : Show nothing (except errors)');
l(' b : show file names with full path'); l(' b : Show file names with full path');
l(' c : show conditionals'); l(' c : Show conditionals');
l(' t : show tried/used files'); l(' t : Show tried/used files');
l(' d : show debug notes and info, enables -vni'); l(' d : Show debug notes and info, enables -vni');
l(' q : show message numbers'); l(' q : Show message numbers');
l(' x : show used tools'); l(' x : Show used tools');
l(' z : write messages to stderr, -o. still uses stdout.'); l(' v : Write pas2jsdebug.log with lots of debugging info');
l(' z : Write messages to stderr, -o. still uses stdout.');
l(' -vm<x>,<y>: Do not show messages numbered <x> and <y>.'); l(' -vm<x>,<y>: Do not show messages numbered <x> and <y>.');
l(' -? : Show this help'); l(' -? : Show this help');
l(' -h : Show this help'); l(' -h : Show this help');
@ -4055,7 +4075,7 @@ var
fco: TP2jsFileCacheOption; fco: TP2jsFileCacheOption;
begin begin
// message encoding // message encoding
Log.LogMsgIgnoreFilter(nMessageEncodingIs,[IntToStr(Log.MsgCount)]); Log.LogMsgIgnoreFilter(nMessageEncodingIs,[BoolToStr(Log.Encoding<>'',Log.Encoding,'system')]);
// target platform // target platform
Log.LogMsgIgnoreFilter(nTargetPlatformIs,[PasToJsPlatformNames[TargetPlatform]]); Log.LogMsgIgnoreFilter(nTargetPlatformIs,[PasToJsPlatformNames[TargetPlatform]]);
Log.LogMsgIgnoreFilter(nTargetProcessorIs,[PasToJsProcessorNames[TargetProcessor]]); Log.LogMsgIgnoreFilter(nTargetProcessorIs,[PasToJsProcessorNames[TargetProcessor]]);

View File

@ -59,6 +59,7 @@ type
TPas2jsLogger = class TPas2jsLogger = class
private private
FDebugLog: TStream;
FEncoding: string; FEncoding: string;
FLastMsgCol: integer; FLastMsgCol: integer;
FLastMsgFile: string; FLastMsgFile: string;
@ -116,6 +117,9 @@ type
procedure CloseOutputFile; procedure CloseOutputFile;
procedure Reset; procedure Reset;
procedure ClearLastMsg; procedure ClearLastMsg;
procedure OpenDebugLog;
procedure CloseDebugLog;
procedure DebugLogWriteLn(Msg: string); overload;
public public
property Encoding: string read FEncoding write SetEncoding; // normalized property Encoding: string read FEncoding write SetEncoding; // normalized
property MsgCount: integer read GetMsgCount; property MsgCount: integer read GetMsgCount;
@ -134,6 +138,7 @@ type
property LastMsgCol: integer read FLastMsgCol write FLastMsgCol; property LastMsgCol: integer read FLastMsgCol write FLastMsgCol;
property LastMsgTxt: string read FLastMsgTxt write FLastMsgTxt; property LastMsgTxt: string read FLastMsgTxt write FLastMsgTxt;
property LastMsgNumber: integer read FLastMsgNumber write FLastMsgNumber; property LastMsgNumber: integer read FLastMsgNumber write FLastMsgNumber;
property DebugLog: TStream read FDebugLog write FDebugLog;
end; end;
function CompareP2JMessage(Item1, Item2: Pointer): Integer; function CompareP2JMessage(Item1, Item2: Pointer): Integer;
@ -511,35 +516,32 @@ begin
end; end;
procedure TPas2jsLogger.DoLogRaw(const Msg: string; SkipEncoding : Boolean); procedure TPas2jsLogger.DoLogRaw(const Msg: string; SkipEncoding : Boolean);
var
Var S: String;
S : String;
begin begin
if SkipEncoding then if SkipEncoding then
S:=Msg S:=Msg
else else begin
begin
if (Encoding='utf8') or (Encoding='json') then if (Encoding='utf8') or (Encoding='json') then
S:=Msg S:=Msg
else if Encoding='console' then else if Encoding='console' then
S:=UTF8ToConsole(Msg) S:=UTF8ToConsole(Msg)
else if Encoding='system' then else if Encoding='system' then
S:=UTF8ToSystemCP(Msg) S:=UTF8ToSystemCP(Msg)
else else begin
begin
// default: write UTF-8 to outputfile and console codepage to console // default: write UTF-8 to outputfile and console codepage to console
if FOutputFile=nil then if FOutputFile=nil then
S:=UTF8ToConsole(Msg); S:=UTF8ToConsole(Msg);
end; end;
end; end;
//writeln('TPas2jsLogger.LogPlain "',Encoding,'" "',DbgStr(S),'"'); //writeln('TPas2jsLogger.LogPlain "',Encoding,'" "',DbgStr(S),'"');
if DebugLog<>nil then
DebugLogWriteLn(S);
if FOnLog<>Nil then if FOnLog<>Nil then
FOnLog(Self,S) FOnLog(Self,S)
else if FOutputFile<>nil then else if FOutputFile<>nil then
FOutputFile.Write(S+LineEnding) FOutputFile.Write(S+LineEnding)
else else begin
begin
// prevent codepage conversion magic // prevent codepage conversion magic
SetCodePage(RawByteString(S), CP_OEMCP, False); SetCodePage(RawByteString(S), CP_OEMCP, False);
{AllowWriteln} {AllowWriteln}
@ -597,6 +599,7 @@ var
i: Integer; i: Integer;
begin begin
CloseOutputFile; CloseOutputFile;
CloseDebugLog;
for i:=0 to FMsg.Count-1 do for i:=0 to FMsg.Count-1 do
TObject(FMsg[i]).Free; TObject(FMsg[i]).Free;
FreeAndNil(FMsg); FreeAndNil(FMsg);
@ -695,6 +698,13 @@ begin
LogRaw(''); LogRaw('');
end; end;
procedure TPas2jsLogger.DebugLogWriteLn(Msg: string);
begin
if FDebugLog=nil then exit;
Msg:=Msg+LineEnding;
FDebugLog.Write(Msg[1],length(Msg));
end;
procedure TPas2jsLogger.LogPlain(const Msg: string); procedure TPas2jsLogger.LogPlain(const Msg: string);
var var
s: String; s: String;
@ -867,5 +877,17 @@ begin
FLastMsgCol:=0; FLastMsgCol:=0;
end; end;
procedure TPas2jsLogger.OpenDebugLog;
const
DbgLogFilename = 'pas2jsdebug.log';
begin
FDebugLog:=TFileStream.Create(DbgLogFilename,fmCreate or fmShareDenyNone);
end;
procedure TPas2jsLogger.CloseDebugLog;
begin
FreeAndNil(FDebugLog);
end;
end. end.

View File

@ -194,21 +194,22 @@ Put + after a boolean switch option to enable it, - to disable it
-Tnodejs : add pas.run(), includes -Jc -Tnodejs : add pas.run(), includes -Jc
-u&lt;x&gt; : Undefines the symbol &lt;x&gt; -u&lt;x&gt; : Undefines the symbol &lt;x&gt;
-v&lt;x&gt; : Be verbose. &lt;x&gt; is a combination of the following letters: -v&lt;x&gt; : Be verbose. &lt;x&gt; is a combination of the following letters:
e : show errors (default) e : Show errors (default)
w : show warnings w : Show warnings
n : show notes n : Show notes
h : show hints h : Show hints
i : show info i : Show info
l : show line numbers l : Show line numbers
a : show everything a : Show everything
0 : show nothing (except errors) 0 : Show nothing (except errors)
b : show file names with full path b : Show file names with full path
c : show conditionals c : Show conditionals
t : show tried/used files t : Show tried/used files
d : show debug notes and info, enables -vni d : Show debug notes and info, enables -vni
q : show message numbers q : Show message numbers
x : show used tools x : Show used tools
z : write messages to stderr, -o. still uses stdout. v : Write pas2jsdebug.log with lots of debugging info
z : Write messages to stderr, -o. still uses stdout.
-vm&lt;x&gt;,&lt;y&gt;: Do not show messages numbered &lt;x&gt; and &lt;y&gt;. -vm&lt;x&gt;,&lt;y&gt;: Do not show messages numbered &lt;x&gt; and &lt;y&gt;.
-? : Show this help -? : Show this help
-h : Show this help -h : Show this help