]> git.saurik.com Git - cycript.git/blob - sig/types.hpp
Add support to @encode, Decode_, and With blocks.
[cycript.git] / sig / types.hpp
1 /* Cycript - Optimizing JavaScript Compiler/Runtime
2 * Copyright (C) 2009-2013 Jay Freeman (saurik)
3 */
4
5 /* GNU General Public License, Version 3 {{{ */
6 /*
7 * Cycript is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation, either version 3 of the License,
10 * or (at your option) any later version.
11 *
12 * Cycript is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Cycript. If not, see <http://www.gnu.org/licenses/>.
19 **/
20 /* }}} */
21
22 #ifndef SIG_TYPES_H
23 #define SIG_TYPES_H
24
25 #include <cstdlib>
26 #include <stdint.h>
27
28 #include "Standard.hpp"
29
30 namespace sig {
31
32 enum Primitive {
33 function_P = '\0',
34 typename_P = '#',
35 union_P = '(',
36 string_P = '*',
37 selector_P = ':',
38 block_P = '?',
39 object_P = 'W',
40 boolean_P = 'B',
41 uchar_P = 'C',
42 uint_P = 'I',
43 ulong_P = 'L',
44 ulonglong_P = 'Q',
45 ushort_P = 'S',
46 array_P = '[',
47 pointer_P = '^',
48 bit_P = 'b',
49 char_P = 'c',
50 double_P = 'd',
51 float_P = 'f',
52 int_P = 'i',
53 long_P = 'l',
54 longlong_P = 'q',
55 short_P = 's',
56 void_P = 'v',
57 struct_P = '{'
58 };
59
60 struct Element {
61 const char *name;
62 struct Type *type;
63 size_t offset;
64 };
65
66 struct Signature {
67 struct Element *elements;
68 size_t count;
69 };
70
71 #define JOC_TYPE_INOUT (1 << 0)
72 #define JOC_TYPE_IN (1 << 1)
73 #define JOC_TYPE_BYCOPY (1 << 2)
74 #define JOC_TYPE_OUT (1 << 3)
75 #define JOC_TYPE_BYREF (1 << 4)
76 #define JOC_TYPE_CONST (1 << 5)
77 #define JOC_TYPE_ONEWAY (1 << 6)
78
79 struct Type {
80 enum Primitive primitive;
81 const char *name;
82 uint8_t flags;
83
84 union {
85 struct {
86 struct Type *type;
87 size_t size;
88 } data;
89
90 struct Signature signature;
91 } data;
92 };
93
94 struct Type *joc_parse_type(char **name, char eos, bool variable, bool signature);
95 void joc_parse_signature(struct Signature *signature, char **name, char eos, bool variable);
96
97 _finline bool IsFunctional(Primitive primitive) {
98 return primitive == block_P || primitive == function_P;
99 }
100
101 _finline bool IsAggregate(Primitive primitive) {
102 return primitive == struct_P || primitive == union_P;
103 }
104
105 }
106
107 #endif/*SIG_TYPES_H*/