hedgewars/pas2c.h
author Xeli
Tue, 22 May 2012 00:40:43 +0200
changeset 7106 aacb90365d3d
parent 7074 3f23bd0f2af2
child 7134 beb16926ae5c
permissions -rw-r--r--
fixed wheelup/down Wheel up and down used to be swapped in both binds.cpp and uKeys.pas (2 wrongs make a right eh) After I fixed uKeys zooming was inverted, so I changed binds.cpp too, but now existing teams will still have its zoom inverted..
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6875
6528171ce36d First try to compile with clang: improve renderer a bit. The result of pas2c is still far from normal C source.
unc0rr
parents:
diff changeset
     1
#pragma once
6528171ce36d First try to compile with clang: improve renderer a bit. The result of pas2c is still far from normal C source.
unc0rr
parents:
diff changeset
     2
6971
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
     3
#include <stdint.h>
6878
0af34406b83d Improve rendering of function types, arrays, and more
unc0rr
parents: 6875
diff changeset
     4
#include <stdbool.h>
7073
26f960656cc9 help pas2c
unc0rr
parents: 7072
diff changeset
     5
#include <wchar.h>
6878
0af34406b83d Improve rendering of function types, arrays, and more
unc0rr
parents: 6875
diff changeset
     6
6896
23b38e530967 Move all strings into constants to make them of string255 type
unc0rr
parents: 6895
diff changeset
     7
typedef union string255_
6883
70aec33185e2 Support string constants
unc0rr
parents: 6878
diff changeset
     8
    {
6896
23b38e530967 Move all strings into constants to make them of string255 type
unc0rr
parents: 6895
diff changeset
     9
        struct {
23b38e530967 Move all strings into constants to make them of string255 type
unc0rr
parents: 6895
diff changeset
    10
            char s[256];
23b38e530967 Move all strings into constants to make them of string255 type
unc0rr
parents: 6895
diff changeset
    11
        };
23b38e530967 Move all strings into constants to make them of string255 type
unc0rr
parents: 6895
diff changeset
    12
        struct {
23b38e530967 Move all strings into constants to make them of string255 type
unc0rr
parents: 6895
diff changeset
    13
            char len;
23b38e530967 Move all strings into constants to make them of string255 type
unc0rr
parents: 6895
diff changeset
    14
            char str[255];
23b38e530967 Move all strings into constants to make them of string255 type
unc0rr
parents: 6895
diff changeset
    15
        };
6883
70aec33185e2 Support string constants
unc0rr
parents: 6878
diff changeset
    16
    } string255;
6889
149638c9cbc4 More string types
unc0rr
parents: 6886
diff changeset
    17
typedef struct string192_
149638c9cbc4 More string types
unc0rr
parents: 6886
diff changeset
    18
    {
149638c9cbc4 More string types
unc0rr
parents: 6886
diff changeset
    19
        char s[193];
149638c9cbc4 More string types
unc0rr
parents: 6886
diff changeset
    20
    } string192;
149638c9cbc4 More string types
unc0rr
parents: 6886
diff changeset
    21
typedef struct string31_
149638c9cbc4 More string types
unc0rr
parents: 6886
diff changeset
    22
    {
149638c9cbc4 More string types
unc0rr
parents: 6886
diff changeset
    23
        char s[32];
149638c9cbc4 More string types
unc0rr
parents: 6886
diff changeset
    24
    } string31;
6891
ab9843957664 Improve rendering of function types, ranges, and more
unc0rr
parents: 6889
diff changeset
    25
typedef struct string15_
ab9843957664 Improve rendering of function types, ranges, and more
unc0rr
parents: 6889
diff changeset
    26
    {
ab9843957664 Improve rendering of function types, ranges, and more
unc0rr
parents: 6889
diff changeset
    27
        char s[16];
ab9843957664 Improve rendering of function types, ranges, and more
unc0rr
parents: 6889
diff changeset
    28
    } string15;
6875
6528171ce36d First try to compile with clang: improve renderer a bit. The result of pas2c is still far from normal C source.
unc0rr
parents:
diff changeset
    29
7072
159616c24bb8 More magic
unc0rr
parents: 7070
diff changeset
    30
typedef string255 shortstring;
159616c24bb8 More magic
unc0rr
parents: 7070
diff changeset
    31
    
6971
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    32
typedef uint8_t Byte;
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    33
typedef int8_t ShortInt;
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    34
typedef uint16_t Word;
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    35
typedef int16_t SmallInt;
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    36
typedef uint32_t LongWord;
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    37
typedef int32_t LongInt;
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    38
typedef uint64_t QWord;
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    39
typedef int64_t Int64;
7073
26f960656cc9 help pas2c
unc0rr
parents: 7072
diff changeset
    40
