| 1 | /* $Id: 572main.cpp 906 2003-12-15 20:33:09Z 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 | 
 | 
|---|
| 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);
 | 
|---|
| 72 | 
 | 
|---|
| 73 | typedef void    (* _Optlink PTypedef1Void)(int a, int b, int c, int d);
 | 
|---|
| 74 | typedef void *  (* _Optlink PTypedef1PVoid)(int a, int b, int c, int d);
 | 
|---|
| 75 | typedef int     (* _Optlink PTypedef1Int)(int a, int b, int c, int d);
 | 
|---|
| 76 | typedef PTYPE   (* _Optlink PTypedef1PType)(int a, int b, int c, int d);
 | 
|---|
| 77 | 
 | 
|---|
| 78 | /* Alternate writing which should have the same effect I think... */
 | 
|---|
| 79 | typedef void    (_Optlink * PTypedef2Void)(int a, int b, int c, int d);
 | 
|---|
| 80 | typedef void *  (_Optlink * PTypedef2PVoid)(int a, int b, int c, int d);
 | 
|---|
| 81 | typedef int     (_Optlink * PTypedef2Int)(int a, int b, int c, int d);
 | 
|---|
| 82 | typedef PTYPE   (_Optlink * PTypedef2PType)(int a, int b, int c, int d);
 | 
|---|
| 83 | 
 | 
|---|
| 84 | 
 | 
|---|
| 85 | /*
 | 
|---|
| 86 |  * Structures.
 | 
|---|
| 87 |  * Should not cause warnings.
 | 
|---|
| 88 |  */
 | 
|---|
| 89 | typedef struct VFT
 | 
|---|
| 90 | {
 | 
|---|
| 91 |     void    (* _Optlink PStructMemberVoid)(int a, int b, int c, int d);
 | 
|---|
| 92 |     void *  (* _Optlink PStructMemberPVoid)(int a, int b, int c, int d);
 | 
|---|
| 93 |     int     (* _Optlink PStructMemberInt)(int a, int b, int c, int d);
 | 
|---|
| 94 |     PTYPE   (* _Optlink PStructMemberPType)(int a, int b, int c, int d);
 | 
|---|
| 95 | 
 | 
|---|
| 96 |     /* Alternate writing which should have the same effect I think... */
 | 
|---|
| 97 |     void    (_Optlink * PStructMember2Void)(int a, int b, int c, int d);
 | 
|---|
| 98 |     void *  (_Optlink * PStructMember2PVoid)(int a, int b, int c, int d);
 | 
|---|
| 99 |     int     (_Optlink * PStructMember2Int)(int a, int b, int c, int d);
 | 
|---|
| 100 |     PTYPE   (_Optlink * PStructMember2PType)(int a, int b, int c, int d);
 | 
|---|
| 101 | 
 | 
|---|
| 102 | } VFT, *PVFT;
 | 
|---|
| 103 | 
 | 
|---|
| 104 | 
 | 
|---|
| 105 | /*
 | 
|---|
| 106 |  * Variables
 | 
|---|
| 107 |  */
 | 
|---|
| 108 | void    (* _Optlink PVar1Void)(int a, int b, int c, int d);
 | 
|---|
| 109 | void *  (* _Optlink PVar1PVoid)(int a, int b, int c, int d);
 | 
|---|
| 110 | int     (* _Optlink PVar1Int)(int a, int b, int c, int d);
 | 
|---|
| 111 | PTYPE   (* _Optlink PVar1PType)(int a, int b, int c, int d);
 | 
|---|
| 112 | 
 | 
|---|
| 113 | /* Alternate writing which should have the same effect I think... */
 | 
|---|
| 114 | void    (_Optlink * PVar2Void)(int a, int b, int c, int d);
 | 
|---|
| 115 | void *  (_Optlink * PVar2PVoid)(int a, int b, int c, int d);
 | 
|---|
| 116 | int     (_Optlink * PVar2Int)(int a, int b, int c, int d);
 | 
|---|
| 117 | PTYPE   (_Optlink * PVar2PType)(int a, int b, int c, int d);
 | 
|---|
| 118 | 
 | 
|---|
| 119 | 
 | 
|---|
| 120 | /*
 | 
|---|
| 121 |  * Parameters.
 | 
|---|
| 122 |  */
 | 
|---|
| 123 | int ParamArgs(
 | 
|---|
| 124 |     void    (* _Optlink pfn1Void)(int a, int b, int c, int d),
 | 
|---|
| 125 |     void *  (* _Optlink pfn1PVoid)(int a, int b, int c, int d),
 | 
|---|
| 126 |     int     (* _Optlink pfn1Int)(int a, int b, int c, int d),
 | 
|---|
| 127 |     PTYPE   (* _Optlink pfn1PType)(int a, int b, int c, int d),
 | 
|---|
| 128 |     void    (_Optlink * pfn2Void)(int a, int b, int c, int d),
 | 
|---|
| 129 |     void *  (_Optlink * pfn2PVoid)(int a, int b, int c, int d),
 | 
|---|
| 130 |     int     (_Optlink * pfn2Int)(int a, int b, int c, int d),
 | 
|---|
| 131 |     PTYPE   (_Optlink * pfn2PType)(int a, int b, int c, int d)
 | 
|---|
| 132 |     )
 | 
