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