typedef LongWord Cardinal;
6878
0af34406b83d Improve rendering of function types, arrays, and more
unc0rr
parents: 6875
diff changeset
    41
6971
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    42
typedef LongInt Integer;
6878
0af34406b83d Improve rendering of function types, arrays, and more
unc0rr
parents: 6875
diff changeset
    43
typedef float extended;
0af34406b83d Improve rendering of function types, arrays, and more
unc0rr
parents: 6875
diff changeset
    44
typedef float real;
7043
7c080e5ac8d0 Some work to make more units compile after conversion to c
unc0rr
parents: 7041
diff changeset
    45
typedef float single;
6878
0af34406b83d Improve rendering of function types, arrays, and more
unc0rr
parents: 6875
diff changeset
    46
0af34406b83d Improve rendering of function types, arrays, and more
unc0rr
parents: 6875
diff changeset
    47
typedef bool boolean;
7043
7c080e5ac8d0 Some work to make more units compile after conversion to c
unc0rr
parents: 7041
diff changeset
    48
typedef int LongBool;
6875
6528171ce36d First try to compile with clang: improve renderer a bit. The result of pas2c is still far from normal C source.
unc0rr
parents:
diff changeset
    49
6528171ce36d First try to compile with clang: improve renderer a bit. The result of pas2c is still far from normal C source.
unc0rr
parents:
diff changeset
    50
typedef void * pointer;
6878
0af34406b83d Improve rendering of function types, arrays, and more
unc0rr
parents: 6875
diff changeset
    51
typedef Byte * PByte;
0af34406b83d Improve rendering of function types, arrays, and more
unc0rr
parents: 6875
diff changeset
    52
typedef char * PChar;
0af34406b83d Improve rendering of function types, arrays, and more
unc0rr
parents: 6875
diff changeset
    53
typedef LongInt * PLongInt;
7060
861d6897917f Properly track type in ref2CF, this fixes issues with functions returning strings used in expression (like "a" + line())
unc0rr
parents: 7054
diff changeset
    54
typedef LongWord * PLongWord;
6878
0af34406b83d Improve rendering of function types, arrays, and more
unc0rr
parents: 6875
diff changeset
    55
typedef Integer * PInteger;
7070
8d4189609e90 oops, wrong type
unc0rr
parents: 7069
diff changeset
    56
typedef int PtrInt;
7073
26f960656cc9 help pas2c
unc0rr
parents: 7072
diff changeset
    57
typedef wchar_t widechar;
6875
6528171ce36d First try to compile with clang: improve renderer a bit. The result of pas2c is still far from normal C source.
unc0rr
parents:
diff changeset
    58
6971
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    59
#ifdef __GNUG__
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    60
#define NULL __null
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    61
#else   /* G++ */
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    62
/* shield NULL definition for non-gnu parsers */
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    63
#ifndef __cplusplus
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    64
#define NULL ((void *)0)
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    65
#else
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    66
#define NULL 0
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    67
#endif  /* __cplusplus */
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    68
#endif  /* G++ */
b7b38e051b5f add NULL definition and align types to their correct bitwidth
koda
parents: 6967
diff changeset
    69
6922
93bdd3d251fe Fix types
unc0rr
parents: 6902
diff changeset
    70
#define new(a) __new((void **)&a, sizeof(*(a)))
93bdd3d251fe Fix types
unc0rr
parents: 6902
diff changeset
    71
void __new(void ** p, int size);
6895
31def088a870 Many small improvements to pas2c
unc0rr
parents: 6894
diff changeset
    72
#define dispose(a) __dispose(a, sizeof(*(a)))
31def088a870 Many small improvements to pas2c
unc0rr
parents: 6894
diff changeset
    73
void __dispose(pointer p, int size);
6894
555a8d8db228 Some more progress with pas2c
unc0rr
parents: 6891
diff changeset
    74
7053
8c9dcaedc7a8 Make pas2c happier with uSound
unc0rr
parents: 7045
diff changeset
    75
void * GetMem(int size);
8c9dcaedc7a8 Make pas2c happier with uSound
unc0rr
parents: 7045
diff changeset
    76
void FreeMem(void * p, int size);
8c9dcaedc7a8 Make pas2c happier with uSound
unc0rr
parents: 7045
diff changeset
    77
6894
555a8d8db228 Some more progress with pas2c
unc0rr
parents: 6891
diff changeset
    78
#define FillChar(a, b, c) __FillChar(&(a), b, c)
555a8d8db228 Some more progress with pas2c
unc0rr
parents: 6891
diff changeset
    79
555a8d8db228 Some more progress with pas2c
unc0rr
parents: 6891
diff changeset
    80
void __FillChar(pointer p, int size, char fill);
555a8d8db228 Some more progress with pas2c
unc0rr
parents: 6891
diff changeset
    81