|---|
| 133 | {
 | 
|---|
| 134 |     pfn1Void(1,2,3,4);
 | 
|---|
| 135 |     pfn1PVoid(1,2,3,4);
 | 
|---|
| 136 |     pfn1Int(1,2,3,4);
 | 
|---|
| 137 |     pfn1PType(1,2,3,4);
 | 
|---|
| 138 | 
 | 
|---|
| 139 |     pfn2Void(1,2,3,4);
 | 
|---|
| 140 |     pfn2PVoid(1,2,3,4);
 | 
|---|
| 141 |     pfn2Int(1,2,3,4);
 | 
|---|
| 142 |     pfn2PType(1,2,3,4);
 | 
|---|
| 143 |     return 0;
 | 
|---|
| 144 | }
 | 
|---|
| 145 | 
 | 
|---|
| 146 | 
 | 
|---|
| 147 | extern "C" int DoC(void);
 | 
|---|
| 148 | int main(void)
 | 
|---|
| 149 | {
 | 
|---|
| 150 |     static VFT vft = {Void, PVoid, Int, PType,
 | 
|---|
| 151 |                       Void, PVoid, Int, PType};
 | 
|---|
| 152 | 
 | 
|---|
| 153 |     static Typedef1Void       * pfnTypedef1Void   = Void;
 | 
|---|
| 154 |     static Typedef1PVoid      * pfnTypedef1PVoid  = PVoid;
 | 
|---|
| 155 |     static Typedef1Int        * pfnTypedef1Int    = Int;
 | 
|---|
| 156 |     static Typedef1PType      * pfnTypedef1PType  = PType;
 | 
|---|
| 157 | 
 | 
|---|
| 158 |     static Typedef2Void       * pfnTypedef2Void   = Void;
 | 
|---|
| 159 |     static Typedef2PVoid      * pfnTypedef2PVoid  = PVoid;
 | 
|---|
| 160 |     static Typedef2Int        * pfnTypedef2Int    = Int;
 | 
|---|
| 161 |     static Typedef2PType      * pfnTypedef2PType  = PType;
 | 
|---|
| 162 | 
 | 
|---|
| 163 |     static PTypedef1Void        pfnPTypedef1Void  = Void;
 | 
|---|
| 164 |     static PTypedef1PVoid       pfnPTypedef1PVoid = PVoid;
 | 
|---|
| 165 |     static PTypedef1Int         pfnPTypedef1Int   = Int;
 | 
|---|
| 166 |     static PTypedef1PType       pfnPTypedef1PType = PType;
 | 
|---|
| 167 | 
 | 
|---|
| 168 |     static PTypedef2Void        pfnPTypedef2Void  = Void;
 | 
|---|
| 169 |     static PTypedef2PVoid       pfnPTypedef2PVoid = PVoid;
 | 
|---|
| 170 |     static PTypedef2Int         pfnPTypedef2Int   = Int;
 | 
|---|
| 171 |     static PTypedef2PType       pfnPTypedef2PType = PType;
 | 
|---|
| 172 | 
 | 
|---|
| 173 |     PVar1Void   = Void;
 | 
|---|
| 174 |     PVar1PVoid  = PVoid;
 | 
|---|
| 175 |     PVar1Int    = Int;
 | 
|---|
| 176 |     PVar1PType  = PType;
 | 
|---|
| 177 | 
 | 
|---|
| 178 |     PVar2Void   = Void;
 | 
|---|
| 179 |     PVar2PVoid  = PVoid;
 | 
|---|
| 180 |     PVar2Int    = Int;
 | 
|---|
| 181 |     PVar2PType  = PType;
 | 
|---|
| 182 | 
 | 
|---|
| 183 | 
 | 
|---|
| 184 |     /* extern functions */
 | 
|---|
| 185 |     ExternCVoid(1,2,3,4);
 | 
|---|
| 186 |     ExternCPVoid(1,2,3,4);
 | 
|---|
| 187 |     ExternCInt(1,2,3,4);
 | 
|---|
| 188 |     ExternCPType(1,2,3,4);
 | 
|---|
| 189 | 
 | 
|---|
| 190 |     Void(1,2,3,4);
 | 
|---|
| 191 |     PVoid(1,2,3,4);
 | 
|---|
| 192 |     Int(1,2,3,4);
 | 
|---|
| 193 |     PType(1,2,3,4);
 | 
|---|
| 194 | 
 | 
|---|
| 195 |     /* class */
 | 
|---|
| 196 |     foo::StaticMemberVoid(1,2,3,4);
 | 
|---|
| 197 |     foo::StaticMemberPVoid(1,2,3,4);
 | 
|---|
| 198 |     foo::StaticMemberInt(1,2,3,4);
 | 
|---|
| 199 |     foo::StaticMemberPType(1,2,3,4);
 | 
|---|
| 200 | 
 | 
|---|
| 201 |     foo obj;
 | 
|---|
| 202 |     obj.MemberVoid(1,2,3,4);
 | 
|---|
| 203 |     obj.MemberPVoid(1,2,3,4);
 | 
|---|
| 204 |     obj.MemberInt(1,2,3,4);
 | 
|---|
| 205 |     obj.MemberPType(1,2,3,4);
 | 
|---|
| 206 | 
 | 
|---|
| 207 |     /* typedefs */
 | 
|---|
| 208 |     pfnTypedef1Void(1,2,3,4);
 | 
|---|
| 209 |     pfnTypedef1PVoid(1,2,3,4);
 | 
|---|
| 210 |     pfnTypedef1Int(1,2,3,4);
 | 
|---|
| 211 |     pfnTypedef1PType(1,2,3,4);
 | 
|---|
| 212 | 
 | 
|---|
| 213 |     pfnTypedef2Void(1,2,3,4);
 | 
|---|
| 214 |     pfnTypedef2PVoid(1,2,3,4);
 | 
|---|
| 215 |     pfnTypedef2Int(1,2,3,4);
 | 
|---|
| 216 |     pfnTypedef2PType(1,2,3,4);
 | 
|---|
| 217 | 
 | 
|---|
| 218 |     pfnPTypedef1Void(1,2,3,4);
 | 
|---|
| 219 |     pfnPTypedef1PVoid(1,2,3,4);
 | 
|---|
| 220 |     pfnPTypedef1Int(1,2,3,4);
 | 
|---|
| 221 |     pfnPTypedef1PType(1,2,3,4);
 | 
|---|
| 222 | 
 | 
|---|
| 223 |     pfnPTypedef2Void(1,2,3,4);
 | 
|---|
| 224 |     pfnPTypedef2PVoid(1,2,3,4);
 | 
|---|
| 225 |     pfnPTypedef2Int(1,2,3,4);
 | 
|---|
| 226 |     pfnPTypedef2PType(1,2,3,4);
 | 
|---|
| 227 | 
 | 
|---|
| 228 | 
 | 
|---|
| 229 |     /* structs */
 | 
|---|
| 230 |     vft.PStructMemberVoid(1,2,3,4);
 | 
|---|
| 231 |     vft.PStructMemberPVoid(1,2,3,4);
 | 
|---|
| 232 |     vft.PStructMemberInt(1,2,3,4);
 | 
|---|
| 233 |     vft.PStructMemberPType(1,2,3,4);
 | 
|---|
| 234 | 
 | 
|---|
| 235 |     vft.PStructMember2Void(1,2,3,4);
 | 
|---|
| 236 |     vft.PStructMember2PVoid(1,2,3,4);
 | 
|---|
| 237 |     vft.PStructMember2Int(1,2,3,4);
 | 
|---|
| 238 |     vft.PStructMember2PType(1,2,3,4);
 | 
|---|
| 239 | 
 | 
|---|
| 240 |     /* variables */
 | 
|---|
| 241 |     PVar1Void(1,2,3,4);
 | 
|---|
| 242 |     PVar1PVoid(1,2,3,4);
 | 
|---|
| 243 |     PVar1Int(1,2,3,4);
 | 
|---|
| 244 |     PVar1PType(1,2,3,4);
 | 
|---|
| 245 | 
 | 
|---|
| 246 |     PVar2Void(1,2,3,4);
 | 
|---|
| 247 |     PVar2PVoid(1,2,3,4);
 | 
|---|
| 248 |     PVar2Int(1,2,3,4);
 | 
|---|
| 249 |     PVar2PType(1,2,3,4);
 | 
|---|
| 250 | 
 | 
|---|
| 251 |     /* parameters */
 | 
|---|
| 252 |     ParamArgs(Void, PVoid, Int, PType,
 | 
|---|
| 253 |               Void, PVoid, Int, PType);
 | 
|---|
| 254 | 
 | 
|---|
| 255 |     /* test C stuff */
 | 
|---|
| 256 |     DoC();
 | 
|---|
| 257 | 
 | 
|---|
| 258 |     printf("Successfully executed _Optlink testcase (assumed).\n");
 | 
|---|
| 259 |     return 0;
 | 
|---|
| 260 | }
 | 
|---|
| 261 | 
 | 
|---|