-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathuniast.ts
More file actions
218 lines (195 loc) · 5.96 KB
/
uniast.ts
File metadata and controls
218 lines (195 loc) · 5.96 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// UNIAST v0.1.3 TypeScript interfaces
// Based on the specification in spec.md
// ================================================================
// Core Structures
// ================================================================
/**
* Root object representing an entire code repository.
*/
export interface Repository {
/** Unique identifier for the repository. Field name in JSON is "id". */
id: string;
/** UNIAST specification version. Fixed to "v0.1.3". */
ASTVersion: string;
/** abcoder version used to parse the repository. Field name in JSON is "ToolVersion". */
ToolVersion: string;
/** File directory of the repository, usually should be an absolute path. */
Path: string;
/** Map of all modules in the repository. Keys are unique path identifiers. */
Modules: Record<string, Module>;
/**
* Global symbol graph. Keys are fully-qualified unique symbol strings, values are the corresponding Node objects.
*/
Graph: Record<string, Node>;
}
/**
* A compilation unit, e.g., a Go module or an npm package.
*/
export interface Module {
Language: 'go' | 'rust' | 'cxx' | 'python' | '';
Version: string;
Name: string;
/** Path relative to the repository root. Empty string "" denotes an external dependency module. */
Dir: string;
/** Map of all packages in the module. Keys are package import paths. */
Packages: Record<string, Package>;
/** (Optional) Map of module dependencies. */
Dependencies?: Record<string, string>;
/** (Optional) Map of metadata for all files in the module. */
Files?: Record<string, File>;
}
/**
* A namespace containing a group of code symbols.
*/
export interface Package {
IsMain: boolean;
IsTest: boolean;
/** Unique import path for this package. Located at the top level of the Package object. */
PkgPath: string;
/** Map of all functions and methods. Keys are symbol names. */
Functions: Record<string, Function>;
/** Map of all type definitions. Keys are type names. */
Types: Record<string, Type>;
/** Map of all global variables and constants. Keys are variable names. */
Vars: Record<string, Var>;
}
// ================================================================
// Core Definitions
// ================================================================
/**
* Globally unique identifier for any code symbol.
*/
export interface Identity {
ModPath: string;
PkgPath: string;
Name: string;
}
/**
* Exact location of a symbol definition or reference in a source file.
*/
export interface FileLine {
File: string;
Line: number; // 1-based line number.
StartOffset: number;
EndOffset: number;
}
/**
* Reference to another code symbol. Contains the target symbol's Identity and the location of the reference.
* Note: the FileLine part is optional.
*/
export type Dependency = Identity & Partial<FileLine>;
// ================================================================
// Concrete Symbol Structures
// ================================================================
export interface Function {
// --- Identity & FileLine (inline fields) ---
ModPath: string;
PkgPath: string;
Name: string;
File: string;
Line: number;
StartOffset: number;
EndOffset: number;
// --- Function-specific Fields ---
Exported: boolean;
IsMethod: boolean;
IsInterfaceMethod: boolean;
/** Complete source code of the function, including signature and body. */
Content: string;
Signature?: string;
Receiver?: Receiver;
Params?: Dependency[];
Results?: Dependency[];
FunctionCalls?: Dependency[];
MethodCalls?: Dependency[];
Types?: Dependency[];
/** References to package-level variables, exported or not. */
GlobalVars?: Dependency[];
}
export interface Type {
// --- Identity & FileLine (inline fields) ---
ModPath: string;
PkgPath: string;
Name: string;
File: string;
Line: number;
StartOffset: number;
EndOffset: number;
// --- Type-specific Fields ---
Exported: boolean;
TypeKind: 'struct' | 'interface' | 'typedef' | 'enum';
Content: string;
SubStruct?: Dependency[];
InlineStruct?: Dependency[];
Methods?: Record<string, Identity>;
Implements?: Identity[];
}
export interface Var {
// --- Identity & FileLine (inline fields) ---
ModPath: string;
PkgPath: string;
Name: string;
File: string;
Line: number;
StartOffset: number;
EndOffset: number;
// --- Var-specific Fields ---
IsExported: boolean;
IsConst: boolean;
IsPointer: boolean;
Content: string;
Type?: Identity;
Dependencies?: Dependency[];
Groups?: Identity[];
}
// ================================================================
// Auxiliary & Graph Structures
// ================================================================
/**
* Represents a node (symbol entity) in the code.
*/
export interface Node {
// --- Identity (inline fields) ---
ModPath: string;
PkgPath: string;
Name: string;
// --- Node-specific Fields ---
Type: 'FUNC' | 'TYPE' | 'VAR' | 'UNKNOWN';
/** (Optional) List of other nodes this node depends on (outgoing edges). */
Dependencies?: Relation[];
/** (Optional) List of nodes that reference this node (incoming edges). */
References?: Relation[];
/** (Optional) List of interface nodes this node implements. */
Implements?: Relation[];
/** (Optional) List of parent nodes this node inherits from. */
Inherits?: Relation[];
/** (Optional) List of other nodes in the same definition group. */
Groups?: Relation[];
}
/**
* Describes a relationship between two nodes.
*/
export interface Relation {
// --- Identity (inline fields) ---
ModPath: string;
PkgPath: string;
Name: string;
// --- Relation-specific Fields ---
Kind: 'Dependency' | 'Implement' | 'Inherit' | 'Group';
}
export interface File {
Path: string;
Imports?: Import[];
Package?: string;
}
/**
* Represents an import declaration. Can be a simple string or an object containing alias and path.
*/
export type Import = string | {
Alias?: string;
Path: string;
};
export interface Receiver {
IsPointer: boolean;
Type: Identity;
}