string255 _strconcat(string255 a, string255 b);
6898
344b0dbd9690 - Remove support for variables in command handlers
unc0rr
parents: 6896
diff changeset
    82
string255 _strappend(string255 s, char c);
344b0dbd9690 - Remove support for variables in command handlers
unc0rr
parents: 6896
diff changeset
    83
string255 _strprepend(char c, string255 s);
6923
d2405a6a86f5 uCommands compiles
unc0rr
parents: 6922
diff changeset
    84
bool _strcompare(string255 a, string255 b);
7054
7e8fb07ef91c Function to compare string to char ftw
unc0rr
parents: 7053
diff changeset
    85
bool _strcomparec(string255 a, char b);
7043
7c080e5ac8d0 Some work to make more units compile after conversion to c
unc0rr
parents: 7041
diff changeset
    86
bool _strncompare(string255 a, string255 b);
6898
344b0dbd9690 - Remove support for variables in command handlers
unc0rr
parents: 6896
diff changeset
    87
char * _pchar(string255 s);
6894
555a8d8db228 Some more progress with pas2c
unc0rr
parents: 6891
diff changeset
    88
6895
31def088a870 Many small improvements to pas2c
unc0rr
parents: 6894
diff changeset
    89
int Length(string255 a);
31def088a870 Many small improvements to pas2c
unc0rr
parents: 6894
diff changeset
    90
string255 copy(string255 a, int s, int l);
31def088a870 Many small improvements to pas2c
unc0rr
parents: 6894
diff changeset
    91
string255 delete(string255 a, int s, int l);
7069
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7062
diff changeset
    92
string255 trim(string255 a);
6895
31def088a870 Many small improvements to pas2c
unc0rr
parents: 6894
diff changeset
    93
6967
1224c6fb36c3 Support recurrent function calls. The code is kinda hackish and ugly, but I really spent a few hours thinking on a good solution.
unc0rr
parents: 6965
diff changeset
    94
#define STRINIT(a) {.len = sizeof(a) - 1, .str = a}
6898
344b0dbd9690 - Remove support for variables in command handlers
unc0rr
parents: 6896
diff changeset
    95
7062
7efe16575779 Recognize length on arrays as a separate function
unc0rr
parents: 7060
diff changeset
    96
7efe16575779 Recognize length on arrays as a separate function
unc0rr
parents: 7060
diff changeset
    97
int length_ar(void * a);
7efe16575779 Recognize length on arrays as a separate function
unc0rr
parents: 7060
diff changeset
    98
6898
344b0dbd9690 - Remove support for variables in command handlers
unc0rr
parents: 6896
diff changeset
    99
typedef int file;
7043
7c080e5ac8d0 Some work to make more units compile after conversion to c
unc0rr
parents: 7041
diff changeset
   100
typedef int TextFile;
6898
344b0dbd9690 - Remove support for variables in command handlers
unc0rr
parents: 6896
diff changeset
   101
extern int FileMode;
344b0dbd9690 - Remove support for variables in command handlers
unc0rr
parents: 6896
diff changeset
   102
extern int IOResult;
7074
3f23bd0f2af2 Make uUtils.c compile
unc0rr
parents: 7073
diff changeset
   103
extern int stderr;
6898
344b0dbd9690 - Remove support for variables in command handlers
unc0rr
parents: 6896
diff changeset
   104
6902
7d4e5ce73b98 Make pas2c even smarter. Now uIO.c compiles fine, and only 1 warning when compiled with -Wall (clang).
unc0rr
parents: 6898
diff changeset
   105
#define assign(a, b) assign_(&(a), b)
7d4e5ce73b98 Make pas2c even smarter. Now uIO.c compiles fine, and only 1 warning when compiled with -Wall (clang).
unc0rr
parents: 6898
diff changeset
   106
void assign_(int * f, string255 fileName);
7069
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7062
diff changeset
   107
void reset_1(int f, int size);
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7062
diff changeset
   108
void reset_2(int f, int size);
6898
344b0dbd9690 - Remove support for variables in command handlers
unc0rr
parents: 6896
diff changeset
   109
#define BlockRead(a, b, c, d) BlockRead_(a, &(b), c, &(d))
344b0dbd9690 - Remove support for variables in command handlers
unc0rr
parents: 6896
diff changeset
   110
void BlockRead_(int f, void * p, int size, int * sizeRead);
7053
8c9dcaedc7a8 Make pas2c happier with uSound
unc0rr
parents: 7045
diff changeset
   111
#define BlockWrite(a, b, c) BlockWrite_(a, &(b), c)
8c9dcaedc7a8 Make pas2c happier with uSound
unc0rr
parents: 7045
diff changeset
   112
