| [601] | 1 | /* $Id: 572main.cpp 1232 2004-02-12 15:21:45Z bird $ */
|
|---|
| 2 | /** @file
|
|---|
| 3 | *
|
|---|
| 4 | * _Optlink declaration and definition testcases.
|
|---|
| 5 | *
|
|---|
| 6 | * InnoTek Systemberatung GmbH confidential
|
|---|
| 7 | *
|
|---|
| 8 | * Copyright (c) 2003 InnoTek Systemberatung GmbH
|
|---|
| 9 | * Author: knut st. osmundsen <bird-srcspam@anduin.net>
|
|---|
| 10 | *
|
|---|
| 11 | * All Rights Reserved
|
|---|
| 12 | *
|
|---|
| 13 | */
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| [600] | 16 | #include <stdio.h>
|
|---|
| 17 | typedef struct some_struct_pointer * PTYPE;
|
|---|
| 18 |
|
|---|
| 19 | /*
|
|---|
| 20 | * Function and method declarations.
|
|---|
| 21 | * Checks mangling.
|
|---|
| 22 | */
|
|---|
| 23 |
|
|---|
| 24 | /* No underscore, No mangling. */
|
|---|
| 25 | extern "C" void _Optlink ExternCVoid(int a, int b, int c, int d);
|
|---|
| 26 | extern "C" void * _Optlink ExternCPVoid(int a, int b, int c, int d);
|
|---|
| 27 | extern "C" int _Optlink ExternCInt(int a, int b, int c, int d);
|
|---|
| 28 | extern "C" PTYPE _Optlink ExternCPType(int a, int b, int c, int d);
|
|---|
| 29 |
|
|---|
| 30 | /* No underscore, No mangling. */
|
|---|
| 31 | void _Optlink Void(int a, int b, int c, int d);
|
|---|
| 32 | void * _Optlink PVoid(int a, int b, int c, int d);
|
|---|
| 33 | int _Optlink Int(int a, int b, int c, int d);
|
|---|
| 34 | PTYPE _Optlink PType(int a, int b, int c, int d);
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | /* Members are mangled. */
|
|---|
| 38 | class foo
|
|---|
| 39 | {
|
|---|
| 40 | public:
|
|---|
| 41 | static void _Optlink StaticMemberVoid(int a, int b, int c, int d);
|
|---|
| 42 | static void * _Optlink StaticMemberPVoid(int a, int b, int c, int d);
|
|---|
| 43 | static int _Optlink StaticMemberInt(int a, int b, int c, int d);
|
|---|
| 44 | static PTYPE _Optlink StaticMemberPType(int a, int b, int c, int d);
|
|---|
| 45 |
|
|---|
| 46 | /* VAC365 allows this too, and actually mangles the
|
|---|
| 47 | * calling convention into the name.
|
|---|
| 48 | * _System: MemberVoid__3fooF__l2_v
|
|---|
| 49 | * default: MemberVoid__3fooFv
|
|---|
| 50 | * We don't need to support this, it's just a curiosity.
|
|---|
| 51 | */
|
|---|
| 52 | void _Optlink MemberVoid(int a, int b, int c, int d);
|
|---|
| 53 | void * _Optlink MemberPVoid(int a, int b, int c, int d);
|
|---|
| 54 | int _Optlink MemberInt(int a, int b, int c, int d);
|
|---|
| 55 | PTYPE _Optlink MemberPType(int a, int b, int c, int d);
|
|---|
| 56 | };
|
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 | /*
|
|---|
| 60 | * Typedefs.
|
|---|
| 61 | * Checks that there is not warnings on these.
|
|---|
| 62 | */
|
|---|
| 63 | typedef void _Optlink Typedef1Void(int a, int b, int c, int d);
|
|---|
| 64 | typedef void * _Optlink Typedef1PVoid(int a, int b, int c, int d);
|
|---|
| 65 | typedef int _Optlink Typedef1Int(int a, int b, int c, int d);
|
|---|
| 66 | typedef PTYPE _Optlink Typedef1PType(int a, int b, int c, int d);
|
|---|
| 67 |
|
|---|
| 68 | typedef void (_Optlink Typedef2Void)(int a, int b, int c, int d);
|
|---|
| 69 | typedef void * (_Optlink Typedef2PVoid)(int a, int b, int c, int d);
|
|---|
| 70 | typedef int (_Optlink Typedef2Int)(int a, int b, int c, int d);
|
|---|
| 71 | typedef PTYPE (_Optlink Typedef2PType)(int a, int b, int c, int d);
|
|---|
| [1232] | 72 | #ifdef __EMX__
|
|---|
| 73 | typedef void _Optlink (Typedef3Void)(int a, int b, int c, int d);
|
|---|
| 74 | typedef void * _Optlink (Typedef3PVoid)(int a, int b, int c, int d);
|
|---|
| 75 | typedef int _Optlink (Typedef3Int)(int a, int b, int c, int d);
|
|---|
| 76 | typedef PTYPE _Optlink (Typedef3PType)(int a, int b, int c, int d);
|
|---|
| 77 | #endif
|
|---|
| [600] | 78 |
|
|---|
| 79 | typedef void (* _Optlink PTypedef1Void)(int a, int b, int c, int d);
|
|---|
| 80 | typedef void * (* _Optlink PTypedef1PVoid)(int a, int b, int c, int d);
|
|---|
| 81 | typedef int (* _Optlink PTypedef1Int)(int a, int b, int c, int d);
|
|---|
| 82 | typedef PTYPE (* _Optlink PTypedef1PType)(int a, int b, int c, int d);
|
|---|
| 83 |
|
|---|
| 84 | /* Alternate writing which should have the same effect I think... */
|
|---|
| 85 | typedef void (_Optlink * PTypedef2Void)(int a, int b, int c, int d);
|
|---|
| 86 | typedef void * (_Optlink * PTypedef2PVoid)(int a, int b, int c, int d);
|
|---|
| 87 | typedef int (_Optlink * PTypedef2Int)(int a, int b, int c, int d);
|
|---|
| 88 | typedef PTYPE (_Optlink * PTypedef2PType)(int a, int b, int c, int d);
|
|---|
| [1232] | 89 | #ifdef __EMX__
|
|---|
| 90 | /* Alternate writing which should have the same effect I think... */
|
|---|
| 91 | typedef void _Optlink (* PTypedef3Void)(int a, int b, int c, int d);
|
|---|
| 92 | typedef void * _Optlink (* PTypedef3PVoid)(int a, int b, int c, int d);
|
|---|
| 93 | typedef int _Optlink (* PTypedef3Int)(int a, int b, int c, int d);
|
|---|
| 94 | typedef PTYPE _Optlink (* PTypedef3PType)(int a, int b, int c, int d);
|
|---|
| 95 | #endif
|
|---|
| [600] | 96 |
|
|---|
| 97 |
|
|---|
| 98 | /*
|
|---|
| 99 | * Structures.
|
|---|
| 100 | * Should not cause warnings.
|
|---|
| 101 | */
|
|---|
| 102 | typedef struct VFT
|
|---|
| 103 | {
|
|---|
| 104 | void (* _Optlink PStructMemberVoid)(int a, int b, int c, int d);
|
|---|
| 105 | void * (* _Optlink PStructMemberPVoid)(int a, int b, int c, int d);
|
|---|
| 106 | int (* _Optlink PStructMemberInt)(int a, int b, int c, int d);
|
|---|
| 107 | PTYPE (* _Optlink PStructMemberPType)(int a, int b, int c, int d);
|
|---|
| 108 |
|
|---|
| 109 | /* Alternate writing which should have the same effect I think... */
|
|---|
| 110 | void (_Optlink * PStructMember2Void)(int a, int b, int c, int d);
|
|---|
| 111 | void * (_Optlink * PStructMember2PVoid)(int a, int b, int c, int d);
|
|---|
| 112 | int (_Optlink * PStructMember2Int)(int a, int b, int c, int d);
|
|---|
| 113 | PTYPE (_Optlink * PStructMember2PType)(int a, int b, int c, int d);
|
|---|
| [1232] | 114 | #ifdef __EMX__
|
|---|
| 115 | /* Alternate writing which should have the same effect I think... */
|
|---|
| 116 | void _Optlink (* PStructMember3Void)(int a, int b, int c, int d);
|
|---|
| 117 | void * _Optlink (* PStructMember3PVoid)(int a, int b, int c, int d);
|
|---|
| 118 | int _Optlink (* PStructMember3Int)(int a, int b, int c, int d);
|
|---|
| 119 | PTYPE _Optlink (* PStructMember3PType)(int a, int b, int c, int d);
|
|---|
| 120 | #endif
|
|---|
| [600] | 121 |
|
|---|
| 122 | } VFT, *PVFT;
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| [639] | 125 | /*
|
|---|
| 126 | * Variables
|
|---|
| 127 | */
|
|---|
| 128 | void (* _Optlink PVar1Void)(int a, int b, int c, int d);
|
|---|
| 129 | void * (* _Optlink PVar1PVoid)(int a, int b, int c, int d);
|
|---|
| 130 | int (* _Optlink PVar1Int)(int a, int b, int c, int d);
|
|---|
| 131 | PTYPE (* _Optlink PVar1PType)(int a, int b, int c, int d);
|
|---|
| 132 |
|
|---|
| 133 | /* Alternate writing which should have the same effect I think... */
|
|---|
| 134 | void (_Optlink * PVar2Void)(int a, int b, int c, int d);
|
|---|
| 135 | void * (_Optlink * PVar2PVoid)(int a, int b, int c, int d);
|
|---|
| 136 | int (_Optlink * PVar2Int)(int a, int b, int c, int d);
|
|---|
| 137 | PTYPE (_Optlink * PVar2PType)(int a, int b, int c, int d);
|
|---|
| [1232] | 138 | #ifdef __EMX__
|
|---|
| 139 | void _Optlink (* PVar3Void)(int a, int b, int c, int d);
|
|---|
| 140 | void * _Optlink (* PVar3PVoid)(int a, int b, int c, int d);
|
|---|
| 141 | int _Optlink (* PVar3Int)(int a, int b, int c, int d);
|
|---|
| 142 | PTYPE _Optlink (* PVar3PType)(int a, int b, int c, int d);
|
|---|
| 143 | #endif
|
|---|
| [639] | 144 |
|
|---|
| 145 |
|
|---|
| [906] | 146 | /*
|
|---|
| 147 | * Parameters.
|
|---|
| 148 | */
|
|---|
| 149 | int ParamArgs(
|
|---|
| 150 | void (* _Optlink pfn1Void)(int a, int b, int c, int d),
|
|---|
| 151 | void * (* _Optlink pfn1PVoid)(int a, int b, int c, int d),
|
|---|
| 152 | int (* _Optlink pfn1Int)(int a, int b, int c, int d),
|
|---|
| 153 | PTYPE (* _Optlink pfn1PType)(int a, int b, int c, int d),
|
|---|
| 154 | void (_Optlink * pfn2Void)(int a, int b, int c, int d),
|
|---|
| 155 | void * (_Optlink * pfn2PVoid)(int a, int b, int c, int d),
|
|---|
| 156 | int (_Optlink * pfn2Int)(int a, int b, int c, int d),
|
|---|
| 157 | PTYPE (_Optlink * pfn2PType)(int a, int b, int c, int d)
|
|---|
| [1232] | 158 | #ifdef __EMX__
|
|---|
| 159 | ,
|
|---|
| 160 | void _Optlink (* pfn3Void)(int a, int b, int c, int d),
|
|---|
| 161 | void * _Optlink (* pfn3PVoid)(int a, int b, int c, int d),
|
|---|
| 162 | int _Optlink (* pfn3Int)(int a, int b, int c, int d),
|
|---|
| 163 | PTYPE _Optlink (* pfn3PType)(int a, int b, int c, int d)
|
|---|
| 164 | #endif
|
|---|
| [906] | 165 | )
|
|---|
| 166 | {
|
|---|
| 167 | pfn1Void(1,2,3,4);
|
|---|
| 168 | pfn1PVoid(1,2,3,4);
|
|---|
| 169 | pfn1Int(1,2,3,4);
|
|---|
| 170 | pfn1PType(1,2,3,4);
|
|---|
| 171 |
|
|---|
| 172 | pfn2Void(1,2,3,4);
|
|---|
| 173 | pfn2PVoid(1,2,3,4);
|
|---|
| 174 | pfn2Int(1,2,3,4);
|
|---|
| 175 | pfn2PType(1,2,3,4);
|
|---|
| [1232] | 176 | #ifdef __EMX__
|
|---|
| 177 | pfn3Void(1,2,3,4);
|
|---|
| 178 | pfn3PVoid(1,2,3,4);
|
|---|
| 179 | pfn3Int(1,2,3,4);
|
|---|
| 180 | pfn3PType(1,2,3,4);
|
|---|
| 181 | #endif
|
|---|
| [906] | 182 | return 0;
|
|---|
| 183 | }
|
|---|
| 184 |
|
|---|
| [1232] | 185 | /* @todo: extend and fix this */
|
|---|
| 186 | extern void ParamArgs_1(void (_Optlink *)(void));
|
|---|
| 187 | extern void ParamArgs_2(void (* _Optlink fixme) (void));
|
|---|
| 188 | #ifdef __EMX__
|
|---|
| 189 | extern void ParamArgs_3(void _Optlink (*)(void));
|
|---|
| 190 | #endif
|
|---|
| [906] | 191 |
|
|---|
| [1232] | 192 |
|
|---|
| [600] | 193 | extern "C" int DoC(void);
|
|---|
| 194 | int main(void)
|
|---|
| 195 | {
|
|---|
| 196 | static VFT vft = {Void, PVoid, Int, PType,
|
|---|
| [1232] | 197 | #ifdef __EMX__
|
|---|
| 198 | Void, PVoid, Int, PType,
|
|---|
| 199 | #endif
|
|---|
| [600] | 200 | Void, PVoid, Int, PType};
|
|---|
| 201 |
|
|---|
| 202 | static Typedef1Void * pfnTypedef1Void = Void;
|
|---|
| 203 | static Typedef1PVoid * pfnTypedef1PVoid = PVoid;
|
|---|
| 204 | static Typedef1Int * pfnTypedef1Int = Int;
|
|---|
| 205 | static Typedef1PType * pfnTypedef1PType = PType;
|
|---|
| 206 |
|
|---|
| 207 | static Typedef2Void * pfnTypedef2Void = Void;
|
|---|
| 208 | static Typedef2PVoid * pfnTypedef2PVoid = PVoid;
|
|---|
| 209 | static Typedef2Int * pfnTypedef2Int = Int;
|
|---|
| 210 | static Typedef2PType * pfnTypedef2PType = PType;
|
|---|
| [1232] | 211 | #ifdef __EMX__
|
|---|
| 212 | static Typedef3Void * pfnTypedef3Void = Void;
|
|---|
| 213 | static Typedef3PVoid * pfnTypedef3PVoid = PVoid;
|
|---|
| 214 | static Typedef3Int * pfnTypedef3Int = Int;
|
|---|
| 215 | static Typedef3PType * pfnTypedef3PType = PType;
|
|---|
| 216 | #endif
|
|---|
| [600] | 217 |
|
|---|
| 218 | static PTypedef1Void pfnPTypedef1Void = Void;
|
|---|
| 219 | static PTypedef1PVoid pfnPTypedef1PVoid = PVoid;
|
|---|
| 220 | static PTypedef1Int pfnPTypedef1Int = Int;
|
|---|
| 221 | static PTypedef1PType pfnPTypedef1PType = PType;
|
|---|
| 222 |
|
|---|
| 223 | static PTypedef2Void pfnPTypedef2Void = Void;
|
|---|
| 224 | static PTypedef2PVoid pfnPTypedef2PVoid = PVoid;
|
|---|
| 225 | static PTypedef2Int pfnPTypedef2Int = Int;
|
|---|
| 226 | static PTypedef2PType pfnPTypedef2PType = PType;
|
|---|
| [1232] | 227 | #ifdef __EMX__
|
|---|
| 228 | static PTypedef3Void pfnPTypedef3Void = Void;
|
|---|
| 229 | static PTypedef3PVoid pfnPTypedef3PVoid = PVoid;
|
|---|
| 230 | static PTypedef3Int pfnPTypedef3Int = Int;
|
|---|
| 231 | static PTypedef3PType pfnPTypedef3PType = PType;
|
|---|
| 232 | #endif
|
|---|
| [600] | 233 |
|
|---|
| [639] | 234 | PVar1Void = Void;
|
|---|
| 235 | PVar1PVoid = PVoid;
|
|---|
| 236 | PVar1Int = Int;
|
|---|
| 237 | PVar1PType = PType;
|
|---|
| 238 |
|
|---|
| 239 | PVar2Void = Void;
|
|---|
| 240 | PVar2PVoid = PVoid;
|
|---|
| 241 | PVar2Int = Int;
|
|---|
| 242 | PVar2PType = PType;
|
|---|
| [1232] | 243 | #ifdef __EMX__
|
|---|
| 244 | PVar3Void = Void;
|
|---|
| 245 | PVar3PVoid = PVoid;
|
|---|
| 246 | PVar3Int = Int;
|
|---|
| 247 | PVar3PType = PType;
|
|---|
| 248 | #endif
|
|---|
| [639] | 249 |
|
|---|
| [600] | 250 | /* extern functions */
|
|---|
| 251 | ExternCVoid(1,2,3,4);
|
|---|
| 252 | ExternCPVoid(1,2,3,4);
|
|---|
| 253 | ExternCInt(1,2,3,4);
|
|---|
| 254 | ExternCPType(1,2,3,4);
|
|---|
| 255 |
|
|---|
| 256 | Void(1,2,3,4);
|
|---|
| 257 | PVoid(1,2,3,4);
|
|---|
| 258 | Int(1,2,3,4);
|
|---|
| 259 | PType(1,2,3,4);
|
|---|
| 260 |
|
|---|
| 261 | /* class */
|
|---|
| 262 | foo::StaticMemberVoid(1,2,3,4);
|
|---|
| 263 | foo::StaticMemberPVoid(1,2,3,4);
|
|---|
| 264 | foo::StaticMemberInt(1,2,3,4);
|
|---|
| 265 | foo::StaticMemberPType(1,2,3,4);
|
|---|
| 266 |
|
|---|
| 267 | foo obj;
|
|---|
| 268 | obj.MemberVoid(1,2,3,4);
|
|---|
| 269 | obj.MemberPVoid(1,2,3,4);
|
|---|
| 270 | obj.MemberInt(1,2,3,4);
|
|---|
| 271 | obj.MemberPType(1,2,3,4);
|
|---|
| 272 |
|
|---|
| 273 | /* typedefs */
|
|---|
| 274 | pfnTypedef1Void(1,2,3,4);
|
|---|
| 275 | pfnTypedef1PVoid(1,2,3,4);
|
|---|
| 276 | pfnTypedef1Int(1,2,3,4);
|
|---|
| 277 | pfnTypedef1PType(1,2,3,4);
|
|---|
| 278 |
|
|---|
| 279 | pfnTypedef2Void(1,2,3,4);
|
|---|
| 280 | pfnTypedef2PVoid(1,2,3,4);
|
|---|
| 281 | pfnTypedef2Int(1,2,3,4);
|
|---|
| 282 | pfnTypedef2PType(1,2,3,4);
|
|---|
| [1232] | 283 | #ifdef __EMX__
|
|---|
| 284 | pfnTypedef3Void(1,2,3,4);
|
|---|
| 285 | pfnTypedef3PVoid(1,2,3,4);
|
|---|
| 286 | pfnTypedef3Int(1,2,3,4);
|
|---|
| 287 | pfnTypedef3PType(1,2,3,4);
|
|---|
| 288 | #endif
|
|---|
| [600] | 289 |
|
|---|
| 290 | pfnPTypedef1Void(1,2,3,4);
|
|---|
| 291 | pfnPTypedef1PVoid(1,2,3,4);
|
|---|
| 292 | pfnPTypedef1Int(1,2,3,4);
|
|---|
| 293 | pfnPTypedef1PType(1,2,3,4);
|
|---|
| 294 |
|
|---|
| 295 | pfnPTypedef2Void(1,2,3,4);
|
|---|
| 296 | pfnPTypedef2PVoid(1,2,3,4);
|
|---|
| 297 | pfnPTypedef2Int(1,2,3,4);
|
|---|
| 298 | pfnPTypedef2PType(1,2,3,4);
|
|---|
| [1232] | 299 | #ifdef __EMX__
|
|---|
| 300 | pfnPTypedef3Void(1,2,3,4);
|
|---|
| 301 | pfnPTypedef3PVoid(1,2,3,4);
|
|---|
| 302 | pfnPTypedef3Int(1,2,3,4);
|
|---|
| 303 | pfnPTypedef3PType(1,2,3,4);
|
|---|
| 304 | #endif
|
|---|
| [600] | 305 |
|
|---|
| 306 |
|
|---|
| 307 | /* structs */
|
|---|
| 308 | vft.PStructMemberVoid(1,2,3,4);
|
|---|
| 309 | vft.PStructMemberPVoid(1,2,3,4);
|
|---|
| 310 | vft.PStructMemberInt(1,2,3,4);
|
|---|
| 311 | vft.PStructMemberPType(1,2,3,4);
|
|---|
| 312 |
|
|---|
| 313 | vft.PStructMember2Void(1,2,3,4);
|
|---|
| 314 | vft.PStructMember2PVoid(1,2,3,4);
|
|---|
| 315 | vft.PStructMember2Int(1,2,3,4);
|
|---|
| 316 | vft.PStructMember2PType(1,2,3,4);
|
|---|
| [1232] | 317 | #ifdef __EMX__
|
|---|
| 318 | vft.PStructMember3Void(1,2,3,4);
|
|---|
| 319 | vft.PStructMember3PVoid(1,2,3,4);
|
|---|
| 320 | vft.PStructMember3Int(1,2,3,4);
|
|---|
| 321 | vft.PStructMember3PType(1,2,3,4);
|
|---|
| 322 | #endif
|
|---|
| [600] | 323 |
|
|---|
| [639] | 324 | /* variables */
|
|---|
| 325 | PVar1Void(1,2,3,4);
|
|---|
| 326 | PVar1PVoid(1,2,3,4);
|
|---|
| 327 | PVar1Int(1,2,3,4);
|
|---|
| 328 | PVar1PType(1,2,3,4);
|
|---|
| 329 |
|
|---|
| 330 | PVar2Void(1,2,3,4);
|
|---|
| 331 | PVar2PVoid(1,2,3,4);
|
|---|
| 332 | PVar2Int(1,2,3,4);
|
|---|
| 333 | PVar2PType(1,2,3,4);
|
|---|
| 334 |
|
|---|
| [906] | 335 | /* parameters */
|
|---|
| 336 | ParamArgs(Void, PVoid, Int, PType,
|
|---|
| [1232] | 337 | #ifdef __EMX__
|
|---|
| 338 | Void, PVoid, Int, PType,
|
|---|
| 339 | #endif
|
|---|
| [906] | 340 | Void, PVoid, Int, PType);
|
|---|
| 341 |
|
|---|
| [600] | 342 | /* test C stuff */
|
|---|
| 343 | DoC();
|
|---|
| 344 |
|
|---|
| 345 | printf("Successfully executed _Optlink testcase (assumed).\n");
|
|---|
| 346 | return 0;
|
|---|
| 347 | }
|
|---|
| 348 |
|
|---|