-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypes.m
160 lines (138 loc) · 3.67 KB
/
Types.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//
// Types.m
// swift2js
//
// Created by Gregory Casamento on 10/20/14.
// Copyright (c) 2014 swiftjs. All rights reserved.
//
#import "Types.h"
#import "AST.h"
@class NamedExpression;
@implementation GenericType
- (id)initWithType: (SwiftType)aType
{
self = [super init];
if(self != nil)
{
self.type = aType;
}
return self;
}
- (GenericType *) operate: (NSString *)op
: (GenericType *)other
{
if( [op isEqualToString: @"==="]
|| [op isEqualToString: @"=="]
|| [op isEqualToString: @"&&"]
|| [op isEqualToString: @"||"] )
{
return [[GenericType alloc] initWithType:BOOLEAN];
}
else if( [op isEqualToString: @"="] )
{
return other;
}
else if (self.type == STRING || other.type == STRING)
{
return [[GenericType alloc] initWithType: STRING];
}
else
{
return self;
}
}
- (NSString *) customBinaryOperator: (ASTNode *)myNode
: (NSString *)op
: (ASTNode *)otherNode
{
return nil;
}
- (GenericType *) fromTypeIdentifier: (NSString *)name
{
if ([name isEqualToString: @"String"])
{
return [[GenericType alloc] initWithType:STRING];
}
else if ([name isEqualToString: @"Int"])
{
return [[GenericType alloc] initWithType:NUMBER];
}
else
{
return [[GenericType alloc] initWithType:UNKOWN];
}
}
@end
@implementation IndirectionType
- (id) initWithPointer: (GenericType *)pointer
{
self = [super initWithType: pointer.type];
if(self != nil)
{
self.pointer = pointer;
}
return self;
}
- (void) update: (GenericType *)pointer
{
}
@end
@implementation TupleType
- (id) initWithList: (ExpressionList *)list
{
self = [super initWithType: TUPLE];
if(self != nil)
{
ExpressionList *item = list;
int index = 0;
id validItem = nil;
self.names = [[NSMutableArray alloc] initWithCapacity:10];
self.types = [[NSMutableArray alloc] initWithCapacity:10];
while((validItem = item) != nil)
{
NamedExpression *namedExpression = nil;
NamedExpression *expression = nil;
if ((namedExpression = [validItem current]) != nil)
{
[self addType: namedExpression.name
: namedExpression.type];
}
else if((expression = validItem.current) != nil)
{
NSString *str = [NSString stringWithFormat:@"%d",index];
[self addType: str
: expression.type];
}
++index;
item = [validItem next];
}
}
}
- (void) addType: (NSString *)name
: (GenericType *)type
{
[self.names addObject:name];
[self.types addObject:type];
}
- (GenericType *) getTypeForIndex:(int)index
{
return (GenericType *)[self.types objectAtIndex:index];
}
@end
// ArrayType...
@interface ArrayType: GenericType
@property (nonatomic, retain) GenericType *innerType;
- (id) initWithInnerType: (GenericType *)innerType;
@end
// DictionaryType...
@interface DictionaryType: GenericType
@property (nonatomic, retain) GenericType *innerType;
- (id) initWithInnerType: (GenericType *)innerType;
@end
// FunctionType...
@interface FunctionType: GenericType
@property (nonatomic, retain) GenericType *returnType;
@property (nonatomic, retain) NSMutableArray *argumentTypes;
- (id) initWithArgumentTypes: (NSMutableArray *)argumentTypes
returnType: (GenericType *)returnType;
- (id) initWithArgumentTypes:(GenericType *)argumentType