ReportTcl fmt and rm casts

This commit is contained in:
James Cherry 2020-04-12 19:19:22 -07:00
parent 85e0254629
commit b104aa7138
1 changed files with 209 additions and 192 deletions

View File

@ -1,33 +1,33 @@
// OpenSTA, Static Timing Analyzer // OpenSTA, Static Timing Analyzer
// Copyright (c) 2020, Parallax Software, Inc. // Copyright (c) 2020, Parallax Software, Inc.
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>. // along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "ReportTcl.hh" #include "ReportTcl.hh"
#include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
namespace sta { namespace sta {
using ::Tcl_Channel;
using ::Tcl_GetChannelType;
using ::Tcl_ChannelType;
using ::ClientData; using ::ClientData;
using ::Tcl_GetChannelInstanceData; using ::Tcl_Channel;
using ::Tcl_DriverOutputProc;
using ::Tcl_ChannelOutputProc; using ::Tcl_ChannelOutputProc;
using ::Tcl_ChannelType;
using ::Tcl_DriverOutputProc;
using ::Tcl_GetChannelInstanceData;
using ::Tcl_GetChannelType;
extern "C" { extern "C" {
@ -38,153 +38,166 @@ extern "C" {
#endif #endif
static int static int
encapOutputProc(ClientData instanceData, CONST84 char *buf, int toWrite, encapOutputProc(ClientData instanceData,
int *errorCodePtr); CONST84 char *buf,
int toWrite,
int *errorCodePtr);
static int static int
encapErrorOutputProc(ClientData instanceData, CONST84 char *buf, int toWrite, encapErrorOutputProc(ClientData instanceData,
int *errorCodePtr); CONST84 char *buf,
int toWrite,
int *errorCodePtr);
static int static int
encapCloseProc(ClientData instanceData, Tcl_Interp *interp); encapCloseProc(ClientData instanceData, Tcl_Interp *interp);
static int static int
encapSetOptionProc(ClientData instanceData, Tcl_Interp *interp, encapSetOptionProc(ClientData instanceData,
CONST84 char *optionName, CONST84 char *value); Tcl_Interp *interp,
CONST84 char *optionName,
CONST84 char *value);
static int static int
encapGetOptionProc(ClientData instanceData, Tcl_Interp *interp, encapGetOptionProc(ClientData instanceData,
CONST84 char *optionName, Tcl_DString *dsPtr); Tcl_Interp *interp,
CONST84 char *optionName,
Tcl_DString *dsPtr);
static int static int
encapInputProc(ClientData instanceData, char *buf, int bufSize, encapInputProc(ClientData instanceData,
int *errorCodePtr); char *buf,
int bufSize,
int *errorCodePtr);
static int static int
encapSeekProc(ClientData instanceData, long offset, int seekMode, encapSeekProc(ClientData instanceData,
int *errorCodePtr); long offset,
int seekMode,
int *errorCodePtr);
static void static void
encapWatchProc(ClientData instanceData, int mask); encapWatchProc(ClientData instanceData, int mask);
static int static int
encapGetHandleProc(ClientData instanceData, int direction, encapGetHandleProc(ClientData instanceData,
ClientData *handlePtr); int direction,
ClientData *handlePtr);
static int static int
encapBlockModeProc(ClientData instanceData, int mode); encapBlockModeProc(ClientData instanceData, int mode);
} // extern "C" } // extern "C"
#ifdef TCL_CHANNEL_VERSION_5 #ifdef TCL_CHANNEL_VERSION_5
Tcl_ChannelType tcl_encap_type_stdout = { Tcl_ChannelType tcl_encap_type_stdout = {
const_cast<char*>("file"), const_cast<char *>("file"),
TCL_CHANNEL_VERSION_4, TCL_CHANNEL_VERSION_4,
encapCloseProc, encapCloseProc,
encapInputProc, encapInputProc,
encapOutputProc, encapOutputProc,
encapSeekProc, encapSeekProc,
encapSetOptionProc, encapSetOptionProc,
encapGetOptionProc, encapGetOptionProc,
encapWatchProc, encapWatchProc,
encapGetHandleProc, encapGetHandleProc,
nullptr, // close2Proc nullptr, // close2Proc
encapBlockModeProc, encapBlockModeProc,
nullptr, // flushProc nullptr, // flushProc
nullptr, // handlerProc nullptr, // handlerProc
nullptr, // wideSeekProc nullptr, // wideSeekProc
nullptr, // threadActionProc nullptr, // threadActionProc
nullptr // truncateProc nullptr // truncateProc
}; };
Tcl_ChannelType tcl_encap_type_stderr = { Tcl_ChannelType tcl_encap_type_stderr = {
const_cast<char*>("file"), const_cast<char *>("file"),
TCL_CHANNEL_VERSION_4, TCL_CHANNEL_VERSION_4,
encapCloseProc, encapCloseProc,
encapInputProc, encapInputProc,
encapErrorOutputProc, encapErrorOutputProc,
encapSeekProc, encapSeekProc,
encapSetOptionProc, encapSetOptionProc,
encapGetOptionProc, encapGetOptionProc,
encapWatchProc, encapWatchProc,
encapGetHandleProc, encapGetHandleProc,
nullptr, // close2Proc nullptr, // close2Proc
encapBlockModeProc, encapBlockModeProc,
nullptr, // flushProc nullptr, // flushProc
nullptr, // handlerProc nullptr, // handlerProc
nullptr, // wideSeekProc nullptr, // wideSeekProc
nullptr, // threadActionProc nullptr, // threadActionProc
nullptr // truncateProc nullptr // truncateProc
}; };
#else #else
#ifdef TCL_CHANNEL_VERSION_4 #ifdef TCL_CHANNEL_VERSION_4
// Tcl 8.4.12 // Tcl 8.4.12
Tcl_ChannelType tcl_encap_type_stdout = { Tcl_ChannelType tcl_encap_type_stdout = {
const_cast<char*>("file"), const_cast<char *>("file"),
TCL_CHANNEL_VERSION_4, TCL_CHANNEL_VERSION_4,
encapCloseProc, encapCloseProc,
encapInputProc, encapInputProc,
encapOutputProc, encapOutputProc,
encapSeekProc, encapSeekProc,
encapSetOptionProc, encapSetOptionProc,
encapGetOptionProc, encapGetOptionProc,
encapWatchProc, encapWatchProc,
encapGetHandleProc, encapGetHandleProc,
nullptr, // close2Proc nullptr, // close2Proc
encapBlockModeProc, encapBlockModeProc,
nullptr, // flushProc nullptr, // flushProc
nullptr, // handlerProc nullptr, // handlerProc
nullptr, // wideSeekProc nullptr, // wideSeekProc
nullptr // threadActionProc nullptr // threadActionProc
}; };
Tcl_ChannelType tcl_encap_type_stderr = { Tcl_ChannelType tcl_encap_type_stderr = {
const_cast<char*>("file"), const_cast<char *>("file"),
TCL_CHANNEL_VERSION_4, TCL_CHANNEL_VERSION_4,
encapCloseProc, encapCloseProc,
encapInputProc, encapInputProc,
encapErrorOutputProc, encapErrorOutputProc,
encapSeekProc, encapSeekProc,
encapSetOptionProc, encapSetOptionProc,
encapGetOptionProc, encapGetOptionProc,
encapWatchProc, encapWatchProc,
encapGetHandleProc, encapGetHandleProc,
nullptr, // close2Proc nullptr, // close2Proc
encapBlockModeProc, encapBlockModeProc,
nullptr, // flushProc nullptr, // flushProc
nullptr, // handlerProc nullptr, // handlerProc
nullptr, // wideSeekProc nullptr, // wideSeekProc
nullptr // threadActionProc nullptr // threadActionProc
}; };
#else #else
#ifdef TCL_CHANNEL_VERSION_3 #ifdef TCL_CHANNEL_VERSION_3
// Tcl 8.4 // Tcl 8.4
Tcl_ChannelType tcl_encap_type_stdout = { Tcl_ChannelType tcl_encap_type_stdout = {
const_cast<char*>("file"), const_cast<char *>("file"),
TCL_CHANNEL_VERSION_3, TCL_CHANNEL_VERSION_3,
encapCloseProc, encapCloseProc,
encapInputProc, encapInputProc,
encapOutputProc, encapOutputProc,
encapSeekProc, encapSeekProc,
encapSetOptionProc, encapSetOptionProc,
encapGetOptionProc, encapGetOptionProc,
encapWatchProc, encapWatchProc,
encapGetHandleProc, encapGetHandleProc,
nullptr, // close2Proc nullptr, // close2Proc
encapBlockModeProc, encapBlockModeProc,
nullptr, // flushProc nullptr, // flushProc
nullptr, // handlerProc nullptr, // handlerProc
nullptr // wideSeekProc nullptr // wideSeekProc
}; };
Tcl_ChannelType tcl_encap_type_stderr = { Tcl_ChannelType tcl_encap_type_stderr = {
const_cast<char*>("file"), const_cast<char *>("file"),
TCL_CHANNEL_VERSION_3, TCL_CHANNEL_VERSION_3,
encapCloseProc, encapCloseProc,
encapInputProc, encapInputProc,
encapErrorOutputProc, encapErrorOutputProc,
encapSeekProc, encapSeekProc,
encapSetOptionProc, encapSetOptionProc,
encapGetOptionProc, encapGetOptionProc,
encapWatchProc, encapWatchProc,
encapGetHandleProc, encapGetHandleProc,
nullptr, // close2Proc nullptr, // close2Proc
encapBlockModeProc, encapBlockModeProc,
nullptr, // flushProc nullptr, // flushProc
nullptr, // handlerProc nullptr, // handlerProc
nullptr // wideSeekProc nullptr // wideSeekProc
}; };
#else #else
@ -192,68 +205,68 @@ Tcl_ChannelType tcl_encap_type_stderr = {
// Tcl 8.3.2 // Tcl 8.3.2
Tcl_ChannelType tcl_encap_type_stdout = { Tcl_ChannelType tcl_encap_type_stdout = {
const_cast<char*>("file"), const_cast<char *>("file"),
TCL_CHANNEL_VERSION_2, TCL_CHANNEL_VERSION_2,
encapCloseProc, encapCloseProc,
encapInputProc, encapInputProc,
encapOutputProc, encapOutputProc,
encapSeekProc, encapSeekProc,
encapSetOptionProc, encapSetOptionProc,
encapGetOptionProc, encapGetOptionProc,
encapWatchProc, encapWatchProc,
encapGetHandleProc, encapGetHandleProc,
nullptr, // close2Proc nullptr, // close2Proc
encapBlockModeProc, encapBlockModeProc,
nullptr, // flushProc nullptr, // flushProc
nullptr // handlerProc nullptr // handlerProc
}; };
Tcl_ChannelType tcl_encap_type_stderr = { Tcl_ChannelType tcl_encap_type_stderr = {
const_cast<char*>("file"), const_cast<char *>("file"),
TCL_CHANNEL_VERSION_2, TCL_CHANNEL_VERSION_2,
encapCloseProc, encapCloseProc,
encapInputProc, encapInputProc,
encapErrorOutputProc, encapErrorOutputProc,
encapSeekProc, encapSeekProc,
encapSetOptionProc, encapSetOptionProc,
encapGetOptionProc, encapGetOptionProc,
encapWatchProc, encapWatchProc,
encapGetHandleProc, encapGetHandleProc,
nullptr, // close2Proc nullptr, // close2Proc
encapBlockModeProc, encapBlockModeProc,
nullptr, // flushProc nullptr, // flushProc
nullptr // handlerProc nullptr // handlerProc
}; };
#else #else
// Tcl 8.2 // Tcl 8.2
Tcl_ChannelType tcl_encap_type_stdout = { Tcl_ChannelType tcl_encap_type_stdout = {
const_cast<char*>("file"), const_cast<char *>("file"),
encapBlockModeProc, encapBlockModeProc,
encapCloseProc, encapCloseProc,
encapInputProc, encapInputProc,
encapOutputProc, encapOutputProc,
encapSeekProc, encapSeekProc,
encapSetOptionProc, encapSetOptionProc,
encapGetOptionProc, encapGetOptionProc,
encapWatchProc, encapWatchProc,
encapGetHandleProc, encapGetHandleProc,
nullptr // close2Proc nullptr // close2Proc
}; };
Tcl_ChannelType tcl_encap_type_stderr = { Tcl_ChannelType tcl_encap_type_stderr = {
const_cast<char*>("file"), const_cast<char *>("file"),
encapBlockModeProc, encapBlockModeProc,
encapCloseProc, encapCloseProc,
encapInputProc, encapInputProc,
encapErrorOutputProc, encapErrorOutputProc,
encapSeekProc, encapSeekProc,
encapSetOptionProc, encapSetOptionProc,
encapGetOptionProc, encapGetOptionProc,
encapWatchProc, encapWatchProc,
encapGetHandleProc, encapGetHandleProc,
nullptr // close2Proc nullptr // close2Proc
}; };
#endif #endif
@ -264,12 +277,8 @@ Tcl_ChannelType tcl_encap_type_stderr = {
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
ReportTcl::ReportTcl() : ReportTcl::ReportTcl() :
Report(), Report(), interp_(nullptr), tcl_stdout_(nullptr), tcl_stderr_(nullptr),
interp_(nullptr), tcl_encap_stdout_(nullptr), tcl_encap_stderr_(nullptr)
tcl_stdout_(nullptr),
tcl_stderr_(nullptr),
tcl_encap_stdout_(nullptr),
tcl_encap_stderr_(nullptr)
{ {
} }
@ -290,10 +299,16 @@ ReportTcl::setTclInterp(Tcl_Interp *interp)
interp_ = interp; interp_ = interp;
tcl_stdout_ = Tcl_GetStdChannel(TCL_STDOUT); tcl_stdout_ = Tcl_GetStdChannel(TCL_STDOUT);
tcl_stderr_ = Tcl_GetStdChannel(TCL_STDERR); tcl_stderr_ = Tcl_GetStdChannel(TCL_STDERR);
tcl_encap_stdout_ = Tcl_StackChannel(interp, &tcl_encap_type_stdout, this, tcl_encap_stdout_ = Tcl_StackChannel(interp,
TCL_WRITABLE, tcl_stdout_); &tcl_encap_type_stdout,
tcl_encap_stderr_ = Tcl_StackChannel(interp, &tcl_encap_type_stderr, this, this,
TCL_WRITABLE, tcl_stderr_); TCL_WRITABLE,
tcl_stdout_);
tcl_encap_stderr_ = Tcl_StackChannel(interp,
&tcl_encap_type_stderr,
this,
TCL_WRITABLE,
tcl_stderr_);
} }
size_t size_t
@ -315,9 +330,10 @@ ReportTcl::printTcl(Tcl_Channel channel, const char *buffer, size_t length)
Tcl_DriverOutputProc *output_proc = Tcl_ChannelOutputProc(ch_type); Tcl_DriverOutputProc *output_proc = Tcl_ChannelOutputProc(ch_type);
int error_code; int error_code;
ClientData clientData = Tcl_GetChannelInstanceData(channel); ClientData clientData = Tcl_GetChannelInstanceData(channel);
return output_proc(clientData, const_cast<char*>(buffer), return output_proc(clientData,
static_cast<int>(length), const_cast<char *>(buffer),
&error_code); length,
&error_code);
} }
// Tcl_Main can eval multiple commands before the flushing the command // Tcl_Main can eval multiple commands before the flushing the command
@ -389,19 +405,20 @@ ReportTcl::redirectStringEnd()
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
static int static int
encapOutputProc(ClientData instanceData, CONST84 char *buf, int toWrite, encapOutputProc(ClientData instanceData, CONST84 char *buf, int toWrite, int *)
int *)
{ {
ReportTcl *report = reinterpret_cast<ReportTcl*>(instanceData); ReportTcl *report = reinterpret_cast<ReportTcl *>(instanceData);
return static_cast<int>(report->printString(buf, toWrite)); return report->printString(buf, toWrite);
} }
static int static int
encapErrorOutputProc(ClientData instanceData, CONST84 char *buf, int toWrite, encapErrorOutputProc(ClientData instanceData,
int *) CONST84 char *buf,
int toWrite,
int *)
{ {
ReportTcl *report = reinterpret_cast<ReportTcl*>(instanceData); ReportTcl *report = reinterpret_cast<ReportTcl *>(instanceData);
return static_cast<int>(report->printString(buf, toWrite)); return report->printString(buf, toWrite);
} }
static int static int
@ -413,7 +430,7 @@ encapInputProc(ClientData, char *, int, int *)
static int static int
encapCloseProc(ClientData instanceData, Tcl_Interp *) encapCloseProc(ClientData instanceData, Tcl_Interp *)
{ {
ReportTcl *report = reinterpret_cast<ReportTcl*>(instanceData); ReportTcl *report = reinterpret_cast<ReportTcl *>(instanceData);
report->logEnd(); report->logEnd();
report->redirectFileEnd(); report->redirectFileEnd();
report->redirectStringEnd(); report->redirectStringEnd();
@ -455,4 +472,4 @@ encapBlockModeProc(ClientData, int)
return 0; return 0;
} }
} // namespace } // namespace sta