1 // Copyright 2020 Blue Static <https://www.bluestatic.org>
2 // This program is free software licensed under the GNU General Public License,
3 // version 3.0. The full text of the license can be found in LICENSE.txt.
4 // SPDX-License-Identifier: GPL-3.0-only
6 import { Line } from './Line';
8 var current: Trace = null;
10 var traces: Trace[] = [];
12 export default class Trace {
13 private _stack: Set<string>[] = [];
15 private _name: string;
17 constructor(line: Line<any>) {
18 this._name = this._formatLine(line);
19 const s = new Set<string>();
21 s.add(`Start: ${this._name}`);
23 if (current === null) {
29 current._stack.push(s);
32 static add(id: string) {
35 current._stack[current._index].add(id);
40 if (current === this) {
46 get traceList(): readonly string[][] {
47 return this._stack.map(s => [...s.values()]);
50 private _formatLine(line: Line<any>): string {
51 if (line.form === undefined)
52 return `${line.constructor.name} (${line.description})`;
53 return `${line.form.name}-${line.id} (${line.description})`;
57 export function getLastTraceList(): readonly string[][] {
58 if (traces.length == 0)
60 return traces[traces.length - 1].traceList;