-
Notifications
You must be signed in to change notification settings - Fork 5
/
Base.swift
159 lines (132 loc) · 3.73 KB
/
Base.swift
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
public enum CGPlatform {
case Echoes
case Cooper
case Toffee
case Gotham
case Island
}
public struct CGLocation {
public var column: Integer
public var virtualColumn: Integer
public var line: Integer
public var offset: Integer
}
public __abstract class CGEntity {
public var startLocation: CGLocation?
public var endLocation: CGLocation?
}
public class CGCodeUnit {
public var FileName: String?
public var Namespace: CGNamespaceReference?
public var HeaderComment = CGCommentStatement()
public var RawHeader: List<String>?
public var RawFooter: List<String>?
public var Directives = List<CGCompilerDirective>() /* will not be language agnostic */
public var Imports = List<CGImport>()
public var FileImports = List<CGImport>()
public var Types = List<CGTypeDefinition>()
public var Globals = List<CGGlobalDefinition>()
public var Attributes = List<CGAttribute>()
public var ImplementationDirectives = List<CGCompilerDirective>() /* Pascal only */
public var ImplementationImports = List<CGImport>() /* Pascal only */
public var Initialization: List<CGStatement>? /* Delphi only */
public var Finalization: List<CGStatement>? /* Delphi only */
public init() {
}
public init(_ namespace: String) {
Namespace = CGNamespaceReference(namespace)
}
public init(_ namespace: CGNamespaceReference) {
Namespace = namespace
}
}
public class CGCompilerDirective {
public var Directive: String /* will not be language agnostic */
public var Condition: CGConditionalDefine?
public init(_ directive: String) {
Directive = directive
}
public convenience init(_ directive: String, _ condition: CGConditionalDefine) {
init(directive)
Condition = condition
}
}
public class CGImport {
public var Namespace: CGNamespaceReference?
public var StaticClass: CGNamedTypeReference?
public var Condition: CGConditionalDefine?
public var Name: String! {
if let ns = Namespace {
return ns.Name
} else if let sc = StaticClass {
return sc.Name
}
return nil
}
public init(_ namespace: String) {
Namespace = CGNamespaceReference(namespace)
}
public init(_ namespace: CGNamespaceReference) {
Namespace = namespace
}
public init(_ staticClass: CGNamedTypeReference) {
StaticClass = staticClass
}
}
public class CGNamespaceReference {
public var Name: String
public init(_ name: String) {
Name = name
}
}
public class CGConditionalDefine {
public var Expression: CGExpression
public init(_ expression: CGExpression) {
Expression = expression
}
public convenience init(_ define: String) {
init(CGNamedIdentifierExpression(define))
}
public init(_ define: String, inverted: Boolean) {
if inverted {
Expression = CGUnaryOperatorExpression.NotExpression(CGNamedIdentifierExpression(define))
} else {
Expression = CGNamedIdentifierExpression(define)
}
}
}
public __abstract class CGGlobalDefinition {
public var RawHeader: List<String>?
public var RawFooter: List<String>?
}
public class CGGlobalFunctionDefinition : CGGlobalDefinition {
public let Function: CGMethodDefinition
public init(_ function: CGMethodDefinition) {
Function = function
}
}
public class CGGlobalVariableDefinition : CGGlobalDefinition {
public let Variable: CGFieldDefinition
public init(_ variable: CGFieldDefinition) {
Variable = variable
}
}
public class CGGlobalPropertyDefinition : CGGlobalDefinition {
public let Property: CGPropertyDefinition
public init(_ property: CGPropertyDefinition) {
Property = property
}
}
public class CGInvariant {
public var Expression: CGExpression
public var Message: String?
public init(_ expression: CGExpression) {
Expression = expression
}
public init(_ expression: CGExpression, _ message: String) {
Expression = expression
if length(message) > 0 {
Message = message;
}
}
}