mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-13 07:10:57 +00:00
(svn r26784) -Codechange [Squirrel]: use WChar for the lexer
This commit is contained in:
parent
0d042630d5
commit
00e1e69187
4
src/3rdparty/squirrel/include/squirrel.h
vendored
4
src/3rdparty/squirrel/include/squirrel.h
vendored
@ -31,6 +31,8 @@ to the following restrictions:
|
|||||||
#ifndef _SQUIRREL_H_
|
#ifndef _SQUIRREL_H_
|
||||||
#define _SQUIRREL_H_
|
#define _SQUIRREL_H_
|
||||||
|
|
||||||
|
#include "../../../string_type.h"
|
||||||
|
|
||||||
typedef __int64 SQInteger;
|
typedef __int64 SQInteger;
|
||||||
typedef unsigned __int64 SQUnsignedInteger;
|
typedef unsigned __int64 SQUnsignedInteger;
|
||||||
typedef unsigned __int64 SQHash; /*should be the same size of a pointer*/
|
typedef unsigned __int64 SQHash; /*should be the same size of a pointer*/
|
||||||
@ -178,7 +180,7 @@ typedef void (*SQPRINTFUNCTION)(HSQUIRRELVM,const SQChar * ,...);
|
|||||||
typedef SQInteger (*SQWRITEFUNC)(SQUserPointer,SQUserPointer,SQInteger);
|
typedef SQInteger (*SQWRITEFUNC)(SQUserPointer,SQUserPointer,SQInteger);
|
||||||
typedef SQInteger (*SQREADFUNC)(SQUserPointer,SQUserPointer,SQInteger);
|
typedef SQInteger (*SQREADFUNC)(SQUserPointer,SQUserPointer,SQInteger);
|
||||||
|
|
||||||
typedef SQInteger (*SQLEXREADFUNC)(SQUserPointer);
|
typedef WChar (*SQLEXREADFUNC)(SQUserPointer);
|
||||||
|
|
||||||
typedef struct tagSQRegFunction{
|
typedef struct tagSQRegFunction{
|
||||||
const SQChar *name;
|
const SQChar *name;
|
||||||
|
2
src/3rdparty/squirrel/squirrel/sqapi.cpp
vendored
2
src/3rdparty/squirrel/squirrel/sqapi.cpp
vendored
@ -1264,7 +1264,7 @@ struct BufState{
|
|||||||
SQInteger size;
|
SQInteger size;
|
||||||
};
|
};
|
||||||
|
|
||||||
SQInteger buf_lexfeed(SQUserPointer file)
|
WChar buf_lexfeed(SQUserPointer file)
|
||||||
{
|
{
|
||||||
BufState *buf=(BufState*)file;
|
BufState *buf=(BufState*)file;
|
||||||
if(buf->size<(buf->ptr+1))
|
if(buf->size<(buf->ptr+1))
|
||||||
|
12
src/3rdparty/squirrel/squirrel/sqlexer.cpp
vendored
12
src/3rdparty/squirrel/squirrel/sqlexer.cpp
vendored
@ -27,11 +27,11 @@ SQLexer::~SQLexer()
|
|||||||
_keywords->Release();
|
_keywords->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SQLexer::APPEND_CHAR(LexChar c)
|
void SQLexer::APPEND_CHAR(WChar c)
|
||||||
{
|
{
|
||||||
char buf[4];
|
char buf[4];
|
||||||
int chars = Utf8Encode(buf, c);
|
size_t chars = Utf8Encode(buf, c);
|
||||||
for (int i = 0; i < chars; i++) {
|
for (size_t i = 0; i < chars; i++) {
|
||||||
_longstr.push_back(buf[i]);
|
_longstr.push_back(buf[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,10 +96,10 @@ void SQLexer::Error(const SQChar *err)
|
|||||||
|
|
||||||
void SQLexer::Next()
|
void SQLexer::Next()
|
||||||
{
|
{
|
||||||
SQInteger t = _readf(_up);
|
WChar t = _readf(_up);
|
||||||
if(t > MAX_CHAR) Error("Invalid character");
|
if(t > MAX_CHAR) Error("Invalid character");
|
||||||
if(t != 0) {
|
if(t != 0) {
|
||||||
_currdata = (LexChar)t;
|
_currdata = t;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_currdata = SQUIRREL_EOB;
|
_currdata = SQUIRREL_EOB;
|
||||||
@ -285,7 +285,7 @@ SQInteger SQLexer::GetIDType(SQChar *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SQInteger SQLexer::ReadString(LexChar ndelim,bool verbatim)
|
SQInteger SQLexer::ReadString(WChar ndelim,bool verbatim)
|
||||||
{
|
{
|
||||||
INIT_TEMP_STRING();
|
INIT_TEMP_STRING();
|
||||||
NEXT();
|
NEXT();
|
||||||
|
8
src/3rdparty/squirrel/squirrel/sqlexer.h
vendored
8
src/3rdparty/squirrel/squirrel/sqlexer.h
vendored
@ -2,8 +2,6 @@
|
|||||||
#ifndef _SQLEXER_H_
|
#ifndef _SQLEXER_H_
|
||||||
#define _SQLEXER_H_
|
#define _SQLEXER_H_
|
||||||
|
|
||||||
typedef unsigned short LexChar;
|
|
||||||
|
|
||||||
struct SQLexer
|
struct SQLexer
|
||||||
{
|
{
|
||||||
SQLexer();
|
SQLexer();
|
||||||
@ -14,7 +12,7 @@ struct SQLexer
|
|||||||
const SQChar *Tok2Str(SQInteger tok);
|
const SQChar *Tok2Str(SQInteger tok);
|
||||||
private:
|
private:
|
||||||
SQInteger GetIDType(SQChar *s);
|
SQInteger GetIDType(SQChar *s);
|
||||||
SQInteger ReadString(LexChar ndelim,bool verbatim);
|
SQInteger ReadString(WChar ndelim,bool verbatim);
|
||||||
SQInteger ReadNumber();
|
SQInteger ReadNumber();
|
||||||
void LexBlockComment();
|
void LexBlockComment();
|
||||||
SQInteger ReadID();
|
SQInteger ReadID();
|
||||||
@ -22,7 +20,7 @@ private:
|
|||||||
SQInteger _curtoken;
|
SQInteger _curtoken;
|
||||||
SQTable *_keywords;
|
SQTable *_keywords;
|
||||||
void INIT_TEMP_STRING() { _longstr.resize(0); }
|
void INIT_TEMP_STRING() { _longstr.resize(0); }
|
||||||
void APPEND_CHAR(LexChar c);
|
void APPEND_CHAR(WChar c);
|
||||||
void TERMINATE_BUFFER() { _longstr.push_back('\0'); }
|
void TERMINATE_BUFFER() { _longstr.push_back('\0'); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -35,7 +33,7 @@ public:
|
|||||||
SQFloat _fvalue;
|
SQFloat _fvalue;
|
||||||
SQLEXREADFUNC _readf;
|
SQLEXREADFUNC _readf;
|
||||||
SQUserPointer _up;
|
SQUserPointer _up;
|
||||||
LexChar _currdata;
|
WChar _currdata;
|
||||||
SQSharedState *_sharedstate;
|
SQSharedState *_sharedstate;
|
||||||
sqvector<SQChar> _longstr;
|
sqvector<SQChar> _longstr;
|
||||||
CompilerErrorFunc _errfunc;
|
CompilerErrorFunc _errfunc;
|
||||||
|
@ -380,14 +380,14 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static SQInteger _io_file_lexfeed_ASCII(SQUserPointer file)
|
static WChar _io_file_lexfeed_ASCII(SQUserPointer file)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
if (((SQFile *)file)->Read(&c, sizeof(c), 1) > 0) return c;
|
if (((SQFile *)file)->Read(&c, sizeof(c), 1) > 0) return c;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SQInteger _io_file_lexfeed_UTF8(SQUserPointer file)
|
static WChar _io_file_lexfeed_UTF8(SQUserPointer file)
|
||||||
{
|
{
|
||||||
static const SQInteger utf8_lengths[16] =
|
static const SQInteger utf8_lengths[16] =
|
||||||
{
|
{
|
||||||
@ -399,7 +399,7 @@ static SQInteger _io_file_lexfeed_UTF8(SQUserPointer file)
|
|||||||
};
|
};
|
||||||
static unsigned char byte_masks[5] = {0, 0, 0x1F, 0x0F, 0x07};
|
static unsigned char byte_masks[5] = {0, 0, 0x1F, 0x0F, 0x07};
|
||||||
unsigned char inchar;
|
unsigned char inchar;
|
||||||
SQInteger c = 0;
|
WChar c = 0;
|
||||||
if (((SQFile *)file)->Read(&inchar, sizeof(inchar), 1) != 1) return 0;
|
if (((SQFile *)file)->Read(&inchar, sizeof(inchar), 1) != 1) return 0;
|
||||||
c = inchar;
|
c = inchar;
|
||||||
|
|
||||||
@ -419,19 +419,19 @@ static SQInteger _io_file_lexfeed_UTF8(SQUserPointer file)
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SQInteger _io_file_lexfeed_UCS2_no_swap(SQUserPointer file)
|
static WChar _io_file_lexfeed_UCS2_no_swap(SQUserPointer file)
|
||||||
{
|
{
|
||||||
wchar_t c;
|
unsigned short c;
|
||||||
if (((SQFile *)file)->Read(&c, sizeof(c), 1) > 0) return (SQChar)c;
|
if (((SQFile *)file)->Read(&c, sizeof(c), 1) > 0) return (WChar)c;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SQInteger _io_file_lexfeed_UCS2_swap(SQUserPointer file)
|
static WChar _io_file_lexfeed_UCS2_swap(SQUserPointer file)
|
||||||
{
|
{
|
||||||
unsigned short c;
|
unsigned short c;
|
||||||
if (((SQFile *)file)->Read(&c, sizeof(c), 1) > 0) {
|
if (((SQFile *)file)->Read(&c, sizeof(c), 1) > 0) {
|
||||||
c = ((c >> 8) & 0x00FF)| ((c << 8) & 0xFF00);
|
c = ((c >> 8) & 0x00FF)| ((c << 8) & 0xFF00);
|
||||||
return (SQChar)c;
|
return (WChar)c;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user