void BlockWrite_(int f, void * p, int size);
6898
344b0dbd9690 - Remove support for variables in command handlers
unc0rr
parents: 6896
diff changeset
   113
void close(int f);
7002
5d817ba976f7 Render float consts into defines
unc0rr
parents: 6971
diff changeset
   114
7054
7e8fb07ef91c Function to compare string to char ftw
unc0rr
parents: 7053
diff changeset
   115
void write(string255 s);
7e8fb07ef91c Function to compare string to char ftw
unc0rr
parents: 7053
diff changeset
   116
7053
8c9dcaedc7a8 Make pas2c happier with uSound
unc0rr
parents: 7045
diff changeset
   117
bool DirectoryExists(string255 dir);
8c9dcaedc7a8 Make pas2c happier with uSound
unc0rr
parents: 7045
diff changeset
   118
bool FileExists(string255 filename);
8c9dcaedc7a8 Make pas2c happier with uSound
unc0rr
parents: 7045
diff changeset
   119
7002
5d817ba976f7 Render float consts into defines
unc0rr
parents: 6971
diff changeset
   120
bool odd(int i);
7038
d853e4385241 Some more definitions and slight fixes
unc0rr
parents: 7002
diff changeset
   121
d853e4385241 Some more definitions and slight fixes
unc0rr
parents: 7002
diff changeset
   122
d853e4385241 Some more definitions and slight fixes
unc0rr
parents: 7002
diff changeset
   123
typedef int TThreadId;
d853e4385241 Some more definitions and slight fixes
unc0rr
parents: 7002
diff changeset
   124
void ThreadSwitch();
d853e4385241 Some more definitions and slight fixes
unc0rr
parents: 7002
diff changeset
   125
#define InterlockedIncrement(a) __InterlockedIncrement(&(a))
d853e4385241 Some more definitions and slight fixes
unc0rr
parents: 7002
diff changeset
   126
#define InterlockedDecrement(a) __InterlockedDecrement(&(a))
d853e4385241 Some more definitions and slight fixes
unc0rr
parents: 7002
diff changeset
   127
void __InterlockedIncrement(int * a);
d853e4385241 Some more definitions and slight fixes
unc0rr
parents: 7002
diff changeset
   128
void __InterlockedDecrement(int * a);
d853e4385241 Some more definitions and slight fixes
unc0rr
parents: 7002
diff changeset
   129
d853e4385241 Some more definitions and slight fixes
unc0rr
parents: 7002
diff changeset
   130
bool Assigned(void * a);
d853e4385241 Some more definitions and slight fixes
unc0rr
parents: 7002
diff changeset
   131
7054
7e8fb07ef91c Function to compare string to char ftw
unc0rr
parents: 7053
diff changeset
   132
void randomize();
7038
d853e4385241 Some more definitions and slight fixes
unc0rr
parents: 7002
diff changeset
   133
int random(int max);
d853e4385241 Some more definitions and slight fixes
unc0rr
parents: 7002
diff changeset
   134
int abs(int i);
7041
76a9274f280f More definitions and mess with pascal code
unc0rr
parents: 7038
diff changeset
   135
double sqr(double n);
76a9274f280f More definitions and mess with pascal code
unc0rr
parents: 7038
diff changeset
   136
double sqrt(double n);
76a9274f280f More definitions and mess with pascal code
unc0rr
parents: 7038
diff changeset
   137
int trunc(double n);
7043
7c080e5ac8d0 Some work to make more units compile after conversion to c
unc0rr
parents: 7041
diff changeset
   138
int round(double n);
7045
197bf70f8599 Declare Param* functions
unc0rr
parents: 7043
diff changeset
   139
197bf70f8599 Declare Param* functions
unc0rr
parents: 7043
diff changeset
   140
string255 ParamStr(int n);
197bf70f8599 Declare Param* functions
unc0rr
parents: 7043
diff changeset
   141
int ParamCount();
7054
7e8fb07ef91c Function to compare string to char ftw
unc0rr
parents: 7053
diff changeset
   142
7e8fb07ef91c Function to compare string to char ftw
unc0rr
parents: 7053
diff changeset
   143
#define val(a, b) _val(a, (LongInt*)&(b))
7e8fb07ef91c Function to compare string to char ftw
unc0rr
parents: 7053
diff changeset
   144
void _val(string255 str, LongInt * a);
7062
7efe16575779 Recognize length on arrays as a separate function
unc0rr
parents: 7060
diff changeset
   145
7efe16575779 Recognize length on arrays as a separate function
unc0rr
parents: 7060
diff changeset
   146
extern double pi;
7069
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7062
diff changeset
   147
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7062
diff changeset
   148
string255 EnumToStr(int a);
bcf9d8e64e92 pas2c stuff again
unc0rr
parents: 7062
diff changeset
   149
string255 ExtractFileName(string255 f);