This repository has been archived by the owner on Mar 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
/
algebraic-type.ts
119 lines (107 loc) · 3.97 KB
/
algebraic-type.ts
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
/**
* Copyright (c) 2016-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import * as Code from './code';
import * as Error from './error';
import * as FileWriter from './file-writer';
import * as CLangCommon from './clang-common';
import * as ObjC from './objc';
import * as ObjectGeneration from './object-generation';
import * as ObjectSpec from './object-spec';
export interface SubtypeAttributeType extends ObjectSpec.AttributeType {}
export interface SubtypeAttribute extends ObjectSpec.BaseAttribute {}
export enum SubtypeDefinitionType {
namedAttributeCollection,
singleAttribute,
}
export interface NamedAttributeCollectionSubtype {
annotations: ObjectGeneration.AnnotationMap;
name: string;
comments: string[];
attributes: SubtypeAttribute[];
}
export class Subtype {
private definitionType: SubtypeDefinitionType;
private singleAttribute?: SubtypeAttribute;
attributeCollectionSubtype?: NamedAttributeCollectionSubtype;
constructor(
definitionType: SubtypeDefinitionType,
singleAttribute?: SubtypeAttribute,
attributeCollectionSubtype?: NamedAttributeCollectionSubtype,
) {
this.definitionType = definitionType;
this.singleAttribute = singleAttribute;
this.attributeCollectionSubtype = attributeCollectionSubtype;
}
static NamedAttributeCollectionDefinition(
namedAttributeCollectionType: NamedAttributeCollectionSubtype,
): Subtype {
return new Subtype(
SubtypeDefinitionType.namedAttributeCollection,
undefined,
namedAttributeCollectionType,
);
}
static SingleAttributeSubtypeDefinition(
attribute: SubtypeAttribute,
): Subtype {
return new Subtype(
SubtypeDefinitionType.singleAttribute,
attribute,
undefined,
);
}
match<T>(
namedAttributeCollection: (
namedAttributeCollectionSubtype: NamedAttributeCollectionSubtype,
) => T,
singleAttributeSubtype: (attribute: SubtypeAttribute) => T,
) {
switch (this.definitionType) {
case SubtypeDefinitionType.namedAttributeCollection:
return namedAttributeCollection(this.attributeCollectionSubtype!);
case SubtypeDefinitionType.singleAttribute:
return singleAttributeSubtype(this.singleAttribute!);
}
}
}
export interface Type {
annotations: ObjectGeneration.AnnotationMap;
comments: string[];
includes: string[];
excludes: string[];
libraryName: string | null;
name: string;
typeLookups: ObjectGeneration.TypeLookup[];
subtypes: Subtype[];
}
export interface Plugin {
additionalFiles: (algebraicType: Type) => Code.File[];
transformBaseFile: (algebraicType: Type, baseFile: Code.File) => Code.File;
blockTypes: (algebraicType: Type) => ObjC.BlockType[];
classMethods: (algebraicType: Type) => ObjC.Method[];
enumerations: (algebraicType: Type) => ObjC.Enumeration[];
transformFileRequest: (
writeRequest: FileWriter.Request,
) => FileWriter.Request;
fileType: (algebraicType: Type) => Code.FileType | null;
forwardDeclarations: (algebraicType: Type) => ObjC.ForwardDeclaration[];
functions: (algebraicType: Type) => ObjC.Function[];
headerComments: (algebraicType: Type) => ObjC.Comment[];
implementedProtocols: (algebraicType: Type) => ObjC.ImplementedProtocol[];
imports: (algebraicType: Type) => ObjC.Import[];
instanceMethods: (algebraicType: Type) => ObjC.Method[];
instanceVariables: (algebraicType: Type) => ObjC.InstanceVariable[];
macros: (algebraicType: Type) => ObjC.Macro[];
requiredIncludesToRun: string[];
staticConstants: (algebraicType: Type) => ObjC.Constant[];
globalVariables?: (algebraicType: Type) => ObjC.GlobalVariable[];
validationErrors: (algebraicType: Type) => Error.Error[];
nullability: (algebraicType: Type) => ObjC.ClassNullability | null;
subclassingRestricted: (algebraicType: Type) => boolean;
structs?: (algebraicType: Type) => Code.Struct[];
baseClass?: (algebraicType: Type) => ObjC.BaseClass | null;
}