@designliquido/delegua 1.1.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.d.ts.map +1 -1
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.js +5 -3
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.js.map +1 -1
- package/avaliador-sintatico/comum.d.ts.map +1 -1
- package/avaliador-sintatico/comum.js +4 -2
- package/avaliador-sintatico/comum.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +14 -2
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/bibliotecas/biblioteca-global.d.ts +22 -1
- package/bibliotecas/biblioteca-global.d.ts.map +1 -1
- package/bibliotecas/biblioteca-global.js +150 -17
- package/bibliotecas/biblioteca-global.js.map +1 -1
- package/bibliotecas/dialetos/pitugues/biblioteca-global.d.ts +21 -0
- package/bibliotecas/dialetos/pitugues/biblioteca-global.d.ts.map +1 -1
- package/bibliotecas/dialetos/pitugues/biblioteca-global.js +155 -6
- package/bibliotecas/dialetos/pitugues/biblioteca-global.js.map +1 -1
- package/bin/package.json +1 -1
- package/declaracoes/ajuda.d.ts +2 -0
- package/declaracoes/ajuda.d.ts.map +1 -1
- package/declaracoes/ajuda.js +3 -0
- package/declaracoes/ajuda.js.map +1 -1
- package/formatadores/formatador-pitugues.d.ts +1 -0
- package/formatadores/formatador-pitugues.d.ts.map +1 -1
- package/formatadores/formatador-pitugues.js +3 -1
- package/formatadores/formatador-pitugues.js.map +1 -1
- package/interfaces/tradutor-interface.d.ts +1 -1
- package/interfaces/tradutor-interface.d.ts.map +1 -1
- package/interfaces/visitante-comum-interface.d.ts +2 -2
- package/interfaces/visitante-comum-interface.d.ts.map +1 -1
- package/interpretador/comum.d.ts +1 -0
- package/interpretador/comum.d.ts.map +1 -1
- package/interpretador/comum.js +22 -0
- package/interpretador/comum.js.map +1 -1
- package/interpretador/dialetos/pitugues/comum.d.ts.map +1 -1
- package/interpretador/dialetos/pitugues/comum.js +13 -0
- package/interpretador/dialetos/pitugues/comum.js.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues.d.ts +1 -2
- package/interpretador/dialetos/pitugues/interpretador-pitugues.d.ts.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues.js +0 -38
- package/interpretador/dialetos/pitugues/interpretador-pitugues.js.map +1 -1
- package/interpretador/interpretador-base.d.ts.map +1 -1
- package/interpretador/interpretador-base.js +1 -12
- package/interpretador/interpretador-base.js.map +1 -1
- package/interpretador/interpretador.d.ts +6 -3
- package/interpretador/interpretador.d.ts.map +1 -1
- package/interpretador/interpretador.js +53 -15
- package/interpretador/interpretador.js.map +1 -1
- package/package.json +1 -1
- package/tradutores/index.d.ts +2 -0
- package/tradutores/index.d.ts.map +1 -1
- package/tradutores/index.js +2 -0
- package/tradutores/index.js.map +1 -1
- package/tradutores/mermaid/index.d.ts +1 -1
- package/tradutores/mermaid/index.js +1 -1
- package/tradutores/mermaid/subgrafo-classe.d.ts +7 -5
- package/tradutores/mermaid/subgrafo-classe.d.ts.map +1 -1
- package/tradutores/mermaid/subgrafo-classe.js +18 -18
- package/tradutores/mermaid/subgrafo-classe.js.map +1 -1
- package/tradutores/mermaid/subgrafo-metodo.d.ts +13 -0
- package/tradutores/mermaid/subgrafo-metodo.d.ts.map +1 -0
- package/tradutores/mermaid/subgrafo-metodo.js +16 -0
- package/tradutores/mermaid/subgrafo-metodo.js.map +1 -0
- package/tradutores/tradutor-elixir.d.ts +141 -0
- package/tradutores/tradutor-elixir.d.ts.map +1 -0
- package/tradutores/tradutor-elixir.js +926 -0
- package/tradutores/tradutor-elixir.js.map +1 -0
- package/tradutores/tradutor-mermaidjs.d.ts +78 -78
- package/tradutores/tradutor-mermaidjs.d.ts.map +1 -1
- package/tradutores/tradutor-mermaidjs.js +501 -372
- package/tradutores/tradutor-mermaidjs.js.map +1 -1
- package/tradutores/tradutor-python.d.ts +11 -0
- package/tradutores/tradutor-python.d.ts.map +1 -1
- package/tradutores/tradutor-python.js +32 -2
- package/tradutores/tradutor-python.js.map +1 -1
- package/tradutores/tradutor-reverso-javascript.d.ts.map +1 -1
- package/tradutores/tradutor-reverso-javascript.js +0 -2
- package/tradutores/tradutor-reverso-javascript.js.map +1 -1
- package/tradutores/tradutor-ruby.d.ts +101 -0
- package/tradutores/tradutor-ruby.d.ts.map +1 -0
- package/tradutores/tradutor-ruby.js +687 -0
- package/tradutores/tradutor-ruby.js.map +1 -0
- package/umd/delegua.js +2681 -723
- package/tradutores/mermaid/diagrama-classe.d.ts +0 -16
- package/tradutores/mermaid/diagrama-classe.d.ts.map +0 -1
- package/tradutores/mermaid/diagrama-classe.js +0 -33
- package/tradutores/mermaid/diagrama-classe.js.map +0 -1
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TradutorMermaidJs = void 0;
|
|
7
|
-
const delegua_1 = __importDefault(require("../tipos-de-simbolos/delegua"));
|
|
8
7
|
const mermaid_1 = require("./mermaid");
|
|
8
|
+
const delegua_1 = __importDefault(require("../tipos-de-simbolos/delegua"));
|
|
9
9
|
/**
|
|
10
10
|
* [MermaidJs](https://mermaid.js.org/) é uma especificação que nos permite
|
|
11
11
|
* criar fluxogramas através de uma notação por texto.
|
|
@@ -19,305 +19,160 @@ const mermaid_1 = require("./mermaid");
|
|
|
19
19
|
* @see VerticeFluxograma
|
|
20
20
|
*/
|
|
21
21
|
class TradutorMermaidJs {
|
|
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
|
-
return `propriedade ${acessoPropriedade.nomePropriedade}`;
|
|
76
|
-
}
|
|
77
|
-
traduzirConstrutoAgrupamento(agrupamento) {
|
|
78
|
-
return this.dicionarioConstrutos[agrupamento.expressao.constructor.name](agrupamento.expressao);
|
|
79
|
-
}
|
|
80
|
-
traduzirConstrutoAtribuir(atribuir) {
|
|
81
|
-
const textoAlvo = this.dicionarioConstrutos[atribuir.alvo.constructor.name](atribuir.alvo);
|
|
82
|
-
const textoValor = this.dicionarioConstrutos[atribuir.valor.constructor.name](atribuir.valor);
|
|
83
|
-
return `${textoAlvo} recebe: ${textoValor}`;
|
|
84
|
-
}
|
|
85
|
-
traduzirConstrutoBinario(binario) {
|
|
86
|
-
const operandoEsquerdo = this.dicionarioConstrutos[binario.esquerda.constructor.name](binario.esquerda);
|
|
87
|
-
const operandoDireito = this.dicionarioConstrutos[binario.direita.constructor.name](binario.direita);
|
|
88
|
-
switch (binario.operador.tipo) {
|
|
89
|
-
case delegua_1.default.ADICAO:
|
|
90
|
-
return `somar ${operandoEsquerdo} e ${operandoDireito}`;
|
|
91
|
-
case delegua_1.default.MENOR:
|
|
92
|
-
return `${operandoEsquerdo} for menor que ${operandoDireito}`;
|
|
93
|
-
}
|
|
94
|
-
return '';
|
|
95
|
-
}
|
|
96
|
-
traduzirConstrutoChamada(chamada) {
|
|
97
|
-
const textoEntidadeChamada = this.dicionarioConstrutos[chamada.entidadeChamada.constructor.name](chamada.entidadeChamada);
|
|
98
|
-
let texto = `chamada a ${textoEntidadeChamada}`;
|
|
99
|
-
if (chamada.argumentos.length > 0) {
|
|
100
|
-
texto += `, com argumentos: `;
|
|
101
|
-
for (const argumento of chamada.argumentos) {
|
|
102
|
-
const textoArgumento = this.dicionarioConstrutos[argumento.constructor.name](argumento);
|
|
103
|
-
texto += `${textoArgumento}, `;
|
|
22
|
+
visitarDeclaracaoCabecalhoPrograma(declaracao) {
|
|
23
|
+
throw new Error('Método não implementado.');
|
|
24
|
+
}
|
|
25
|
+
async visitarDeclaracaoClasse(declaracao) {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
const nomeClasse = declaracao.simbolo.lexema;
|
|
28
|
+
const superClasse = declaracao.superClasse
|
|
29
|
+
? (((_a = declaracao.superClasse.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) || ((_b = declaracao.superClasse.nome) === null || _b === void 0 ? void 0 : _b.lexema))
|
|
30
|
+
: undefined;
|
|
31
|
+
const linha = declaracao.linha;
|
|
32
|
+
// Cria arestas de entrada e saída para a classe
|
|
33
|
+
const textoInicio = `Classe${nomeClasse}Inicio[Início: Classe ${nomeClasse}]`;
|
|
34
|
+
const arestaInicial = new mermaid_1.ArestaFluxograma(declaracao, textoInicio);
|
|
35
|
+
const textoFim = `Classe${nomeClasse}Fim[Fim: Classe ${nomeClasse}]`;
|
|
36
|
+
const arestaFinal = new mermaid_1.ArestaFluxograma(declaracao, textoFim);
|
|
37
|
+
// Cria o subgrafo da classe
|
|
38
|
+
const subgrafo = new mermaid_1.SubgrafoClasse(nomeClasse, linha, arestaInicial, arestaFinal, superClasse);
|
|
39
|
+
// Salva o estado anterior
|
|
40
|
+
const anterioresAntes = [...this.anteriores];
|
|
41
|
+
// Processa métodos
|
|
42
|
+
if (declaracao.metodos && declaracao.metodos.length > 0) {
|
|
43
|
+
for (const metodoDeclaracao of declaracao.metodos) {
|
|
44
|
+
const nomeMetodo = metodoDeclaracao.simbolo.lexema;
|
|
45
|
+
const linhaMetodo = metodoDeclaracao.linha;
|
|
46
|
+
const ehConstrutor = nomeMetodo === 'construtor' || nomeMetodo === 'iniciar';
|
|
47
|
+
// Cria arestas de entrada e saída para o método
|
|
48
|
+
const textoInicioMetodo = `Metodo${nomeMetodo}${nomeClasse}Inicio[Início: ${nomeMetodo}()]`;
|
|
49
|
+
const arestaInicialMetodo = new mermaid_1.ArestaFluxograma(metodoDeclaracao, textoInicioMetodo);
|
|
50
|
+
const textoFimMetodo = `Metodo${nomeMetodo}${nomeClasse}Fim[Fim: ${nomeMetodo}()]`;
|
|
51
|
+
const arestaFinalMetodo = new mermaid_1.ArestaFluxograma(metodoDeclaracao, textoFimMetodo);
|
|
52
|
+
// Cria o subgrafo do método
|
|
53
|
+
const subgrafoMetodo = new mermaid_1.SubgrafoMetodo(nomeMetodo, nomeClasse, linhaMetodo, arestaInicialMetodo, arestaFinalMetodo, ehConstrutor);
|
|
54
|
+
// Traduz o corpo do método
|
|
55
|
+
this.anteriores = [arestaInicialMetodo];
|
|
56
|
+
if (metodoDeclaracao.funcao.corpo && metodoDeclaracao.funcao.corpo.length > 0) {
|
|
57
|
+
for (const declaracaoCorpo of metodoDeclaracao.funcao.corpo) {
|
|
58
|
+
const verticesCorpo = await declaracaoCorpo.aceitar(this);
|
|
59
|
+
subgrafoMetodo.vertices = subgrafoMetodo.vertices.concat(verticesCorpo);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Conecta o último vértice do corpo ao fim do método
|
|
63
|
+
if (this.anteriores.length > 0) {
|
|
64
|
+
for (const anterior of this.anteriores) {
|
|
65
|
+
subgrafoMetodo.vertices.push(new mermaid_1.VerticeFluxograma(anterior, arestaFinalMetodo));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Adiciona o método ao subgrafo da classe
|
|
69
|
+
if (ehConstrutor) {
|
|
70
|
+
subgrafo.construtor = subgrafoMetodo;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
subgrafo.metodos.push(subgrafoMetodo);
|
|
74
|
+
}
|
|
104
75
|
}
|
|
105
|
-
texto = texto.slice(0, -2);
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
texto += `, sem argumentos`;
|
|
109
76
|
}
|
|
110
|
-
|
|
77
|
+
// Restaura o estado anterior
|
|
78
|
+
this.anteriores = anterioresAntes;
|
|
79
|
+
// Armazena o subgrafo da classe
|
|
80
|
+
this.declaracoesClasses[nomeClasse] = subgrafo;
|
|
81
|
+
return Promise.resolve([]);
|
|
111
82
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const textoValor = this.dicionarioConstrutos[definirValor.valor.constructor.name](definirValor.valor);
|
|
115
|
-
return `${definirValor.nome.lexema} em ${textoObjeto} recebe ${textoValor}`;
|
|
83
|
+
async visitarDeclaracaoComentario(declaracao) {
|
|
84
|
+
return Promise.resolve('');
|
|
116
85
|
}
|
|
117
|
-
|
|
118
|
-
let texto = `
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
86
|
+
async visitarDeclaracaoConst(declaracao) {
|
|
87
|
+
let texto = `Linha${declaracao.linha}(variável: ${declaracao.simbolo.lexema}`;
|
|
88
|
+
texto += await this.logicaComumTraducaoVarEConst(declaracao, texto);
|
|
89
|
+
const aresta = new mermaid_1.ArestaFluxograma(declaracao, texto);
|
|
90
|
+
const vertices = this.logicaComumConexaoArestas(aresta);
|
|
91
|
+
this.anteriores.push(aresta);
|
|
92
|
+
return Promise.resolve(vertices);
|
|
93
|
+
}
|
|
94
|
+
visitarDeclaracaoConstMultiplo(declaracao) {
|
|
95
|
+
throw new Error('Método não implementado.');
|
|
96
|
+
}
|
|
97
|
+
async visitarDeclaracaoDeExpressao(declaracao) {
|
|
98
|
+
// Verifica se é uma chamada de função
|
|
99
|
+
if (declaracao.expressao.constructor.name === 'Chamada') {
|
|
100
|
+
const chamada = declaracao.expressao;
|
|
101
|
+
const verticesChamada = await this.traduzirChamadaFuncao(declaracao, chamada);
|
|
102
|
+
if (verticesChamada.length > 0) {
|
|
103
|
+
return Promise.resolve(verticesChamada);
|
|
123
104
|
}
|
|
124
105
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
106
|
+
// Se não for uma chamada de função ou não for uma função conhecida,
|
|
107
|
+
// trata como expressão normal
|
|
108
|
+
let texto = `Linha${declaracao.linha}(`;
|
|
109
|
+
const textoConstruto = await declaracao.expressao.aceitar(this);
|
|
110
|
+
texto += textoConstruto + ')';
|
|
111
|
+
const aresta = new mermaid_1.ArestaFluxograma(declaracao, texto);
|
|
112
|
+
const vertices = this.logicaComumConexaoArestas(aresta);
|
|
113
|
+
this.anteriores.push(aresta);
|
|
114
|
+
return Promise.resolve(vertices);
|
|
115
|
+
}
|
|
116
|
+
async visitarDeclaracaoDefinicaoFuncao(declaracao) {
|
|
117
|
+
const nomeFuncao = declaracao.simbolo.lexema;
|
|
118
|
+
const linha = declaracao.linha;
|
|
119
|
+
// Cria arestas de entrada e saída para a função
|
|
120
|
+
const textoInicio = `Func${nomeFuncao}Inicio[Início: ${nomeFuncao}()]`;
|
|
121
|
+
const arestaInicial = new mermaid_1.ArestaFluxograma(declaracao, textoInicio);
|
|
122
|
+
const textoFim = `Func${nomeFuncao}Fim[Fim: ${nomeFuncao}()]`;
|
|
123
|
+
const arestaFinal = new mermaid_1.ArestaFluxograma(declaracao, textoFim);
|
|
124
|
+
// Cria o subgrafo da função
|
|
125
|
+
const subgrafo = new mermaid_1.SubgrafoFuncao(nomeFuncao, linha, arestaInicial, arestaFinal);
|
|
126
|
+
// Salva o estado atual de anteriores
|
|
127
|
+
const anterioresAntes = [...this.anteriores];
|
|
128
|
+
this.anteriores = [arestaInicial];
|
|
129
|
+
// Processa o corpo da função
|
|
130
|
+
if (declaracao.funcao.corpo && declaracao.funcao.corpo.length > 0) {
|
|
131
|
+
for (const declaracaoCorpo of declaracao.funcao.corpo) {
|
|
132
|
+
const verticesCorpo = await declaracaoCorpo.aceitar(this);
|
|
133
|
+
subgrafo.vertices = subgrafo.vertices.concat(verticesCorpo);
|
|
141
134
|
}
|
|
142
135
|
}
|
|
143
|
-
|
|
136
|
+
// Conecta o fim do corpo à aresta final
|
|
144
137
|
if (this.anteriores.length > 0) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
console.log(verticesRestantes);
|
|
148
|
-
}
|
|
149
|
-
return vertices;
|
|
150
|
-
}
|
|
151
|
-
traduzirConstrutoLeia(leia) {
|
|
152
|
-
let texto = 'leia da entrada';
|
|
153
|
-
if (leia.argumentos && leia.argumentos.length > 0) {
|
|
154
|
-
const textoArgumento = this.dicionarioConstrutos[leia.argumentos[0].constructor.name](leia.argumentos[0]);
|
|
155
|
-
texto += `, imprimindo antes: \\'${textoArgumento}\\'`;
|
|
156
|
-
}
|
|
157
|
-
return texto;
|
|
158
|
-
}
|
|
159
|
-
traduzirConstrutoLiteral(literal) {
|
|
160
|
-
switch (literal.tipo) {
|
|
161
|
-
case 'lógico':
|
|
162
|
-
return literal.valor ? 'verdadeiro' : 'falso';
|
|
163
|
-
case 'texto':
|
|
164
|
-
return `\\'${literal.valor}\\'`;
|
|
165
|
-
default:
|
|
166
|
-
return String(literal.valor);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
traduzirConstrutoSeparador(separador) {
|
|
170
|
-
return `${separador.conteudo} `;
|
|
171
|
-
}
|
|
172
|
-
traduzirConstrutoUnario(unario) {
|
|
173
|
-
const textoOperando = this.dicionarioConstrutos[unario.operando.constructor.name](unario.operando);
|
|
174
|
-
let textoOperador = '';
|
|
175
|
-
switch (unario.operador.tipo) {
|
|
176
|
-
case delegua_1.default.INCREMENTAR:
|
|
177
|
-
textoOperador = `incrementar ${textoOperando} em 1`;
|
|
178
|
-
break;
|
|
179
|
-
case delegua_1.default.DECREMENTAR:
|
|
180
|
-
textoOperador = `decrementar ${textoOperando} de 1`;
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
switch (unario.incidenciaOperador) {
|
|
184
|
-
case 'ANTES':
|
|
185
|
-
return `${textoOperador}, devolver valor de ${textoOperando}`;
|
|
186
|
-
case 'DEPOIS':
|
|
187
|
-
return `devolver valor de ${textoOperando}, ${textoOperador}`;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
traduzirConstrutoVariavel(variavel) {
|
|
191
|
-
return variavel.simbolo.lexema;
|
|
192
|
-
}
|
|
193
|
-
traduzirConstrutoVetor(vetor) {
|
|
194
|
-
let texto = `vetor: `;
|
|
195
|
-
for (const elemento of vetor.valores) {
|
|
196
|
-
texto += this.dicionarioConstrutos[elemento.constructor.name](elemento);
|
|
197
|
-
}
|
|
198
|
-
return texto;
|
|
199
|
-
}
|
|
200
|
-
logicaComumConexaoArestas(aresta) {
|
|
201
|
-
const vertices = [];
|
|
202
|
-
while (this.anteriores.length > 0) {
|
|
203
|
-
const anterior = this.anteriores.shift();
|
|
204
|
-
let textoVertice = undefined;
|
|
205
|
-
if (this.ultimaDicaVertice) {
|
|
206
|
-
textoVertice = String(this.ultimaDicaVertice);
|
|
207
|
-
this.ultimaDicaVertice = undefined;
|
|
208
|
-
}
|
|
209
|
-
vertices.push(new mermaid_1.VerticeFluxograma(anterior, aresta, textoVertice));
|
|
210
|
-
}
|
|
211
|
-
return vertices;
|
|
212
|
-
}
|
|
213
|
-
traduzirDeclaracaoBloco(declaracaoBloco) {
|
|
214
|
-
let vertices = [];
|
|
215
|
-
for (const declaracao of declaracaoBloco.declaracoes) {
|
|
216
|
-
const verticesDeclaracao = this.dicionarioDeclaracoes[declaracao.constructor.name](declaracao);
|
|
217
|
-
vertices = vertices.concat(verticesDeclaracao);
|
|
218
|
-
}
|
|
219
|
-
return vertices;
|
|
220
|
-
}
|
|
221
|
-
traduzirDeclaracaoClasse(declaracaoClasse) {
|
|
222
|
-
const nomeClasse = declaracaoClasse.simbolo.lexema;
|
|
223
|
-
const superClasse = declaracaoClasse.superClasse
|
|
224
|
-
? declaracaoClasse.superClasse.nome.lexema
|
|
225
|
-
: undefined;
|
|
226
|
-
// Cria o diagrama de classe
|
|
227
|
-
const diagramaClasse = new mermaid_1.DiagramaClasse(nomeClasse, superClasse);
|
|
228
|
-
// Adiciona métodos ao diagrama
|
|
229
|
-
if (declaracaoClasse.metodos && declaracaoClasse.metodos.length > 0) {
|
|
230
|
-
for (const metodo of declaracaoClasse.metodos) {
|
|
231
|
-
const parametros = [];
|
|
232
|
-
if (metodo.funcao.parametros && metodo.funcao.parametros.length > 0) {
|
|
233
|
-
for (const param of metodo.funcao.parametros) {
|
|
234
|
-
const nomeParam = param.nome.lexema;
|
|
235
|
-
const tipoParam = param.tipoDado || 'qualquer';
|
|
236
|
-
parametros.push(`${nomeParam}: ${tipoParam}`);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
const tipoRetorno = metodo.funcao.tipo;
|
|
240
|
-
diagramaClasse.metodos.push({
|
|
241
|
-
nome: metodo.simbolo.lexema,
|
|
242
|
-
parametros,
|
|
243
|
-
tipoRetorno
|
|
244
|
-
});
|
|
138
|
+
for (const anterior of this.anteriores) {
|
|
139
|
+
subgrafo.vertices.push(new mermaid_1.VerticeFluxograma(anterior, arestaFinal));
|
|
245
140
|
}
|
|
246
141
|
}
|
|
247
|
-
//
|
|
248
|
-
this.
|
|
249
|
-
//
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
this.anteriores.push(aresta);
|
|
254
|
-
return vertices;
|
|
255
|
-
}
|
|
256
|
-
traduzirDeclaracaoConst(declaracaoConst) {
|
|
257
|
-
let texto = `Linha${declaracaoConst.linha}(variável: ${declaracaoConst.simbolo.lexema}`;
|
|
258
|
-
texto += this.logicaComumTraducaoVarEConst(declaracaoConst, texto);
|
|
259
|
-
const aresta = new mermaid_1.ArestaFluxograma(declaracaoConst, texto);
|
|
260
|
-
const vertices = this.logicaComumConexaoArestas(aresta);
|
|
261
|
-
this.anteriores.push(aresta);
|
|
262
|
-
return vertices;
|
|
142
|
+
// Restaura o estado anterior
|
|
143
|
+
this.anteriores = anterioresAntes;
|
|
144
|
+
// Armazena o subgrafo
|
|
145
|
+
this.declaracoesFuncoes[nomeFuncao] = subgrafo;
|
|
146
|
+
// Não adiciona ao fluxo principal
|
|
147
|
+
return Promise.resolve([]);
|
|
263
148
|
}
|
|
264
|
-
|
|
265
|
-
let texto = `Linha${
|
|
266
|
-
const condicao =
|
|
149
|
+
async visitarDeclaracaoEnquanto(declaracao) {
|
|
150
|
+
let texto = `Linha${declaracao.linha}(enquanto `;
|
|
151
|
+
const condicao = await declaracao.condicao.aceitar(this);
|
|
267
152
|
texto += condicao + ')';
|
|
268
|
-
const aresta = new mermaid_1.ArestaFluxograma(
|
|
153
|
+
const aresta = new mermaid_1.ArestaFluxograma(declaracao, texto);
|
|
269
154
|
let vertices = this.logicaComumConexaoArestas(aresta);
|
|
270
155
|
this.anteriores.push(aresta);
|
|
271
156
|
// Corpo, normalmente um `Bloco`.
|
|
272
|
-
const verticesCorpo =
|
|
157
|
+
const verticesCorpo = await declaracao.corpo.aceitar(this);
|
|
273
158
|
vertices = vertices.concat(verticesCorpo);
|
|
274
159
|
const ultimaArestaCorpo = verticesCorpo[verticesCorpo.length - 1].destino;
|
|
275
160
|
const verticeLaco = new mermaid_1.VerticeFluxograma(ultimaArestaCorpo, aresta);
|
|
276
161
|
vertices.push(verticeLaco);
|
|
277
|
-
return vertices;
|
|
162
|
+
return Promise.resolve(vertices);
|
|
278
163
|
}
|
|
279
|
-
|
|
280
|
-
let
|
|
281
|
-
|
|
282
|
-
textoCaso = `caso ${textoIdentificadorOuLiteral} seja igual a `;
|
|
283
|
-
for (const condicao of caminhoEscolha.condicoes) {
|
|
284
|
-
const textoCondicao = this.dicionarioConstrutos[condicao.constructor.name](condicao);
|
|
285
|
-
textoCaso += `${textoCondicao} ou `;
|
|
286
|
-
}
|
|
287
|
-
textoCaso = textoCaso.slice(0, -4);
|
|
288
|
-
textoCaso += ':';
|
|
289
|
-
}
|
|
290
|
-
else {
|
|
291
|
-
textoCaso = `caso ${textoIdentificadorOuLiteral} tenha qualquer outro valor:`;
|
|
292
|
-
}
|
|
293
|
-
let textoCaminho = `Linha${linha}(${textoCaso})`;
|
|
294
|
-
const arestaCondicaoCaminho = new mermaid_1.ArestaFluxograma(declaracaoEscolha, textoCaminho);
|
|
295
|
-
this.anteriores.push(arestaCondicaoCaminho);
|
|
296
|
-
let verticesResolvidos = [];
|
|
297
|
-
for (const declaracaoCaminho of caminhoEscolha.declaracoes) {
|
|
298
|
-
const verticesDeclaracoes = this.dicionarioDeclaracoes[declaracaoCaminho.constructor.name](declaracaoCaminho);
|
|
299
|
-
verticesResolvidos = verticesResolvidos.concat(verticesDeclaracoes);
|
|
300
|
-
this.anteriores.pop();
|
|
301
|
-
this.anteriores.push(verticesDeclaracoes[verticesDeclaracoes.length - 1].destino);
|
|
302
|
-
}
|
|
303
|
-
this.anteriores.pop();
|
|
304
|
-
return {
|
|
305
|
-
caminho: arestaCondicaoCaminho,
|
|
306
|
-
declaracoesCaminho: verticesResolvidos,
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
traduzirDeclaracaoEscolha(declaracaoEscolha) {
|
|
310
|
-
let texto = `Linha${declaracaoEscolha.linha}(escolha um caminho pelo valor de `;
|
|
311
|
-
const textoIdentificadorOuLiteral = this.dicionarioConstrutos[declaracaoEscolha.identificadorOuLiteral.constructor.name](declaracaoEscolha.identificadorOuLiteral);
|
|
164
|
+
async visitarDeclaracaoEscolha(declaracao) {
|
|
165
|
+
let texto = `Linha${declaracao.linha}(escolha um caminho pelo valor de `;
|
|
166
|
+
const textoIdentificadorOuLiteral = await declaracao.identificadorOuLiteral.aceitar(this);
|
|
312
167
|
texto += textoIdentificadorOuLiteral + ')';
|
|
313
|
-
const aresta = new mermaid_1.ArestaFluxograma(
|
|
168
|
+
const aresta = new mermaid_1.ArestaFluxograma(declaracao, texto);
|
|
314
169
|
let vertices = this.logicaComumConexaoArestas(aresta);
|
|
315
170
|
const arestasCaminho = [];
|
|
316
|
-
for (const caminho of
|
|
317
|
-
arestasCaminho.push(this.logicaComumCaminhoEscolha(
|
|
171
|
+
for (const caminho of declaracao.caminhos) {
|
|
172
|
+
arestasCaminho.push(await this.logicaComumCaminhoEscolha(declaracao, caminho, caminho.condicoes[0].linha, textoIdentificadorOuLiteral, false));
|
|
318
173
|
}
|
|
319
|
-
if (
|
|
320
|
-
arestasCaminho.push(this.logicaComumCaminhoEscolha(
|
|
174
|
+
if (declaracao.caminhoPadrao) {
|
|
175
|
+
arestasCaminho.push(await this.logicaComumCaminhoEscolha(declaracao, declaracao.caminhoPadrao, declaracao.caminhoPadrao.declaracoes[0].linha - 1, textoIdentificadorOuLiteral, true));
|
|
321
176
|
}
|
|
322
177
|
for (const conjunto of Object.values(arestasCaminho)) {
|
|
323
178
|
const verticeEscolhaECaminho = new mermaid_1.VerticeFluxograma(aresta, conjunto.caminho);
|
|
@@ -325,101 +180,91 @@ class TradutorMermaidJs {
|
|
|
325
180
|
vertices = vertices.concat(conjunto.declaracoesCaminho);
|
|
326
181
|
this.anteriores.push(conjunto.declaracoesCaminho[conjunto.declaracoesCaminho.length - 1].destino);
|
|
327
182
|
}
|
|
328
|
-
return vertices;
|
|
183
|
+
return Promise.resolve(vertices);
|
|
329
184
|
}
|
|
330
|
-
|
|
331
|
-
let texto = `Linha${
|
|
332
|
-
for (const argumento of
|
|
333
|
-
const valor =
|
|
185
|
+
async visitarDeclaracaoEscreva(declaracao) {
|
|
186
|
+
let texto = `Linha${declaracao.linha}(escreva: `;
|
|
187
|
+
for (const argumento of declaracao.argumentos) {
|
|
188
|
+
const valor = await argumento.aceitar(this);
|
|
334
189
|
texto += valor + ', ';
|
|
335
190
|
}
|
|
336
191
|
texto = texto.slice(0, -2);
|
|
337
192
|
texto += ')';
|
|
338
|
-
const aresta = new mermaid_1.ArestaFluxograma(
|
|
193
|
+
const aresta = new mermaid_1.ArestaFluxograma(declaracao, texto);
|
|
339
194
|
const vertices = this.logicaComumConexaoArestas(aresta);
|
|
340
195
|
this.anteriores.push(aresta);
|
|
341
|
-
return vertices;
|
|
196
|
+
return Promise.resolve(vertices);
|
|
342
197
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
const textoConstruto = this.dicionarioConstrutos[declaracaoExpressao.expressao.constructor.name](declaracaoExpressao.expressao);
|
|
346
|
-
texto += textoConstruto + ')';
|
|
347
|
-
const aresta = new mermaid_1.ArestaFluxograma(declaracaoExpressao, texto);
|
|
348
|
-
const vertices = this.logicaComumConexaoArestas(aresta);
|
|
349
|
-
this.anteriores.push(aresta);
|
|
350
|
-
return vertices;
|
|
198
|
+
visitarDeclaracaoEscrevaMesmaLinha(declaracao) {
|
|
199
|
+
throw new Error('Método não implementado.');
|
|
351
200
|
}
|
|
352
|
-
|
|
353
|
-
const texto = `Linha${
|
|
354
|
-
const aresta = new mermaid_1.ArestaFluxograma(
|
|
201
|
+
async visitarDeclaracaoFazer(declaracao) {
|
|
202
|
+
const texto = `Linha${declaracao.linha}(fazer)`;
|
|
203
|
+
const aresta = new mermaid_1.ArestaFluxograma(declaracao, texto);
|
|
355
204
|
let vertices = this.logicaComumConexaoArestas(aresta);
|
|
356
205
|
this.anteriores.push(aresta);
|
|
357
206
|
// Corpo, normalmente um `Bloco`.
|
|
358
|
-
const verticesCorpo =
|
|
207
|
+
const verticesCorpo = await declaracao.caminhoFazer.aceitar(this);
|
|
359
208
|
vertices = vertices.concat(verticesCorpo);
|
|
360
209
|
const ultimaArestaCorpo = verticesCorpo[verticesCorpo.length - 1].destino;
|
|
361
|
-
const condicao =
|
|
362
|
-
let textoEnquanto = `Linha${
|
|
363
|
-
const arestaEnquanto = new mermaid_1.ArestaFluxograma(
|
|
210
|
+
const condicao = await declaracao.condicaoEnquanto.aceitar(this);
|
|
211
|
+
let textoEnquanto = `Linha${declaracao.condicaoEnquanto.linha}(enquanto ${condicao})`;
|
|
212
|
+
const arestaEnquanto = new mermaid_1.ArestaFluxograma(declaracao, textoEnquanto);
|
|
364
213
|
const verticeEnquanto = new mermaid_1.VerticeFluxograma(ultimaArestaCorpo, arestaEnquanto);
|
|
365
214
|
vertices.push(verticeEnquanto);
|
|
366
215
|
const verticeCondicaoComFazer = new mermaid_1.VerticeFluxograma(arestaEnquanto, aresta);
|
|
367
216
|
vertices.push(verticeCondicaoComFazer);
|
|
368
217
|
this.anteriores.pop();
|
|
369
218
|
this.anteriores.push(arestaEnquanto);
|
|
370
|
-
return vertices;
|
|
219
|
+
return Promise.resolve(vertices);
|
|
220
|
+
}
|
|
221
|
+
visitarDeclaracaoInicioAlgoritmo(declaracao) {
|
|
222
|
+
throw new Error('Método não implementado.');
|
|
371
223
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
// das declarações do corpo (via dicionarioDeclaracoes).
|
|
392
|
-
return [];
|
|
393
|
-
}
|
|
394
|
-
traduzirDeclaracaoPara(declaracaoPara) {
|
|
395
|
-
let texto = `Linha${declaracaoPara.linha}(para `;
|
|
396
|
-
if (declaracaoPara.inicializador) {
|
|
397
|
-
for (const declaracaoInicializadora of declaracaoPara.inicializador) {
|
|
224
|
+
async visitarDeclaracaoParaCada(declaracao) {
|
|
225
|
+
const textoVariavelIteracao = await declaracao.variavelIteracao.aceitar(this);
|
|
226
|
+
let texto = `Linha${declaracao.linha}(para cada ${textoVariavelIteracao} em `;
|
|
227
|
+
const textoVariavelIterada = await declaracao.vetorOuDicionario.aceitar(this);
|
|
228
|
+
texto += textoVariavelIterada + ')';
|
|
229
|
+
const aresta = new mermaid_1.ArestaFluxograma(declaracao, texto);
|
|
230
|
+
let vertices = this.logicaComumConexaoArestas(aresta);
|
|
231
|
+
this.anteriores.push(aresta);
|
|
232
|
+
// Corpo, normalmente um `Bloco`.
|
|
233
|
+
const verticesCorpo = await declaracao.corpo.aceitar(this);
|
|
234
|
+
vertices = vertices.concat(verticesCorpo);
|
|
235
|
+
const ultimaArestaCorpo = verticesCorpo[verticesCorpo.length - 1].destino;
|
|
236
|
+
vertices.push(new mermaid_1.VerticeFluxograma(ultimaArestaCorpo, aresta));
|
|
237
|
+
return Promise.resolve(vertices);
|
|
238
|
+
}
|
|
239
|
+
async visitarDeclaracaoPara(declaracao) {
|
|
240
|
+
let texto = `Linha${declaracao.linha}(para `;
|
|
241
|
+
if (declaracao.inicializador) {
|
|
242
|
+
for (const declaracaoInicializadora of declaracao.inicializador) {
|
|
398
243
|
// Normalmente é `Var`.
|
|
399
244
|
const declaracaoVar = declaracaoInicializadora;
|
|
400
|
-
const valorInicializacao =
|
|
245
|
+
const valorInicializacao = await declaracaoVar.inicializador.aceitar(this);
|
|
401
246
|
texto += `uma variável ${declaracaoVar.simbolo.lexema} inicializada com ${valorInicializacao}, `;
|
|
402
247
|
}
|
|
403
248
|
texto = texto.slice(0, -2);
|
|
404
249
|
}
|
|
405
250
|
texto += ')';
|
|
406
|
-
const aresta = new mermaid_1.ArestaFluxograma(
|
|
251
|
+
const aresta = new mermaid_1.ArestaFluxograma(declaracao, texto);
|
|
407
252
|
let vertices = this.logicaComumConexaoArestas(aresta);
|
|
408
253
|
this.anteriores.push(aresta);
|
|
409
254
|
// Condição
|
|
410
|
-
const textoCondicao =
|
|
411
|
-
const textoArestaCondicao = `Linha${
|
|
412
|
-
const arestaCondicao = new mermaid_1.ArestaFluxograma(
|
|
255
|
+
const textoCondicao = await declaracao.condicao.aceitar(this);
|
|
256
|
+
const textoArestaCondicao = `Linha${declaracao.linha}Condicao{se ${textoCondicao}}`;
|
|
257
|
+
const arestaCondicao = new mermaid_1.ArestaFluxograma(declaracao, textoArestaCondicao);
|
|
413
258
|
vertices = vertices.concat(this.logicaComumConexaoArestas(arestaCondicao));
|
|
414
259
|
this.anteriores.push(arestaCondicao);
|
|
415
260
|
this.ultimaDicaVertice = 'Sim';
|
|
416
261
|
// Corpo, normalmente um `Bloco`.
|
|
417
|
-
const verticesCorpo =
|
|
262
|
+
const verticesCorpo = await declaracao.corpo.aceitar(this);
|
|
418
263
|
vertices = vertices.concat(verticesCorpo);
|
|
419
264
|
// Incremento
|
|
420
265
|
const ultimaArestaCorpo = verticesCorpo[verticesCorpo.length - 1].destino;
|
|
421
|
-
const textoIncremento =
|
|
422
|
-
const arestaIncremento = new mermaid_1.ArestaFluxograma(
|
|
266
|
+
const textoIncremento = await declaracao.incrementar.aceitar(this);
|
|
267
|
+
const arestaIncremento = new mermaid_1.ArestaFluxograma(declaracao, `Linha${declaracao.linha}Incremento(${textoIncremento})`);
|
|
423
268
|
const verticeIncremento = new mermaid_1.VerticeFluxograma(ultimaArestaCorpo, arestaIncremento);
|
|
424
269
|
vertices.push(verticeIncremento);
|
|
425
270
|
const verticeLaco = new mermaid_1.VerticeFluxograma(arestaIncremento, arestaCondicao);
|
|
@@ -428,80 +273,364 @@ class TradutorMermaidJs {
|
|
|
428
273
|
this.anteriores.pop();
|
|
429
274
|
this.anteriores.push(arestaCondicao);
|
|
430
275
|
this.ultimaDicaVertice = 'Não';
|
|
431
|
-
return vertices;
|
|
276
|
+
return Promise.resolve(vertices);
|
|
432
277
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
const textoVariavelIterada = this.dicionarioConstrutos[declaracaoParaCada.vetorOuDicionario.constructor.name](declaracaoParaCada.vetorOuDicionario);
|
|
437
|
-
texto += textoVariavelIterada + ')';
|
|
438
|
-
const aresta = new mermaid_1.ArestaFluxograma(declaracaoParaCada, texto);
|
|
439
|
-
let vertices = this.logicaComumConexaoArestas(aresta);
|
|
440
|
-
this.anteriores.push(aresta);
|
|
441
|
-
// Corpo, normalmente um `Bloco`.
|
|
442
|
-
const verticesCorpo = this.dicionarioDeclaracoes[declaracaoParaCada.corpo.constructor.name](declaracaoParaCada.corpo);
|
|
443
|
-
vertices = vertices.concat(verticesCorpo);
|
|
444
|
-
const ultimaArestaCorpo = verticesCorpo[verticesCorpo.length - 1].destino;
|
|
445
|
-
vertices.push(new mermaid_1.VerticeFluxograma(ultimaArestaCorpo, aresta));
|
|
446
|
-
return vertices;
|
|
447
|
-
}
|
|
448
|
-
traduzirDeclaracaoSe(declaracaoSe) {
|
|
449
|
-
let texto = `Linha${declaracaoSe.linha}{se `;
|
|
450
|
-
const condicao = this.dicionarioConstrutos[declaracaoSe.condicao.constructor.name](declaracaoSe.condicao);
|
|
278
|
+
async visitarDeclaracaoSe(declaracao) {
|
|
279
|
+
let texto = `Linha${declaracao.linha}{se `;
|
|
280
|
+
const condicao = await declaracao.condicao.aceitar(this);
|
|
451
281
|
texto += condicao;
|
|
452
282
|
texto += `}`;
|
|
453
|
-
const aresta = new mermaid_1.ArestaFluxograma(
|
|
283
|
+
const aresta = new mermaid_1.ArestaFluxograma(declaracao, texto);
|
|
454
284
|
let vertices = this.logicaComumConexaoArestas(aresta);
|
|
455
285
|
this.anteriores.push(aresta);
|
|
456
286
|
this.ultimaDicaVertice = 'Sim';
|
|
457
287
|
// Caminho então, normalmente um `Bloco`.
|
|
458
|
-
const verticesEntao =
|
|
288
|
+
const verticesEntao = await declaracao.caminhoEntao.aceitar(this);
|
|
459
289
|
vertices = vertices.concat(verticesEntao);
|
|
460
290
|
const ultimaArestaEntao = verticesEntao[verticesEntao.length - 1].destino;
|
|
461
|
-
if (
|
|
291
|
+
if (declaracao.caminhoSenao) {
|
|
462
292
|
this.anteriores = [];
|
|
463
|
-
const arestaSenao = new mermaid_1.ArestaFluxograma(
|
|
293
|
+
const arestaSenao = new mermaid_1.ArestaFluxograma(declaracao, `Linha${declaracao.caminhoSenao.linha}(senão)`);
|
|
464
294
|
vertices.push(new mermaid_1.VerticeFluxograma(aresta, arestaSenao, 'Não'));
|
|
465
295
|
this.anteriores.push(arestaSenao);
|
|
466
|
-
const verticesSenao =
|
|
296
|
+
const verticesSenao = await declaracao.caminhoSenao.aceitar(this);
|
|
467
297
|
vertices = vertices.concat(verticesSenao);
|
|
468
298
|
}
|
|
469
299
|
this.anteriores.push(ultimaArestaEntao);
|
|
470
|
-
return vertices;
|
|
300
|
+
return Promise.resolve(vertices);
|
|
471
301
|
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
302
|
+
async visitarDeclaracaoTendoComo(declaracao) {
|
|
303
|
+
const textoVariavelIteracao = await declaracao.inicializacaoVariavel.aceitar(this);
|
|
304
|
+
let texto = `Linha${declaracao.linha}(tendo ${textoVariavelIteracao} como `;
|
|
305
|
+
texto += declaracao.simboloVariavel.lexema + ')';
|
|
306
|
+
const aresta = new mermaid_1.ArestaFluxograma(declaracao, texto);
|
|
307
|
+
let vertices = this.logicaComumConexaoArestas(aresta);
|
|
308
|
+
this.anteriores.push(aresta);
|
|
309
|
+
// Corpo, normalmente um `Bloco`.
|
|
310
|
+
const verticesCorpo = await declaracao.corpo.aceitar(this);
|
|
311
|
+
vertices = vertices.concat(verticesCorpo);
|
|
312
|
+
const ultimaArestaCorpo = verticesCorpo[verticesCorpo.length - 1].destino;
|
|
313
|
+
vertices.push(new mermaid_1.VerticeFluxograma(ultimaArestaCorpo, aresta));
|
|
314
|
+
return Promise.resolve(vertices);
|
|
315
|
+
}
|
|
316
|
+
visitarDeclaracaoTente(declaracao) {
|
|
317
|
+
throw new Error('Método não implementado.');
|
|
318
|
+
}
|
|
319
|
+
visitarDeclaracaoTextoDocumentacao(declaracao) {
|
|
320
|
+
throw new Error('Método não implementado.');
|
|
321
|
+
}
|
|
322
|
+
async visitarDeclaracaoVar(declaracao) {
|
|
323
|
+
let texto = `Linha${declaracao.linha}(variável: ${declaracao.simbolo.lexema}`;
|
|
324
|
+
texto += await this.logicaComumTraducaoVarEConst(declaracao, texto);
|
|
325
|
+
const aresta = new mermaid_1.ArestaFluxograma(declaracao, texto);
|
|
326
|
+
const vertices = this.logicaComumConexaoArestas(aresta);
|
|
327
|
+
this.anteriores.push(aresta);
|
|
328
|
+
return Promise.resolve(vertices);
|
|
329
|
+
}
|
|
330
|
+
visitarDeclaracaoVarMultiplo(declaracao) {
|
|
331
|
+
throw new Error('Método não implementado.');
|
|
332
|
+
}
|
|
333
|
+
async visitarExpressaoDeAtribuicao(expressao) {
|
|
334
|
+
const textoAlvo = await expressao.alvo.aceitar(this);
|
|
335
|
+
const textoValor = await expressao.valor.aceitar(this);
|
|
336
|
+
return Promise.resolve(`${textoAlvo} recebe: ${textoValor}`);
|
|
337
|
+
}
|
|
338
|
+
async visitarExpressaoAcessoIndiceVariavel(expressao) {
|
|
339
|
+
const textoIndice = await expressao.indice.aceitar(this);
|
|
340
|
+
return Promise.resolve(`no índice ${textoIndice}`);
|
|
341
|
+
}
|
|
342
|
+
visitarExpressaoAcessoIntervaloVariavel(expressao) {
|
|
343
|
+
throw new Error('Método não implementado.');
|
|
344
|
+
}
|
|
345
|
+
visitarExpressaoAcessoElementoMatriz(expressao) {
|
|
346
|
+
throw new Error('Método não implementado.');
|
|
347
|
+
}
|
|
348
|
+
async visitarExpressaoAcessoMetodo(expressao) {
|
|
349
|
+
return Promise.resolve(`método ${expressao.nomeMetodo}`);
|
|
350
|
+
}
|
|
351
|
+
async visitarExpressaoAcessoMetodoOuPropriedade(expressao) {
|
|
352
|
+
return Promise.resolve(`método ou propriedade ${expressao.simbolo.lexema}`);
|
|
353
|
+
}
|
|
354
|
+
async visitarExpressaoAcessoPropriedade(expressao) {
|
|
355
|
+
return Promise.resolve(`propriedade ${expressao.nomePropriedade}`);
|
|
356
|
+
}
|
|
357
|
+
async visitarExpressaoAgrupamento(expressao) {
|
|
358
|
+
return await expressao.expressao.aceitar(this);
|
|
359
|
+
}
|
|
360
|
+
visitarExpressaoArgumentoReferenciaFuncao(expressao) {
|
|
361
|
+
throw new Error('Método não implementado.');
|
|
362
|
+
}
|
|
363
|
+
visitarExpressaoAtribuicaoPorIndice(expressao) {
|
|
364
|
+
throw new Error('Método não implementado.');
|
|
365
|
+
}
|
|
366
|
+
visitarExpressaoAtribuicaoPorIndicesMatriz(expressao) {
|
|
367
|
+
throw new Error('Método não implementado.');
|
|
368
|
+
}
|
|
369
|
+
async visitarExpressaoBinaria(expressao) {
|
|
370
|
+
const operandoEsquerdo = await expressao.esquerda.aceitar(this);
|
|
371
|
+
const operandoDireito = await expressao.direita.aceitar(this);
|
|
372
|
+
switch (expressao.operador.tipo) {
|
|
373
|
+
case delegua_1.default.ADICAO:
|
|
374
|
+
return Promise.resolve(`somar ${operandoEsquerdo} e ${operandoDireito}`);
|
|
375
|
+
case delegua_1.default.MENOR:
|
|
376
|
+
return Promise.resolve(`${operandoEsquerdo} for menor que ${operandoDireito}`);
|
|
475
377
|
}
|
|
476
|
-
|
|
477
|
-
|
|
378
|
+
return Promise.resolve('');
|
|
379
|
+
}
|
|
380
|
+
async visitarExpressaoBloco(bloco) {
|
|
381
|
+
let vertices = [];
|
|
382
|
+
for (const declaracao of bloco.declaracoes) {
|
|
383
|
+
const verticesDeclaracao = await declaracao.aceitar(this);
|
|
384
|
+
vertices = vertices.concat(verticesDeclaracao);
|
|
385
|
+
}
|
|
386
|
+
return Promise.resolve(vertices);
|
|
387
|
+
}
|
|
388
|
+
async visitarExpressaoComentario(expressao) {
|
|
389
|
+
return Promise.resolve('');
|
|
390
|
+
}
|
|
391
|
+
visitarExpressaoContinua(declaracao) {
|
|
392
|
+
throw new Error('Método não implementado.');
|
|
393
|
+
}
|
|
394
|
+
async visitarExpressaoDeChamada(expressao) {
|
|
395
|
+
const textoEntidadeChamada = await expressao.entidadeChamada.aceitar(this);
|
|
396
|
+
let texto = `chamada a ${textoEntidadeChamada}`;
|
|
397
|
+
if (expressao.argumentos.length > 0) {
|
|
398
|
+
texto += `, com argumentos: `;
|
|
399
|
+
for (const argumento of expressao.argumentos) {
|
|
400
|
+
const textoArgumento = await argumento.aceitar(this);
|
|
401
|
+
texto += `${textoArgumento}, `;
|
|
402
|
+
}
|
|
403
|
+
texto = texto.slice(0, -2);
|
|
404
|
+
}
|
|
405
|
+
else {
|
|
406
|
+
texto += `, sem argumentos`;
|
|
407
|
+
}
|
|
408
|
+
return Promise.resolve(texto);
|
|
409
|
+
}
|
|
410
|
+
async visitarExpressaoDefinirValor(expressao) {
|
|
411
|
+
const textoObjeto = await expressao.objeto.aceitar(this);
|
|
412
|
+
const textoValor = await expressao.valor.aceitar(this);
|
|
413
|
+
return Promise.resolve(`${expressao.nome.lexema} em ${textoObjeto} recebe ${textoValor}`);
|
|
414
|
+
}
|
|
415
|
+
visitarExpressaoFuncaoConstruto(expressao) {
|
|
416
|
+
throw new Error('Método não implementado.');
|
|
417
|
+
}
|
|
418
|
+
async visitarExpressaoDeVariavel(expressao) {
|
|
419
|
+
return Promise.resolve(expressao.simbolo.lexema);
|
|
420
|
+
}
|
|
421
|
+
async visitarExpressaoDicionario(expressao) {
|
|
422
|
+
let texto = `dicionário`;
|
|
423
|
+
if (expressao.chaves.length > 0) {
|
|
424
|
+
texto += `, com `;
|
|
425
|
+
for (const [chave, indice] of Object.entries(expressao.chaves)) {
|
|
426
|
+
texto += `chave ${chave} definida com o valor ${expressao.valores[0]}`;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
texto += ' vazio';
|
|
431
|
+
}
|
|
432
|
+
return Promise.resolve(texto);
|
|
433
|
+
}
|
|
434
|
+
visitarExpressaoExpressaoRegular(expressao) {
|
|
435
|
+
throw new Error('Método não implementado.');
|
|
436
|
+
}
|
|
437
|
+
visitarExpressaoFalhar(expressao) {
|
|
438
|
+
throw new Error('Método não implementado.');
|
|
439
|
+
}
|
|
440
|
+
visitarExpressaoFimPara(declaracao) {
|
|
441
|
+
throw new Error('Método não implementado.');
|
|
442
|
+
}
|
|
443
|
+
visitarExpressaoFormatacaoEscrita(declaracao) {
|
|
444
|
+
throw new Error('Método não implementado.');
|
|
445
|
+
}
|
|
446
|
+
async visitarExpressaoIsto(expressao) {
|
|
447
|
+
return Promise.resolve('this');
|
|
448
|
+
}
|
|
449
|
+
async visitarExpressaoLeia(expressao) {
|
|
450
|
+
let texto = 'leia da entrada';
|
|
451
|
+
if (expressao.argumentos && expressao.argumentos.length > 0) {
|
|
452
|
+
const textoArgumento = await expressao.argumentos[0].aceitar(this);
|
|
453
|
+
texto += `, imprimindo antes: \\'${textoArgumento}\\'`;
|
|
454
|
+
}
|
|
455
|
+
return Promise.resolve(texto);
|
|
456
|
+
}
|
|
457
|
+
async visitarExpressaoLiteral(expressao) {
|
|
458
|
+
switch (expressao.tipo) {
|
|
459
|
+
case 'lógico':
|
|
460
|
+
return Promise.resolve(expressao.valor ? 'verdadeiro' : 'falso');
|
|
461
|
+
case 'texto':
|
|
462
|
+
return Promise.resolve(`\\'${expressao.valor}\\'`);
|
|
463
|
+
default:
|
|
464
|
+
return Promise.resolve(String(expressao.valor));
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
visitarExpressaoLogica(expressao) {
|
|
468
|
+
throw new Error('Método não implementado.');
|
|
469
|
+
}
|
|
470
|
+
visitarExpressaoReferenciaFuncao(expressao) {
|
|
471
|
+
throw new Error('Método não implementado.');
|
|
478
472
|
}
|
|
479
|
-
|
|
480
|
-
let texto = `Linha${
|
|
481
|
-
|
|
482
|
-
|
|
473
|
+
async visitarExpressaoRetornar(expressao) {
|
|
474
|
+
let texto = `Linha${expressao.linha}(retorna`;
|
|
475
|
+
if (expressao.valor) {
|
|
476
|
+
texto += `: ${await expressao.valor.aceitar(this)}`;
|
|
477
|
+
}
|
|
478
|
+
texto += ')';
|
|
479
|
+
const aresta = new mermaid_1.ArestaFluxograma(expressao, texto);
|
|
483
480
|
const vertices = this.logicaComumConexaoArestas(aresta);
|
|
484
481
|
this.anteriores.push(aresta);
|
|
482
|
+
return Promise.resolve(vertices);
|
|
483
|
+
}
|
|
484
|
+
async visitarExpressaoSeparador(expressao) {
|
|
485
|
+
return Promise.resolve(`${expressao.conteudo} `);
|
|
486
|
+
}
|
|
487
|
+
visitarExpressaoSuper(expressao) {
|
|
488
|
+
throw new Error('Método não implementado.');
|
|
489
|
+
}
|
|
490
|
+
visitarExpressaoSustar(declaracao) {
|
|
491
|
+
throw new Error('Método não implementado.');
|
|
492
|
+
}
|
|
493
|
+
visitarExpressaoTupla(expressao) {
|
|
494
|
+
throw new Error('Método não implementado.');
|
|
495
|
+
}
|
|
496
|
+
visitarExpressaoTuplaN(expressao) {
|
|
497
|
+
throw new Error('Método não implementado.');
|
|
498
|
+
}
|
|
499
|
+
visitarExpressaoTipoDe(expressao) {
|
|
500
|
+
throw new Error('Método não implementado.');
|
|
501
|
+
}
|
|
502
|
+
async visitarExpressaoUnaria(expressao) {
|
|
503
|
+
const textoOperando = await expressao.operando.aceitar(this);
|
|
504
|
+
let textoOperador = '';
|
|
505
|
+
switch (expressao.operador.tipo) {
|
|
506
|
+
case delegua_1.default.INCREMENTAR:
|
|
507
|
+
textoOperador = `incrementar ${textoOperando} em 1`;
|
|
508
|
+
break;
|
|
509
|
+
case delegua_1.default.DECREMENTAR:
|
|
510
|
+
textoOperador = `decrementar ${textoOperando} de 1`;
|
|
511
|
+
break;
|
|
512
|
+
}
|
|
513
|
+
switch (expressao.incidenciaOperador) {
|
|
514
|
+
case 'ANTES':
|
|
515
|
+
return Promise.resolve(`${textoOperador}, devolver valor de ${textoOperando}`);
|
|
516
|
+
case 'DEPOIS':
|
|
517
|
+
return Promise.resolve(`devolver valor de ${textoOperando}, ${textoOperador}`);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
async visitarExpressaoVetor(expressao) {
|
|
521
|
+
let texto = `vetor: `;
|
|
522
|
+
for (const elemento of expressao.valores) {
|
|
523
|
+
texto += await elemento.aceitar(this);
|
|
524
|
+
}
|
|
525
|
+
return Promise.resolve(texto);
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Traduz uma declaração de Expressao que contém uma chamada de função,
|
|
529
|
+
* criando os vértices necessários para conectar ao subgrafo da função.
|
|
530
|
+
*/
|
|
531
|
+
async traduzirChamadaFuncao(declaracaoExpressao, chamada) {
|
|
532
|
+
// Verifica se é uma chamada a uma função conhecida
|
|
533
|
+
if (chamada.entidadeChamada.constructor.name === 'Variavel') {
|
|
534
|
+
const variavel = chamada.entidadeChamada;
|
|
535
|
+
const nomeFuncao = variavel.simbolo.lexema;
|
|
536
|
+
if (this.declaracoesFuncoes[nomeFuncao]) {
|
|
537
|
+
const subgrafo = this.declaracoesFuncoes[nomeFuncao];
|
|
538
|
+
let vertices = [];
|
|
539
|
+
// Conecta do fluxo atual para a entrada da função
|
|
540
|
+
const textoPreChamada = `Linha${declaracaoExpressao.linha}(${await chamada.aceitar(this)})`;
|
|
541
|
+
const arestaPreChamada = new mermaid_1.ArestaFluxograma(declaracaoExpressao, textoPreChamada);
|
|
542
|
+
vertices = vertices.concat(this.logicaComumConexaoArestas(arestaPreChamada));
|
|
543
|
+
// Conecta a pré-chamada ao início da função
|
|
544
|
+
vertices.push(new mermaid_1.VerticeFluxograma(arestaPreChamada, subgrafo.arestaInicial));
|
|
545
|
+
// A saída da função volta para o fluxo principal
|
|
546
|
+
this.anteriores = [subgrafo.arestaFinal];
|
|
547
|
+
return Promise.resolve(vertices);
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
// Se não for uma função conhecida, trata como expressão normal
|
|
551
|
+
return Promise.resolve([]);
|
|
552
|
+
}
|
|
553
|
+
logicaComumConexaoArestas(aresta) {
|
|
554
|
+
const vertices = [];
|
|
555
|
+
while (this.anteriores.length > 0) {
|
|
556
|
+
const anterior = this.anteriores.shift();
|
|
557
|
+
let textoVertice = undefined;
|
|
558
|
+
if (this.ultimaDicaVertice) {
|
|
559
|
+
textoVertice = String(this.ultimaDicaVertice);
|
|
560
|
+
this.ultimaDicaVertice = undefined;
|
|
561
|
+
}
|
|
562
|
+
vertices.push(new mermaid_1.VerticeFluxograma(anterior, aresta, textoVertice));
|
|
563
|
+
}
|
|
485
564
|
return vertices;
|
|
486
565
|
}
|
|
566
|
+
async logicaComumCaminhoEscolha(declaracaoEscolha, caminhoEscolha, linha, textoIdentificadorOuLiteral, caminhoPadrao) {
|
|
567
|
+
let textoCaso = '';
|
|
568
|
+
if (!caminhoPadrao) {
|
|
569
|
+
textoCaso = `caso ${textoIdentificadorOuLiteral} seja igual a `;
|
|
570
|
+
for (const condicao of caminhoEscolha.condicoes) {
|
|
571
|
+
const textoCondicao = await condicao.aceitar(this);
|
|
572
|
+
textoCaso += `${textoCondicao} ou `;
|
|
573
|
+
}
|
|
574
|
+
textoCaso = textoCaso.slice(0, -4);
|
|
575
|
+
textoCaso += ':';
|
|
576
|
+
}
|
|
577
|
+
else {
|
|
578
|
+
textoCaso = `caso ${textoIdentificadorOuLiteral} tenha qualquer outro valor:`;
|
|
579
|
+
}
|
|
580
|
+
let textoCaminho = `Linha${linha}(${textoCaso})`;
|
|
581
|
+
const arestaCondicaoCaminho = new mermaid_1.ArestaFluxograma(declaracaoEscolha, textoCaminho);
|
|
582
|
+
this.anteriores.push(arestaCondicaoCaminho);
|
|
583
|
+
let verticesResolvidos = [];
|
|
584
|
+
for (const declaracaoCaminho of caminhoEscolha.declaracoes) {
|
|
585
|
+
const verticesDeclaracoes = await declaracaoCaminho.aceitar(this);
|
|
586
|
+
verticesResolvidos = verticesResolvidos.concat(verticesDeclaracoes);
|
|
587
|
+
this.anteriores.pop();
|
|
588
|
+
this.anteriores.push(verticesDeclaracoes[verticesDeclaracoes.length - 1].destino);
|
|
589
|
+
}
|
|
590
|
+
this.anteriores.pop();
|
|
591
|
+
return Promise.resolve({
|
|
592
|
+
caminho: arestaCondicaoCaminho,
|
|
593
|
+
declaracoesCaminho: verticesResolvidos,
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
async logicaComumTraducaoVarEConst(declaracaoVarOuConst, textoInicial) {
|
|
597
|
+
if (declaracaoVarOuConst.inicializador) {
|
|
598
|
+
textoInicial += `, iniciada com: ${await declaracaoVarOuConst.inicializador.aceitar(this)}`;
|
|
599
|
+
}
|
|
600
|
+
textoInicial += ')';
|
|
601
|
+
return Promise.resolve(textoInicial);
|
|
602
|
+
}
|
|
487
603
|
/**
|
|
488
604
|
* Ponto de entrada para a tradução de declarações em um fluxograma
|
|
489
605
|
* no formato MermaidJs.
|
|
490
606
|
* @param {Declaracao[]} declaracoes As declarações a serem traduzidas.
|
|
491
607
|
* @returns {string} Texto no formato MermaidJs representando o fluxograma.
|
|
492
608
|
*/
|
|
493
|
-
traduzir(declaracoes) {
|
|
609
|
+
async traduzir(declaracoes) {
|
|
494
610
|
this.anteriores = [];
|
|
495
611
|
this.vertices = [];
|
|
496
612
|
let resultado = 'graph TD;\n';
|
|
497
613
|
this.indentacaoAtual = 4;
|
|
498
|
-
this.
|
|
614
|
+
this.declaracoesFuncoes = {};
|
|
615
|
+
this.declaracoesClasses = {};
|
|
499
616
|
for (const declaracao of declaracoes) {
|
|
500
|
-
this.vertices = this.vertices.concat(
|
|
617
|
+
this.vertices = this.vertices.concat(await declaracao.aceitar(this));
|
|
618
|
+
}
|
|
619
|
+
// Renderiza os subgrafos de funções
|
|
620
|
+
if (Object.keys(this.declaracoesFuncoes).length > 0) {
|
|
621
|
+
for (const [nomeFuncao, subgrafo] of Object.entries(this.declaracoesFuncoes)) {
|
|
622
|
+
resultado += ` subgraph ${nomeFuncao}["Função: ${nomeFuncao}()"]\n`;
|
|
623
|
+
// Renderiza os vértices da função
|
|
624
|
+
for (const vertice of subgrafo.vertices) {
|
|
625
|
+
resultado += ' ' + vertice.paraTexto();
|
|
626
|
+
}
|
|
627
|
+
resultado += ` end\n`;
|
|
628
|
+
}
|
|
501
629
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
630
|
+
// Renderiza os subgrafos de classes
|
|
631
|
+
if (Object.keys(this.declaracoesClasses).length > 0) {
|
|
632
|
+
for (const [nomeClasse, subgrafo] of Object.entries(this.declaracoesClasses)) {
|
|
633
|
+
resultado += subgrafo.paraTexto();
|
|
505
634
|
}
|
|
506
635
|
}
|
|
507
636
|
if (this.vertices.length === 0 && this.anteriores.length === 0) {
|