Use symbolic constants names in the generated wxSTC files.
Update the script generating stc.cpp to put the symbolic constants names and not their raw numeric values into the generated code. This makes it much easier to read and understand. Closes #15783. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@75443 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
03c0dc0235
commit
3d5f3bcac7
@ -16,6 +16,7 @@ from fileinput import FileInput
|
||||
|
||||
|
||||
IFACE = os.path.abspath('./scintilla/include/Scintilla.iface')
|
||||
HDR_SCN = os.path.abspath('./scintilla/include/Scintilla.h')
|
||||
H_TEMPLATE = os.path.abspath('./stc.h.in')
|
||||
IH_TEMPLATE = os.path.abspath('./stc.interface.h.in')
|
||||
CPP_TEMPLATE = os.path.abspath('./stc.cpp.in')
|
||||
@ -243,7 +244,7 @@ methodOverrideMap = {
|
||||
'wxString %s(int line) const;',
|
||||
|
||||
'''wxString %s(int line) const {
|
||||
long msg = %s;
|
||||
const int msg = %s;
|
||||
long len = SendMsg(msg, line, 0);
|
||||
|
||||
wxMemoryBuffer mbuf(len+1);
|
||||
@ -259,7 +260,7 @@ methodOverrideMap = {
|
||||
'wxString %s(int line) const;',
|
||||
|
||||
'''wxString %s(int line) const {
|
||||
long msg = %s;
|
||||
const int msg = %s;
|
||||
long len = SendMsg(msg, line, 0);
|
||||
|
||||
wxMemoryBuffer mbuf(len+1);
|
||||
@ -280,7 +281,7 @@ methodOverrideMap = {
|
||||
'wxString %s(int line) const;',
|
||||
|
||||
'''wxString %s(int line) const {
|
||||
long msg = %s;
|
||||
const int msg = %s;
|
||||
long len = SendMsg(msg, line, 0);
|
||||
|
||||
wxMemoryBuffer mbuf(len+1);
|
||||
@ -296,7 +297,7 @@ methodOverrideMap = {
|
||||
'wxString %s(int line) const;',
|
||||
|
||||
'''wxString %s(int line) const {
|
||||
long msg = %s;
|
||||
const int msg = %s;
|
||||
long len = SendMsg(msg, line, 0);
|
||||
|
||||
wxMemoryBuffer mbuf(len+1);
|
||||
@ -318,7 +319,7 @@ methodOverrideMap = {
|
||||
('StyleGetFaceName',
|
||||
'wxString %s(int style);',
|
||||
'''wxString %s(int style) {
|
||||
long msg = %s;
|
||||
const int msg = %s;
|
||||
long len = SendMsg(msg, style, 0);
|
||||
wxMemoryBuffer mbuf(len+1);
|
||||
char* buf = (char*)mbuf.GetWriteBuf(len+1);
|
||||
@ -761,7 +762,7 @@ methodOverrideMap = {
|
||||
'wxString %s() const;',
|
||||
|
||||
'''wxString %s() const {
|
||||
int msg = %s;
|
||||
const int msg = %s;
|
||||
int len = SendMsg(msg, 0, (sptr_t)NULL);
|
||||
if (!len) return wxEmptyString;
|
||||
|
||||
@ -779,7 +780,7 @@ methodOverrideMap = {
|
||||
'wxString %s(int tagNumber) const;',
|
||||
|
||||
'''wxString %s(int tagNumber) const {
|
||||
int msg = %s;
|
||||
const int msg = %s;
|
||||
int len = SendMsg(msg, tagNumber, (sptr_t)NULL);
|
||||
if (!len) return wxEmptyString;
|
||||
|
||||
@ -796,7 +797,7 @@ methodOverrideMap = {
|
||||
'wxString %s() const;',
|
||||
|
||||
'''wxString %s() const {
|
||||
int msg = %s;
|
||||
const int msg = %s;
|
||||
int len = SendMsg(msg, 0, (sptr_t)NULL);
|
||||
if (!len) return wxEmptyString;
|
||||
|
||||
@ -814,7 +815,7 @@ methodOverrideMap = {
|
||||
'wxString %s() const;',
|
||||
|
||||
'''wxString %s() const {
|
||||
int msg = %s;
|
||||
const int msg = %s;
|
||||
int len = SendMsg(msg, 0, (sptr_t)NULL);
|
||||
if (!len) return wxEmptyString;
|
||||
|
||||
@ -832,7 +833,7 @@ methodOverrideMap = {
|
||||
'wxString %s() const;',
|
||||
|
||||
'''wxString %s() const {
|
||||
int msg = %s;
|
||||
const int msg = %s;
|
||||
int len = SendMsg(msg, 0, (sptr_t)NULL);
|
||||
if (!len) return wxEmptyString;
|
||||
|
||||
@ -851,7 +852,7 @@ methodOverrideMap = {
|
||||
'wxString %s(const wxString& name) const;',
|
||||
|
||||
'''wxString %s(const wxString& name) const {
|
||||
int msg = %s;
|
||||
const int msg = %s;
|
||||
int len = SendMsg(msg, (sptr_t)(const char*)wx2stc(name), (sptr_t)NULL);
|
||||
if (!len) return wxEmptyString;
|
||||
|
||||
@ -870,7 +871,7 @@ methodOverrideMap = {
|
||||
'wxString %s() const;',
|
||||
|
||||
'''wxString %s() const {
|
||||
int msg = %s;
|
||||
const int msg = %s;
|
||||
int len = SendMsg(msg, 0, (sptr_t)NULL);
|
||||
if (!len) return wxEmptyString;
|
||||
|
||||
@ -942,7 +943,7 @@ constNonGetterMethods = (
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
def processIface(iface, h_tmplt, cpp_tmplt, ih_tmplt, h_dest, cpp_dest, docstr_dest, ih_dest):
|
||||
def processIface(iface, h_tmplt, cpp_tmplt, ih_tmplt, h_dest, cpp_dest, docstr_dest, ih_dest, msgcodes):
|
||||
curDocStrings = []
|
||||
values = []
|
||||
methods = []
|
||||
@ -965,7 +966,7 @@ def processIface(iface, h_tmplt, cpp_tmplt, ih_tmplt, h_dest, cpp_dest, docstr_d
|
||||
curDocStrings = []
|
||||
|
||||
elif op == 'fun ' or op == 'set ' or op == 'get ':
|
||||
parseFun(line[4:], methods, curDocStrings, cmds, op == 'get ')
|
||||
parseFun(line[4:], methods, curDocStrings, cmds, op == 'get ', msgcodes)
|
||||
curDocStrings = []
|
||||
|
||||
elif op == 'cat ':
|
||||
@ -1017,6 +1018,30 @@ def joinWithNewLines(values):
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
# parse header file for message codes
|
||||
def processHeader(hdr_scn, codeDict):
|
||||
fh = FileInput(hdr_scn)
|
||||
for line in fh:
|
||||
line = line[:-1]
|
||||
if line[:8] != '#define ':
|
||||
continue
|
||||
|
||||
op = line[8:]
|
||||
tokens = op.split()
|
||||
if len(tokens) != 2:
|
||||
continue
|
||||
|
||||
symbname = tokens[0]
|
||||
symbval = tokens[1]
|
||||
if symbname[:4] == 'SCI_':
|
||||
# add symbol and its value to the dictionary
|
||||
if symbval in codeDict:
|
||||
print("***** Duplicated message code for " + symbname)
|
||||
else:
|
||||
codeDict[symbval] = symbname
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
def processVals(values):
|
||||
text = []
|
||||
for name, value, docs in values:
|
||||
@ -1180,7 +1205,7 @@ funregex = re.compile(r'\s*([a-zA-Z0-9_]+)' # <ws>return type
|
||||
'\(([ a-zA-Z0-9_]*),' # (param,
|
||||
'([ a-zA-Z0-9_]*),*\)') # param)
|
||||
|
||||
def parseFun(line, methods, docs, values, is_const):
|
||||
def parseFun(line, methods, docs, values, is_const, msgcodes):
|
||||
def parseParam(param):
|
||||
param = param.strip()
|
||||
if param == '':
|
||||
@ -1209,7 +1234,12 @@ def parseFun(line, methods, docs, values, is_const):
|
||||
if not FUNC_FOR_CMD:
|
||||
return
|
||||
|
||||
methods.append( (retType, name, number, param1, param2, tuple(docs),
|
||||
# if possible, replace numeric value with symbol
|
||||
if number in msgcodes:
|
||||
code = msgcodes[number]
|
||||
else:
|
||||
code = number
|
||||
methods.append( (retType, name, code, param1, param2, tuple(docs),
|
||||
is_const or name in constNonGetterMethods) )
|
||||
|
||||
|
||||
@ -1223,8 +1253,12 @@ def main(args):
|
||||
print('Please run this script from src/stc subdirectory.')
|
||||
sys.exit(1)
|
||||
|
||||
# parse header file for message codes and create dictionary
|
||||
msgcodes = {}
|
||||
processHeader(HDR_SCN, msgcodes)
|
||||
|
||||
# Now just do it
|
||||
processIface(IFACE, H_TEMPLATE, CPP_TEMPLATE, IH_TEMPLATE, H_DEST, CPP_DEST, DOCSTR_DEST, IH_DEST)
|
||||
processIface(IFACE, H_TEMPLATE, CPP_TEMPLATE, IH_TEMPLATE, H_DEST, CPP_DEST, DOCSTR_DEST, IH_DEST, msgcodes)
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user