实现 C++ 到 C 的转换器 (tools/pcc-cpp.c),pcc 检测 .cpp 文件时
自动转换后编译。阶段 1 支持:
1. class 定义 → struct (数据成员 + 继承的 __base 嵌套)
2. 成员函数 (类内声明/类外定义/内联定义)
- 名称修饰: Class::method → Class_method
- 自动添加 this 参数: (struct Class *this)
- 方法体内裸成员名 → this->member
- 基类成员 → this->__base.member
3. 构造函数/析构函数
- 名称修饰: Class::Class → Class_ctor, ~Class → Class_dtor
- 局部对象声明时自动调用构造
- 支持带参构造 (var(a,b) → Ctor(&var, a, b))
- 初始化列表跳过 (: Base(args))
4. 成员调用: obj.method(args) → Class_method(&obj, args)
5. 继承: class B : public A → struct B { struct A __base; }
6. 简单继承的成员访问/方法遮蔽
同时修复:
- AFF_TYPE_CPP 与 AFF_PRINT_ERROR 位冲突 (0x10)
- #pragma pack(push,MACRO) 宏展开 (x86_64 下 TOK_ASM_push 未定义)
- 头文件 _CRT_PACKING pragma 改为数字
验证: pcc test.cpp 直接编译运行, 含继承/构造/成员的程序 exit=0
173 行
4.7 KiB
C
173 行
4.7 KiB
C
/**
|
|
* This file has no copyright assigned and is placed in the Public Domain.
|
|
* This file is part of the w64 mingw-runtime package.
|
|
* No warranty is given; refer to the file DISCLAIMER within this package.
|
|
*/
|
|
#ifndef _INC_WCTYPE
|
|
#define _INC_WCTYPE
|
|
|
|
#ifndef _WIN32
|
|
#error Only Win32 target is supported!
|
|
#endif
|
|
|
|
#include <_mingw.h>
|
|
|
|
#pragma pack(push,8)
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#ifndef _CRTIMP
|
|
#define _CRTIMP __declspec(dllimport)
|
|
#endif
|
|
|
|
#ifndef _WCHAR_T_DEFINED
|
|
typedef unsigned short wchar_t;
|
|
#define _WCHAR_T_DEFINED
|
|
#endif
|
|
|
|
#ifndef _WCTYPE_T_DEFINED
|
|
typedef unsigned short wint_t;
|
|
typedef unsigned short wctype_t;
|
|
#define _WCTYPE_T_DEFINED
|
|
#endif
|
|
|
|
#ifndef WEOF
|
|
#define WEOF (wint_t)(0xFFFF)
|
|
#endif
|
|
|
|
#ifndef _CRT_CTYPEDATA_DEFINED
|
|
#define _CRT_CTYPEDATA_DEFINED
|
|
#ifndef _CTYPE_DISABLE_MACROS
|
|
|
|
#ifndef __PCTYPE_FUNC
|
|
#define __PCTYPE_FUNC __pctype_func()
|
|
#ifdef _MSVCRT_
|
|
#define __pctype_func() (_pctype)
|
|
#else
|
|
#define __pctype_func() (*_imp___pctype)
|
|
#endif
|
|
#endif
|
|
|
|
#ifndef _pctype
|
|
#ifdef _MSVCRT_
|
|
extern unsigned short *_pctype;
|
|
#else
|
|
extern unsigned short **_imp___pctype;
|
|
#define _pctype (*_imp___pctype)
|
|
#endif
|
|
#endif
|
|
|
|
#endif
|
|
#endif
|
|
|
|
#ifndef _CRT_WCTYPEDATA_DEFINED
|
|
#define _CRT_WCTYPEDATA_DEFINED
|
|
#ifndef _CTYPE_DISABLE_MACROS
|
|
#ifndef _wctype
|
|
#ifdef _MSVCRT_
|
|
extern unsigned short *_wctype;
|
|
#else
|
|
extern unsigned short **_imp___wctype;
|
|
#define _wctype (*_imp___wctype)
|
|
#endif
|
|
#endif
|
|
|
|
#ifndef _pwctype
|
|
#ifdef _MSVCRT_
|
|
extern unsigned short *_pwctype;
|
|
#else
|
|
extern unsigned short **_imp___pwctype;
|
|
#define _pwctype (*_imp___pwctype)
|
|
#define __pwctype_func() (*_imp___pwctype)
|
|
#endif
|
|
#endif
|
|
#endif
|
|
#endif
|
|
|
|
#define _UPPER 0x1
|
|
#define _LOWER 0x2
|
|
#define _DIGIT 0x4
|
|
#define _SPACE 0x8
|
|
|
|
#define _PUNCT 0x10
|
|
#define _CONTROL 0x20
|
|
#define _BLANK 0x40
|
|
#define _HEX 0x80
|
|
|
|
#define _LEADBYTE 0x8000
|
|
#define _ALPHA (0x0100|_UPPER|_LOWER)
|
|
|
|
#ifndef _WCTYPE_DEFINED
|
|
#define _WCTYPE_DEFINED
|
|
|
|
int __cdecl iswalpha(wint_t);
|
|
int __cdecl iswupper(wint_t);
|
|
int __cdecl iswlower(wint_t);
|
|
int __cdecl iswdigit(wint_t);
|
|
int __cdecl iswxdigit(wint_t);
|
|
int __cdecl iswspace(wint_t);
|
|
int __cdecl iswpunct(wint_t);
|
|
int __cdecl iswalnum(wint_t);
|
|
int __cdecl iswprint(wint_t);
|
|
int __cdecl iswgraph(wint_t);
|
|
int __cdecl iswcntrl(wint_t);
|
|
int __cdecl iswascii(wint_t);
|
|
int __cdecl isleadbyte(int);
|
|
wint_t __cdecl towupper(wint_t);
|
|
wint_t __cdecl towlower(wint_t);
|
|
int __cdecl iswctype(wint_t,wctype_t);
|
|
_CRTIMP int __cdecl __iswcsymf(wint_t);
|
|
_CRTIMP int __cdecl __iswcsym(wint_t);
|
|
int __cdecl is_wctype(wint_t,wctype_t);
|
|
#if (defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || !defined (NO_OLDNAMES)
|
|
int __cdecl isblank(int _C);
|
|
#endif
|
|
#endif
|
|
|
|
#ifndef _WCTYPE_INLINE_DEFINED
|
|
#define _WCTYPE_INLINE_DEFINED
|
|
#ifndef __cplusplus
|
|
#define iswalpha(_c) (iswctype(_c,_ALPHA))
|
|
#define iswupper(_c) (iswctype(_c,_UPPER))
|
|
#define iswlower(_c) (iswctype(_c,_LOWER))
|
|
#define iswdigit(_c) (iswctype(_c,_DIGIT))
|
|
#define iswxdigit(_c) (iswctype(_c,_HEX))
|
|
#define iswspace(_c) (iswctype(_c,_SPACE))
|
|
#define iswpunct(_c) (iswctype(_c,_PUNCT))
|
|
#define iswalnum(_c) (iswctype(_c,_ALPHA|_DIGIT))
|
|
#define iswprint(_c) (iswctype(_c,_BLANK|_PUNCT|_ALPHA|_DIGIT))
|
|
#define iswgraph(_c) (iswctype(_c,_PUNCT|_ALPHA|_DIGIT))
|
|
#define iswcntrl(_c) (iswctype(_c,_CONTROL))
|
|
#define iswascii(_c) ((unsigned)(_c) < 0x80)
|
|
#define isleadbyte(c) (__pctype_func()[(unsigned char)(c)] & _LEADBYTE)
|
|
#else
|
|
__CRT_INLINE int __cdecl iswalpha(wint_t _C) {return (iswctype(_C,_ALPHA)); }
|
|
__CRT_INLINE int __cdecl iswupper(wint_t _C) {return (iswctype(_C,_UPPER)); }
|
|
__CRT_INLINE int __cdecl iswlower(wint_t _C) {return (iswctype(_C,_LOWER)); }
|
|
__CRT_INLINE int __cdecl iswdigit(wint_t _C) {return (iswctype(_C,_DIGIT)); }
|
|
__CRT_INLINE int __cdecl iswxdigit(wint_t _C) {return (iswctype(_C,_HEX)); }
|
|
__CRT_INLINE int __cdecl iswspace(wint_t _C) {return (iswctype(_C,_SPACE)); }
|
|
__CRT_INLINE int __cdecl iswpunct(wint_t _C) {return (iswctype(_C,_PUNCT)); }
|
|
__CRT_INLINE int __cdecl iswalnum(wint_t _C) {return (iswctype(_C,_ALPHA|_DIGIT)); }
|
|
__CRT_INLINE int __cdecl iswprint(wint_t _C) {return (iswctype(_C,_BLANK|_PUNCT|_ALPHA|_DIGIT)); }
|
|
__CRT_INLINE int __cdecl iswgraph(wint_t _C) {return (iswctype(_C,_PUNCT|_ALPHA|_DIGIT)); }
|
|
__CRT_INLINE int __cdecl iswcntrl(wint_t _C) {return (iswctype(_C,_CONTROL)); }
|
|
__CRT_INLINE int __cdecl iswascii(wint_t _C) {return ((unsigned)(_C) < 0x80); }
|
|
__CRT_INLINE int __cdecl isleadbyte(int _C) {return (__pctype_func()[(unsigned char)(_C)] & _LEADBYTE); }
|
|
#endif
|
|
#endif
|
|
|
|
typedef wchar_t wctrans_t;
|
|
wint_t __cdecl towctrans(wint_t,wctrans_t);
|
|
wctrans_t __cdecl wctrans(const char *);
|
|
wctype_t __cdecl wctype(const char *);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#pragma pack(pop)
|
|
#endif
|