@designliquido/delegua 1.11.0 → 1.11.1
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/analisador-semantico-base.d.ts +2 -2
- package/analisador-semantico/analisador-semantico-base.d.ts.map +1 -1
- package/analisador-semantico/analisador-semantico-base.js +14 -6
- package/analisador-semantico/analisador-semantico-base.js.map +1 -1
- package/analisador-semantico/analisador-semantico.d.ts.map +1 -1
- package/analisador-semantico/analisador-semantico.js +38 -19
- package/analisador-semantico/analisador-semantico.js.map +1 -1
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.d.ts.map +1 -1
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.js +41 -18
- package/analisador-semantico/dialetos/analisador-semantico-pitugues.js.map +1 -1
- package/analisador-semantico/funcao-hipotetica-interface.d.ts +1 -1
- package/analisador-semantico/gerenciador-escopos.d.ts +1 -1
- package/analisador-semantico/pilha-variaveis.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico-base.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico-base.js.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/avaliador-sintatico.js +80 -36
- package/avaliador-sintatico/avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/comum.d.ts.map +1 -1
- package/avaliador-sintatico/comum.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-calango.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-calango.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-egua-classico.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-guarani.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-guarani.js +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-guarani.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js +59 -49
- package/avaliador-sintatico/dialetos/avaliador-sintatico-pitugues.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.js +4 -4
- package/avaliador-sintatico/dialetos/avaliador-sintatico-prisma.js.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-tenda.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-tenda.js +1 -1
- package/avaliador-sintatico/dialetos/avaliador-sintatico-tenda.js.map +1 -1
- package/avaliador-sintatico/dialetos/micro-avaliador-sintatico-pitugues.d.ts.map +1 -1
- package/avaliador-sintatico/dialetos/micro-avaliador-sintatico-pitugues.js.map +1 -1
- package/avaliador-sintatico/erro-avaliador-sintatico.d.ts +18 -0
- package/avaliador-sintatico/erro-avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/erro-avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/micro-avaliador-sintatico.d.ts.map +1 -1
- package/avaliador-sintatico/micro-avaliador-sintatico.js.map +1 -1
- package/avaliador-sintatico/traducao/avaliador-sintatico-javascript.d.ts.map +1 -1
- package/avaliador-sintatico/traducao/avaliador-sintatico-javascript.js.map +1 -1
- package/bibliotecas/biblioteca-global.d.ts.map +1 -1
- package/bibliotecas/biblioteca-global.js +93 -31
- package/bibliotecas/biblioteca-global.js.map +1 -1
- package/bibliotecas/dialetos/pitugues/biblioteca-global.d.ts.map +1 -1
- package/bibliotecas/dialetos/pitugues/biblioteca-global.js +12 -8
- package/bibliotecas/dialetos/pitugues/biblioteca-global.js.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-dicionario.d.ts.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-dicionario.js.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-numero.d.ts.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-numero.js.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-texto.d.ts.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-texto.js.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-tupla.d.ts.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-tupla.js +3 -4
- package/bibliotecas/dialetos/pitugues/primitivas-tupla.js.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-vetor.d.ts.map +1 -1
- package/bibliotecas/dialetos/pitugues/primitivas-vetor.js +9 -11
- package/bibliotecas/dialetos/pitugues/primitivas-vetor.js.map +1 -1
- package/bibliotecas/primitivas-dicionario.d.ts.map +1 -1
- package/bibliotecas/primitivas-dicionario.js +1 -1
- package/bibliotecas/primitivas-dicionario.js.map +1 -1
- package/bibliotecas/primitivas-numero.d.ts.map +1 -1
- package/bibliotecas/primitivas-numero.js.map +1 -1
- package/bibliotecas/primitivas-texto.d.ts.map +1 -1
- package/bibliotecas/primitivas-texto.js +1 -1
- package/bibliotecas/primitivas-texto.js.map +1 -1
- package/bibliotecas/primitivas-tupla.d.ts.map +1 -1
- package/bibliotecas/primitivas-tupla.js +34 -14
- package/bibliotecas/primitivas-tupla.js.map +1 -1
- package/bibliotecas/primitivas-vetor.d.ts.map +1 -1
- package/bibliotecas/primitivas-vetor.js +1 -1
- package/bibliotecas/primitivas-vetor.js.map +1 -1
- package/bin/package.json +1 -1
- package/construtos/ajuda-como-construto.d.ts +2 -2
- package/construtos/ajuda-como-construto.js +1 -1
- package/construtos/atribuir.d.ts.map +1 -1
- package/construtos/atribuir.js +5 -2
- package/construtos/atribuir.js.map +1 -1
- package/construtos/binario.d.ts.map +1 -1
- package/construtos/binario.js +1 -2
- package/construtos/binario.js.map +1 -1
- package/construtos/comentario-como-construto.d.ts.map +1 -1
- package/construtos/comentario-como-construto.js.map +1 -1
- package/construtos/decorador.d.ts.map +1 -1
- package/construtos/decorador.js +3 -1
- package/construtos/decorador.js.map +1 -1
- package/construtos/dicionario.d.ts.map +1 -1
- package/construtos/dicionario.js.map +1 -1
- package/construtos/tupla-n.d.ts +3 -3
- package/construtos/tupla-n.d.ts.map +1 -1
- package/construtos/tupla-n.js +4 -2
- package/construtos/tupla-n.js.map +1 -1
- package/declaracoes/ajuda.d.ts +3 -3
- package/declaracoes/interface.d.ts.map +1 -1
- package/declaracoes/interface.js.map +1 -1
- package/declaracoes/texto-documentacao.d.ts.map +1 -1
- package/declaracoes/texto-documentacao.js.map +1 -1
- package/estilizador/estilizador-delegua.d.ts.map +1 -1
- package/estilizador/estilizador-delegua.js +5 -1
- package/estilizador/estilizador-delegua.js.map +1 -1
- package/formatadores/formatador-delegua.d.ts.map +1 -1
- package/formatadores/formatador-delegua.js.map +1 -1
- package/formatadores/formatador-pitugues.d.ts.map +1 -1
- package/formatadores/formatador-pitugues.js +74 -29
- package/formatadores/formatador-pitugues.js.map +1 -1
- package/geracao-identificadores/index.js +2 -2
- package/geracao-identificadores/index.js.map +1 -1
- package/interfaces/componente-modulo-classe-interface.d.ts.map +1 -1
- package/interfaces/componente-modulo-funcao-interface.d.ts.map +1 -1
- package/interfaces/interpretador-com-depuracao-interface.d.ts.map +1 -1
- package/interfaces/modulo-interface.d.ts +2 -2
- package/interfaces/modulo-interface.d.ts.map +1 -1
- package/interfaces/visitante-comum-interface.d.ts.map +1 -1
- package/interpretador/comum.d.ts.map +1 -1
- package/interpretador/comum.js +55 -55
- package/interpretador/comum.js.map +1 -1
- package/interpretador/depuracao/avaliador-expressao-depuracao.d.ts.map +1 -1
- package/interpretador/depuracao/avaliador-expressao-depuracao.js.map +1 -1
- package/interpretador/depuracao/comum.d.ts.map +1 -1
- package/interpretador/depuracao/comum.js +8 -4
- package/interpretador/depuracao/comum.js.map +1 -1
- package/interpretador/dialetos/egua-classico/interpretador-egua-classico.d.ts.map +1 -1
- package/interpretador/dialetos/egua-classico/interpretador-egua-classico.js +1 -3
- package/interpretador/dialetos/egua-classico/interpretador-egua-classico.js.map +1 -1
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.d.ts.map +1 -1
- package/interpretador/dialetos/egua-classico/resolvedor/resolvedor.js.map +1 -1
- package/interpretador/dialetos/pitugues/comum.d.ts +2 -2
- package/interpretador/dialetos/pitugues/comum.d.ts.map +1 -1
- package/interpretador/dialetos/pitugues/comum.js +2 -3
- package/interpretador/dialetos/pitugues/comum.js.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues-com-depuracao.d.ts +2 -2
- package/interpretador/dialetos/pitugues/interpretador-pitugues-com-depuracao.d.ts.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues-com-depuracao.js +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues-com-depuracao.js.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues.d.ts +3 -3
- package/interpretador/dialetos/pitugues/interpretador-pitugues.d.ts.map +1 -1
- package/interpretador/dialetos/pitugues/interpretador-pitugues.js +3 -2
- package/interpretador/dialetos/pitugues/interpretador-pitugues.js.map +1 -1
- package/interpretador/dialetos/portugol-ipt/interpretador-portugol-ipt.d.ts.map +1 -1
- package/interpretador/dialetos/portugol-ipt/interpretador-portugol-ipt.js.map +1 -1
- package/interpretador/estruturas/classe-de-modulo.d.ts.map +1 -1
- package/interpretador/estruturas/delegua-funcao.d.ts.map +1 -1
- package/interpretador/estruturas/delegua-funcao.js +3 -1
- package/interpretador/estruturas/delegua-funcao.js.map +1 -1
- package/interpretador/estruturas/descritor-tipo-classe.d.ts.map +1 -1
- package/interpretador/estruturas/descritor-tipo-classe.js +6 -6
- package/interpretador/estruturas/descritor-tipo-classe.js.map +1 -1
- package/interpretador/estruturas/metodo-polimorfico.d.ts.map +1 -1
- package/interpretador/estruturas/metodo-polimorfico.js +13 -9
- package/interpretador/estruturas/metodo-polimorfico.js.map +1 -1
- package/interpretador/estruturas/metodo-primitiva.d.ts.map +1 -1
- package/interpretador/estruturas/metodo-primitiva.js.map +1 -1
- package/interpretador/estruturas/objeto-base.d.ts.map +1 -1
- package/interpretador/estruturas/objeto-base.js.map +1 -1
- package/interpretador/estruturas/objeto-delegua-classe.d.ts.map +1 -1
- package/interpretador/estruturas/objeto-delegua-classe.js +10 -6
- package/interpretador/estruturas/objeto-delegua-classe.js.map +1 -1
- package/interpretador/interpretador-base.d.ts +4 -4
- package/interpretador/interpretador-base.d.ts.map +1 -1
- package/interpretador/interpretador-base.js +121 -50
- package/interpretador/interpretador-base.js.map +1 -1
- package/interpretador/interpretador.d.ts.map +1 -1
- package/interpretador/interpretador.js +14 -13
- package/interpretador/interpretador.js.map +1 -1
- package/interpretador/pilha-escopos-execucao.d.ts.map +1 -1
- package/interpretador/pilha-escopos-execucao.js.map +1 -1
- package/lexador/dialetos/lexador-calango.d.ts.map +1 -1
- package/lexador/dialetos/lexador-calango.js.map +1 -1
- package/lexador/dialetos/lexador-egua-classico.d.ts.map +1 -1
- package/lexador/dialetos/lexador-egua-classico.js.map +1 -1
- package/lexador/dialetos/lexador-pitugues.d.ts.map +1 -1
- package/lexador/dialetos/lexador-pitugues.js +3 -1
- package/lexador/dialetos/lexador-pitugues.js.map +1 -1
- package/lexador/dialetos/lexador-portugol-ipt.d.ts.map +1 -1
- package/lexador/dialetos/lexador-portugol-ipt.js.map +1 -1
- package/lexador/dialetos/lexador-prisma.d.ts.map +1 -1
- package/lexador/dialetos/lexador-prisma.js +25 -3
- package/lexador/dialetos/lexador-prisma.js.map +1 -1
- package/lexador/dialetos/lexador-tenda.d.ts.map +1 -1
- package/lexador/dialetos/lexador-tenda.js.map +1 -1
- package/lexador/filtro-paradigma.d.ts.map +1 -1
- package/lexador/filtro-paradigma.js.map +1 -1
- package/lexador/lexador-base-linha-unica.d.ts.map +1 -1
- package/lexador/lexador-base-linha-unica.js.map +1 -1
- package/lexador/lexador-base.d.ts.map +1 -1
- package/lexador/lexador-base.js.map +1 -1
- package/lexador/lexador.d.ts.map +1 -1
- package/lexador/lexador.js.map +1 -1
- package/lexador/mapeamento-paradigmas.d.ts.map +1 -1
- package/lexador/mapeamento-paradigmas.js.map +1 -1
- package/lexador/palavras-reservadas.js +2 -2
- package/lexador/palavras-reservadas.js.map +1 -1
- package/lexador/simbolo.d.ts.map +1 -1
- package/lexador/simbolo.js.map +1 -1
- package/lexador/traducao/lexador-javascript.d.ts.map +1 -1
- package/package.json +1 -1
- package/tradutores/mermaid/aresta-fluxograma.d.ts +1 -1
- package/tradutores/mermaid/subgrafo-classe.d.ts +3 -3
- package/tradutores/mermaid/subgrafo-funcao.d.ts +2 -2
- package/tradutores/mermaid/subgrafo-funcao.d.ts.map +1 -1
- package/tradutores/mermaid/subgrafo-funcao.js.map +1 -1
- package/tradutores/mermaid/subgrafo-metodo.d.ts +2 -2
- package/tradutores/mermaid/vertice-fluxograma.d.ts +1 -1
- package/tradutores/tradutor-assembly-arm.d.ts.map +1 -1
- package/tradutores/tradutor-assembly-arm.js +164 -156
- package/tradutores/tradutor-assembly-arm.js.map +1 -1
- package/tradutores/tradutor-assembly-x64.d.ts.map +1 -1
- package/tradutores/tradutor-assembly-x64.js +136 -127
- package/tradutores/tradutor-assembly-x64.js.map +1 -1
- package/tradutores/tradutor-assemblyscript.d.ts.map +1 -1
- package/tradutores/tradutor-assemblyscript.js +10 -6
- package/tradutores/tradutor-assemblyscript.js.map +1 -1
- package/tradutores/tradutor-calango.d.ts.map +1 -1
- package/tradutores/tradutor-calango.js.map +1 -1
- package/tradutores/tradutor-elixir.d.ts.map +1 -1
- package/tradutores/tradutor-elixir.js +9 -7
- package/tradutores/tradutor-elixir.js.map +1 -1
- package/tradutores/tradutor-javascript.d.ts.map +1 -1
- package/tradutores/tradutor-javascript.js +2 -1
- package/tradutores/tradutor-javascript.js.map +1 -1
- package/tradutores/tradutor-mermaidjs.d.ts.map +1 -1
- package/tradutores/tradutor-mermaidjs.js +4 -8
- package/tradutores/tradutor-mermaidjs.js.map +1 -1
- package/tradutores/tradutor-portugol-ipt.d.ts.map +1 -1
- package/tradutores/tradutor-portugol-ipt.js.map +1 -1
- package/tradutores/tradutor-python.d.ts.map +1 -1
- package/tradutores/tradutor-python.js +1 -1
- package/tradutores/tradutor-python.js.map +1 -1
- package/tradutores/tradutor-reverso-javascript.d.ts.map +1 -1
- package/tradutores/tradutor-ruby.d.ts.map +1 -1
- package/tradutores/tradutor-ruby.js +1 -1
- package/tradutores/tradutor-ruby.js.map +1 -1
- package/umd/delegua.js +969 -646
package/umd/delegua.js
CHANGED
|
@@ -12,7 +12,7 @@ const interfaces_1 = require("../interfaces");
|
|
|
12
12
|
*/
|
|
13
13
|
class AnalisadorSemanticoBase {
|
|
14
14
|
diagnosticoJaExiste(simbolo, mensagem) {
|
|
15
|
-
return this.diagnosticos.some(d => d.linha === simbolo.linha &&
|
|
15
|
+
return this.diagnosticos.some((d) => d.linha === simbolo.linha &&
|
|
16
16
|
d.mensagem === mensagem &&
|
|
17
17
|
d.simbolo.lexema === simbolo.lexema);
|
|
18
18
|
}
|
|
@@ -63,7 +63,7 @@ class AnalisadorSemanticoBase {
|
|
|
63
63
|
for (let [indice, parametro] of parametros.entries()) {
|
|
64
64
|
const argumento = argumentos[indice];
|
|
65
65
|
if (argumento) {
|
|
66
|
-
// Usando `obterTipoExpressao` para resolver adequadamente o tipo do argumento,
|
|
66
|
+
// Usando `obterTipoExpressao` para resolver adequadamente o tipo do argumento,
|
|
67
67
|
// independentemente de ser um `Literal` (tipo já resolvido), `Variavel` (tipo inferido do
|
|
68
68
|
// escopo), `Binario`, `Agrupamento`, ou qualquer outro construto (retorna `null` quando
|
|
69
69
|
// o tipo não pode ser determinado em tempo de compilação).
|
|
@@ -119,7 +119,14 @@ class AnalisadorSemanticoBase {
|
|
|
119
119
|
*/
|
|
120
120
|
inferirTipoBinario(binario) {
|
|
121
121
|
const operadoresMatematicos = ['ADICAO', 'SUBTRACAO', 'MULTIPLICACAO', 'DIVISAO', 'MODULO'];
|
|
122
|
-
const operadoresComparacao = [
|
|
122
|
+
const operadoresComparacao = [
|
|
123
|
+
'MAIOR',
|
|
124
|
+
'MAIOR_IGUAL',
|
|
125
|
+
'MENOR',
|
|
126
|
+
'MENOR_IGUAL',
|
|
127
|
+
'IGUAL',
|
|
128
|
+
'DIFERENTE',
|
|
129
|
+
];
|
|
123
130
|
// Operadores de comparação sempre retornam lógico
|
|
124
131
|
if (operadoresComparacao.includes(binario.operador.tipo)) {
|
|
125
132
|
return 'lógico';
|
|
@@ -146,8 +153,8 @@ class AnalisadorSemanticoBase {
|
|
|
146
153
|
return 'qualquer';
|
|
147
154
|
}
|
|
148
155
|
/**
|
|
149
|
-
|
|
150
|
-
|
|
156
|
+
* Marca as variáveis usadas em uma expressão.
|
|
157
|
+
*/
|
|
151
158
|
marcarVariaveisUsadasEmExpressao(expressao) {
|
|
152
159
|
if (expressao instanceof construtos_1.Variavel) {
|
|
153
160
|
this.gerenciadorEscopos.marcarComoUsada(expressao.simbolo.lexema);
|
|
@@ -233,7 +240,8 @@ class AnalisadorSemanticoBase {
|
|
|
233
240
|
if (!caminhoSenaoResolvido || ((_a = caminhoSenaoResolvido.declaracoes) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
|
234
241
|
return false;
|
|
235
242
|
}
|
|
236
|
-
if (caminhoSenaoResolvido instanceof declaracoes_1.Se &&
|
|
243
|
+
if (caminhoSenaoResolvido instanceof declaracoes_1.Se &&
|
|
244
|
+
((_b = caminhoSenaoResolvido.caminhoEntao.declaracoes) === null || _b === void 0 ? void 0 : _b.length) === 1) {
|
|
237
245
|
const senaoSeRetorna = this.verificarSeRetorna(caminhoSenaoResolvido);
|
|
238
246
|
return entaoRetorna && senaoSeRetorna;
|
|
239
247
|
}
|
|
@@ -592,7 +600,8 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
592
600
|
}
|
|
593
601
|
visitarChamadaPorVariavel(entidadeChamadaVariavel, argumentos) {
|
|
594
602
|
const variavel = entidadeChamadaVariavel;
|
|
595
|
-
const funcaoChamada = this.gerenciadorEscopos.buscar(variavel.simbolo.lexema) ||
|
|
603
|
+
const funcaoChamada = this.gerenciadorEscopos.buscar(variavel.simbolo.lexema) ||
|
|
604
|
+
this.funcoes[variavel.simbolo.lexema];
|
|
596
605
|
if (!funcaoChamada) {
|
|
597
606
|
this.erro(entidadeChamadaVariavel.simbolo, `Chamada da função '${entidadeChamadaVariavel.simbolo.lexema}' não existe.`);
|
|
598
607
|
return Promise.resolve();
|
|
@@ -889,15 +898,18 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
889
898
|
// Verifica se a expressão problemática é um Leia ou uma variável inicializada com Leia
|
|
890
899
|
let mensagemAdicional = '';
|
|
891
900
|
if (expressaoProblematica instanceof construtos_1.Leia) {
|
|
892
|
-
mensagemAdicional =
|
|
901
|
+
mensagemAdicional =
|
|
902
|
+
" Função 'leia()' retorna texto. Use 'inteiro(leia(...))' ou 'real(leia(...))' para converter.";
|
|
893
903
|
}
|
|
894
904
|
else if (expressaoProblematica instanceof construtos_1.Variavel) {
|
|
895
905
|
const variavel = this.gerenciadorEscopos.buscar(expressaoProblematica.simbolo.lexema);
|
|
896
906
|
if (variavel && variavel.valor instanceof construtos_1.Leia) {
|
|
897
|
-
mensagemAdicional =
|
|
907
|
+
mensagemAdicional =
|
|
908
|
+
" A variável foi inicializada com 'leia()' que retorna texto. Use 'inteiro(leia(...))' ou 'real(leia(...))' para converter.";
|
|
898
909
|
}
|
|
899
910
|
else {
|
|
900
|
-
mensagemAdicional =
|
|
911
|
+
mensagemAdicional =
|
|
912
|
+
" Use 'inteiro(...)' ou 'real(...)' para converter texto em número.";
|
|
901
913
|
}
|
|
902
914
|
}
|
|
903
915
|
this.erro(binario.operador, `Operação aritmética com tipo incompatível: operando ${ladoProblematico} é do tipo 'texto', mas a operação requer número.${mensagemAdicional}`);
|
|
@@ -906,8 +918,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
906
918
|
}
|
|
907
919
|
if (tipoEsquerda && tipoDireita && tipoEsquerda !== tipoDireita) {
|
|
908
920
|
// Verificar se são tipos numéricos compatíveis
|
|
909
|
-
const ambosNumericos = tiposNumericos.includes(tipoEsquerda) &&
|
|
910
|
-
tiposNumericos.includes(tipoDireita);
|
|
921
|
+
const ambosNumericos = tiposNumericos.includes(tipoEsquerda) && tiposNumericos.includes(tipoDireita);
|
|
911
922
|
if (!ambosNumericos) {
|
|
912
923
|
this.aviso(binario.operador, `Operação entre tipos diferentes: tipo esquerdo '${tipoEsquerda}' e tipo direito '${tipoDireita}'. O resultado será resolvido implicitamente.`);
|
|
913
924
|
}
|
|
@@ -1015,7 +1026,15 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1015
1026
|
let entidadeChamadaVariavel = chamada.entidadeChamada;
|
|
1016
1027
|
const nomeFuncao = entidadeChamadaVariavel.simbolo.lexema;
|
|
1017
1028
|
// Lista de funções built-in que não precisam ser declaradas
|
|
1018
|
-
const funcoesBuiltIn = [
|
|
1029
|
+
const funcoesBuiltIn = [
|
|
1030
|
+
'inteiro',
|
|
1031
|
+
'real',
|
|
1032
|
+
'número',
|
|
1033
|
+
'texto',
|
|
1034
|
+
'leia',
|
|
1035
|
+
'escreva',
|
|
1036
|
+
'tipo',
|
|
1037
|
+
];
|
|
1019
1038
|
// Classes/construtores geralmente começam com letra maiúscula
|
|
1020
1039
|
const pareceSerClasse = nomeFuncao[0] === nomeFuncao[0].toUpperCase();
|
|
1021
1040
|
// Só verifica se a função existe se não for built-in e não parecer ser classe
|
|
@@ -1070,7 +1089,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1070
1089
|
tipo: 'IDENTIFICADOR',
|
|
1071
1090
|
linha: literal.linha,
|
|
1072
1091
|
hashArquivo: literal.hashArquivo,
|
|
1073
|
-
literal: null
|
|
1092
|
+
literal: null,
|
|
1074
1093
|
}, `Variável ou função '${nomeVariavel}' usada em interpolação não existe.`);
|
|
1075
1094
|
}
|
|
1076
1095
|
else if (variavel) {
|
|
@@ -1083,7 +1102,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1083
1102
|
tipo: 'IDENTIFICADOR',
|
|
1084
1103
|
linha: literal.linha,
|
|
1085
1104
|
hashArquivo: literal.hashArquivo,
|
|
1086
|
-
literal: null
|
|
1105
|
+
literal: null,
|
|
1087
1106
|
}, `Variável '${nomeVariavel}' usada em interpolação pode não ter sido inicializada.`);
|
|
1088
1107
|
}
|
|
1089
1108
|
}
|
|
@@ -1146,7 +1165,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1146
1165
|
inicializada: true,
|
|
1147
1166
|
usada: false,
|
|
1148
1167
|
hashArquivo: declaracao.simbolo.hashArquivo,
|
|
1149
|
-
linha: declaracao.simbolo.linha
|
|
1168
|
+
linha: declaracao.simbolo.linha,
|
|
1150
1169
|
});
|
|
1151
1170
|
// TODO: Verificar inicializador.
|
|
1152
1171
|
return Promise.resolve();
|
|
@@ -1178,7 +1197,8 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1178
1197
|
if (tipoValor === 'string' && tipoRetornoFuncao !== 'texto') {
|
|
1179
1198
|
this.erro(declaracao.simbolo, `Esperado retorno do tipo '${tipoRetornoFuncao}' dentro da função.`);
|
|
1180
1199
|
}
|
|
1181
|
-
if (tipoValor === 'number' &&
|
|
1200
|
+
if (tipoValor === 'number' &&
|
|
1201
|
+
!['inteiro', 'real', 'número'].includes(tipoRetornoFuncao)) {
|
|
1182
1202
|
this.erro(declaracao.simbolo, `Esperado retorno do tipo '${tipoRetornoFuncao}' dentro da função.`);
|
|
1183
1203
|
}
|
|
1184
1204
|
}
|
|
@@ -1203,17 +1223,21 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1203
1223
|
tipoInferido = this.obterTipoExpressao(declaracao.inicializador);
|
|
1204
1224
|
}
|
|
1205
1225
|
// Sugestão de tipo melhor quando 'qualquer' é usado explicitamente
|
|
1206
|
-
if (declaracao.tipoExplicito &&
|
|
1226
|
+
if (declaracao.tipoExplicito &&
|
|
1227
|
+
declaracao.tipoOriginal === 'qualquer' &&
|
|
1228
|
+
declaracao.inicializador) {
|
|
1207
1229
|
const tipoMelhor = this.obterTipoExpressao(declaracao.inicializador);
|
|
1208
1230
|
if (tipoMelhor && tipoMelhor !== 'qualquer') {
|
|
1209
|
-
this.sugestao(declaracao.simbolo, 'Um tipo melhor pode ser inferido.', [
|
|
1231
|
+
this.sugestao(declaracao.simbolo, 'Um tipo melhor pode ser inferido.', [
|
|
1232
|
+
{
|
|
1210
1233
|
titulo: `Alterar tipo para '${tipoMelhor}'`,
|
|
1211
1234
|
textoOriginal: 'qualquer',
|
|
1212
1235
|
textoSubstituto: tipoMelhor,
|
|
1213
1236
|
linha: declaracao.simbolo.linha,
|
|
1214
1237
|
colunaInicio: declaracao.simbolo.colunaInicio,
|
|
1215
1238
|
colunaFim: declaracao.simbolo.colunaFim,
|
|
1216
|
-
}
|
|
1239
|
+
},
|
|
1240
|
+
]);
|
|
1217
1241
|
}
|
|
1218
1242
|
}
|
|
1219
1243
|
const variavel = {
|
|
@@ -1224,7 +1248,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1224
1248
|
inicializada: declaracao.inicializador !== null && declaracao.inicializador !== undefined,
|
|
1225
1249
|
usada: false,
|
|
1226
1250
|
hashArquivo: declaracao.simbolo.hashArquivo,
|
|
1227
|
-
linha: declaracao.simbolo.linha
|
|
1251
|
+
linha: declaracao.simbolo.linha,
|
|
1228
1252
|
};
|
|
1229
1253
|
const declaradaComSucesso = this.gerenciadorEscopos.declarar(declaracao.simbolo.lexema, variavel);
|
|
1230
1254
|
if (!declaradaComSucesso) {
|
|
@@ -1369,7 +1393,9 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1369
1393
|
retorno.tipo === 'qualquer');
|
|
1370
1394
|
// Se a função é 'vazio' e há retornos com tipo indeterminado,
|
|
1371
1395
|
// tenta inferir o tipo e fornece mensagem útil ao desenvolvedor
|
|
1372
|
-
if (tipoRetornoFuncao === 'vazio' &&
|
|
1396
|
+
if (tipoRetornoFuncao === 'vazio' &&
|
|
1397
|
+
declaracao.funcao.tipoExplicito &&
|
|
1398
|
+
retornosComTipoIndeterminado.length > 0) {
|
|
1373
1399
|
const retornoComValor = retornosComTipoIndeterminado[0];
|
|
1374
1400
|
const tipoInferido = this.obterTipoExpressao(retornoComValor.valor);
|
|
1375
1401
|
if (tipoInferido && tipoInferido !== 'qualquer') {
|
|
@@ -1388,7 +1414,8 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1388
1414
|
if (tipoValor === 'string' && tipoRetornoFuncao !== 'texto') {
|
|
1389
1415
|
this.erro(declaracao.simbolo, `Esperado retorno do tipo '${tipoRetornoFuncao}' dentro da função.`);
|
|
1390
1416
|
}
|
|
1391
|
-
if (tipoValor === 'number' &&
|
|
1417
|
+
if (tipoValor === 'number' &&
|
|
1418
|
+
!['inteiro', 'real', 'número'].includes(tipoRetornoFuncao)) {
|
|
1392
1419
|
this.erro(declaracao.simbolo, `Esperado retorno do tipo '${tipoRetornoFuncao}' dentro da função.`);
|
|
1393
1420
|
}
|
|
1394
1421
|
}
|
|
@@ -1404,7 +1431,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1404
1431
|
const naoUsadas = this.gerenciadorEscopos.obterVariaveisNaoUsadas();
|
|
1405
1432
|
for (let variavel of naoUsadas) {
|
|
1406
1433
|
// Verifica se já existe um erro associado à variável.
|
|
1407
|
-
const temErro = this.diagnosticos.some(d => d.severidade === erros_1.DiagnosticoSeveridade.ERRO &&
|
|
1434
|
+
const temErro = this.diagnosticos.some((d) => d.severidade === erros_1.DiagnosticoSeveridade.ERRO &&
|
|
1408
1435
|
d.simbolo.lexema === variavel.nome);
|
|
1409
1436
|
// Se a variável já tem um erro associado, não emitir aviso de não usada.
|
|
1410
1437
|
if (temErro) {
|
|
@@ -1414,7 +1441,7 @@ class AnalisadorSemantico extends analisador_semantico_base_1.AnalisadorSemantic
|
|
|
1414
1441
|
lexema: variavel.nome,
|
|
1415
1442
|
linha: variavel.linha,
|
|
1416
1443
|
tipo: variavel.tipo,
|
|
1417
|
-
hashArquivo: variavel.hashArquivo
|
|
1444
|
+
hashArquivo: variavel.hashArquivo,
|
|
1418
1445
|
}, `Variável '${variavel.nome}' foi declarada mas nunca usada.`);
|
|
1419
1446
|
}
|
|
1420
1447
|
}
|
|
@@ -1952,7 +1979,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
1952
1979
|
}
|
|
1953
1980
|
async construtoAjuda() {
|
|
1954
1981
|
const simboloAjuda = this.avancarEDevolverAnterior();
|
|
1955
|
-
if (this.estaNoFinal() ||
|
|
1982
|
+
if (this.estaNoFinal() ||
|
|
1983
|
+
this.simbolos[this.atual].tipo !== delegua_2.default.PARENTESE_ESQUERDO) {
|
|
1956
1984
|
return new construtos_1.AjudaComoConstruto(simboloAjuda.hashArquivo, simboloAjuda.linha, undefined, false);
|
|
1957
1985
|
}
|
|
1958
1986
|
this.avancarEDevolverAnterior(); // parêntese esquerdo
|
|
@@ -2379,7 +2407,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
2379
2407
|
// o analisador semântico emitir o diagnóstico quando apropriado.
|
|
2380
2408
|
tipoIdentificadorCorrespondente = 'qualquer';
|
|
2381
2409
|
}
|
|
2382
|
-
if (!tipoIdentificadorCorrespondente.endsWith('[]') &&
|
|
2410
|
+
if (!tipoIdentificadorCorrespondente.endsWith('[]') &&
|
|
2411
|
+
!['dicionário', 'qualquer', 'texto', 'tupla', 'vetor'].includes(tipoIdentificadorCorrespondente)) {
|
|
2383
2412
|
throw this.erro(this.simbolos[this.atual], `Tipo ${tipoIdentificadorCorrespondente} não suporta acesso por índice.`);
|
|
2384
2413
|
}
|
|
2385
2414
|
let tipoAcesso = 'qualquer';
|
|
@@ -2453,8 +2482,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
2453
2482
|
if (expressaoAnterior.tipo === 'dicionário' &&
|
|
2454
2483
|
expressaoAnterior.constructor !== construtos_1.Dicionario) {
|
|
2455
2484
|
const elementoMontaoTipos = this.resolverElementoMontao(expressaoAnterior);
|
|
2456
|
-
if (elementoMontaoTipos &&
|
|
2457
|
-
nome.lexema in elementoMontaoTipos.subElementos) {
|
|
2485
|
+
if (elementoMontaoTipos && nome.lexema in elementoMontaoTipos.subElementos) {
|
|
2458
2486
|
tipoInferido = elementoMontaoTipos.subElementos[nome.lexema].tipo;
|
|
2459
2487
|
}
|
|
2460
2488
|
}
|
|
@@ -2711,7 +2739,9 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
2711
2739
|
if (construto instanceof construtos_1.Unario) {
|
|
2712
2740
|
const operando = construto.operando;
|
|
2713
2741
|
// Verifica se o operando é um vetor
|
|
2714
|
-
if (operando instanceof construtos_1.Vetor ||
|
|
2742
|
+
if (operando instanceof construtos_1.Vetor ||
|
|
2743
|
+
operando.tipo === 'vetor' ||
|
|
2744
|
+
operando.tipo.endsWith('[]')) {
|
|
2715
2745
|
return true;
|
|
2716
2746
|
}
|
|
2717
2747
|
// Verifica recursivamente para casos como !![]
|
|
@@ -3322,7 +3352,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3322
3352
|
}
|
|
3323
3353
|
async declaracaoSe() {
|
|
3324
3354
|
const condicao = await this.expressao();
|
|
3325
|
-
const caminhoEntao = await this.resolverDeclaracao();
|
|
3355
|
+
const caminhoEntao = (await this.resolverDeclaracao());
|
|
3326
3356
|
let caminhoSenao = null;
|
|
3327
3357
|
if (this.verificarSeSimboloAtualEIgualA(delegua_2.default.SENAO, delegua_2.default.SENÃO)) {
|
|
3328
3358
|
caminhoSenao = await this.resolverDeclaracao();
|
|
@@ -3453,20 +3483,16 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3453
3483
|
// Uma delas é a variável/constante ser uma classe padrão.
|
|
3454
3484
|
// Isso ocorre quando a importação é feita de uma biblioteca Node.js.
|
|
3455
3485
|
// Nesse caso, o tipo de `entidadeChamada.objeto` começa com uma letra maiúscula.
|
|
3456
|
-
if (entidadeChamada.objeto.tipo &&
|
|
3457
|
-
entidadeChamada.objeto.tipo.match(/^[A-Z]/)) {
|
|
3486
|
+
if (entidadeChamada.objeto.tipo && entidadeChamada.objeto.tipo.match(/^[A-Z]/)) {
|
|
3458
3487
|
const tipoCorrespondente = this.tiposDefinidosPorBibliotecas[entidadeChamada.objeto.tipo];
|
|
3459
3488
|
if (!tipoCorrespondente) {
|
|
3460
3489
|
throw new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(entidadeChamada.simbolo, `Tipo '${entidadeChamada.objeto.tipo}' não foi encontrado entre os tipos definidos por bibliotecas.`);
|
|
3461
3490
|
}
|
|
3462
|
-
if (!(entidadeChamada.simbolo.lexema in
|
|
3463
|
-
tipoCorrespondente.
|
|
3464
|
-
!(entidadeChamada.simbolo.lexema in
|
|
3465
|
-
tipoCorrespondente.propriedades)) {
|
|
3491
|
+
if (!(entidadeChamada.simbolo.lexema in tipoCorrespondente.metodos) &&
|
|
3492
|
+
!(entidadeChamada.simbolo.lexema in tipoCorrespondente.propriedades)) {
|
|
3466
3493
|
throw new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(entidadeChamada.simbolo, `Membro '${entidadeChamada.simbolo.lexema}' não existe no tipo '${entidadeChamada.objeto.tipo}'.`);
|
|
3467
3494
|
}
|
|
3468
|
-
if (entidadeChamada.simbolo.lexema in
|
|
3469
|
-
tipoCorrespondente.metodos) {
|
|
3495
|
+
if (entidadeChamada.simbolo.lexema in tipoCorrespondente.metodos) {
|
|
3470
3496
|
const metodoCorrespondente = tipoCorrespondente.metodos[entidadeChamada.simbolo.lexema];
|
|
3471
3497
|
return metodoCorrespondente.tipoRetorno || 'qualquer';
|
|
3472
3498
|
}
|
|
@@ -3819,7 +3845,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3819
3845
|
this.consumir(delegua_2.default.CHAVE_ESQUERDA, "Esperado '{' antes do corpo da interface.");
|
|
3820
3846
|
const metodos = [];
|
|
3821
3847
|
const propriedades = [];
|
|
3822
|
-
while (!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA) &&
|
|
3848
|
+
while (!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA) &&
|
|
3849
|
+
!this.estaNoFinal()) {
|
|
3823
3850
|
this.verificarSeSimboloAtualEIgualA(delegua_2.default.PONTO_E_VIRGULA);
|
|
3824
3851
|
if (this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA))
|
|
3825
3852
|
break;
|
|
@@ -3870,7 +3897,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3870
3897
|
const simbolo = this.consumir(delegua_2.default.IDENTIFICADOR, 'Esperado nome da classe.');
|
|
3871
3898
|
// Pré-registro para permitir auto-referência no corpo da própria classe,
|
|
3872
3899
|
// como em `MinhaClasse.propriedadeEstatica` dentro de métodos.
|
|
3873
|
-
this.tiposDefinidosEmCodigo[simbolo.lexema] =
|
|
3900
|
+
this.tiposDefinidosEmCodigo[simbolo.lexema] =
|
|
3901
|
+
(_a = this.tiposDefinidosEmCodigo[simbolo.lexema]) !== null && _a !== void 0 ? _a : {};
|
|
3874
3902
|
const pilhaDecoradoresClasse = Array.from(this.pilhaDecoradores);
|
|
3875
3903
|
// Verificar `herda SuperclasseA, SuperclasseB`
|
|
3876
3904
|
const superClasses = [];
|
|
@@ -3908,7 +3936,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3908
3936
|
*/
|
|
3909
3937
|
const compreenderMembros = async (acessoPadrao, ehEstaticoPadrao, ehAbstratoPadrao = false) => {
|
|
3910
3938
|
var _a;
|
|
3911
|
-
while (!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA) &&
|
|
3939
|
+
while (!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA) &&
|
|
3940
|
+
!this.estaNoFinal()) {
|
|
3912
3941
|
// Pular comentários normais dentro do corpo da classe.
|
|
3913
3942
|
if (this.simbolos[this.atual].tipo === delegua_2.default.COMENTARIO ||
|
|
3914
3943
|
this.simbolos[this.atual].tipo === delegua_2.default.LINHA_COMENTARIO) {
|
|
@@ -3929,12 +3958,12 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
3929
3958
|
// Detecção de bloco de contexto: modificador seguido de '{'
|
|
3930
3959
|
const tipoAtual = this.simbolos[this.atual].tipo;
|
|
3931
3960
|
const tipoProximo = (_a = this.simbolos[this.atual + 1]) === null || _a === void 0 ? void 0 : _a.tipo;
|
|
3932
|
-
const ehBlocoAcesso = [delegua_2.default.PRIVADO, delegua_2.default.PROTEGIDO].includes(tipoAtual)
|
|
3933
|
-
|
|
3934
|
-
const ehBlocoEstatico = tipoAtual === delegua_2.default.ESTATICO
|
|
3935
|
-
|
|
3936
|
-
const ehBlocoAbstrato = tipoAtual === delegua_2.default.ABSTRATO
|
|
3937
|
-
|
|
3961
|
+
const ehBlocoAcesso = [delegua_2.default.PRIVADO, delegua_2.default.PROTEGIDO].includes(tipoAtual) &&
|
|
3962
|
+
tipoProximo === delegua_2.default.CHAVE_ESQUERDA;
|
|
3963
|
+
const ehBlocoEstatico = tipoAtual === delegua_2.default.ESTATICO &&
|
|
3964
|
+
tipoProximo === delegua_2.default.CHAVE_ESQUERDA;
|
|
3965
|
+
const ehBlocoAbstrato = tipoAtual === delegua_2.default.ABSTRATO &&
|
|
3966
|
+
tipoProximo === delegua_2.default.CHAVE_ESQUERDA;
|
|
3938
3967
|
if (ehBlocoAcesso) {
|
|
3939
3968
|
const novoAcesso = tipoAtual === delegua_2.default.PRIVADO ? 'privado' : 'protegido';
|
|
3940
3969
|
this.avancarEDevolverAnterior(); // consume modificador de acesso
|
|
@@ -4031,14 +4060,17 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4031
4060
|
for (const declaracao of corpo) {
|
|
4032
4061
|
expressoesRetorna = expressoesRetorna.concat((0, comum_1.buscarRetornos)(declaracao));
|
|
4033
4062
|
}
|
|
4034
|
-
const tiposRetornos = new Set(expressoesRetorna
|
|
4063
|
+
const tiposRetornos = new Set(expressoesRetorna
|
|
4064
|
+
.filter((e) => e.tipo !== 'qualquer')
|
|
4065
|
+
.map((e) => e.tipo));
|
|
4035
4066
|
const retornaChamadoExplicitamente = tiposRetornos.size > 0;
|
|
4036
4067
|
tiposRetornos.delete('qualquer');
|
|
4037
4068
|
if (tipoRetorno === 'qualquer') {
|
|
4038
4069
|
if (tiposRetornos.size > 0) {
|
|
4039
4070
|
tipoRetorno = tiposRetornos.values().next().value;
|
|
4040
4071
|
}
|
|
4041
|
-
else if (!retornaChamadoExplicitamente &&
|
|
4072
|
+
else if (!retornaChamadoExplicitamente &&
|
|
4073
|
+
!definicaoExplicitaDeTipo) {
|
|
4042
4074
|
tipoRetorno = 'vazio';
|
|
4043
4075
|
}
|
|
4044
4076
|
}
|
|
@@ -4094,13 +4126,18 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4094
4126
|
let tipoAcessor = 'qualquer';
|
|
4095
4127
|
let expressoesRetornaAcessor = [];
|
|
4096
4128
|
for (const declaracao of corpoAcessor) {
|
|
4097
|
-
expressoesRetornaAcessor =
|
|
4129
|
+
expressoesRetornaAcessor =
|
|
4130
|
+
expressoesRetornaAcessor.concat((0, comum_1.buscarRetornos)(declaracao));
|
|
4098
4131
|
}
|
|
4099
|
-
const tiposRetornosAcessor = new Set(expressoesRetornaAcessor
|
|
4132
|
+
const tiposRetornosAcessor = new Set(expressoesRetornaAcessor
|
|
4133
|
+
.filter((e) => e.tipo !== 'qualquer')
|
|
4134
|
+
.map((e) => e.tipo));
|
|
4100
4135
|
const retornaExplicitamenteAcessor = tiposRetornosAcessor.size > 0;
|
|
4101
4136
|
tiposRetornosAcessor.delete('qualquer');
|
|
4102
4137
|
if (tiposRetornosAcessor.size > 0) {
|
|
4103
|
-
tipoAcessor = tiposRetornosAcessor
|
|
4138
|
+
tipoAcessor = tiposRetornosAcessor
|
|
4139
|
+
.values()
|
|
4140
|
+
.next().value;
|
|
4104
4141
|
}
|
|
4105
4142
|
else if (!retornaExplicitamenteAcessor) {
|
|
4106
4143
|
tipoAcessor = 'vazio';
|
|
@@ -4152,24 +4189,55 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4152
4189
|
await compreenderMembros('publico', false);
|
|
4153
4190
|
this.consumir(delegua_2.default.CHAVE_DIREITA, "Esperado '}' após o escopo da classe.");
|
|
4154
4191
|
// Verificação em tempo de análise: classe deve implementar todos os contratos das interfaces.
|
|
4192
|
+
const linhaFinalClasse = this.simbolos[this.atual - 1].linha;
|
|
4155
4193
|
for (const nomeInterface of implementaInterfaces) {
|
|
4156
4194
|
const interfaceDecl = this.interfacesDeclaradas[nomeInterface.lexema];
|
|
4157
4195
|
if (!interfaceDecl) {
|
|
4158
4196
|
this.erros.push(this.erro(nomeInterface, `Interface '${nomeInterface.lexema}' não foi declarada antes da classe '${simbolo.lexema}'.`));
|
|
4159
4197
|
continue;
|
|
4160
4198
|
}
|
|
4199
|
+
const membrosFaltando = [];
|
|
4161
4200
|
for (const assinatura of interfaceDecl.metodos) {
|
|
4162
4201
|
const nomeMetodo = assinatura.nome.lexema;
|
|
4163
4202
|
const implementado = metodos.some((m) => m.simbolo.lexema === nomeMetodo);
|
|
4164
4203
|
if (!implementado) {
|
|
4165
|
-
|
|
4204
|
+
membrosFaltando.push({
|
|
4205
|
+
tipo: 'metodo',
|
|
4206
|
+
nome: nomeMetodo,
|
|
4207
|
+
parametros: assinatura.parametros.map((p) => ({
|
|
4208
|
+
nome: p.nome.lexema,
|
|
4209
|
+
tipoDado: p.tipoDado,
|
|
4210
|
+
})),
|
|
4211
|
+
tipoRetorno: assinatura.tipoRetorno,
|
|
4212
|
+
});
|
|
4166
4213
|
}
|
|
4167
4214
|
}
|
|
4168
4215
|
for (const prop of interfaceDecl.propriedades) {
|
|
4169
4216
|
const nomeProp = prop.nome.lexema;
|
|
4170
4217
|
const implementada = propriedades.some((p) => p.nome.lexema === nomeProp);
|
|
4171
4218
|
if (!implementada) {
|
|
4172
|
-
|
|
4219
|
+
membrosFaltando.push({
|
|
4220
|
+
tipo: 'propriedade',
|
|
4221
|
+
nome: nomeProp,
|
|
4222
|
+
tipoPropriedade: prop.tipo,
|
|
4223
|
+
});
|
|
4224
|
+
}
|
|
4225
|
+
}
|
|
4226
|
+
if (membrosFaltando.length > 0) {
|
|
4227
|
+
const correcaoSugerida = {
|
|
4228
|
+
tipo: 'implementar-interface',
|
|
4229
|
+
nomeInterface: nomeInterface.lexema,
|
|
4230
|
+
nomeClasse: simbolo.lexema,
|
|
4231
|
+
membrosFaltando,
|
|
4232
|
+
linhaFinalClasse,
|
|
4233
|
+
};
|
|
4234
|
+
for (const membro of membrosFaltando) {
|
|
4235
|
+
const mensagem = membro.tipo === 'metodo'
|
|
4236
|
+
? `Classe '${simbolo.lexema}' não implementa o método '${membro.nome}' exigido pela interface '${nomeInterface.lexema}'.`
|
|
4237
|
+
: `Classe '${simbolo.lexema}' não declara a propriedade '${membro.nome}' exigida pela interface '${nomeInterface.lexema}'.`;
|
|
4238
|
+
const erro = this.erro(simbolo, mensagem);
|
|
4239
|
+
erro.correcaoSugerida = correcaoSugerida;
|
|
4240
|
+
this.erros.push(erro);
|
|
4173
4241
|
}
|
|
4174
4242
|
}
|
|
4175
4243
|
}
|
|
@@ -4197,7 +4265,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4197
4265
|
if (!this.primitivasConhecidas[nomeTipo]) {
|
|
4198
4266
|
this.primitivasConhecidas[nomeTipo] = {};
|
|
4199
4267
|
}
|
|
4200
|
-
while (!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA) &&
|
|
4268
|
+
while (!this.verificarTipoSimboloAtual(delegua_2.default.CHAVE_DIREITA) &&
|
|
4269
|
+
!this.estaNoFinal()) {
|
|
4201
4270
|
// Pular comentários dentro do corpo da extensão.
|
|
4202
4271
|
if (this.simbolos[this.atual].tipo === delegua_2.default.COMENTARIO ||
|
|
4203
4272
|
this.simbolos[this.atual].tipo === delegua_2.default.LINHA_COMENTARIO) {
|
|
@@ -4245,7 +4314,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4245
4314
|
const metodo = new declaracoes_1.FuncaoDeclaracao(nomeMetodo, corpoFuncao, tipoDaFuncao);
|
|
4246
4315
|
metodos.push(metodo);
|
|
4247
4316
|
const argumentos = params.map((parametro) => new informacao_elemento_sintatico_1.InformacaoElementoSintatico(parametro.nome.lexema, parametro.tipoDado || 'qualquer', parametro.valorPadrao === undefined));
|
|
4248
|
-
this.primitivasConhecidas[nomeTipo][nomeMetodo.lexema] =
|
|
4317
|
+
this.primitivasConhecidas[nomeTipo][nomeMetodo.lexema] =
|
|
4318
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico(nomeMetodo.lexema, tipoRetorno, true, argumentos);
|
|
4249
4319
|
}
|
|
4250
4320
|
this.consumir(delegua_2.default.CHAVE_DIREITA, "Esperado '}' ao final da extensão.");
|
|
4251
4321
|
return new declaracoes_1.Extensao(simboloTipo, metodos, ehGlobal, this.hashArquivo);
|
|
@@ -4277,7 +4347,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4277
4347
|
this.verificarTipoSimboloAtual(delegua_2.default.FUNÇÃO)) &&
|
|
4278
4348
|
this.verificarTipoProximoSimbolo(delegua_2.default.IDENTIFICADOR)) {
|
|
4279
4349
|
this.avancarEDevolverAnterior();
|
|
4280
|
-
const declaracaoFuncao = await this.funcao('funcao');
|
|
4350
|
+
const declaracaoFuncao = (await this.funcao('funcao'));
|
|
4281
4351
|
declaracaoFuncao.documentacao = docTopLevel;
|
|
4282
4352
|
return declaracaoFuncao;
|
|
4283
4353
|
}
|
|
@@ -4351,7 +4421,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4351
4421
|
this.verificarTipoSimboloAtual(delegua_2.default.FUNÇÃO)) &&
|
|
4352
4422
|
this.verificarTipoProximoSimbolo(delegua_2.default.IDENTIFICADOR)) {
|
|
4353
4423
|
this.avancarEDevolverAnterior();
|
|
4354
|
-
const declaracaoFuncao = await this.funcao('funcao');
|
|
4424
|
+
const declaracaoFuncao = (await this.funcao('funcao'));
|
|
4355
4425
|
declaracaoFuncao.documentacao = new construtos_1.ComentarioComoConstruto(simboloDoc);
|
|
4356
4426
|
return declaracaoFuncao;
|
|
4357
4427
|
}
|
|
@@ -4421,7 +4491,8 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4421
4491
|
}
|
|
4422
4492
|
async declaracaoAjuda() {
|
|
4423
4493
|
const simboloAjuda = this.avancarEDevolverAnterior();
|
|
4424
|
-
if (this.estaNoFinal() ||
|
|
4494
|
+
if (this.estaNoFinal() ||
|
|
4495
|
+
this.simbolos[this.atual].tipo !== delegua_2.default.PARENTESE_ESQUERDO) {
|
|
4425
4496
|
return new declaracoes_1.Ajuda(simboloAjuda.hashArquivo, simboloAjuda.linha, undefined, false);
|
|
4426
4497
|
}
|
|
4427
4498
|
this.avancarEDevolverAnterior(); // parêntese esquerdo
|
|
@@ -4563,7 +4634,7 @@ class AvaliadorSintatico extends avaliador_sintatico_base_1.AvaliadorSintaticoBa
|
|
|
4563
4634
|
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('valorParaConverter', 'qualquer'),
|
|
4564
4635
|
]));
|
|
4565
4636
|
this.pilhaEscopos.definirInformacoesVariavel('todos', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('todos', 'lógico', true, [
|
|
4566
|
-
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer')
|
|
4637
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
|
|
4567
4638
|
]));
|
|
4568
4639
|
this.pilhaEscopos.definirInformacoesVariavel('todosEmCondicao', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('todosEmCondicao', 'lógico', true, [
|
|
4569
4640
|
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
|
|
@@ -5442,20 +5513,16 @@ class AvaliadorSintaticoPitugues {
|
|
|
5442
5513
|
// Uma delas é a variável/constante ser uma classe padrão.
|
|
5443
5514
|
// Isso ocorre quando a importação é feita de uma biblioteca Node.js.
|
|
5444
5515
|
// Nesse caso, o tipo de `entidadeChamada.objeto` começa com uma letra maiúscula.
|
|
5445
|
-
if (entidadeChamada.objeto.tipo &&
|
|
5446
|
-
entidadeChamada.objeto.tipo.match(/^[A-Z]/)) {
|
|
5516
|
+
if (entidadeChamada.objeto.tipo && entidadeChamada.objeto.tipo.match(/^[A-Z]/)) {
|
|
5447
5517
|
const tipoCorrespondente = this.tiposDefinidosPorBibliotecas[entidadeChamada.objeto.tipo];
|
|
5448
5518
|
if (!tipoCorrespondente) {
|
|
5449
5519
|
throw new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(entidadeChamada.simbolo, `Tipo '${entidadeChamada.objeto.tipo}' não foi encontrado entre os tipos definidos por bibliotecas.`);
|
|
5450
5520
|
}
|
|
5451
|
-
if (!(entidadeChamada.simbolo.lexema in
|
|
5452
|
-
tipoCorrespondente.
|
|
5453
|
-
!(entidadeChamada.simbolo.lexema in
|
|
5454
|
-
tipoCorrespondente.propriedades)) {
|
|
5521
|
+
if (!(entidadeChamada.simbolo.lexema in tipoCorrespondente.metodos) &&
|
|
5522
|
+
!(entidadeChamada.simbolo.lexema in tipoCorrespondente.propriedades)) {
|
|
5455
5523
|
throw new erro_avaliador_sintatico_1.ErroAvaliadorSintatico(entidadeChamada.simbolo, `Membro '${entidadeChamada.simbolo.lexema}' não existe no tipo '${entidadeChamada.objeto.tipo}'.`);
|
|
5456
5524
|
}
|
|
5457
|
-
if (entidadeChamada.simbolo.lexema in
|
|
5458
|
-
tipoCorrespondente.metodos) {
|
|
5525
|
+
if (entidadeChamada.simbolo.lexema in tipoCorrespondente.metodos) {
|
|
5459
5526
|
const metodoCorrespondente = tipoCorrespondente.metodos[entidadeChamada.simbolo.lexema];
|
|
5460
5527
|
return metodoCorrespondente.tipoRetorno || 'qualquer';
|
|
5461
5528
|
}
|
|
@@ -5588,7 +5655,8 @@ class AvaliadorSintaticoPitugues {
|
|
|
5588
5655
|
pos++;
|
|
5589
5656
|
}
|
|
5590
5657
|
// Verifica se há um identificador obrigatório
|
|
5591
|
-
if (pos >= this.simbolos.length ||
|
|
5658
|
+
if (pos >= this.simbolos.length ||
|
|
5659
|
+
this.simbolos[pos].tipo !== pitugues_2.default.IDENTIFICADOR) {
|
|
5592
5660
|
return false;
|
|
5593
5661
|
}
|
|
5594
5662
|
pos++;
|
|
@@ -5611,7 +5679,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
5611
5679
|
}
|
|
5612
5680
|
temPadraoVarComoPalavraChave() {
|
|
5613
5681
|
// Verifica padrão: var identificador = ...
|
|
5614
|
-
if (this.simbolos[this.atual].lexema !==
|
|
5682
|
+
if (this.simbolos[this.atual].lexema !== 'var') {
|
|
5615
5683
|
return false;
|
|
5616
5684
|
}
|
|
5617
5685
|
const proximo = this.simbolos[this.atual + 1];
|
|
@@ -5644,7 +5712,9 @@ class AvaliadorSintaticoPitugues {
|
|
|
5644
5712
|
this.consumir(pitugues_2.default.MULTIPLICACAO, '');
|
|
5645
5713
|
ehRestoAtual = true;
|
|
5646
5714
|
}
|
|
5647
|
-
const identificador = this.consumir(pitugues_2.default.IDENTIFICADOR, ehRestoAtual
|
|
5715
|
+
const identificador = this.consumir(pitugues_2.default.IDENTIFICADOR, ehRestoAtual
|
|
5716
|
+
? 'Esperado nome de variável após operador *.'
|
|
5717
|
+
: 'Esperado nome de variável.');
|
|
5648
5718
|
// Verifica * no nome da variável
|
|
5649
5719
|
if (identificador.lexema.startsWith('*')) {
|
|
5650
5720
|
ehRestoAtual = true;
|
|
@@ -5672,10 +5742,10 @@ class AvaliadorSintaticoPitugues {
|
|
|
5672
5742
|
}
|
|
5673
5743
|
construirValidacaoDesempacotamento(identificador, origem, qtdEsperada) {
|
|
5674
5744
|
const linha = identificador.linha;
|
|
5675
|
-
const chamadaTamanho = new construtos_1.Chamada(this.hashArquivo, new construtos_1.Variavel(this.hashArquivo, new lexador_1.Simbolo(pitugues_2.default.IDENTIFICADOR,
|
|
5676
|
-
const condicaoErro = new construtos_1.Binario(this.hashArquivo, chamadaTamanho, new lexador_1.Simbolo(pitugues_2.default.DIFERENTE,
|
|
5745
|
+
const chamadaTamanho = new construtos_1.Chamada(this.hashArquivo, new construtos_1.Variavel(this.hashArquivo, new lexador_1.Simbolo(pitugues_2.default.IDENTIFICADOR, 'tamanho', null, linha, -1)), [origem]);
|
|
5746
|
+
const condicaoErro = new construtos_1.Binario(this.hashArquivo, chamadaTamanho, new lexador_1.Simbolo(pitugues_2.default.DIFERENTE, '!=', null, linha, -1), new construtos_1.Literal(this.hashArquivo, linha, qtdEsperada, 'número'));
|
|
5677
5747
|
const mensagem = `Erro de execução: Você tentou desempacotar em ${qtdEsperada} variáveis, mas o vetor possui tamanho diferente.`;
|
|
5678
|
-
const falha = new declaracoes_1.Falhar(new lexador_1.Simbolo(pitugues_2.default.FALHAR,
|
|
5748
|
+
const falha = new declaracoes_1.Falhar(new lexador_1.Simbolo(pitugues_2.default.FALHAR, 'falhar', null, linha, -1), new construtos_1.Literal(this.hashArquivo, linha, mensagem, 'texto'));
|
|
5679
5749
|
return new declaracoes_1.Se(condicaoErro, new declaracoes_1.Bloco(this.hashArquivo, linha, [falha]), [], null);
|
|
5680
5750
|
}
|
|
5681
5751
|
async declaracaoDeVariaveis() {
|
|
@@ -5687,7 +5757,8 @@ class AvaliadorSintaticoPitugues {
|
|
|
5687
5757
|
const ehDesempacotamento = qtdIdentificadores > 1 && qtdValores === 1;
|
|
5688
5758
|
if (indexResto > -1) {
|
|
5689
5759
|
if (qtdValores < qtdIdentificadores - 1) {
|
|
5690
|
-
if (!ehDesempacotamento ||
|
|
5760
|
+
if (!ehDesempacotamento ||
|
|
5761
|
+
(ehDesempacotamento && inicializadores[0] instanceof construtos_1.Literal)) {
|
|
5691
5762
|
throw this.erro(this.simboloAnterior(), 'Quantidade insuficiente de valores para desempacotamento com operador de resto.');
|
|
5692
5763
|
}
|
|
5693
5764
|
}
|
|
@@ -5723,7 +5794,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
5723
5794
|
for (let i = 0; i < identificadores.length; i++) {
|
|
5724
5795
|
const identificador = identificadores[i];
|
|
5725
5796
|
let inicializador;
|
|
5726
|
-
let tipo =
|
|
5797
|
+
let tipo = 'qualquer';
|
|
5727
5798
|
if (i === indexResto) {
|
|
5728
5799
|
const valoresResto = inicializadores.slice(cursorValores, cursorValores + qtdParaResto);
|
|
5729
5800
|
let tipoInferido = (0, inferenciador_1.inferirTipoVariavel)(valoresResto);
|
|
@@ -5930,17 +6001,19 @@ class AvaliadorSintaticoPitugues {
|
|
|
5930
6001
|
case pitugues_2.default.INTERPOLACAO:
|
|
5931
6002
|
const simboloInterpolacao = this.avancarEDevolverAnterior();
|
|
5932
6003
|
const conteudoOriginal = simboloInterpolacao.literal;
|
|
5933
|
-
const codigoTransformado = '"' +
|
|
5934
|
-
|
|
5935
|
-
|
|
5936
|
-
|
|
5937
|
-
|
|
5938
|
-
|
|
5939
|
-
|
|
6004
|
+
const codigoTransformado = '"' +
|
|
6005
|
+
conteudoOriginal.replace(/\{(.*?)\}/g, (_, miolo) => {
|
|
6006
|
+
// 'miolo' é o texto que estava dentro das chaves. Ex: "valor" ou "valor:.2f"
|
|
6007
|
+
if (miolo.includes(':')) {
|
|
6008
|
+
const [variavel, formato] = miolo.split(':').map((s) => s.trim());
|
|
6009
|
+
if (variavel !== '') {
|
|
6010
|
+
// Transforma {valor:.2f} em "{:.2f}".formatar(valor)
|
|
6011
|
+
return '" + "{:' + formato + '}".formatar(' + variavel + ') + "';
|
|
6012
|
+
}
|
|
5940
6013
|
}
|
|
5941
|
-
|
|
5942
|
-
|
|
5943
|
-
|
|
6014
|
+
return '" + (' + miolo.trim() + ') + "';
|
|
6015
|
+
}) +
|
|
6016
|
+
'"';
|
|
5944
6017
|
const microLexador = new micro_lexador_pitugues_1.MicroLexadorPitugues();
|
|
5945
6018
|
const retornoMicroLexador = microLexador.mapear(codigoTransformado);
|
|
5946
6019
|
const microAvaliadorSintatico = new micro_avaliador_sintatico_pitugues_1.MicroAvaliadorSintaticoPitugues();
|
|
@@ -5953,7 +6026,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
5953
6026
|
}
|
|
5954
6027
|
catch (erro) {
|
|
5955
6028
|
this.erros.push(erro);
|
|
5956
|
-
return new construtos_1.Literal(this.hashArquivo, simboloInterpolacao.linha,
|
|
6029
|
+
return new construtos_1.Literal(this.hashArquivo, simboloInterpolacao.linha, '');
|
|
5957
6030
|
}
|
|
5958
6031
|
const declaracao = retornoMicroAvaliador.declaracoes[0];
|
|
5959
6032
|
return declaracao.expressao;
|
|
@@ -6011,11 +6084,11 @@ class AvaliadorSintaticoPitugues {
|
|
|
6011
6084
|
let passo = null;
|
|
6012
6085
|
if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.DOIS_PONTOS)) {
|
|
6013
6086
|
ehFatiamento = true;
|
|
6014
|
-
if (!this.verificarTipoSimboloAtual(pitugues_2.default.DOIS_PONTOS)
|
|
6015
|
-
|
|
6087
|
+
if (!this.verificarTipoSimboloAtual(pitugues_2.default.DOIS_PONTOS) &&
|
|
6088
|
+
!this.verificarTipoSimboloAtual(pitugues_2.default.COLCHETE_DIREITO))
|
|
6016
6089
|
fim = await this.expressao();
|
|
6017
|
-
if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.DOIS_PONTOS)
|
|
6018
|
-
|
|
6090
|
+
if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.DOIS_PONTOS) &&
|
|
6091
|
+
!this.verificarTipoSimboloAtual(pitugues_2.default.COLCHETE_DIREITO))
|
|
6019
6092
|
passo = await this.expressao();
|
|
6020
6093
|
}
|
|
6021
6094
|
const simboloFechamento = this.consumir(pitugues_2.default.COLCHETE_DIREITO, "Esperado ']' após escrita do indice.");
|
|
@@ -6147,11 +6220,13 @@ class AvaliadorSintaticoPitugues {
|
|
|
6147
6220
|
}
|
|
6148
6221
|
async seTernario() {
|
|
6149
6222
|
let expressaoEntao = await this.ou();
|
|
6150
|
-
if (this.simbolos[this.atual] &&
|
|
6223
|
+
if (this.simbolos[this.atual] &&
|
|
6224
|
+
this.simbolos[this.atual].tipo === pitugues_2.default.SE &&
|
|
6225
|
+
expressaoEntao.linha === this.simbolos[this.atual].linha) {
|
|
6151
6226
|
while (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.SE)) {
|
|
6152
6227
|
const operador = this.simbolos[this.atual - 1];
|
|
6153
6228
|
const expressaoOuCondicao = await this.seTernario();
|
|
6154
|
-
this.consumir(pitugues_2.default.SENAO, `Esperado 'senão' ou 'senao' após caminho positivo em se ternário. Atual:
|
|
6229
|
+
this.consumir(pitugues_2.default.SENAO, `Esperado 'senão' ou 'senao' após caminho positivo em se ternário. Atual:
|
|
6155
6230
|
${this.simbolos[this.atual].lexema}.`);
|
|
6156
6231
|
const expressaoSenao = await this.seTernario();
|
|
6157
6232
|
expressaoEntao = new construtos_1.SeTernario(this.hashArquivo, expressaoOuCondicao, expressaoEntao, operador, expressaoSenao);
|
|
@@ -6296,7 +6371,8 @@ class AvaliadorSintaticoPitugues {
|
|
|
6296
6371
|
simboloAtual = this.simboloAtual();
|
|
6297
6372
|
if (!simboloAtual)
|
|
6298
6373
|
break;
|
|
6299
|
-
espacosIndentacaoLinhaAtual =
|
|
6374
|
+
espacosIndentacaoLinhaAtual =
|
|
6375
|
+
this.localizacoes[simboloAtual.linha].espacosIndentacao;
|
|
6300
6376
|
}
|
|
6301
6377
|
}
|
|
6302
6378
|
this.pilhaEscopos.removerUltimo();
|
|
@@ -6306,7 +6382,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6306
6382
|
try {
|
|
6307
6383
|
this.blocos += 1;
|
|
6308
6384
|
const condicao = await this.expressao();
|
|
6309
|
-
const bloco = await this.resolverDeclaracao();
|
|
6385
|
+
const bloco = (await this.resolverDeclaracao());
|
|
6310
6386
|
return new declaracoes_1.Enquanto(condicao, bloco);
|
|
6311
6387
|
}
|
|
6312
6388
|
finally {
|
|
@@ -6380,7 +6456,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6380
6456
|
}
|
|
6381
6457
|
this.pilhaEscopos.definirInformacoesVariavel(nomeVariavelIteracao.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(nomeVariavelIteracao.lexema, tipoVetor.slice(0, -2)));
|
|
6382
6458
|
// TODO: Talvez não seja uma ideia melhor chamar o método de `Bloco` aqui?
|
|
6383
|
-
const corpo = await this.resolverDeclaracao();
|
|
6459
|
+
const corpo = (await this.resolverDeclaracao());
|
|
6384
6460
|
return new declaracoes_1.ParaCada(this.hashArquivo, Number(simboloPara.linha), new construtos_1.Variavel(this.hashArquivo, nomeVariavelIteracao), vetor, corpo);
|
|
6385
6461
|
}
|
|
6386
6462
|
async declaracaoPara() {
|
|
@@ -6412,7 +6488,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6412
6488
|
this.pilhaEscopos.definirInformacoesVariavel(simboloSegundaVariavel.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(simboloSegundaVariavel.lexema, 'qualquer'));
|
|
6413
6489
|
}
|
|
6414
6490
|
// TODO: Talvez não seja uma ideia melhor chamar o método de `Bloco` aqui?
|
|
6415
|
-
const corpo = await this.resolverDeclaracao();
|
|
6491
|
+
const corpo = (await this.resolverDeclaracao());
|
|
6416
6492
|
return new declaracoes_1.ParaCada(this.hashArquivo, Number(simboloPara.linha), variavelIteracao, alvoIteracao, corpo);
|
|
6417
6493
|
}
|
|
6418
6494
|
finally {
|
|
@@ -6441,7 +6517,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6441
6517
|
}
|
|
6442
6518
|
async declaracaoSe() {
|
|
6443
6519
|
const condicao = await this.expressao();
|
|
6444
|
-
const caminhoEntao = await this.resolverDeclaracao();
|
|
6520
|
+
const caminhoEntao = (await this.resolverDeclaracao());
|
|
6445
6521
|
let caminhoSenao = null;
|
|
6446
6522
|
if (this.verificarSeSimboloAtualEIgualA(pitugues_2.default.SENAO, pitugues_2.default.SENÃO)) {
|
|
6447
6523
|
caminhoSenao = await this.resolverDeclaracao();
|
|
@@ -6519,11 +6595,13 @@ class AvaliadorSintaticoPitugues {
|
|
|
6519
6595
|
this.consumir(pitugues_2.default.DOIS_PONTOS, `Esperado ':' antes do escopo do bloco 'pegue'.`);
|
|
6520
6596
|
this.pilhaEscopos.definirInformacoesVariavel(variavelExcecao.lexema, new informacao_elemento_sintatico_1.InformacaoElementoSintatico(variavelExcecao.lexema, 'qualquer'));
|
|
6521
6597
|
const corpo = await this.blocoEscopo();
|
|
6522
|
-
blocoPegue = new construtos_1.FuncaoConstruto(this.hashArquivo, simboloTente.linha, [
|
|
6523
|
-
|
|
6598
|
+
blocoPegue = new construtos_1.FuncaoConstruto(this.hashArquivo, simboloTente.linha, [
|
|
6599
|
+
{
|
|
6600
|
+
abrangencia: 'padrao',
|
|
6524
6601
|
nome: variavelExcecao,
|
|
6525
|
-
tipoDado:
|
|
6526
|
-
}
|
|
6602
|
+
tipoDado: 'qualquer',
|
|
6603
|
+
},
|
|
6604
|
+
], corpo, 'vazio', false);
|
|
6527
6605
|
}
|
|
6528
6606
|
else {
|
|
6529
6607
|
// Caso 2: sem parâmetro de erro.
|
|
@@ -6548,7 +6626,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6548
6626
|
const simboloFazer = this.simboloAnterior();
|
|
6549
6627
|
try {
|
|
6550
6628
|
this.blocos += 1;
|
|
6551
|
-
const declaracaoOuBlocoFazer = await this.resolverDeclaracao();
|
|
6629
|
+
const declaracaoOuBlocoFazer = (await this.resolverDeclaracao());
|
|
6552
6630
|
this.consumir(pitugues_2.default.ENQUANTO, "Esperado declaração do 'enquanto' após o escopo da declaração 'fazer'.");
|
|
6553
6631
|
const condicaoEnquanto = await this.expressao();
|
|
6554
6632
|
return new declaracoes_1.Fazer(simboloFazer.hashArquivo, Number(simboloFazer.linha), declaracaoOuBlocoFazer, condicaoEnquanto);
|
|
@@ -6714,7 +6792,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6714
6792
|
const simboloAnterior = this.simbolos[this.atual - 1];
|
|
6715
6793
|
if (simboloAnterior.tipo === pitugues_2.default.IDENTIFICADOR) {
|
|
6716
6794
|
this.consumir(pitugues_2.default.DOIS_PONTOS, "Esperado ':' antes do escopo da classe.");
|
|
6717
|
-
const tipoPropriedade = this.consumir(pitugues_2.default.IDENTIFICADOR,
|
|
6795
|
+
const tipoPropriedade = this.consumir(pitugues_2.default.IDENTIFICADOR, 'Esperado tipo de propriedade após dois-pontos, em declaração de classe.');
|
|
6718
6796
|
const propriedade = new declaracoes_1.PropriedadeClasse(simboloAnterior, tipoPropriedade.lexema, []);
|
|
6719
6797
|
propriedades.push(propriedade);
|
|
6720
6798
|
}
|
|
@@ -6869,8 +6947,10 @@ class AvaliadorSintaticoPitugues {
|
|
|
6869
6947
|
case pitugues_2.default.DE: {
|
|
6870
6948
|
const proximo = this.simbolos[this.atual + 1];
|
|
6871
6949
|
const aposProximo = this.simbolos[this.atual + 2];
|
|
6872
|
-
if (proximo &&
|
|
6873
|
-
|
|
6950
|
+
if (proximo &&
|
|
6951
|
+
proximo.tipo === pitugues_2.default.IDENTIFICADOR &&
|
|
6952
|
+
aposProximo &&
|
|
6953
|
+
aposProximo.tipo === pitugues_2.default.IMPORTAR) {
|
|
6874
6954
|
this.avancarEDevolverAnterior();
|
|
6875
6955
|
return this.declaracaoImportarDe();
|
|
6876
6956
|
}
|
|
@@ -6985,7 +7065,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6985
7065
|
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('elemento', 'qualquer'),
|
|
6986
7066
|
]));
|
|
6987
7067
|
this.pilhaEscopos.definirInformacoesVariavel('todos', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('todos', 'lógico', true, [
|
|
6988
|
-
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer')
|
|
7068
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
|
|
6989
7069
|
]));
|
|
6990
7070
|
this.pilhaEscopos.definirInformacoesVariavel('todosEmCondicao', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('todosEmCondicao', 'lógico', true, [
|
|
6991
7071
|
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('iteravel', 'qualquer'),
|
|
@@ -6995,7 +7075,7 @@ class AvaliadorSintaticoPitugues {
|
|
|
6995
7075
|
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'qualquer[]'),
|
|
6996
7076
|
]));
|
|
6997
7077
|
this.pilhaEscopos.definirInformacoesVariavel('vetor', new informacao_elemento_sintatico_1.InformacaoElementoSintatico('vetor', 'vetor', true, [
|
|
6998
|
-
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('tupla', 'qualquer')
|
|
7078
|
+
new informacao_elemento_sintatico_1.InformacaoElementoSintatico('tupla', 'qualquer'),
|
|
6999
7079
|
]));
|
|
7000
7080
|
}
|
|
7001
7081
|
async analisar(retornoLexador, hashArquivo) {
|
|
@@ -7022,7 +7102,8 @@ class AvaliadorSintaticoPitugues {
|
|
|
7022
7102
|
else {
|
|
7023
7103
|
declaracoes.push(retornoDeclaracao);
|
|
7024
7104
|
}
|
|
7025
|
-
if (!this.estaNoFinal() &&
|
|
7105
|
+
if (!this.estaNoFinal() &&
|
|
7106
|
+
this.verificarTipoSimboloAtual(pitugues_2.default.PONTO_E_VIRGULA)) {
|
|
7026
7107
|
// Verificar se este ; está na mesma linha da declaração anterior
|
|
7027
7108
|
const declaracaoAnterior = declaracoes[declaracoes.length - 1];
|
|
7028
7109
|
const linhaDeclaraoAnterior = declaracaoAnterior.linha || 0;
|
|
@@ -7408,12 +7489,12 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
7408
7489
|
*/
|
|
7409
7490
|
construtoTextoMultilinhas() {
|
|
7410
7491
|
const segundoColchete = this.consumir(prisma_1.default.COLCHETE_ESQUERDO, "Esperado '[' antes do texto multilinhas.");
|
|
7411
|
-
let texto =
|
|
7492
|
+
let texto = '';
|
|
7412
7493
|
let linha = segundoColchete.linha;
|
|
7413
7494
|
while (!this.verificarSeSimboloAtualEIgualA(prisma_1.default.COLCHETE_DIREITO)) {
|
|
7414
|
-
texto += this.simbolos[this.atual].lexema +
|
|
7495
|
+
texto += this.simbolos[this.atual].lexema + ' ';
|
|
7415
7496
|
if (this.simbolos[this.atual].linha !== linha) {
|
|
7416
|
-
texto +=
|
|
7497
|
+
texto += '\n';
|
|
7417
7498
|
linha = this.simbolos[this.atual].linha;
|
|
7418
7499
|
}
|
|
7419
7500
|
this.avancarEDevolverAnterior();
|
|
@@ -7645,7 +7726,7 @@ class AvaliadorSintaticoPrisma extends avaliador_sintatico_base_1.AvaliadorSinta
|
|
|
7645
7726
|
try {
|
|
7646
7727
|
this.blocos += 1;
|
|
7647
7728
|
const condicao = await this.expressao();
|
|
7648
|
-
const bloco = await this.resolverDeclaracao();
|
|
7729
|
+
const bloco = (await this.resolverDeclaracao());
|
|
7649
7730
|
return new declaracoes_1.Enquanto(condicao, bloco);
|
|
7650
7731
|
}
|
|
7651
7732
|
finally {
|
|
@@ -8671,7 +8752,7 @@ class AvaliadorSintaticoTenda extends avaliador_sintatico_base_1.AvaliadorSintat
|
|
|
8671
8752
|
async declaracaoSe() {
|
|
8672
8753
|
const condicao = await this.expressao();
|
|
8673
8754
|
this.consumir(tenda_1.default.ENTÃO, "Esperado 'então' após a condição.");
|
|
8674
|
-
const caminhoEntao = await this.resolverDeclaracao();
|
|
8755
|
+
const caminhoEntao = (await this.resolverDeclaracao());
|
|
8675
8756
|
let caminhoSenao = null;
|
|
8676
8757
|
if (this.verificarSeSimboloAtualEIgualA(tenda_1.default.SENÃO)) {
|
|
8677
8758
|
caminhoSenao = await this.resolverDeclaracao();
|
|
@@ -9782,15 +9863,51 @@ const estruturas_1 = require("../interpretador/estruturas");
|
|
|
9782
9863
|
const construtos_1 = require("../construtos");
|
|
9783
9864
|
const quebras_1 = require("../quebras");
|
|
9784
9865
|
const configTuplas = {
|
|
9785
|
-
|
|
9786
|
-
|
|
9787
|
-
|
|
9788
|
-
|
|
9789
|
-
|
|
9790
|
-
|
|
9791
|
-
|
|
9792
|
-
|
|
9793
|
-
|
|
9866
|
+
Dupla: { Classe: construtos_1.Dupla, props: ['primeiro', 'segundo'] },
|
|
9867
|
+
Trio: { Classe: construtos_1.Trio, props: ['primeiro', 'segundo', 'terceiro'] },
|
|
9868
|
+
Quarteto: { Classe: construtos_1.Quarteto, props: ['primeiro', 'segundo', 'terceiro', 'quarto'] },
|
|
9869
|
+
Quinteto: { Classe: construtos_1.Quinteto, props: ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto'] },
|
|
9870
|
+
Sexteto: {
|
|
9871
|
+
Classe: construtos_1.Sexteto,
|
|
9872
|
+
props: ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto', 'sexto'],
|
|
9873
|
+
},
|
|
9874
|
+
Septeto: {
|
|
9875
|
+
Classe: construtos_1.Septeto,
|
|
9876
|
+
props: ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto', 'sexto', 'setimo'],
|
|
9877
|
+
},
|
|
9878
|
+
Octeto: {
|
|
9879
|
+
Classe: construtos_1.Octeto,
|
|
9880
|
+
props: ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto', 'sexto', 'setimo', 'oitavo'],
|
|
9881
|
+
},
|
|
9882
|
+
Noneto: {
|
|
9883
|
+
Classe: construtos_1.Noneto,
|
|
9884
|
+
props: [
|
|
9885
|
+
'primeiro',
|
|
9886
|
+
'segundo',
|
|
9887
|
+
'terceiro',
|
|
9888
|
+
'quarto',
|
|
9889
|
+
'quinto',
|
|
9890
|
+
'sexto',
|
|
9891
|
+
'setimo',
|
|
9892
|
+
'oitavo',
|
|
9893
|
+
'nono',
|
|
9894
|
+
],
|
|
9895
|
+
},
|
|
9896
|
+
Deceto: {
|
|
9897
|
+
Classe: construtos_1.Deceto,
|
|
9898
|
+
props: [
|
|
9899
|
+
'primeiro',
|
|
9900
|
+
'segundo',
|
|
9901
|
+
'terceiro',
|
|
9902
|
+
'quarto',
|
|
9903
|
+
'quinto',
|
|
9904
|
+
'sexto',
|
|
9905
|
+
'setimo',
|
|
9906
|
+
'oitavo',
|
|
9907
|
+
'nono',
|
|
9908
|
+
'decimo',
|
|
9909
|
+
],
|
|
9910
|
+
},
|
|
9794
9911
|
};
|
|
9795
9912
|
const mapaConstrutoresTupla = {
|
|
9796
9913
|
2: construtos_1.Dupla,
|
|
@@ -9801,18 +9918,39 @@ const mapaConstrutoresTupla = {
|
|
|
9801
9918
|
7: construtos_1.Septeto,
|
|
9802
9919
|
8: construtos_1.Octeto,
|
|
9803
9920
|
9: construtos_1.Noneto,
|
|
9804
|
-
10: construtos_1.Deceto
|
|
9921
|
+
10: construtos_1.Deceto,
|
|
9805
9922
|
};
|
|
9806
9923
|
const mapaPropriedadesTuplas = {
|
|
9807
|
-
|
|
9808
|
-
|
|
9809
|
-
|
|
9810
|
-
|
|
9811
|
-
|
|
9812
|
-
|
|
9813
|
-
|
|
9814
|
-
|
|
9815
|
-
|
|
9924
|
+
Dupla: ['primeiro', 'segundo'],
|
|
9925
|
+
Trio: ['primeiro', 'segundo', 'terceiro'],
|
|
9926
|
+
Quarteto: ['primeiro', 'segundo', 'terceiro', 'quarto'],
|
|
9927
|
+
Quinteto: ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto'],
|
|
9928
|
+
Sexteto: ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto', 'sexto'],
|
|
9929
|
+
Septeto: ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto', 'sexto', 'setimo'],
|
|
9930
|
+
Octeto: ['primeiro', 'segundo', 'terceiro', 'quarto', 'quinto', 'sexto', 'setimo', 'oitavo'],
|
|
9931
|
+
Noneto: [
|
|
9932
|
+
'primeiro',
|
|
9933
|
+
'segundo',
|
|
9934
|
+
'terceiro',
|
|
9935
|
+
'quarto',
|
|
9936
|
+
'quinto',
|
|
9937
|
+
'sexto',
|
|
9938
|
+
'setimo',
|
|
9939
|
+
'oitavo',
|
|
9940
|
+
'nono',
|
|
9941
|
+
],
|
|
9942
|
+
Deceto: [
|
|
9943
|
+
'primeiro',
|
|
9944
|
+
'segundo',
|
|
9945
|
+
'terceiro',
|
|
9946
|
+
'quarto',
|
|
9947
|
+
'quinto',
|
|
9948
|
+
'sexto',
|
|
9949
|
+
'setimo',
|
|
9950
|
+
'oitavo',
|
|
9951
|
+
'nono',
|
|
9952
|
+
'decimo',
|
|
9953
|
+
],
|
|
9816
9954
|
};
|
|
9817
9955
|
/**
|
|
9818
9956
|
* Compara dois valores (números ou vetores).
|
|
@@ -9930,16 +10068,15 @@ async function arredondar(interpretador, numero, casasDecimais) {
|
|
|
9930
10068
|
const valorNumero = interpretador.resolverValor(numero);
|
|
9931
10069
|
const valorCasas = interpretador.resolverValor(casasDecimais);
|
|
9932
10070
|
if (numero == undefined || numero == null) {
|
|
9933
|
-
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null,
|
|
10071
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null, 'Erro: arredondar() deve receber um número.', interpretador.linhaDeclaracaoAtual));
|
|
9934
10072
|
}
|
|
9935
|
-
if (typeof numero !==
|
|
10073
|
+
if (typeof numero !== 'number') {
|
|
9936
10074
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null, `Erro de Tipo: arredondar() espera um número, mas recebeu '${typeof valorNumero}'.`, interpretador.linhaDeclaracaoAtual));
|
|
9937
10075
|
}
|
|
9938
10076
|
const fator = Math.pow(10, valorCasas);
|
|
9939
10077
|
const resultado = Math.round(valorNumero * fator) / fator;
|
|
9940
10078
|
return Promise.resolve(resultado);
|
|
9941
10079
|
}
|
|
9942
|
-
;
|
|
9943
10080
|
/**
|
|
9944
10081
|
* Clona profundamente uma variável ou constante em Delégua.
|
|
9945
10082
|
* @param {InterpretadorInterface} interpretador A instância do interpretador.
|
|
@@ -10328,8 +10465,10 @@ async function intervalo(interpretador, valorInicial, valorFinal, valorPasso) {
|
|
|
10328
10465
|
}
|
|
10329
10466
|
// intervalo(inicio, parada) ou intervalo(inicio, parada, passo)
|
|
10330
10467
|
else {
|
|
10331
|
-
if (typeof primeiroParam !== 'number' ||
|
|
10332
|
-
|
|
10468
|
+
if (typeof primeiroParam !== 'number' ||
|
|
10469
|
+
isNaN(primeiroParam) ||
|
|
10470
|
+
typeof segundoParam !== 'number' ||
|
|
10471
|
+
isNaN(segundoParam)) {
|
|
10333
10472
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
10334
10473
|
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
10335
10474
|
linha: interpretador.linhaDeclaracaoAtual,
|
|
@@ -10712,14 +10851,18 @@ async function tamanho(interpretador, objeto) {
|
|
|
10712
10851
|
const metodos = valorObjeto.metodos;
|
|
10713
10852
|
let tamanho = 0;
|
|
10714
10853
|
const metodoInicializacao = metodos.inicializacao;
|
|
10715
|
-
if (metodoInicializacao &&
|
|
10854
|
+
if (metodoInicializacao &&
|
|
10855
|
+
!Array.isArray(metodoInicializacao) &&
|
|
10856
|
+
metodoInicializacao.eInicializador) {
|
|
10716
10857
|
tamanho = metodoInicializacao.declaracao.parametros.length;
|
|
10717
10858
|
}
|
|
10718
10859
|
else if (Array.isArray(metodoInicializacao)) {
|
|
10719
10860
|
// Em caso de construtores sobrecarregados, `metodos.inicializacao` pode ser um array.
|
|
10720
10861
|
// Usamos o maior número de parâmetros entre as sobrecargas que são inicializadores.
|
|
10721
10862
|
for (const inicializador of metodoInicializacao) {
|
|
10722
|
-
if (inicializador &&
|
|
10863
|
+
if (inicializador &&
|
|
10864
|
+
inicializador.eInicializador &&
|
|
10865
|
+
((_a = inicializador.declaracao) === null || _a === void 0 ? void 0 : _a.parametros)) {
|
|
10723
10866
|
const aridade = inicializador.declaracao.parametros.length;
|
|
10724
10867
|
if (aridade > tamanho) {
|
|
10725
10868
|
tamanho = aridade;
|
|
@@ -10789,8 +10932,7 @@ async function todosEmCondicao(interpretador, iteravel, funcaoCondicional) {
|
|
|
10789
10932
|
}, 'Parâmetro inválido. O primeiro parâmetro deve ser um iterável.'));
|
|
10790
10933
|
}
|
|
10791
10934
|
const valorFuncao = interpretador.resolverValor(funcaoCondicional);
|
|
10792
|
-
const ehFuncaoValida = valorFuncao instanceof estruturas_1.DeleguaFuncao ||
|
|
10793
|
-
valorFuncao instanceof funcao_padrao_1.FuncaoPadrao;
|
|
10935
|
+
const ehFuncaoValida = valorFuncao instanceof estruturas_1.DeleguaFuncao || valorFuncao instanceof funcao_padrao_1.FuncaoPadrao;
|
|
10794
10936
|
if (!ehFuncaoValida) {
|
|
10795
10937
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao({
|
|
10796
10938
|
hashArquivo: interpretador.hashArquivoDeclaracaoAtual,
|
|
@@ -10815,7 +10957,7 @@ async function todosEmCondicao(interpretador, iteravel, funcaoCondicional) {
|
|
|
10815
10957
|
*/
|
|
10816
10958
|
async function tupla(interpretador, vetor) {
|
|
10817
10959
|
const valorVetor = interpretador.resolverValor(vetor);
|
|
10818
|
-
const elementos = valorVetor.map(item => new construtos_1.Literal(interpretador.hashArquivoDeclaracaoAtual, interpretador.linhaDeclaracaoAtual, interpretador.resolverValor(item)));
|
|
10960
|
+
const elementos = valorVetor.map((item) => new construtos_1.Literal(interpretador.hashArquivoDeclaracaoAtual, interpretador.linhaDeclaracaoAtual, interpretador.resolverValor(item)));
|
|
10819
10961
|
return new construtos_1.TuplaN(interpretador.hashArquivoDeclaracaoAtual, interpretador.linhaDeclaracaoAtual, elementos);
|
|
10820
10962
|
}
|
|
10821
10963
|
async function vetor(interpretador, tupla) {
|
|
@@ -10834,9 +10976,10 @@ async function vetor(interpretador, tupla) {
|
|
|
10834
10976
|
const nomeClasse = objetoTupla.constructor.name;
|
|
10835
10977
|
const props = mapaPropriedadesTuplas[nomeClasse];
|
|
10836
10978
|
if (props) {
|
|
10837
|
-
resultado = props.map(prop => objetoTupla[prop]);
|
|
10979
|
+
resultado = props.map((prop) => objetoTupla[prop]);
|
|
10838
10980
|
}
|
|
10839
|
-
else if (objetoTupla.elementos &&
|
|
10981
|
+
else if (objetoTupla.elementos &&
|
|
10982
|
+
Array.isArray(objetoTupla.elementos)) {
|
|
10840
10983
|
resultado = objetoTupla.elementos;
|
|
10841
10984
|
}
|
|
10842
10985
|
}
|
|
@@ -10862,14 +11005,13 @@ exports.default = {
|
|
|
10862
11005
|
if (!(objetoTupla instanceof construtos_1.TuplaN)) {
|
|
10863
11006
|
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(null, `A função "paraVetor" só pode ser chamada em tuplas.`, interpretador.linhaDeclaracaoAtual));
|
|
10864
11007
|
}
|
|
10865
|
-
const valoresPuros = objetoTupla.elementos.map(elemento => interpretador.resolverValor(elemento));
|
|
11008
|
+
const valoresPuros = objetoTupla.elementos.map((elemento) => interpretador.resolverValor(elemento));
|
|
10866
11009
|
return Promise.resolve(valoresPuros);
|
|
10867
11010
|
},
|
|
10868
11011
|
assinaturaFormato: 'tupla.paraVetor()',
|
|
10869
|
-
documentacao: '# `tupla.paraVetor()` \n \n' +
|
|
10870
|
-
'Converte a tupla atual em um array.',
|
|
11012
|
+
documentacao: '# `tupla.paraVetor()` \n \n' + 'Converte a tupla atual em um array.',
|
|
10871
11013
|
exemploCodigo: 'tupla.paraVetor()',
|
|
10872
|
-
}
|
|
11014
|
+
},
|
|
10873
11015
|
};
|
|
10874
11016
|
|
|
10875
11017
|
},{"../../../construtos":62,"../../../excecoes":131}],29:[function(require,module,exports){
|
|
@@ -10951,7 +11093,7 @@ exports.default = {
|
|
|
10951
11093
|
implementacao: (interpretador, valor) => {
|
|
10952
11094
|
return Promise.resolve(Object.values(valor));
|
|
10953
11095
|
},
|
|
10954
|
-
}
|
|
11096
|
+
},
|
|
10955
11097
|
};
|
|
10956
11098
|
|
|
10957
11099
|
},{"../construtos":62,"../informacao-elemento-sintatico":138}],30:[function(require,module,exports){
|
|
@@ -11072,7 +11214,7 @@ const implementacaoParticao = (interpretador, texto, separador, ...args) => {
|
|
|
11072
11214
|
const depois = texto.substring(indice + separador.length);
|
|
11073
11215
|
partes = [antes, separador, depois];
|
|
11074
11216
|
}
|
|
11075
|
-
const elementos = partes.map(p => new construtos_1.Literal(interpretador.hashArquivoDeclaracaoAtual, interpretador.linhaDeclaracaoAtual, p, 'texto'));
|
|
11217
|
+
const elementos = partes.map((p) => new construtos_1.Literal(interpretador.hashArquivoDeclaracaoAtual, interpretador.linhaDeclaracaoAtual, p, 'texto'));
|
|
11076
11218
|
const tupla = new construtos_1.TuplaN(interpretador.hashArquivoDeclaracaoAtual, interpretador.linhaDeclaracaoAtual, elementos);
|
|
11077
11219
|
return Promise.resolve(tupla);
|
|
11078
11220
|
};
|
|
@@ -11454,7 +11596,7 @@ const mapaConstrutoresTupla = {
|
|
|
11454
11596
|
7: construtos_1.Septeto,
|
|
11455
11597
|
8: construtos_1.Octeto,
|
|
11456
11598
|
9: construtos_1.Noneto,
|
|
11457
|
-
10: construtos_1.Deceto
|
|
11599
|
+
10: construtos_1.Deceto,
|
|
11458
11600
|
};
|
|
11459
11601
|
exports.default = {
|
|
11460
11602
|
adicionar: {
|
|
@@ -12085,7 +12227,7 @@ class AjudaComoConstruto {
|
|
|
12085
12227
|
return retorno;
|
|
12086
12228
|
}
|
|
12087
12229
|
paraTextoSaida() {
|
|
12088
|
-
throw new Error(
|
|
12230
|
+
throw new Error('Method not implemented.');
|
|
12089
12231
|
}
|
|
12090
12232
|
}
|
|
12091
12233
|
exports.AjudaComoConstruto = AjudaComoConstruto;
|
|
@@ -12191,9 +12333,12 @@ class Atribuir {
|
|
|
12191
12333
|
const alvoComoVariavel = alvo;
|
|
12192
12334
|
const tipoAlvo = alvoComoVariavel === null || alvoComoVariavel === void 0 ? void 0 : alvoComoVariavel.tipo;
|
|
12193
12335
|
const alvoSuportaIndice = alvo instanceof variavel_1.Variavel &&
|
|
12194
|
-
(tipoAlvo === 'vetor' ||
|
|
12336
|
+
(tipoAlvo === 'vetor' ||
|
|
12337
|
+
tipoAlvo === 'dicionário' ||
|
|
12338
|
+
tipoAlvo === 'qualquer' ||
|
|
12339
|
+
(tipoAlvo === null || tipoAlvo === void 0 ? void 0 : tipoAlvo.endsWith('[]')));
|
|
12195
12340
|
if (!alvoSuportaIndice) {
|
|
12196
|
-
throw new Error(
|
|
12341
|
+
throw new Error('`indice` só pode ser informado quando o alvo for uma variável de vetor ou dicionário.');
|
|
12197
12342
|
}
|
|
12198
12343
|
this.indice = indice;
|
|
12199
12344
|
}
|
|
@@ -12262,8 +12407,7 @@ class Binario {
|
|
|
12262
12407
|
['logico', 'lógico'].includes(this.direita.tipo)) {
|
|
12263
12408
|
return 'lógico';
|
|
12264
12409
|
}
|
|
12265
|
-
if (this.esquerda.tipo === 'texto' ||
|
|
12266
|
-
this.direita.tipo === 'texto') {
|
|
12410
|
+
if (this.esquerda.tipo === 'texto' || this.direita.tipo === 'texto') {
|
|
12267
12411
|
return 'texto';
|
|
12268
12412
|
}
|
|
12269
12413
|
if (['numero', 'número'].includes(this.esquerda.tipo) ||
|
|
@@ -12429,7 +12573,9 @@ class Decorador {
|
|
|
12429
12573
|
continue;
|
|
12430
12574
|
}
|
|
12431
12575
|
const valor = this.atributos[chave];
|
|
12432
|
-
const valorTexto = valor && typeof valor === 'object' && typeof valor.paraTexto === 'function'
|
|
12576
|
+
const valorTexto = valor && typeof valor === 'object' && typeof valor.paraTexto === 'function'
|
|
12577
|
+
? valor.paraTexto()
|
|
12578
|
+
: valor;
|
|
12433
12579
|
atributos += `${chave}=${valorTexto} `;
|
|
12434
12580
|
}
|
|
12435
12581
|
if (atributos.length > 0) {
|
|
@@ -13130,11 +13276,13 @@ class TuplaN extends tupla_1.Tupla {
|
|
|
13130
13276
|
return await visitante.visitarExpressaoTuplaN(this);
|
|
13131
13277
|
}
|
|
13132
13278
|
paraTexto() {
|
|
13133
|
-
const elementosTexto = this.elementos.map(elemento => elemento.paraTexto()).join(', ');
|
|
13279
|
+
const elementosTexto = this.elementos.map((elemento) => elemento.paraTexto()).join(', ');
|
|
13134
13280
|
return `(${elementosTexto})`;
|
|
13135
13281
|
}
|
|
13136
13282
|
paraTextoSaida() {
|
|
13137
|
-
const elementosTexto = this.elementos
|
|
13283
|
+
const elementosTexto = this.elementos
|
|
13284
|
+
.map((elemento) => elemento.paraTextoSaida())
|
|
13285
|
+
.join(', ');
|
|
13138
13286
|
return `(${elementosTexto})`;
|
|
13139
13287
|
}
|
|
13140
13288
|
}
|
|
@@ -14675,7 +14823,11 @@ class EstilizadorDelegua {
|
|
|
14675
14823
|
* Verifica se um objeto é uma Declaração.
|
|
14676
14824
|
*/
|
|
14677
14825
|
ehDeclaracao(obj) {
|
|
14678
|
-
return obj &&
|
|
14826
|
+
return (obj &&
|
|
14827
|
+
typeof obj === 'object' &&
|
|
14828
|
+
'paraTexto' in obj &&
|
|
14829
|
+
'linha' in obj &&
|
|
14830
|
+
'hashArquivo' in obj);
|
|
14679
14831
|
}
|
|
14680
14832
|
/**
|
|
14681
14833
|
* Verifica se um objeto é um Construto.
|
|
@@ -15902,24 +16054,60 @@ class FormatadorPitugues {
|
|
|
15902
16054
|
this.nívelIndentação -= this.tamanhoIndentação;
|
|
15903
16055
|
}
|
|
15904
16056
|
// Métodos obrigatórios da interface, não usados no Pituguês.
|
|
15905
|
-
visitarDeclaracaoCabecalhoPrograma() {
|
|
15906
|
-
|
|
15907
|
-
|
|
15908
|
-
|
|
15909
|
-
|
|
15910
|
-
|
|
15911
|
-
|
|
15912
|
-
|
|
15913
|
-
|
|
15914
|
-
|
|
15915
|
-
|
|
15916
|
-
|
|
15917
|
-
|
|
15918
|
-
|
|
15919
|
-
|
|
15920
|
-
|
|
15921
|
-
|
|
15922
|
-
|
|
16057
|
+
visitarDeclaracaoCabecalhoPrograma() {
|
|
16058
|
+
return Promise.resolve();
|
|
16059
|
+
}
|
|
16060
|
+
visitarDeclaracaoConstMultiplo() {
|
|
16061
|
+
return Promise.resolve();
|
|
16062
|
+
}
|
|
16063
|
+
visitarDeclaracaoEscrevaMesmaLinha() {
|
|
16064
|
+
return Promise.resolve();
|
|
16065
|
+
}
|
|
16066
|
+
visitarDeclaracaoInicioAlgoritmo() {
|
|
16067
|
+
return Promise.resolve();
|
|
16068
|
+
}
|
|
16069
|
+
visitarDeclaracaoTendoComo() {
|
|
16070
|
+
return Promise.resolve();
|
|
16071
|
+
}
|
|
16072
|
+
visitarDeclaracaoVarMultiplo() {
|
|
16073
|
+
return Promise.resolve();
|
|
16074
|
+
}
|
|
16075
|
+
visitarExpressaoAcessoElementoMatriz() {
|
|
16076
|
+
return Promise.resolve();
|
|
16077
|
+
}
|
|
16078
|
+
visitarExpressaoAcessoMetodo() {
|
|
16079
|
+
return Promise.resolve();
|
|
16080
|
+
}
|
|
16081
|
+
visitarExpressaoAcessoPropriedade() {
|
|
16082
|
+
return Promise.resolve();
|
|
16083
|
+
}
|
|
16084
|
+
visitarExpressaoArgumentoReferenciaFuncao() {
|
|
16085
|
+
return Promise.resolve();
|
|
16086
|
+
}
|
|
16087
|
+
visitarExpressaoAtribuicaoPorIndicesMatriz() {
|
|
16088
|
+
return Promise.resolve();
|
|
16089
|
+
}
|
|
16090
|
+
visitarExpressaoComentario() {
|
|
16091
|
+
return Promise.resolve();
|
|
16092
|
+
}
|
|
16093
|
+
visitarExpressaoExpressaoRegular() {
|
|
16094
|
+
return Promise.resolve();
|
|
16095
|
+
}
|
|
16096
|
+
visitarExpressaoFimPara() {
|
|
16097
|
+
return Promise.resolve();
|
|
16098
|
+
}
|
|
16099
|
+
visitarExpressaoFormatacaoEscrita() {
|
|
16100
|
+
return Promise.resolve();
|
|
16101
|
+
}
|
|
16102
|
+
visitarExpressaoReferenciaFuncao() {
|
|
16103
|
+
return Promise.resolve();
|
|
16104
|
+
}
|
|
16105
|
+
visitarExpressaoSeparador() {
|
|
16106
|
+
return Promise.resolve();
|
|
16107
|
+
}
|
|
16108
|
+
visitarExpressaoTupla() {
|
|
16109
|
+
return Promise.resolve();
|
|
16110
|
+
}
|
|
15923
16111
|
async visitarExpressaoTuplaN(expressao) {
|
|
15924
16112
|
this.códigoFormatado += '(';
|
|
15925
16113
|
for (let i = 0; i < expressao.elementos.length; i++) {
|
|
@@ -15933,7 +16121,7 @@ class FormatadorPitugues {
|
|
|
15933
16121
|
}
|
|
15934
16122
|
async visitarDeclaracaoDeExpressao(declaracao) {
|
|
15935
16123
|
this.códigoFormatado += this.indentar();
|
|
15936
|
-
this.códigoFormatado += await declaracao.expressao.aceitar(this) + `\n`;
|
|
16124
|
+
this.códigoFormatado += (await declaracao.expressao.aceitar(this)) + `\n`;
|
|
15937
16125
|
}
|
|
15938
16126
|
async visitarDeclaracaoClasse(declaração) {
|
|
15939
16127
|
this.adicionarLinha(`classe ${declaração.simbolo.lexema}:`);
|
|
@@ -16088,7 +16276,9 @@ class FormatadorPitugues {
|
|
|
16088
16276
|
if (declaração.caminhoPegue) {
|
|
16089
16277
|
this.adicionarLinha('pegue como erro:');
|
|
16090
16278
|
this.aumentarIndentação();
|
|
16091
|
-
const declaracoes = declaração.caminhoPegue instanceof construtos_1.FuncaoConstruto
|
|
16279
|
+
const declaracoes = declaração.caminhoPegue instanceof construtos_1.FuncaoConstruto
|
|
16280
|
+
? declaração.caminhoPegue.corpo
|
|
16281
|
+
: declaração.caminhoPegue;
|
|
16092
16282
|
for (const instrução of declaracoes) {
|
|
16093
16283
|
await instrução.aceitar(this);
|
|
16094
16284
|
}
|
|
@@ -16103,7 +16293,9 @@ class FormatadorPitugues {
|
|
|
16103
16293
|
}
|
|
16104
16294
|
}
|
|
16105
16295
|
async visitarDeclaracaoEscreva(declaração) {
|
|
16106
|
-
this.códigoFormatado +=
|
|
16296
|
+
this.códigoFormatado +=
|
|
16297
|
+
this.indentar() +
|
|
16298
|
+
`${declaração.simboloEscreva ? declaração.simboloEscreva.lexema : 'imprima'}(`;
|
|
16107
16299
|
for (let i = 0; i < declaração.argumentos.length; i++) {
|
|
16108
16300
|
this.códigoFormatado += await declaração.argumentos[i].aceitar(this);
|
|
16109
16301
|
if (i < declaração.argumentos.length - 1)
|
|
@@ -16178,8 +16370,10 @@ class FormatadorPitugues {
|
|
|
16178
16370
|
return `(${await expressão.expressao.aceitar(this)})`;
|
|
16179
16371
|
}
|
|
16180
16372
|
async visitarExpressaoUnaria(expressão) {
|
|
16181
|
-
const operador = expressão.operador.tipo === pitugues_1.default.SUBTRACAO
|
|
16182
|
-
|
|
16373
|
+
const operador = expressão.operador.tipo === pitugues_1.default.SUBTRACAO
|
|
16374
|
+
? '-'
|
|
16375
|
+
: expressão.operador.tipo === pitugues_1.default.NEGACAO
|
|
16376
|
+
? 'não '
|
|
16183
16377
|
: '';
|
|
16184
16378
|
const operando = await expressão.operando.aceitar(this);
|
|
16185
16379
|
return expressão.incidenciaOperador === 'ANTES'
|
|
@@ -16188,7 +16382,7 @@ class FormatadorPitugues {
|
|
|
16188
16382
|
}
|
|
16189
16383
|
async visitarExpressaoDeChamada(expressão) {
|
|
16190
16384
|
const função = await expressão.entidadeChamada.aceitar(this);
|
|
16191
|
-
const argumentos = await Promise.all(expressão.argumentos.map(a => a.aceitar(this)));
|
|
16385
|
+
const argumentos = await Promise.all(expressão.argumentos.map((a) => a.aceitar(this)));
|
|
16192
16386
|
return `${função}(${argumentos.join(', ')})`;
|
|
16193
16387
|
}
|
|
16194
16388
|
visitarExpressaoIsto() {
|
|
@@ -16198,7 +16392,7 @@ class FormatadorPitugues {
|
|
|
16198
16392
|
return 'super()';
|
|
16199
16393
|
}
|
|
16200
16394
|
async visitarExpressaoVetor(expressão) {
|
|
16201
|
-
const valores = await Promise.all(expressão.valores.map(v => v.aceitar(this)));
|
|
16395
|
+
const valores = await Promise.all(expressão.valores.map((v) => v.aceitar(this)));
|
|
16202
16396
|
return `[${valores.join(', ')}]`;
|
|
16203
16397
|
}
|
|
16204
16398
|
async visitarExpressaoDicionario(expressão) {
|
|
@@ -16236,15 +16430,18 @@ class FormatadorPitugues {
|
|
|
16236
16430
|
return `${objeto}.${expressão.nome.lexema} = ${valor}`;
|
|
16237
16431
|
}
|
|
16238
16432
|
async visitarExpressaoFuncaoConstruto(expressão) {
|
|
16239
|
-
const parâmetros = expressão.parametros
|
|
16433
|
+
const parâmetros = expressão.parametros
|
|
16434
|
+
.map((p) => {
|
|
16240
16435
|
const tipo = p.tipoDado ? `: ${p.tipoDado}` : '';
|
|
16241
16436
|
return p.nome.lexema + tipo;
|
|
16242
|
-
})
|
|
16437
|
+
})
|
|
16438
|
+
.join(', ');
|
|
16243
16439
|
let funçãoStr = `função(${parâmetros || ''}):\n`;
|
|
16244
16440
|
this.aumentarIndentação();
|
|
16245
16441
|
for (const instrução of expressão.corpo) {
|
|
16246
16442
|
const linha = await instrução.aceitar(this);
|
|
16247
|
-
if (linha) {
|
|
16443
|
+
if (linha) {
|
|
16444
|
+
// Only add if it returns something
|
|
16248
16445
|
funçãoStr += this.indentar() + linha;
|
|
16249
16446
|
if (!linha.endsWith('\n'))
|
|
16250
16447
|
funçãoStr += '\n';
|
|
@@ -16254,7 +16451,7 @@ class FormatadorPitugues {
|
|
|
16254
16451
|
return funçãoStr.trimEnd();
|
|
16255
16452
|
}
|
|
16256
16453
|
async visitarExpressaoLeia(expressão) {
|
|
16257
|
-
const argumentos = await Promise.all(expressão.argumentos.map(a => a.aceitar(this)));
|
|
16454
|
+
const argumentos = await Promise.all(expressão.argumentos.map((a) => a.aceitar(this)));
|
|
16258
16455
|
return argumentos.length > 0 ? `input(${argumentos.join(', ')})` : 'input()';
|
|
16259
16456
|
}
|
|
16260
16457
|
async visitarExpressaoTipoDe(expressão) {
|
|
@@ -16340,12 +16537,12 @@ function uuidv4() {
|
|
|
16340
16537
|
let r = Math.random() * 16; // random number between 0 and 16
|
|
16341
16538
|
if (d > 0) {
|
|
16342
16539
|
// Use timestamp until depleted
|
|
16343
|
-
r = (d + r) % 16 | 0;
|
|
16540
|
+
r = ((d + r) % 16) | 0;
|
|
16344
16541
|
d = Math.floor(d / 16);
|
|
16345
16542
|
}
|
|
16346
16543
|
else {
|
|
16347
16544
|
// Use microseconds since page-load if supported
|
|
16348
|
-
r = (d2 + r) % 16 | 0;
|
|
16545
|
+
r = ((d2 + r) % 16) | 0;
|
|
16349
16546
|
d2 = Math.floor(d2 / 16);
|
|
16350
16547
|
}
|
|
16351
16548
|
return (c === 'x' ? r : (r & 0x3) | 0x8).toString(16);
|
|
@@ -16817,23 +17014,23 @@ function carregarBibliotecasGlobais(pilhaEscoposExecucao) {
|
|
|
16817
17014
|
}
|
|
16818
17015
|
function pontoEntradaAjuda(funcao, topico) {
|
|
16819
17016
|
if (!funcao) {
|
|
16820
|
-
return
|
|
17017
|
+
return 'Para usar a ajuda, use como uma função: ajuda(objeto).';
|
|
16821
17018
|
}
|
|
16822
17019
|
if (!topico) {
|
|
16823
|
-
return
|
|
16824
|
-
|
|
16825
|
-
"Use ajuda('tópico') para obter informações sobre um tópico específico.\n\n";
|
|
17020
|
+
return ('Te damos as boas-vindas ao utilitário de ajuda de Delégua!\n\n' +
|
|
17021
|
+
'Use ajuda(objeto) para obter informações sobre um objeto, função, classe ou módulo.\n' +
|
|
17022
|
+
"Use ajuda('tópico') para obter informações sobre um tópico específico.\n\n");
|
|
16826
17023
|
}
|
|
16827
17024
|
return obterTopicoAjuda(topico);
|
|
16828
17025
|
}
|
|
16829
17026
|
function obterTopicoAjuda(topico) {
|
|
16830
17027
|
switch (topico.constructor) {
|
|
16831
17028
|
case construtos_1.Leia:
|
|
16832
|
-
return `A instrução 'leia' permite capturar a entrada do usuário durante a execução do programa. ` +
|
|
17029
|
+
return (`A instrução 'leia' permite capturar a entrada do usuário durante a execução do programa. ` +
|
|
16833
17030
|
`Você pode usar 'leia()' para ler uma linha de entrada do usuário e armazená-la em uma variável. ` +
|
|
16834
17031
|
`Exemplo de uso:\n\n` +
|
|
16835
17032
|
`\tvar minhaVariavel = leia()\n\n` +
|
|
16836
|
-
`Isto irá ler a entrada do usuário e atribuí-la à variável 'minhaVariavel'
|
|
17033
|
+
`Isto irá ler a entrada do usuário e atribuí-la à variável 'minhaVariavel'.`);
|
|
16837
17034
|
case funcao_padrao_1.FuncaoPadrao:
|
|
16838
17035
|
return obterAjudaFuncaoPadrao(topico);
|
|
16839
17036
|
case delegua_funcao_1.DeleguaFuncao:
|
|
@@ -16888,21 +17085,21 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16888
17085
|
const aridade = funcaoPadrao.valorAridade;
|
|
16889
17086
|
const implementacao = funcaoPadrao.funcao;
|
|
16890
17087
|
// Mapeamento de funções por nome
|
|
16891
|
-
const nomeFuncao = Object.keys(bibliotecaGlobal).find(key => bibliotecaGlobal[key] === implementacao);
|
|
17088
|
+
const nomeFuncao = Object.keys(bibliotecaGlobal).find((key) => bibliotecaGlobal[key] === implementacao);
|
|
16892
17089
|
if (!nomeFuncao) {
|
|
16893
17090
|
return 'Função não identificada. Não há documentação disponível.';
|
|
16894
17091
|
}
|
|
16895
17092
|
switch (nomeFuncao) {
|
|
16896
17093
|
case 'aleatorio':
|
|
16897
|
-
return `# aleatorio()\n\n` +
|
|
17094
|
+
return (`# aleatorio()\n\n` +
|
|
16898
17095
|
`Retorna um número aleatório entre 0 e 1.\n\n` +
|
|
16899
17096
|
`**Sintaxe:** aleatorio()\n\n` +
|
|
16900
17097
|
`**Retorno:** Número real entre 0 (inclusivo) e 1 (exclusivo).\n\n` +
|
|
16901
17098
|
`**Exemplo:**\n` +
|
|
16902
17099
|
`\tvar numeroSorteado = aleatorio()\n` +
|
|
16903
|
-
`\tescreva(numeroSorteado) // Pode retornar algo como 0.4829374657\n
|
|
17100
|
+
`\tescreva(numeroSorteado) // Pode retornar algo como 0.4829374657\n`);
|
|
16904
17101
|
case 'aleatorioEntre':
|
|
16905
|
-
return `# aleatorioEntre(minimo, maximo)\n\n` +
|
|
17102
|
+
return (`# aleatorioEntre(minimo, maximo)\n\n` +
|
|
16906
17103
|
`Retorna um número aleatório inteiro de acordo com os parâmetros passados.\n` +
|
|
16907
17104
|
`Mínimo (inclusivo) - Máximo (exclusivo).\n\n` +
|
|
16908
17105
|
`**Sintaxe:** aleatorioEntre(minimo: número, maximo: número)\n\n` +
|
|
@@ -16912,9 +17109,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16912
17109
|
`**Retorno:** Número inteiro entre minimo e maximo-1.\n\n` +
|
|
16913
17110
|
`**Exemplo:**\n` +
|
|
16914
17111
|
`\tvar dado = aleatorioEntre(1, 7)\n` +
|
|
16915
|
-
`\tescreva(dado) // Retorna um número entre 1 e 6\n
|
|
17112
|
+
`\tescreva(dado) // Retorna um número entre 1 e 6\n`);
|
|
16916
17113
|
case 'algum':
|
|
16917
|
-
return `# algum(vetor, funcaoPesquisa)\n\n` +
|
|
17114
|
+
return (`# algum(vetor, funcaoPesquisa)\n\n` +
|
|
16918
17115
|
`Verifica se algum dos elementos do vetor satisfaz a condição definida pela função de pesquisa.\n\n` +
|
|
16919
17116
|
`**Sintaxe:** algum(vetor: qualquer[], funcaoPesquisa: função)\n\n` +
|
|
16920
17117
|
`**Parâmetros:**\n` +
|
|
@@ -16924,9 +17121,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16924
17121
|
`**Exemplo:**\n` +
|
|
16925
17122
|
`\tvar numeros = [1, 2, 3, 4, 5]\n` +
|
|
16926
17123
|
`\tvar temPar = algum(numeros, funcao(n) { retorna n % 2 == 0 })\n` +
|
|
16927
|
-
`\tescreva(temPar) // verdadeiro\n
|
|
17124
|
+
`\tescreva(temPar) // verdadeiro\n`);
|
|
16928
17125
|
case 'clonar':
|
|
16929
|
-
return `# clonar(valor)\n\n` +
|
|
17126
|
+
return (`# clonar(valor)\n\n` +
|
|
16930
17127
|
`Clona profundamente uma variável ou constante em Delégua, criando uma cópia independente.\n\n` +
|
|
16931
17128
|
`**Sintaxe:** clonar(valor: qualquer)\n\n` +
|
|
16932
17129
|
`**Parâmetros:**\n` +
|
|
@@ -16937,9 +17134,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16937
17134
|
`\tvar copia = clonar(original)\n` +
|
|
16938
17135
|
`\tcopia[2][0] = 99\n` +
|
|
16939
17136
|
`\tescreva(original[2][0]) // 3 (não foi modificado)\n` +
|
|
16940
|
-
`\tescreva(copia[2][0]) // 99\n
|
|
17137
|
+
`\tescreva(copia[2][0]) // 99\n`);
|
|
16941
17138
|
case 'encontrar':
|
|
16942
|
-
return `# encontrar(vetor, funcaoPesquisa)\n\n` +
|
|
17139
|
+
return (`# encontrar(vetor, funcaoPesquisa)\n\n` +
|
|
16943
17140
|
`Encontra o primeiro elemento de um vetor cuja função de pesquisa retorne verdadeiro.\n\n` +
|
|
16944
17141
|
`**Sintaxe:** encontrar(vetor: qualquer[], funcaoPesquisa: função)\n\n` +
|
|
16945
17142
|
`**Parâmetros:**\n` +
|
|
@@ -16949,9 +17146,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16949
17146
|
`**Exemplo:**\n` +
|
|
16950
17147
|
`\tvar numeros = [1, 3, 5, 8, 10]\n` +
|
|
16951
17148
|
`\tvar primeiroPar = encontrar(numeros, funcao(n) { retorna n % 2 == 0 })\n` +
|
|
16952
|
-
`\tescreva(primeiroPar) // 8\n
|
|
17149
|
+
`\tescreva(primeiroPar) // 8\n`);
|
|
16953
17150
|
case 'encontrarIndice':
|
|
16954
|
-
return `# encontrarIndice(vetor, funcaoPesquisa)\n\n` +
|
|
17151
|
+
return (`# encontrarIndice(vetor, funcaoPesquisa)\n\n` +
|
|
16955
17152
|
`Encontra o índice do primeiro elemento de um vetor cuja função de pesquisa retorne verdadeiro.\n\n` +
|
|
16956
17153
|
`**Sintaxe:** encontrarIndice(vetor: qualquer[], funcaoPesquisa: função)\n\n` +
|
|
16957
17154
|
`**Parâmetros:**\n` +
|
|
@@ -16961,9 +17158,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16961
17158
|
`**Exemplo:**\n` +
|
|
16962
17159
|
`\tvar frutas = ["maçã", "banana", "laranja"]\n` +
|
|
16963
17160
|
`\tvar indice = encontrarIndice(frutas, funcao(f) { retorna f == "banana" })\n` +
|
|
16964
|
-
`\tescreva(indice) // 1\n
|
|
17161
|
+
`\tescreva(indice) // 1\n`);
|
|
16965
17162
|
case 'encontrarUltimo':
|
|
16966
|
-
return `# encontrarUltimo(vetor, funcaoPesquisa)\n\n` +
|
|
17163
|
+
return (`# encontrarUltimo(vetor, funcaoPesquisa)\n\n` +
|
|
16967
17164
|
`Encontra o último elemento de um vetor cuja função de pesquisa retorne verdadeiro.\n\n` +
|
|
16968
17165
|
`**Sintaxe:** encontrarUltimo(vetor: qualquer[], funcaoPesquisa: função)\n\n` +
|
|
16969
17166
|
`**Parâmetros:**\n` +
|
|
@@ -16973,9 +17170,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16973
17170
|
`**Exemplo:**\n` +
|
|
16974
17171
|
`\tvar numeros = [2, 4, 6, 7, 9]\n` +
|
|
16975
17172
|
`\tvar ultimoPar = encontrarUltimo(numeros, funcao(n) { retorna n % 2 == 0 })\n` +
|
|
16976
|
-
`\tescreva(ultimoPar) // 6\n
|
|
17173
|
+
`\tescreva(ultimoPar) // 6\n`);
|
|
16977
17174
|
case 'encontrarUltimoIndice':
|
|
16978
|
-
return `# encontrarUltimoIndice(vetor, funcaoPesquisa)\n\n` +
|
|
17175
|
+
return (`# encontrarUltimoIndice(vetor, funcaoPesquisa)\n\n` +
|
|
16979
17176
|
`Encontra o índice do último elemento de um vetor cuja função de pesquisa retorne verdadeiro.\n\n` +
|
|
16980
17177
|
`**Sintaxe:** encontrarUltimoIndice(vetor: qualquer[], funcaoPesquisa: função)\n\n` +
|
|
16981
17178
|
`**Parâmetros:**\n` +
|
|
@@ -16985,9 +17182,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16985
17182
|
`**Exemplo:**\n` +
|
|
16986
17183
|
`\tvar numeros = [2, 4, 6, 7, 9]\n` +
|
|
16987
17184
|
`\tvar indiceUltimoPar = encontrarUltimoIndice(numeros, funcao(n) { retorna n % 2 == 0 })\n` +
|
|
16988
|
-
`\tescreva(indiceUltimoPar) // 2\n
|
|
17185
|
+
`\tescreva(indiceUltimoPar) // 2\n`);
|
|
16989
17186
|
case 'filtrarPor':
|
|
16990
|
-
return `# filtrarPor(vetor, funcaoFiltragem)\n\n` +
|
|
17187
|
+
return (`# filtrarPor(vetor, funcaoFiltragem)\n\n` +
|
|
16991
17188
|
`Cria um novo vetor com todos os elementos que passam no teste implementado pela função de filtragem.\n\n` +
|
|
16992
17189
|
`**Sintaxe:** filtrarPor(vetor: qualquer[], funcaoFiltragem: função)\n\n` +
|
|
16993
17190
|
`**Parâmetros:**\n` +
|
|
@@ -16997,9 +17194,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
16997
17194
|
`**Exemplo:**\n` +
|
|
16998
17195
|
`\tvar numeros = [1, 2, 3, 4, 5, 6]\n` +
|
|
16999
17196
|
`\tvar pares = filtrarPor(numeros, funcao(n) { retorna n % 2 == 0 })\n` +
|
|
17000
|
-
`\tescreva(pares) // [2, 4, 6]\n
|
|
17197
|
+
`\tescreva(pares) // [2, 4, 6]\n`);
|
|
17001
17198
|
case 'incluido':
|
|
17002
|
-
return `# incluido(vetor, valor)\n\n` +
|
|
17199
|
+
return (`# incluido(vetor, valor)\n\n` +
|
|
17003
17200
|
`Verifica se um valor está incluído em um vetor.\n\n` +
|
|
17004
17201
|
`**Sintaxe:** incluido(vetor: qualquer[], valor: qualquer)\n\n` +
|
|
17005
17202
|
`**Parâmetros:**\n` +
|
|
@@ -17009,9 +17206,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17009
17206
|
`**Exemplo:**\n` +
|
|
17010
17207
|
`\tvar frutas = ["maçã", "banana", "laranja"]\n` +
|
|
17011
17208
|
`\tescreva(incluido(frutas, "banana")) // verdadeiro\n` +
|
|
17012
|
-
`\tescreva(incluido(frutas, "uva")) // falso\n
|
|
17209
|
+
`\tescreva(incluido(frutas, "uva")) // falso\n`);
|
|
17013
17210
|
case 'inteiro':
|
|
17014
|
-
return `# inteiro(valor)\n\n` +
|
|
17211
|
+
return (`# inteiro(valor)\n\n` +
|
|
17015
17212
|
`Converte um valor em um número inteiro.\n\n` +
|
|
17016
17213
|
`**Sintaxe:** inteiro(valor: número | texto)\n\n` +
|
|
17017
17214
|
`**Parâmetros:**\n` +
|
|
@@ -17020,9 +17217,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17020
17217
|
`**Exemplo:**\n` +
|
|
17021
17218
|
`\tescreva(inteiro(3.14)) // 3\n` +
|
|
17022
17219
|
`\tescreva(inteiro("42")) // 42\n` +
|
|
17023
|
-
`\tescreva(inteiro("3.99")) // 3\n
|
|
17220
|
+
`\tescreva(inteiro("3.99")) // 3\n`);
|
|
17024
17221
|
case 'intervalo':
|
|
17025
|
-
return `# intervalo(valorInicial, valorFinal)\n\n` +
|
|
17222
|
+
return (`# intervalo(valorInicial, valorFinal)\n\n` +
|
|
17026
17223
|
`Cria um vetor com números inteiros no intervalo especificado.\n` +
|
|
17027
17224
|
`O valor inicial é inclusivo e o valor final é exclusivo.\n\n` +
|
|
17028
17225
|
`**Sintaxe:** intervalo(valorInicial: número, valorFinal: número)\n\n` +
|
|
@@ -17032,9 +17229,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17032
17229
|
`**Retorno:** Vetor com os números no intervalo especificado.\n\n` +
|
|
17033
17230
|
`**Exemplo:**\n` +
|
|
17034
17231
|
`\tvar numeros = intervalo(1, 6)\n` +
|
|
17035
|
-
`\tescreva(numeros) // [1, 2, 3, 4, 5]\n
|
|
17232
|
+
`\tescreva(numeros) // [1, 2, 3, 4, 5]\n`);
|
|
17036
17233
|
case 'mapear':
|
|
17037
|
-
return `# mapear(vetor, funcaoMapeamento)\n\n` +
|
|
17234
|
+
return (`# mapear(vetor, funcaoMapeamento)\n\n` +
|
|
17038
17235
|
`Cria um novo vetor com os resultados da aplicação de uma função a cada elemento do vetor original.\n\n` +
|
|
17039
17236
|
`**Sintaxe:** mapear(vetor: qualquer[], funcaoMapeamento: função)\n\n` +
|
|
17040
17237
|
`**Parâmetros:**\n` +
|
|
@@ -17044,13 +17241,13 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17044
17241
|
`**Exemplo:**\n` +
|
|
17045
17242
|
`\tvar numeros = [1, 2, 3, 4]\n` +
|
|
17046
17243
|
`\tvar quadrados = mapear(numeros, funcao(n) { retorna n * n })\n` +
|
|
17047
|
-
`\tescreva(quadrados) // [1, 4, 9, 16]\n
|
|
17244
|
+
`\tescreva(quadrados) // [1, 4, 9, 16]\n`);
|
|
17048
17245
|
case 'maximo':
|
|
17049
17246
|
return `# maximo(vetor)\n\nRetorna o maior valor encontrado em um vetor de números.`;
|
|
17050
17247
|
case 'minimo':
|
|
17051
17248
|
return `# minimo(vetor)\n\nRetorna o menor valor encontrado em um vetor de números.`;
|
|
17052
17249
|
case 'numero':
|
|
17053
|
-
return `# numero(valor)\n\n` +
|
|
17250
|
+
return (`# numero(valor)\n\n` +
|
|
17054
17251
|
`Converte um valor em um número (pode ter parte decimal).\n\n` +
|
|
17055
17252
|
`**Sintaxe:** numero(valor: número | texto)\n\n` +
|
|
17056
17253
|
`**Parâmetros:**\n` +
|
|
@@ -17059,9 +17256,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17059
17256
|
`**Exemplo:**\n` +
|
|
17060
17257
|
`\tescreva(numero("3.14")) // 3.14\n` +
|
|
17061
17258
|
`\tescreva(numero("42")) // 42\n` +
|
|
17062
|
-
`\tescreva(numero(5)) // 5\n
|
|
17259
|
+
`\tescreva(numero(5)) // 5\n`);
|
|
17063
17260
|
case 'ordenar':
|
|
17064
|
-
return `# ordenar(vetor)\n\n` +
|
|
17261
|
+
return (`# ordenar(vetor)\n\n` +
|
|
17065
17262
|
`Ordena os elementos de um vetor em ordem crescente (números) ou alfabética (textos).\n\n` +
|
|
17066
17263
|
`**Sintaxe:** ordenar(vetor: qualquer[])\n\n` +
|
|
17067
17264
|
`**Parâmetros:**\n` +
|
|
@@ -17070,9 +17267,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17070
17267
|
`**Exemplo:**\n` +
|
|
17071
17268
|
`\tvar numeros = [5, 2, 8, 1, 9]\n` +
|
|
17072
17269
|
`\tordenar(numeros)\n` +
|
|
17073
|
-
`\tescreva(numeros) // [1, 2, 5, 8, 9]\n
|
|
17270
|
+
`\tescreva(numeros) // [1, 2, 5, 8, 9]\n`);
|
|
17074
17271
|
case 'paraCada':
|
|
17075
|
-
return `# paraCada(vetor, funcao)\n\n` +
|
|
17272
|
+
return (`# paraCada(vetor, funcao)\n\n` +
|
|
17076
17273
|
`Executa uma função para cada elemento do vetor.\n\n` +
|
|
17077
17274
|
`**Sintaxe:** paraCada(vetor: qualquer[], funcao: função)\n\n` +
|
|
17078
17275
|
`**Parâmetros:**\n` +
|
|
@@ -17083,9 +17280,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17083
17280
|
`\tvar nomes = ["Ana", "Bruno", "Carlos"]\n` +
|
|
17084
17281
|
`\tparaCada(nomes, funcao(nome) {\n` +
|
|
17085
17282
|
`\t\tescreva("Olá, " + nome)\n` +
|
|
17086
|
-
`\t})\n
|
|
17283
|
+
`\t})\n`);
|
|
17087
17284
|
case 'primeiroEmCondicao':
|
|
17088
|
-
return `# primeiroEmCondicao(vetor, funcaoFiltragem)\n\n` +
|
|
17285
|
+
return (`# primeiroEmCondicao(vetor, funcaoFiltragem)\n\n` +
|
|
17089
17286
|
`Retorna o primeiro elemento que satisfaz a condição especificada pela função de filtragem.\n\n` +
|
|
17090
17287
|
`**Sintaxe:** primeiroEmCondicao(vetor: qualquer[], funcaoFiltragem: função)\n\n` +
|
|
17091
17288
|
`**Parâmetros:**\n` +
|
|
@@ -17095,9 +17292,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17095
17292
|
`**Exemplo:**\n` +
|
|
17096
17293
|
`\tvar numeros = [1, 3, 5, 8, 10]\n` +
|
|
17097
17294
|
`\tvar resultado = primeiroEmCondicao(numeros, funcao(n) { retorna n > 5 })\n` +
|
|
17098
|
-
`\tescreva(resultado) // 8\n
|
|
17295
|
+
`\tescreva(resultado) // 8\n`);
|
|
17099
17296
|
case 'real':
|
|
17100
|
-
return `# real(valor)\n\n` +
|
|
17297
|
+
return (`# real(valor)\n\n` +
|
|
17101
17298
|
`Converte um valor em um número real (ponto flutuante).\n\n` +
|
|
17102
17299
|
`**Sintaxe:** real(valor: número | texto)\n\n` +
|
|
17103
17300
|
`**Parâmetros:**\n` +
|
|
@@ -17105,9 +17302,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17105
17302
|
`**Retorno:** Número real correspondente ao valor fornecido.\n\n` +
|
|
17106
17303
|
`**Exemplo:**\n` +
|
|
17107
17304
|
`\tescreva(real("3.14")) // 3.14\n` +
|
|
17108
|
-
`\tescreva(real(42)) // 42.0\n
|
|
17305
|
+
`\tescreva(real(42)) // 42.0\n`);
|
|
17109
17306
|
case 'reduzir':
|
|
17110
|
-
return `# reduzir(vetor, funcaoReducao, valorInicial)\n\n` +
|
|
17307
|
+
return (`# reduzir(vetor, funcaoReducao, valorInicial)\n\n` +
|
|
17111
17308
|
`Aplica uma função a um acumulador e cada elemento do vetor para reduzi-lo a um único valor.\n\n` +
|
|
17112
17309
|
`**Sintaxe:** reduzir(vetor: qualquer[], funcaoReducao: função, valorInicial?: qualquer)\n\n` +
|
|
17113
17310
|
`**Parâmetros:**\n` +
|
|
@@ -17118,11 +17315,11 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17118
17315
|
`**Exemplo:**\n` +
|
|
17119
17316
|
`\tvar numeros = [1, 2, 3, 4]\n` +
|
|
17120
17317
|
`\tvar soma = reduzir(numeros, funcao(acc, n) { retorna acc + n }, 0)\n` +
|
|
17121
|
-
`\tescreva(soma) // 10\n
|
|
17318
|
+
`\tescreva(soma) // 10\n`);
|
|
17122
17319
|
case 'somar':
|
|
17123
17320
|
return `# somar(vetor)\n\nRetorna a soma de todos os elementos de um vetor numérico.`;
|
|
17124
17321
|
case 'tamanho':
|
|
17125
|
-
return `# tamanho(objeto)\n\n` +
|
|
17322
|
+
return (`# tamanho(objeto)\n\n` +
|
|
17126
17323
|
`Retorna o tamanho de um objeto (vetor, texto, função, etc.).\n\n` +
|
|
17127
17324
|
`**Sintaxe:** tamanho(objeto: qualquer)\n\n` +
|
|
17128
17325
|
`**Parâmetros:**\n` +
|
|
@@ -17131,9 +17328,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17131
17328
|
`Para funções, retorna o número de parâmetros.\n\n` +
|
|
17132
17329
|
`**Exemplo:**\n` +
|
|
17133
17330
|
`\tescreva(tamanho([1, 2, 3])) // 3\n` +
|
|
17134
|
-
`\tescreva(tamanho("Delégua")) // 7\n
|
|
17331
|
+
`\tescreva(tamanho("Delégua")) // 7\n`);
|
|
17135
17332
|
case 'texto':
|
|
17136
|
-
return `# texto(valor)\n\n` +
|
|
17333
|
+
return (`# texto(valor)\n\n` +
|
|
17137
17334
|
`Transforma o valor ou variável em texto.\n\n` +
|
|
17138
17335
|
`**Sintaxe:** texto(valor: qualquer)\n\n` +
|
|
17139
17336
|
`**Parâmetros:**\n` +
|
|
@@ -17142,9 +17339,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17142
17339
|
`**Exemplo:**\n` +
|
|
17143
17340
|
`\tescreva(texto(42)) // "42"\n` +
|
|
17144
17341
|
`\tescreva(texto(verdadeiro)) // "verdadeiro"\n` +
|
|
17145
|
-
`\tescreva(texto([1, 2, 3])) // "[1, 2, 3]"\n
|
|
17342
|
+
`\tescreva(texto([1, 2, 3])) // "[1, 2, 3]"\n`);
|
|
17146
17343
|
case 'todosEmCondicao':
|
|
17147
|
-
return `# todosEmCondicao(vetor, funcaoCondicional)\n\n` +
|
|
17344
|
+
return (`# todosEmCondicao(vetor, funcaoCondicional)\n\n` +
|
|
17148
17345
|
`Retorna verdadeiro se todos os elementos do vetor satisfazem a condição especificada pela função.\n\n` +
|
|
17149
17346
|
`**Sintaxe:** todosEmCondicao(vetor: qualquer[], funcaoCondicional: função)\n\n` +
|
|
17150
17347
|
`**Parâmetros:**\n` +
|
|
@@ -17154,9 +17351,9 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17154
17351
|
`**Exemplo:**\n` +
|
|
17155
17352
|
`\tvar numeros = [2, 4, 6, 8]\n` +
|
|
17156
17353
|
`\tvar todosPares = todosEmCondicao(numeros, funcao(n) { retorna n % 2 == 0 })\n` +
|
|
17157
|
-
`\tescreva(todosPares) // verdadeiro\n
|
|
17354
|
+
`\tescreva(todosPares) // verdadeiro\n`);
|
|
17158
17355
|
case 'tupla':
|
|
17159
|
-
return `# tupla(vetor)\n\n` +
|
|
17356
|
+
return (`# tupla(vetor)\n\n` +
|
|
17160
17357
|
`Transforma um vetor de elementos em uma tupla de N elementos, sendo N a largura do vetor.\n` +
|
|
17161
17358
|
`Tuplas são estruturas imutáveis de tamanho fixo.\n\n` +
|
|
17162
17359
|
`**Sintaxe:** tupla(vetor: qualquer[])\n\n` +
|
|
@@ -17166,10 +17363,10 @@ function obterAjudaFuncaoPadrao(funcaoPadrao) {
|
|
|
17166
17363
|
`**Exemplo:**\n` +
|
|
17167
17364
|
`\tvar coordenadas = tupla([10, 20])\n` +
|
|
17168
17365
|
`\tescreva(coordenadas.primeiro) // 10\n` +
|
|
17169
|
-
`\tescreva(coordenadas.segundo) // 20\n
|
|
17366
|
+
`\tescreva(coordenadas.segundo) // 20\n`);
|
|
17170
17367
|
default:
|
|
17171
|
-
return `Função global identificada, mas documentação específica não disponível.\n` +
|
|
17172
|
-
`Aridade: ${aridade} parâmetro(s)
|
|
17368
|
+
return (`Função global identificada, mas documentação específica não disponível.\n` +
|
|
17369
|
+
`Aridade: ${aridade} parâmetro(s).`);
|
|
17173
17370
|
}
|
|
17174
17371
|
}
|
|
17175
17372
|
|
|
@@ -17426,7 +17623,9 @@ class DeleguaFuncao extends chamavel_1.Chamavel {
|
|
|
17426
17623
|
if (this.instancia !== undefined) {
|
|
17427
17624
|
ambiente.valores['isto'] = {
|
|
17428
17625
|
valor: this.instancia,
|
|
17429
|
-
tipo: this.instancia instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse
|
|
17626
|
+
tipo: this.instancia instanceof objeto_delegua_classe_1.ObjetoDeleguaClasse
|
|
17627
|
+
? 'objeto'
|
|
17628
|
+
: tipoDeDados(this.instancia),
|
|
17430
17629
|
imutavel: false,
|
|
17431
17630
|
};
|
|
17432
17631
|
}
|
|
@@ -17509,11 +17708,11 @@ const chamavel_1 = require("./chamavel");
|
|
|
17509
17708
|
const metodo_polimorfico_1 = require("./metodo-polimorfico");
|
|
17510
17709
|
const objeto_delegua_classe_1 = require("./objeto-delegua-classe");
|
|
17511
17710
|
const mapaDeNormalizacao = {
|
|
17512
|
-
|
|
17513
|
-
|
|
17514
|
-
|
|
17515
|
-
|
|
17516
|
-
|
|
17711
|
+
numero: 'número',
|
|
17712
|
+
logico: 'lógico',
|
|
17713
|
+
funcao: 'função',
|
|
17714
|
+
dicionario: 'dicionário',
|
|
17715
|
+
modulo: 'módulo',
|
|
17517
17716
|
};
|
|
17518
17717
|
function normalizarTipo(tipo) {
|
|
17519
17718
|
if (!tipo || tipo === 'qualquer')
|
|
@@ -17764,7 +17963,7 @@ class DescritorTipoClasse extends chamavel_1.Chamavel {
|
|
|
17764
17963
|
var _a, _b;
|
|
17765
17964
|
const nome = (_b = (_a = this.simboloOriginal) === null || _a === void 0 ? void 0 : _a.lexema) !== null && _b !== void 0 ? _b : 'Objeto';
|
|
17766
17965
|
const nomesMetodos = Object.keys(this.metodos).join(', ');
|
|
17767
|
-
const nomesPropriedades = this.propriedades.map(p => p.nome.lexema).join(', ');
|
|
17966
|
+
const nomesPropriedades = this.propriedades.map((p) => p.nome.lexema).join(', ');
|
|
17768
17967
|
return `<[ ${nome} estático métodos=[${nomesMetodos}] propriedades=[${nomesPropriedades}] ]>`;
|
|
17769
17968
|
}
|
|
17770
17969
|
/**
|
|
@@ -17893,11 +18092,11 @@ const excecoes_1 = require("../../excecoes");
|
|
|
17893
18092
|
const chamavel_1 = require("./chamavel");
|
|
17894
18093
|
const tiposNumericos = ['inteiro', 'número', 'real', 'longo'];
|
|
17895
18094
|
const mapaDeNormalizacao = {
|
|
17896
|
-
|
|
17897
|
-
|
|
17898
|
-
|
|
17899
|
-
|
|
17900
|
-
|
|
18095
|
+
numero: 'número',
|
|
18096
|
+
logico: 'lógico',
|
|
18097
|
+
funcao: 'função',
|
|
18098
|
+
dicionario: 'dicionário',
|
|
18099
|
+
modulo: 'módulo',
|
|
17901
18100
|
};
|
|
17902
18101
|
function normalizarTipo(tipo) {
|
|
17903
18102
|
if (!tipo || tipo === 'qualquer')
|
|
@@ -17987,8 +18186,10 @@ class MetodoPolimorfico extends chamavel_1.Chamavel {
|
|
|
17987
18186
|
? argumentos[i].valor
|
|
17988
18187
|
: argumentos[i];
|
|
17989
18188
|
// Se o valor é uma VariavelInterface, extrair o valor real
|
|
17990
|
-
if (valorArgumento &&
|
|
17991
|
-
|
|
18189
|
+
if (valorArgumento &&
|
|
18190
|
+
typeof valorArgumento === 'object' &&
|
|
18191
|
+
valorArgumento.hasOwnProperty('valor') &&
|
|
18192
|
+
valorArgumento.hasOwnProperty('tipo')) {
|
|
17992
18193
|
valorArgumento = valorArgumento.valor;
|
|
17993
18194
|
}
|
|
17994
18195
|
const tipoArgumento = (0, inferenciador_1.inferirTipoVariavel)(valorArgumento);
|
|
@@ -18009,8 +18210,10 @@ class MetodoPolimorfico extends chamavel_1.Chamavel {
|
|
|
18009
18210
|
if (!melhorSobrecarga) {
|
|
18010
18211
|
const tiposArgs = argumentos.map((a) => {
|
|
18011
18212
|
let val = a && a.hasOwnProperty('valor') ? a.valor : a;
|
|
18012
|
-
if (val &&
|
|
18013
|
-
|
|
18213
|
+
if (val &&
|
|
18214
|
+
typeof val === 'object' &&
|
|
18215
|
+
val.hasOwnProperty('valor') &&
|
|
18216
|
+
val.hasOwnProperty('tipo')) {
|
|
18014
18217
|
val = val.valor;
|
|
18015
18218
|
}
|
|
18016
18219
|
return normalizarTipo((0, inferenciador_1.inferirTipoVariavel)(val));
|
|
@@ -18224,10 +18427,14 @@ const excecoes_1 = require("../../excecoes");
|
|
|
18224
18427
|
class ObjetoDeleguaClasse {
|
|
18225
18428
|
valorPadraoParaTipo(tipo) {
|
|
18226
18429
|
switch (tipo) {
|
|
18227
|
-
case 'numero':
|
|
18228
|
-
|
|
18229
|
-
case '
|
|
18230
|
-
|
|
18430
|
+
case 'numero':
|
|
18431
|
+
return 0;
|
|
18432
|
+
case 'texto':
|
|
18433
|
+
return '';
|
|
18434
|
+
case 'logico':
|
|
18435
|
+
return false;
|
|
18436
|
+
default:
|
|
18437
|
+
return undefined;
|
|
18231
18438
|
}
|
|
18232
18439
|
}
|
|
18233
18440
|
constructor(classe) {
|
|
@@ -18298,7 +18505,7 @@ class ObjetoDeleguaClasse {
|
|
|
18298
18505
|
return await metodoObtenedor.chamar(visitante, []);
|
|
18299
18506
|
}
|
|
18300
18507
|
// Auto-property: acessa o campo de armazenamento interno '_nome'
|
|
18301
|
-
const propAuto = this.classe.propriedades.find(p => p.nome.lexema === simbolo.lexema);
|
|
18508
|
+
const propAuto = this.classe.propriedades.find((p) => p.nome.lexema === simbolo.lexema);
|
|
18302
18509
|
if (propAuto === null || propAuto === void 0 ? void 0 : propAuto.autoObter) {
|
|
18303
18510
|
this.verificarAcessoLeitura(simbolo.lexema, simbolo, visitante);
|
|
18304
18511
|
return this.propriedades['_' + simbolo.lexema];
|
|
@@ -18343,7 +18550,7 @@ class ObjetoDeleguaClasse {
|
|
|
18343
18550
|
return;
|
|
18344
18551
|
}
|
|
18345
18552
|
// Auto-property: armazena no campo interno '_nome'
|
|
18346
|
-
const propAuto = this.classe.propriedades.find(p => p.nome.lexema === simbolo.lexema);
|
|
18553
|
+
const propAuto = this.classe.propriedades.find((p) => p.nome.lexema === simbolo.lexema);
|
|
18347
18554
|
if (propAuto === null || propAuto === void 0 ? void 0 : propAuto.autoDefinir) {
|
|
18348
18555
|
this.verificarAcessoLeitura(simbolo.lexema, simbolo, visitante);
|
|
18349
18556
|
this.propriedades['_' + simbolo.lexema] = valor;
|
|
@@ -18640,7 +18847,7 @@ class InterpretadorBase {
|
|
|
18640
18847
|
}
|
|
18641
18848
|
// Se é array, resolve recursivamente todos os elementos
|
|
18642
18849
|
if (Array.isArray(objeto)) {
|
|
18643
|
-
return objeto.map(elemento => this.resolverValorRecursivo(elemento));
|
|
18850
|
+
return objeto.map((elemento) => this.resolverValorRecursivo(elemento));
|
|
18644
18851
|
}
|
|
18645
18852
|
// Se é objeto plano, resolve recursivamente todas as propriedades
|
|
18646
18853
|
if (objeto && objeto.constructor && objeto.constructor === Object) {
|
|
@@ -18683,8 +18890,18 @@ class InterpretadorBase {
|
|
|
18683
18890
|
async visitarExpressaoTupla(expressao) {
|
|
18684
18891
|
// Lista de propriedades válidas para tuplas (ignorar propriedades de controle)
|
|
18685
18892
|
const propriedadesValidas = [
|
|
18686
|
-
'primeiro',
|
|
18687
|
-
'
|
|
18893
|
+
'primeiro',
|
|
18894
|
+
'segundo',
|
|
18895
|
+
'terceiro',
|
|
18896
|
+
'quarto',
|
|
18897
|
+
'quinto',
|
|
18898
|
+
'sexto',
|
|
18899
|
+
'sétimo',
|
|
18900
|
+
'setimo',
|
|
18901
|
+
'oitavo',
|
|
18902
|
+
'nono',
|
|
18903
|
+
'décimo',
|
|
18904
|
+
'decimo',
|
|
18688
18905
|
];
|
|
18689
18906
|
const valores = [];
|
|
18690
18907
|
for (let propriedade of propriedadesValidas) {
|
|
@@ -18701,7 +18918,7 @@ class InterpretadorBase {
|
|
|
18701
18918
|
const res = await this.avaliar(expressao.elementos[i]);
|
|
18702
18919
|
elementos.push(this.resolverValor(res));
|
|
18703
18920
|
}
|
|
18704
|
-
const elementosComoConstrutos = elementos.map(valor => new construtos_1.Literal(expressao.hashArquivo, expressao.linha, valor));
|
|
18921
|
+
const elementosComoConstrutos = elementos.map((valor) => new construtos_1.Literal(expressao.hashArquivo, expressao.linha, valor));
|
|
18705
18922
|
return new construtos_1.TuplaN(expressao.hashArquivo, expressao.linha, elementosComoConstrutos);
|
|
18706
18923
|
}
|
|
18707
18924
|
async visitarExpressaoAtribuicaoPorIndicesMatriz(expressao) {
|
|
@@ -19043,8 +19260,12 @@ class InterpretadorBase {
|
|
|
19043
19260
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
19044
19261
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
19045
19262
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
19046
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19047
|
-
|
|
19263
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19264
|
+
? valorEsquerdo
|
|
19265
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19266
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19267
|
+
? valorDireito
|
|
19268
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19048
19269
|
return esq ** dir;
|
|
19049
19270
|
}
|
|
19050
19271
|
const resultadoExponenciacao = Math.pow(valorEsquerdo, valorDireito);
|
|
@@ -19072,8 +19293,12 @@ class InterpretadorBase {
|
|
|
19072
19293
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
19073
19294
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
19074
19295
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
19075
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19076
|
-
|
|
19296
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19297
|
+
? valorEsquerdo
|
|
19298
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19299
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19300
|
+
? valorDireito
|
|
19301
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19077
19302
|
return esq - dir;
|
|
19078
19303
|
}
|
|
19079
19304
|
return Number(valorEsquerdo) - Number(valorDireito);
|
|
@@ -19085,8 +19310,12 @@ class InterpretadorBase {
|
|
|
19085
19310
|
}
|
|
19086
19311
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
19087
19312
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
19088
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19089
|
-
|
|
19313
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19314
|
+
? valorEsquerdo
|
|
19315
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19316
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19317
|
+
? valorDireito
|
|
19318
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19090
19319
|
return esq + dir;
|
|
19091
19320
|
}
|
|
19092
19321
|
if (this.tiposNumericos.includes(tipoEsquerdo) &&
|
|
@@ -19116,8 +19345,12 @@ class InterpretadorBase {
|
|
|
19116
19345
|
}
|
|
19117
19346
|
// Retorna BigInt se qualquer operando for BigInt
|
|
19118
19347
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
19119
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19120
|
-
|
|
19348
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19349
|
+
? valorEsquerdo
|
|
19350
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19351
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19352
|
+
? valorDireito
|
|
19353
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19121
19354
|
return esq / dir; // Trunca automaticamente
|
|
19122
19355
|
}
|
|
19123
19356
|
return Math.floor(Number(valorEsquerdo) / Number(valorDireito));
|
|
@@ -19127,8 +19360,12 @@ class InterpretadorBase {
|
|
|
19127
19360
|
if ((typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') &&
|
|
19128
19361
|
tipoEsquerdo !== delegua_2.default.TEXTO &&
|
|
19129
19362
|
tipoDireito !== delegua_2.default.TEXTO) {
|
|
19130
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19131
|
-
|
|
19363
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19364
|
+
? valorEsquerdo
|
|
19365
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19366
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19367
|
+
? valorDireito
|
|
19368
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19132
19369
|
return esq * dir;
|
|
19133
19370
|
}
|
|
19134
19371
|
if (tipoEsquerdo === delegua_2.default.TEXTO ||
|
|
@@ -19161,7 +19398,8 @@ class InterpretadorBase {
|
|
|
19161
19398
|
case delegua_1.default.MODULO:
|
|
19162
19399
|
case delegua_1.default.MODULO_IGUAL:
|
|
19163
19400
|
// Se o operando esquerdo é uma string, usar formatação de string
|
|
19164
|
-
if (tipoEsquerdo === delegua_2.default.TEXTO ||
|
|
19401
|
+
if (tipoEsquerdo === delegua_2.default.TEXTO ||
|
|
19402
|
+
typeof valorEsquerdo === 'string') {
|
|
19165
19403
|
return this.formatarStringComOperadorPorcentagem(String(valorEsquerdo), direita, // Passar 'direita' ao invés de 'valorDireito' para preservar arrays de tuplas
|
|
19166
19404
|
expressao.operador);
|
|
19167
19405
|
}
|
|
@@ -19175,8 +19413,12 @@ class InterpretadorBase {
|
|
|
19175
19413
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
19176
19414
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
19177
19415
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
19178
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19179
|
-
|
|
19416
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19417
|
+
? valorEsquerdo
|
|
19418
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19419
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19420
|
+
? valorDireito
|
|
19421
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19180
19422
|
return esq & dir;
|
|
19181
19423
|
}
|
|
19182
19424
|
return Number(valorEsquerdo) & Number(valorDireito);
|
|
@@ -19187,8 +19429,12 @@ class InterpretadorBase {
|
|
|
19187
19429
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
19188
19430
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
19189
19431
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
19190
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19191
|
-
|
|
19432
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19433
|
+
? valorEsquerdo
|
|
19434
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19435
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19436
|
+
? valorDireito
|
|
19437
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19192
19438
|
return esq ^ dir;
|
|
19193
19439
|
}
|
|
19194
19440
|
return Number(valorEsquerdo) ^ Number(valorDireito);
|
|
@@ -19199,8 +19445,12 @@ class InterpretadorBase {
|
|
|
19199
19445
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
19200
19446
|
// Auto-promove para BigInt se qualquer operando for BigInt
|
|
19201
19447
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
19202
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19203
|
-
|
|
19448
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19449
|
+
? valorEsquerdo
|
|
19450
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19451
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19452
|
+
? valorDireito
|
|
19453
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19204
19454
|
return esq | dir;
|
|
19205
19455
|
}
|
|
19206
19456
|
return Number(valorEsquerdo) | Number(valorDireito);
|
|
@@ -19208,9 +19458,15 @@ class InterpretadorBase {
|
|
|
19208
19458
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
19209
19459
|
// Auto-promove para BigInt (interno para longo) se qualquer operando for BigInt ou se deslocamento >= 32
|
|
19210
19460
|
const tamanhoDeslocamentoEsquerda = Number(valorDireito);
|
|
19211
|
-
if (typeof valorEsquerdo === 'bigint' ||
|
|
19212
|
-
|
|
19213
|
-
|
|
19461
|
+
if (typeof valorEsquerdo === 'bigint' ||
|
|
19462
|
+
typeof valorDireito === 'bigint' ||
|
|
19463
|
+
tamanhoDeslocamentoEsquerda >= 32) {
|
|
19464
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19465
|
+
? valorEsquerdo
|
|
19466
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19467
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19468
|
+
? valorDireito
|
|
19469
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19214
19470
|
return esq << dir;
|
|
19215
19471
|
}
|
|
19216
19472
|
return Number(valorEsquerdo) << Number(valorDireito);
|
|
@@ -19218,9 +19474,15 @@ class InterpretadorBase {
|
|
|
19218
19474
|
this.verificarOperandosNumeros(expressao.operador, esquerda, direita);
|
|
19219
19475
|
// Auto-promove para BigInt (interno para longo) se qualquer operando for BigInt ou se deslocamento >= 32
|
|
19220
19476
|
const tamanhoDeslocamentoDireita = Number(valorDireito);
|
|
19221
|
-
if (typeof valorEsquerdo === 'bigint' ||
|
|
19222
|
-
|
|
19223
|
-
|
|
19477
|
+
if (typeof valorEsquerdo === 'bigint' ||
|
|
19478
|
+
typeof valorDireito === 'bigint' ||
|
|
19479
|
+
tamanhoDeslocamentoDireita >= 32) {
|
|
19480
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19481
|
+
? valorEsquerdo
|
|
19482
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19483
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19484
|
+
? valorDireito
|
|
19485
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19224
19486
|
return esq >> dir;
|
|
19225
19487
|
}
|
|
19226
19488
|
return Number(valorEsquerdo) >> Number(valorDireito);
|
|
@@ -19341,7 +19603,8 @@ class InterpretadorBase {
|
|
|
19341
19603
|
// Casos que passam aqui: chamadas a métodos de bibliotecas de Delégua.
|
|
19342
19604
|
if (typeof entidadeChamada === primitivos_1.default.FUNCAO) {
|
|
19343
19605
|
let objeto = null;
|
|
19344
|
-
if (expressao.entidadeChamada.objeto) {
|
|
19606
|
+
if (expressao.entidadeChamada.objeto) {
|
|
19607
|
+
// TODO: Qual o tipo certo aqui?
|
|
19345
19608
|
objeto = await this.avaliar(expressao.entidadeChamada.objeto);
|
|
19346
19609
|
}
|
|
19347
19610
|
return entidadeChamada.apply(this.resolverValor(objeto), argumentos);
|
|
@@ -19400,7 +19663,8 @@ class InterpretadorBase {
|
|
|
19400
19663
|
}
|
|
19401
19664
|
logicaContemOuEm(esquerda, direita, expressao) {
|
|
19402
19665
|
const valorDireitoResolvido = this.resolverValor(direita);
|
|
19403
|
-
if (Array.isArray(valorDireitoResolvido) ||
|
|
19666
|
+
if (Array.isArray(valorDireitoResolvido) ||
|
|
19667
|
+
typeof valorDireitoResolvido === primitivos_1.default.TEXTO) {
|
|
19404
19668
|
const avaliacao = valorDireitoResolvido.includes(esquerda);
|
|
19405
19669
|
return expressao.negado ? !avaliacao : avaliacao;
|
|
19406
19670
|
}
|
|
@@ -19432,13 +19696,19 @@ class InterpretadorBase {
|
|
|
19432
19696
|
const valorDireito = this.resolverValor(direita);
|
|
19433
19697
|
if (typeof valorDireito === 'number' || typeof valorDireito === 'bigint') {
|
|
19434
19698
|
if (typeof valorEsquerdo === 'bigint' || typeof valorDireito === 'bigint') {
|
|
19435
|
-
const esq = typeof valorEsquerdo === 'bigint'
|
|
19436
|
-
|
|
19437
|
-
|
|
19699
|
+
const esq = typeof valorEsquerdo === 'bigint'
|
|
19700
|
+
? valorEsquerdo
|
|
19701
|
+
: BigInt(Math.floor(Number(valorEsquerdo)));
|
|
19702
|
+
const dir = typeof valorDireito === 'bigint'
|
|
19703
|
+
? valorDireito
|
|
19704
|
+
: BigInt(Math.floor(Number(valorDireito)));
|
|
19705
|
+
return expressao.operador.tipo === delegua_1.default.E
|
|
19706
|
+
? esq & dir
|
|
19707
|
+
: esq | dir;
|
|
19438
19708
|
}
|
|
19439
19709
|
return expressao.operador.tipo === delegua_1.default.E
|
|
19440
|
-
?
|
|
19441
|
-
:
|
|
19710
|
+
? Number(valorEsquerdo) & Number(valorDireito)
|
|
19711
|
+
: Number(valorEsquerdo) | Number(valorDireito);
|
|
19442
19712
|
}
|
|
19443
19713
|
// Demais casos sem diferença de tipos
|
|
19444
19714
|
if (expressao.operador.tipo === delegua_1.default.OU) {
|
|
@@ -19532,7 +19802,7 @@ class InterpretadorBase {
|
|
|
19532
19802
|
const valorComoDupla = valorVetorResolvido[declaracao.posicaoAtual];
|
|
19533
19803
|
const promises = await Promise.all([
|
|
19534
19804
|
this.avaliar(declaracao.variavelIteracao.primeiro),
|
|
19535
|
-
this.avaliar(declaracao.variavelIteracao.segundo)
|
|
19805
|
+
this.avaliar(declaracao.variavelIteracao.segundo),
|
|
19536
19806
|
]);
|
|
19537
19807
|
// TODO: O que fazer quando não forem literais?
|
|
19538
19808
|
this.pilhaEscoposExecucao.definirVariavel(String(promises[0].valor), valorComoDupla.primeiro);
|
|
@@ -19712,7 +19982,9 @@ class InterpretadorBase {
|
|
|
19712
19982
|
let formatoTexto = '';
|
|
19713
19983
|
for (const argumento of argumentos) {
|
|
19714
19984
|
let resultadoAvaliacao = await this.avaliar(argumento);
|
|
19715
|
-
if (resultadoAvaliacao &&
|
|
19985
|
+
if (resultadoAvaliacao &&
|
|
19986
|
+
resultadoAvaliacao.hasOwnProperty &&
|
|
19987
|
+
resultadoAvaliacao.hasOwnProperty('valorRetornado')) {
|
|
19716
19988
|
resultadoAvaliacao = resultadoAvaliacao.valorRetornado;
|
|
19717
19989
|
}
|
|
19718
19990
|
let valor = this.resolverValor(resultadoAvaliacao);
|
|
@@ -19953,12 +20225,12 @@ class InterpretadorBase {
|
|
|
19953
20225
|
}, 'Somente listas, dicionários, classes e objetos podem ter seus valores indexados.', expressao.linha));
|
|
19954
20226
|
}
|
|
19955
20227
|
/**
|
|
19956
|
-
|
|
19957
|
-
|
|
19958
|
-
|
|
19959
|
-
|
|
20228
|
+
* Método base para acesso a intervalo.
|
|
20229
|
+
* Por padrão lança erro, pois a maioria dos dialetos (como Delégua padrão)
|
|
20230
|
+
* ainda não suporta isso nativamente, apenas Pituguês.
|
|
20231
|
+
*/
|
|
19960
20232
|
visitarExpressaoAcessoIntervaloVariavel(expressao) {
|
|
19961
|
-
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento,
|
|
20233
|
+
return Promise.reject(new excecoes_1.ErroEmTempoDeExecucao(expressao.simboloFechamento, 'Acesso por intervalo não implementado para este dialeto.', expressao.linha));
|
|
19962
20234
|
}
|
|
19963
20235
|
async visitarExpressaoDefinirValor(expressao) {
|
|
19964
20236
|
const variavelObjeto = await this.avaliar(expressao.objeto);
|
|
@@ -20042,9 +20314,7 @@ class InterpretadorBase {
|
|
|
20042
20314
|
const funcao = new estruturas_1.DeleguaFuncao(nomeMetodo, metodoAtual.funcao, undefined, eInicializador);
|
|
20043
20315
|
funcao.documentacao = metodoAtual.documentacao;
|
|
20044
20316
|
// Numa classe estática, todos os métodos (exceto construtor) são estáticos.
|
|
20045
|
-
const ehEstatico = declaracao.classeEstatica
|
|
20046
|
-
? !eInicializador
|
|
20047
|
-
: metodoAtual.estatico;
|
|
20317
|
+
const ehEstatico = declaracao.classeEstatica ? !eInicializador : metodoAtual.estatico;
|
|
20048
20318
|
if (metodoAtual.eObtenedor) {
|
|
20049
20319
|
if (ehEstatico) {
|
|
20050
20320
|
obtenedoresEstaticos[nomeMetodo] = funcao;
|
|
@@ -20100,7 +20370,9 @@ class InterpretadorBase {
|
|
|
20100
20370
|
// Toda classe sem superclasse explícita herda implicitamente de `Objeto`.
|
|
20101
20371
|
// Isso só deve acontecer quando OBJETO_BASE já estiver inicializado e a classe
|
|
20102
20372
|
// atual não for o próprio OBJETO_BASE, para evitar cadeias de herança recursivas.
|
|
20103
|
-
if (descritorTipoClasse.superClasses.length === 0 &&
|
|
20373
|
+
if (descritorTipoClasse.superClasses.length === 0 &&
|
|
20374
|
+
estruturas_1.OBJETO_BASE &&
|
|
20375
|
+
descritorTipoClasse !== estruturas_1.OBJETO_BASE) {
|
|
20104
20376
|
descritorTipoClasse.superClasses = [estruturas_1.OBJETO_BASE];
|
|
20105
20377
|
}
|
|
20106
20378
|
// Calcular o OReM (linearização C3) após os pais estarem definidos.
|
|
@@ -20363,21 +20635,25 @@ class InterpretadorBase {
|
|
|
20363
20635
|
let valoresArray;
|
|
20364
20636
|
// Verificar se é uma TuplaN (verifica instanceof OU propriedade elementos/tipo para maior compatibilidade)
|
|
20365
20637
|
if (valores instanceof construtos_1.TuplaN ||
|
|
20366
|
-
(valores &&
|
|
20638
|
+
(valores &&
|
|
20639
|
+
valores.tipo === 'tupla' &&
|
|
20640
|
+
valores.elementos &&
|
|
20641
|
+
Array.isArray(valores.elementos))) {
|
|
20367
20642
|
valoresArray = valores.elementos.map((elem) => {
|
|
20368
|
-
if (elem instanceof construtos_1.Literal ||
|
|
20643
|
+
if (elem instanceof construtos_1.Literal ||
|
|
20644
|
+
(elem && typeof elem === 'object' && elem.hasOwnProperty('valor'))) {
|
|
20369
20645
|
return this.resolverValor(elem.valor);
|
|
20370
20646
|
}
|
|
20371
20647
|
return this.resolverValor(elem);
|
|
20372
20648
|
});
|
|
20373
20649
|
}
|
|
20374
20650
|
else if (Array.isArray(valores)) {
|
|
20375
|
-
valoresArray = valores.map(v => this.resolverValor(v));
|
|
20651
|
+
valoresArray = valores.map((v) => this.resolverValor(v));
|
|
20376
20652
|
}
|
|
20377
20653
|
else {
|
|
20378
20654
|
const valorResolvido = this.resolverValor(valores);
|
|
20379
20655
|
if (Array.isArray(valorResolvido)) {
|
|
20380
|
-
valoresArray = valorResolvido.map(v => this.resolverValor(v));
|
|
20656
|
+
valoresArray = valorResolvido.map((v) => this.resolverValor(v));
|
|
20381
20657
|
}
|
|
20382
20658
|
else {
|
|
20383
20659
|
valoresArray = [valorResolvido];
|
|
@@ -20499,7 +20775,9 @@ class InterpretadorBase {
|
|
|
20499
20775
|
return objeto.valor.paraTexto();
|
|
20500
20776
|
if (objeto instanceof construtos_1.Literal)
|
|
20501
20777
|
return this.paraTexto(objeto.valor);
|
|
20502
|
-
if (objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
|
|
20778
|
+
if (objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
|
|
20779
|
+
objeto instanceof estruturas_1.DeleguaFuncao ||
|
|
20780
|
+
objeto instanceof estruturas_1.DescritorTipoClasse)
|
|
20503
20781
|
return objeto.paraTexto();
|
|
20504
20782
|
if (objeto instanceof quebras_1.RetornoQuebra) {
|
|
20505
20783
|
if (typeof objeto.valor === 'boolean')
|
|
@@ -20764,10 +21042,7 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
20764
21042
|
return objeto;
|
|
20765
21043
|
}
|
|
20766
21044
|
serializarSemEspacos(objeto) {
|
|
20767
|
-
return JSON
|
|
20768
|
-
.stringify(objeto)
|
|
20769
|
-
.replace(/,\s+/g, ',')
|
|
20770
|
-
.replace(/:\s+/g, ':');
|
|
21045
|
+
return JSON.stringify(objeto).replace(/,\s+/g, ',').replace(/:\s+/g, ':');
|
|
20771
21046
|
}
|
|
20772
21047
|
paraTexto(objeto) {
|
|
20773
21048
|
if (objeto === null || objeto === undefined)
|
|
@@ -20782,7 +21057,9 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
20782
21057
|
return objeto.valor.paraTexto();
|
|
20783
21058
|
if (objeto instanceof construtos_1.Literal || objeto instanceof construtos_1.Tupla)
|
|
20784
21059
|
return objeto.paraTextoSaida();
|
|
20785
|
-
if (objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
|
|
21060
|
+
if (objeto instanceof estruturas_1.ObjetoDeleguaClasse ||
|
|
21061
|
+
objeto instanceof estruturas_1.DeleguaFuncao ||
|
|
21062
|
+
objeto instanceof estruturas_1.DescritorTipoClasse)
|
|
20786
21063
|
return objeto.paraTexto();
|
|
20787
21064
|
if (objeto instanceof quebras_1.RetornoQuebra) {
|
|
20788
21065
|
if (typeof objeto.valor === 'boolean')
|
|
@@ -21058,11 +21335,11 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
21058
21335
|
const valorComoDupla = valorVetorOuDicionarioResolvido[paraCada.posicaoAtual];
|
|
21059
21336
|
const nomesVariaveis = await Promise.all([
|
|
21060
21337
|
this.avaliar(paraCada.variavelIteracao.primeiro),
|
|
21061
|
-
this.avaliar(paraCada.variavelIteracao.segundo)
|
|
21338
|
+
this.avaliar(paraCada.variavelIteracao.segundo),
|
|
21062
21339
|
]);
|
|
21063
21340
|
const valoresDupla = await Promise.all([
|
|
21064
21341
|
this.avaliar(valorComoDupla.primeiro),
|
|
21065
|
-
this.avaliar(valorComoDupla.segundo)
|
|
21342
|
+
this.avaliar(valorComoDupla.segundo),
|
|
21066
21343
|
]);
|
|
21067
21344
|
// nomesVariaveis são strings (nomes das variáveis)
|
|
21068
21345
|
this.pilhaEscoposExecucao.definirVariavel(String(nomesVariaveis[0]), valoresDupla[0]);
|
|
@@ -21808,18 +22085,20 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
21808
22085
|
// Tratamento especial para expressões unárias aplicadas a chamadas de método em literais numéricos.
|
|
21809
22086
|
// Por exemplo: -5.absoluto() deve ser avaliado como (-5).absoluto(), não como -(5.absoluto())
|
|
21810
22087
|
// Isso garante que o operador unário seja aplicado ao literal antes de chamar o método.
|
|
21811
|
-
if ((expressao.operador.tipo === delegua_2.default.SUBTRACAO ||
|
|
22088
|
+
if ((expressao.operador.tipo === delegua_2.default.SUBTRACAO ||
|
|
22089
|
+
expressao.operador.tipo === delegua_2.default.ADICAO) &&
|
|
21812
22090
|
expressao.operando instanceof construtos_1.Chamada) {
|
|
21813
22091
|
const entidadeChamada = expressao.operando.entidadeChamada;
|
|
21814
22092
|
// Verifica se é AcessoMetodo ou AcessoMetodoOuPropriedade
|
|
21815
|
-
if (entidadeChamada instanceof construtos_1.AcessoMetodo ||
|
|
22093
|
+
if (entidadeChamada instanceof construtos_1.AcessoMetodo ||
|
|
22094
|
+
entidadeChamada instanceof construtos_1.AcessoMetodoOuPropriedade) {
|
|
21816
22095
|
const objetoAcesso = entidadeChamada.objeto;
|
|
21817
22096
|
// Verifica se o objeto do método é um literal numérico
|
|
21818
22097
|
if (objetoAcesso instanceof construtos_1.Literal && typeof objetoAcesso.valor === 'number') {
|
|
21819
22098
|
// Cria um novo literal com o sinal aplicado
|
|
21820
|
-
const novoLiteral = new construtos_1.Literal(objetoAcesso.hashArquivo, objetoAcesso.linha, expressao.operador.tipo === delegua_2.default.SUBTRACAO
|
|
21821
|
-
-objetoAcesso.valor
|
|
21822
|
-
+objetoAcesso.valor);
|
|
22099
|
+
const novoLiteral = new construtos_1.Literal(objetoAcesso.hashArquivo, objetoAcesso.linha, expressao.operador.tipo === delegua_2.default.SUBTRACAO
|
|
22100
|
+
? -objetoAcesso.valor
|
|
22101
|
+
: +objetoAcesso.valor);
|
|
21823
22102
|
// Cria um novo acesso com o literal modificado
|
|
21824
22103
|
let novoAcesso;
|
|
21825
22104
|
if (entidadeChamada instanceof construtos_1.AcessoMetodo) {
|
|
@@ -21841,7 +22120,7 @@ class Interpretador extends interpretador_base_1.InterpretadorBase {
|
|
|
21841
22120
|
async visitarExpressaoVetor(expressao) {
|
|
21842
22121
|
// Delega ao interpretador base para processar o vetor
|
|
21843
22122
|
const vetor = await super.visitarExpressaoVetor(expressao);
|
|
21844
|
-
// Adiciona referência no montão (comportamento específico deste interpretador)
|
|
22123
|
+
// Adiciona referência no montão (comportamento específico deste interpretador)
|
|
21845
22124
|
const enderecoVetorMontao = this.montao.adicionarReferencia(vetor);
|
|
21846
22125
|
this.pilhaEscoposExecucao.registrarReferenciaMontao(enderecoVetorMontao);
|
|
21847
22126
|
return new estruturas_1.ReferenciaMontao(enderecoVetorMontao);
|
|
@@ -23175,7 +23454,9 @@ class LexadorPitugues {
|
|
|
23175
23454
|
}
|
|
23176
23455
|
const deslocamento = ehFString ? 2 : 1;
|
|
23177
23456
|
const textoCompleto = this.codigo[this.linha].substring(this.inicioSimbolo + deslocamento, this.atual);
|
|
23178
|
-
if (textoCompleto.length === 0 &&
|
|
23457
|
+
if (textoCompleto.length === 0 &&
|
|
23458
|
+
!this.eFinalDoCodigo() &&
|
|
23459
|
+
this.codigo[this.linha].charAt(this.atual + 1) === delimitador) {
|
|
23179
23460
|
this.avancar(); // Avança para o próximo delimitador
|
|
23180
23461
|
this.analisarTextoMultilinha(delimitador);
|
|
23181
23462
|
return;
|
|
@@ -23786,9 +24067,31 @@ class LexadorPrisma {
|
|
|
23786
24067
|
}
|
|
23787
24068
|
eAlfabeto(caractere) {
|
|
23788
24069
|
const acentuacoes = [
|
|
23789
|
-
'á',
|
|
23790
|
-
'
|
|
23791
|
-
'
|
|
24070
|
+
'á',
|
|
24071
|
+
'Á',
|
|
24072
|
+
'ã',
|
|
24073
|
+
'Ã',
|
|
24074
|
+
'â',
|
|
24075
|
+
'Â',
|
|
24076
|
+
'à',
|
|
24077
|
+
'À',
|
|
24078
|
+
'é',
|
|
24079
|
+
'É',
|
|
24080
|
+
'ê',
|
|
24081
|
+
'Ê',
|
|
24082
|
+
'í',
|
|
24083
|
+
'Í',
|
|
24084
|
+
'ó',
|
|
24085
|
+
'Ó',
|
|
24086
|
+
'õ',
|
|
24087
|
+
'Õ',
|
|
24088
|
+
'ô',
|
|
24089
|
+
'Ô',
|
|
24090
|
+
'ú',
|
|
24091
|
+
'Ú',
|
|
24092
|
+
'ç',
|
|
24093
|
+
'Ç',
|
|
24094
|
+
'_',
|
|
23792
24095
|
];
|
|
23793
24096
|
return ((caractere >= 'a' && caractere <= 'z') ||
|
|
23794
24097
|
(caractere >= 'A' && caractere <= 'Z') ||
|
|
@@ -26308,7 +26611,7 @@ exports.palavrasReservadasDelegua = {
|
|
|
26308
26611
|
falso: delegua_1.default.FALSO,
|
|
26309
26612
|
faca: delegua_1.default.FAZER,
|
|
26310
26613
|
fazer: delegua_1.default.FAZER,
|
|
26311
|
-
|
|
26614
|
+
faça: delegua_1.default.FAZER,
|
|
26312
26615
|
finalmente: delegua_1.default.FINALMENTE,
|
|
26313
26616
|
fixo: delegua_1.default.CONSTANTE,
|
|
26314
26617
|
funcao: delegua_1.default.FUNCAO,
|
|
@@ -26354,7 +26657,7 @@ exports.palavrasReservadasDelegua = {
|
|
|
26354
26657
|
var: delegua_1.default.VARIAVEL,
|
|
26355
26658
|
variavel: delegua_1.default.VARIAVEL,
|
|
26356
26659
|
variável: delegua_1.default.VARIAVEL,
|
|
26357
|
-
verdadeiro: delegua_1.default.VERDADEIRO
|
|
26660
|
+
verdadeiro: delegua_1.default.VERDADEIRO,
|
|
26358
26661
|
};
|
|
26359
26662
|
exports.palavrasReservadasMicroGramatica = {
|
|
26360
26663
|
e: delegua_1.default.E,
|
|
@@ -39840,10 +40143,10 @@ class TradutorAssemblyARM {
|
|
|
39840
40143
|
// Para android: ainda é um binário standalone, mas com rótulo Delegua_main
|
|
39841
40144
|
// para deixar claro que não é o _start do CRT padrão.
|
|
39842
40145
|
const entryLabel = this.alvo === 'android' ? 'Delegua_main' : '_start';
|
|
39843
|
-
this.text = `
|
|
39844
|
-
.text
|
|
39845
|
-
.global ${entryLabel}
|
|
39846
|
-
|
|
40146
|
+
this.text = `
|
|
40147
|
+
.text
|
|
40148
|
+
.global ${entryLabel}
|
|
40149
|
+
|
|
39847
40150
|
${entryLabel}:`;
|
|
39848
40151
|
}
|
|
39849
40152
|
gerarDigitoAleatorio() {
|
|
@@ -39885,11 +40188,11 @@ ${entryLabel}:`;
|
|
|
39885
40188
|
}
|
|
39886
40189
|
const indice = this.dicionarioConstrutos[construto.indice.constructor.name](construto.indice);
|
|
39887
40190
|
const reg = this.obterRegistrador();
|
|
39888
|
-
this.text += `
|
|
39889
|
-
ldr ${reg}, =${nomeVar}
|
|
39890
|
-
ldr r0, =${indice}
|
|
39891
|
-
lsl r0, r0, #2 @ multiply index by 4 (word size)
|
|
39892
|
-
add ${reg}, ${reg}, r0
|
|
40191
|
+
this.text += `
|
|
40192
|
+
ldr ${reg}, =${nomeVar}
|
|
40193
|
+
ldr r0, =${indice}
|
|
40194
|
+
lsl r0, r0, #2 @ multiply index by 4 (word size)
|
|
40195
|
+
add ${reg}, ${reg}, r0
|
|
39893
40196
|
ldr r0, [${reg}]`;
|
|
39894
40197
|
this.liberarRegistrador(reg);
|
|
39895
40198
|
return 'r0';
|
|
@@ -39913,12 +40216,12 @@ ${entryLabel}:`;
|
|
|
39913
40216
|
const indice = this.dicionarioConstrutos[construto.indice.constructor.name](construto.indice);
|
|
39914
40217
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
39915
40218
|
const reg = this.obterRegistrador();
|
|
39916
|
-
this.text += `
|
|
39917
|
-
ldr ${reg}, =${nomeVar}
|
|
39918
|
-
ldr r1, =${indice}
|
|
39919
|
-
lsl r1, r1, #2 @ multiply by 4
|
|
39920
|
-
add ${reg}, ${reg}, r1
|
|
39921
|
-
ldr r1, =${valor}
|
|
40219
|
+
this.text += `
|
|
40220
|
+
ldr ${reg}, =${nomeVar}
|
|
40221
|
+
ldr r1, =${indice}
|
|
40222
|
+
lsl r1, r1, #2 @ multiply by 4
|
|
40223
|
+
add ${reg}, ${reg}, r1
|
|
40224
|
+
ldr r1, =${valor}
|
|
39922
40225
|
str r1, [${reg}]`;
|
|
39923
40226
|
this.liberarRegistrador(reg);
|
|
39924
40227
|
}
|
|
@@ -39937,9 +40240,9 @@ ${entryLabel}:`;
|
|
|
39937
40240
|
this.bss += ` ${varLabel}: .space 4\n`;
|
|
39938
40241
|
this.variaveis.set(nomeVar, varLabel);
|
|
39939
40242
|
}
|
|
39940
|
-
this.text += `
|
|
39941
|
-
ldr r0, =${valor}
|
|
39942
|
-
ldr r1, =${this.variaveis.get(nomeVar)}
|
|
40243
|
+
this.text += `
|
|
40244
|
+
ldr r0, =${valor}
|
|
40245
|
+
ldr r1, =${this.variaveis.get(nomeVar)}
|
|
39943
40246
|
str r0, [r1]`;
|
|
39944
40247
|
}
|
|
39945
40248
|
traduzirConstrutoBinario(construto) {
|
|
@@ -39949,75 +40252,75 @@ ${entryLabel}:`;
|
|
|
39949
40252
|
const reg = this.obterRegistrador();
|
|
39950
40253
|
// Load left operand into r0
|
|
39951
40254
|
if (esquerda !== 'r0') {
|
|
39952
|
-
this.text += `
|
|
40255
|
+
this.text += `
|
|
39953
40256
|
ldr r0, =${esquerda}`;
|
|
39954
40257
|
}
|
|
39955
40258
|
// Load right operand into reg
|
|
39956
|
-
this.text += `
|
|
40259
|
+
this.text += `
|
|
39957
40260
|
ldr ${reg}, =${direita}`;
|
|
39958
40261
|
switch (operador) {
|
|
39959
40262
|
case '+':
|
|
39960
|
-
this.text += `
|
|
40263
|
+
this.text += `
|
|
39961
40264
|
add r0, r0, ${reg}`;
|
|
39962
40265
|
break;
|
|
39963
40266
|
case '-':
|
|
39964
|
-
this.text += `
|
|
40267
|
+
this.text += `
|
|
39965
40268
|
sub r0, r0, ${reg}`;
|
|
39966
40269
|
break;
|
|
39967
40270
|
case '*':
|
|
39968
|
-
this.text += `
|
|
40271
|
+
this.text += `
|
|
39969
40272
|
mul r0, r0, ${reg}`;
|
|
39970
40273
|
break;
|
|
39971
40274
|
case '/':
|
|
39972
|
-
this.text += `
|
|
40275
|
+
this.text += `
|
|
39973
40276
|
sdiv r0, r0, ${reg}`;
|
|
39974
40277
|
break;
|
|
39975
40278
|
case '%':
|
|
39976
|
-
this.text += `
|
|
39977
|
-
sdiv r1, r0, ${reg}
|
|
39978
|
-
mul r1, r1, ${reg}
|
|
40279
|
+
this.text += `
|
|
40280
|
+
sdiv r1, r0, ${reg}
|
|
40281
|
+
mul r1, r1, ${reg}
|
|
39979
40282
|
sub r0, r0, r1 @ r0 = r0 - (r0/reg)*reg`;
|
|
39980
40283
|
break;
|
|
39981
40284
|
case '<':
|
|
39982
|
-
this.text += `
|
|
39983
|
-
cmp r0, ${reg}
|
|
39984
|
-
movlt r0, #1
|
|
40285
|
+
this.text += `
|
|
40286
|
+
cmp r0, ${reg}
|
|
40287
|
+
movlt r0, #1
|
|
39985
40288
|
movge r0, #0`;
|
|
39986
40289
|
break;
|
|
39987
40290
|
case '>':
|
|
39988
|
-
this.text += `
|
|
39989
|
-
cmp r0, ${reg}
|
|
39990
|
-
movgt r0, #1
|
|
40291
|
+
this.text += `
|
|
40292
|
+
cmp r0, ${reg}
|
|
40293
|
+
movgt r0, #1
|
|
39991
40294
|
movle r0, #0`;
|
|
39992
40295
|
break;
|
|
39993
40296
|
case '<=':
|
|
39994
|
-
this.text += `
|
|
39995
|
-
cmp r0, ${reg}
|
|
39996
|
-
movle r0, #1
|
|
40297
|
+
this.text += `
|
|
40298
|
+
cmp r0, ${reg}
|
|
40299
|
+
movle r0, #1
|
|
39997
40300
|
movgt r0, #0`;
|
|
39998
40301
|
break;
|
|
39999
40302
|
case '>=':
|
|
40000
|
-
this.text += `
|
|
40001
|
-
cmp r0, ${reg}
|
|
40002
|
-
movge r0, #1
|
|
40303
|
+
this.text += `
|
|
40304
|
+
cmp r0, ${reg}
|
|
40305
|
+
movge r0, #1
|
|
40003
40306
|
movlt r0, #0`;
|
|
40004
40307
|
break;
|
|
40005
40308
|
case '==':
|
|
40006
40309
|
case '===':
|
|
40007
|
-
this.text += `
|
|
40008
|
-
cmp r0, ${reg}
|
|
40009
|
-
moveq r0, #1
|
|
40310
|
+
this.text += `
|
|
40311
|
+
cmp r0, ${reg}
|
|
40312
|
+
moveq r0, #1
|
|
40010
40313
|
movne r0, #0`;
|
|
40011
40314
|
break;
|
|
40012
40315
|
case '!=':
|
|
40013
40316
|
case '!==':
|
|
40014
|
-
this.text += `
|
|
40015
|
-
cmp r0, ${reg}
|
|
40016
|
-
movne r0, #1
|
|
40317
|
+
this.text += `
|
|
40318
|
+
cmp r0, ${reg}
|
|
40319
|
+
movne r0, #1
|
|
40017
40320
|
moveq r0, #0`;
|
|
40018
40321
|
break;
|
|
40019
40322
|
default:
|
|
40020
|
-
this.text += `
|
|
40323
|
+
this.text += `
|
|
40021
40324
|
@ Operador ${operador} não implementado`;
|
|
40022
40325
|
}
|
|
40023
40326
|
this.liberarRegistrador(reg);
|
|
@@ -40035,35 +40338,35 @@ ${entryLabel}:`;
|
|
|
40035
40338
|
if (index < registrosArgs.length) {
|
|
40036
40339
|
const valorArg = this.dicionarioConstrutos[arg.constructor.name](arg);
|
|
40037
40340
|
if (valorArg !== registrosArgs[index]) {
|
|
40038
|
-
this.text += `
|
|
40341
|
+
this.text += `
|
|
40039
40342
|
ldr ${registrosArgs[index]}, =${valorArg}`;
|
|
40040
40343
|
}
|
|
40041
40344
|
}
|
|
40042
40345
|
else {
|
|
40043
40346
|
// Push extra args on stack
|
|
40044
40347
|
const valorArg = this.dicionarioConstrutos[arg.constructor.name](arg);
|
|
40045
|
-
this.text += `
|
|
40046
|
-
ldr r0, =${valorArg}
|
|
40348
|
+
this.text += `
|
|
40349
|
+
ldr r0, =${valorArg}
|
|
40047
40350
|
push {r0}`;
|
|
40048
40351
|
}
|
|
40049
40352
|
});
|
|
40050
|
-
this.text += `
|
|
40353
|
+
this.text += `
|
|
40051
40354
|
bl ${nomeFuncao}`;
|
|
40052
40355
|
}
|
|
40053
40356
|
traduzirConstrutoDefinirValor(construto) {
|
|
40054
40357
|
const objeto = this.dicionarioConstrutos[construto.objeto.constructor.name](construto.objeto);
|
|
40055
40358
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
40056
|
-
this.text += `
|
|
40057
|
-
ldr r0, =${valor}
|
|
40058
|
-
ldr r1, =${objeto}
|
|
40359
|
+
this.text += `
|
|
40360
|
+
ldr r0, =${valor}
|
|
40361
|
+
ldr r1, =${objeto}
|
|
40059
40362
|
str r0, [r1]`;
|
|
40060
40363
|
}
|
|
40061
40364
|
traduzirFuncaoConstruto(construto) {
|
|
40062
40365
|
const labelFuncao = `func_${this.gerarDigitoAleatorio()}`;
|
|
40063
|
-
this.text += `
|
|
40064
|
-
|
|
40065
|
-
${labelFuncao}:
|
|
40066
|
-
push {fp, lr}
|
|
40366
|
+
this.text += `
|
|
40367
|
+
|
|
40368
|
+
${labelFuncao}:
|
|
40369
|
+
push {fp, lr}
|
|
40067
40370
|
mov fp, sp`;
|
|
40068
40371
|
// Traduzir corpo da função
|
|
40069
40372
|
if (construto.corpo && Array.isArray(construto.corpo)) {
|
|
@@ -40073,8 +40376,8 @@ ${labelFuncao}:
|
|
|
40073
40376
|
}
|
|
40074
40377
|
});
|
|
40075
40378
|
}
|
|
40076
|
-
this.text += `
|
|
40077
|
-
mov sp, fp
|
|
40379
|
+
this.text += `
|
|
40380
|
+
mov sp, fp
|
|
40078
40381
|
pop {fp, pc}`;
|
|
40079
40382
|
}
|
|
40080
40383
|
traduzirConstrutoLiteral(construto) {
|
|
@@ -40089,29 +40392,29 @@ ${labelFuncao}:
|
|
|
40089
40392
|
const operador = construto.operador.lexema;
|
|
40090
40393
|
const labelVerdadeiro = this.gerarLabel();
|
|
40091
40394
|
const labelFim = this.gerarLabel();
|
|
40092
|
-
this.text += `
|
|
40093
|
-
ldr r0, =${esquerda}
|
|
40395
|
+
this.text += `
|
|
40396
|
+
ldr r0, =${esquerda}
|
|
40094
40397
|
cmp r0, #0`;
|
|
40095
40398
|
if (operador === 'e' || operador === '&&') {
|
|
40096
|
-
this.text += `
|
|
40097
|
-
beq ${labelFim}
|
|
40098
|
-
ldr r0, =${direita}
|
|
40099
|
-
cmp r0, #0
|
|
40100
|
-
beq ${labelFim}
|
|
40101
|
-
${labelVerdadeiro}:
|
|
40102
|
-
mov r0, #1
|
|
40399
|
+
this.text += `
|
|
40400
|
+
beq ${labelFim}
|
|
40401
|
+
ldr r0, =${direita}
|
|
40402
|
+
cmp r0, #0
|
|
40403
|
+
beq ${labelFim}
|
|
40404
|
+
${labelVerdadeiro}:
|
|
40405
|
+
mov r0, #1
|
|
40103
40406
|
${labelFim}:`;
|
|
40104
40407
|
}
|
|
40105
40408
|
else if (operador === 'ou' || operador === '||') {
|
|
40106
|
-
this.text += `
|
|
40107
|
-
bne ${labelVerdadeiro}
|
|
40108
|
-
ldr r0, =${direita}
|
|
40109
|
-
cmp r0, #0
|
|
40110
|
-
bne ${labelVerdadeiro}
|
|
40111
|
-
mov r0, #0
|
|
40112
|
-
b ${labelFim}
|
|
40113
|
-
${labelVerdadeiro}:
|
|
40114
|
-
mov r0, #1
|
|
40409
|
+
this.text += `
|
|
40410
|
+
bne ${labelVerdadeiro}
|
|
40411
|
+
ldr r0, =${direita}
|
|
40412
|
+
cmp r0, #0
|
|
40413
|
+
bne ${labelVerdadeiro}
|
|
40414
|
+
mov r0, #0
|
|
40415
|
+
b ${labelFim}
|
|
40416
|
+
${labelVerdadeiro}:
|
|
40417
|
+
mov r0, #1
|
|
40115
40418
|
${labelFim}:`;
|
|
40116
40419
|
}
|
|
40117
40420
|
return 'r0';
|
|
@@ -40123,16 +40426,16 @@ ${labelFim}:`;
|
|
|
40123
40426
|
traduzirConstrutoUnario(construto) {
|
|
40124
40427
|
const operando = this.dicionarioConstrutos[construto.operando.constructor.name](construto.operando);
|
|
40125
40428
|
const operador = construto.operador.lexema;
|
|
40126
|
-
this.text += `
|
|
40429
|
+
this.text += `
|
|
40127
40430
|
ldr r0, =${operando}`;
|
|
40128
40431
|
if (operador === '-') {
|
|
40129
|
-
this.text += `
|
|
40432
|
+
this.text += `
|
|
40130
40433
|
neg r0, r0`;
|
|
40131
40434
|
}
|
|
40132
40435
|
else if (operador === '!' || operador === 'nao') {
|
|
40133
|
-
this.text += `
|
|
40134
|
-
cmp r0, #0
|
|
40135
|
-
moveq r0, #1
|
|
40436
|
+
this.text += `
|
|
40437
|
+
cmp r0, #0
|
|
40438
|
+
moveq r0, #1
|
|
40136
40439
|
movne r0, #0`;
|
|
40137
40440
|
}
|
|
40138
40441
|
return 'r0';
|
|
@@ -40142,8 +40445,8 @@ ${labelFim}:`;
|
|
|
40142
40445
|
const nomeVar = (_a = construto.simbolo) === null || _a === void 0 ? void 0 : _a.lexema;
|
|
40143
40446
|
if (nomeVar && this.variaveis.has(nomeVar)) {
|
|
40144
40447
|
const varLabel = this.variaveis.get(nomeVar);
|
|
40145
|
-
this.text += `
|
|
40146
|
-
ldr r0, =${varLabel}
|
|
40448
|
+
this.text += `
|
|
40449
|
+
ldr r0, =${varLabel}
|
|
40147
40450
|
ldr r0, [r0]`;
|
|
40148
40451
|
return 'r0';
|
|
40149
40452
|
}
|
|
@@ -40158,9 +40461,9 @@ ${labelFim}:`;
|
|
|
40158
40461
|
construto.valores.forEach((valor, index) => {
|
|
40159
40462
|
if (this.dicionarioConstrutos[valor.constructor.name]) {
|
|
40160
40463
|
const valorTraduzido = this.dicionarioConstrutos[valor.constructor.name](valor);
|
|
40161
|
-
this.text += `
|
|
40162
|
-
ldr r0, =${valorTraduzido}
|
|
40163
|
-
ldr r1, =${labelVetor}
|
|
40464
|
+
this.text += `
|
|
40465
|
+
ldr r0, =${valorTraduzido}
|
|
40466
|
+
ldr r1, =${labelVetor}
|
|
40164
40467
|
str r0, [r1, #${index * 4}]`;
|
|
40165
40468
|
}
|
|
40166
40469
|
});
|
|
@@ -40180,17 +40483,17 @@ ${labelFim}:`;
|
|
|
40180
40483
|
traduzirDeclaracaoEnquanto(declaracao) {
|
|
40181
40484
|
const labelInicio = this.gerarLabel();
|
|
40182
40485
|
const labelFim = this.gerarLabel();
|
|
40183
|
-
this.text += `
|
|
40486
|
+
this.text += `
|
|
40184
40487
|
${labelInicio}:`;
|
|
40185
40488
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
40186
|
-
this.text += `
|
|
40187
|
-
cmp ${condicao}, #0
|
|
40489
|
+
this.text += `
|
|
40490
|
+
cmp ${condicao}, #0
|
|
40188
40491
|
beq ${labelFim}`;
|
|
40189
40492
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
40190
40493
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
40191
40494
|
}
|
|
40192
|
-
this.text += `
|
|
40193
|
-
b ${labelInicio}
|
|
40495
|
+
this.text += `
|
|
40496
|
+
b ${labelInicio}
|
|
40194
40497
|
${labelFim}:`;
|
|
40195
40498
|
}
|
|
40196
40499
|
traduzirDeclaracaoEscolha(declaracao) {
|
|
@@ -40201,10 +40504,10 @@ ${labelFim}:`;
|
|
|
40201
40504
|
const labelProximo = this.gerarLabel();
|
|
40202
40505
|
if (caminho.condicoes && caminho.condicoes[0]) {
|
|
40203
40506
|
const valorCaso = this.dicionarioConstrutos[caminho.condicoes[0].constructor.name](caminho.condicoes[0]);
|
|
40204
|
-
this.text += `
|
|
40205
|
-
ldr r0, =${valorEscolha}
|
|
40206
|
-
ldr r1, =${valorCaso}
|
|
40207
|
-
cmp r0, r1
|
|
40507
|
+
this.text += `
|
|
40508
|
+
ldr r0, =${valorEscolha}
|
|
40509
|
+
ldr r1, =${valorCaso}
|
|
40510
|
+
cmp r0, r1
|
|
40208
40511
|
bne ${labelProximo}`;
|
|
40209
40512
|
if (caminho.declaracoes && Array.isArray(caminho.declaracoes)) {
|
|
40210
40513
|
caminho.declaracoes.forEach((decl) => {
|
|
@@ -40213,23 +40516,24 @@ ${labelFim}:`;
|
|
|
40213
40516
|
}
|
|
40214
40517
|
});
|
|
40215
40518
|
}
|
|
40216
|
-
this.text += `
|
|
40217
|
-
b ${labelFim}
|
|
40519
|
+
this.text += `
|
|
40520
|
+
b ${labelFim}
|
|
40218
40521
|
${labelProximo}:`;
|
|
40219
40522
|
}
|
|
40220
40523
|
});
|
|
40221
40524
|
}
|
|
40222
|
-
this.text += `
|
|
40525
|
+
this.text += `
|
|
40223
40526
|
${labelFim}:`;
|
|
40224
40527
|
}
|
|
40225
40528
|
traduzirDeclaracaoExpressao(declaracao) {
|
|
40226
|
-
if (declaracao.expressao &&
|
|
40529
|
+
if (declaracao.expressao &&
|
|
40530
|
+
this.dicionarioConstrutos[declaracao.expressao.constructor.name]) {
|
|
40227
40531
|
this.dicionarioConstrutos[declaracao.expressao.constructor.name](declaracao.expressao);
|
|
40228
40532
|
}
|
|
40229
40533
|
}
|
|
40230
40534
|
traduzirDeclaracaoFazer(declaracao) {
|
|
40231
40535
|
const labelInicio = this.gerarLabel();
|
|
40232
|
-
this.text += `
|
|
40536
|
+
this.text += `
|
|
40233
40537
|
${labelInicio}:`;
|
|
40234
40538
|
if (declaracao.caminhoFazer && declaracao.caminhoFazer.declaracoes) {
|
|
40235
40539
|
declaracao.caminhoFazer.declaracoes.forEach((decl) => {
|
|
@@ -40240,52 +40544,58 @@ ${labelInicio}:`;
|
|
|
40240
40544
|
}
|
|
40241
40545
|
if (declaracao.condicaoEnquanto) {
|
|
40242
40546
|
const condicao = this.dicionarioConstrutos[declaracao.condicaoEnquanto.constructor.name](declaracao.condicaoEnquanto);
|
|
40243
|
-
this.text += `
|
|
40244
|
-
cmp ${condicao}, #0
|
|
40547
|
+
this.text += `
|
|
40548
|
+
cmp ${condicao}, #0
|
|
40245
40549
|
bne ${labelInicio}`;
|
|
40246
40550
|
}
|
|
40247
40551
|
}
|
|
40248
40552
|
traduzirDeclaracaoFalhar(declaracao) {
|
|
40249
40553
|
let mensagem = '"Erro"';
|
|
40250
|
-
if (declaracao.explicacao &&
|
|
40554
|
+
if (declaracao.explicacao &&
|
|
40555
|
+
typeof declaracao.explicacao === 'object' &&
|
|
40556
|
+
'constructor' in declaracao.explicacao) {
|
|
40251
40557
|
const explicacao = declaracao.explicacao;
|
|
40252
40558
|
if (explicacao.constructor && this.dicionarioConstrutos[explicacao.constructor.name]) {
|
|
40253
40559
|
mensagem = this.dicionarioConstrutos[explicacao.constructor.name](explicacao);
|
|
40254
40560
|
}
|
|
40255
40561
|
}
|
|
40256
|
-
this.text += `
|
|
40257
|
-
@ Falhar com mensagem: ${mensagem}
|
|
40258
|
-
mov r0, #1
|
|
40259
|
-
mov r7, #1 @ sys_exit
|
|
40562
|
+
this.text += `
|
|
40563
|
+
@ Falhar com mensagem: ${mensagem}
|
|
40564
|
+
mov r0, #1
|
|
40565
|
+
mov r7, #1 @ sys_exit
|
|
40260
40566
|
swi 0`;
|
|
40261
40567
|
}
|
|
40262
40568
|
traduzirDeclaracaoFuncao(declaracao) {
|
|
40263
40569
|
var _a;
|
|
40264
40570
|
const nomeFuncao = ((_a = declaracao.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) || 'funcao';
|
|
40265
|
-
this.text += `
|
|
40266
|
-
|
|
40267
|
-
${nomeFuncao}:
|
|
40268
|
-
push {fp, lr}
|
|
40571
|
+
this.text += `
|
|
40572
|
+
|
|
40573
|
+
${nomeFuncao}:
|
|
40574
|
+
push {fp, lr}
|
|
40269
40575
|
mov fp, sp`;
|
|
40270
|
-
if (declaracao.funcao &&
|
|
40576
|
+
if (declaracao.funcao &&
|
|
40577
|
+
declaracao.funcao.corpo &&
|
|
40578
|
+
Array.isArray(declaracao.funcao.corpo)) {
|
|
40271
40579
|
declaracao.funcao.corpo.forEach((decl) => {
|
|
40272
40580
|
if (this.dicionarioDeclaracoes[decl.constructor.name]) {
|
|
40273
40581
|
this.dicionarioDeclaracoes[decl.constructor.name](decl);
|
|
40274
40582
|
}
|
|
40275
40583
|
});
|
|
40276
40584
|
}
|
|
40277
|
-
this.text += `
|
|
40278
|
-
mov sp, fp
|
|
40585
|
+
this.text += `
|
|
40586
|
+
mov sp, fp
|
|
40279
40587
|
pop {fp, pc}`;
|
|
40280
40588
|
}
|
|
40281
40589
|
traduzirDeclaracaoImportar(declaracao) {
|
|
40282
|
-
this.text += `
|
|
40590
|
+
this.text += `
|
|
40283
40591
|
@ Importar: ${declaracao.caminho || 'unknown'}`;
|
|
40284
40592
|
}
|
|
40285
40593
|
traduzirDeclaracaoLeia(declaracao) {
|
|
40286
40594
|
var _a;
|
|
40287
40595
|
let nomeVar;
|
|
40288
|
-
if (declaracao.argumentos &&
|
|
40596
|
+
if (declaracao.argumentos &&
|
|
40597
|
+
declaracao.argumentos[0] &&
|
|
40598
|
+
declaracao.argumentos[0] instanceof construtos_1.Variavel) {
|
|
40289
40599
|
nomeVar = (_a = declaracao.argumentos[0].simbolo) === null || _a === void 0 ? void 0 : _a.lexema;
|
|
40290
40600
|
}
|
|
40291
40601
|
if (!nomeVar)
|
|
@@ -40295,11 +40605,11 @@ ${nomeFuncao}:
|
|
|
40295
40605
|
this.bss += ` ${varLabel}: .space 256\n`;
|
|
40296
40606
|
this.variaveis.set(nomeVar, varLabel);
|
|
40297
40607
|
}
|
|
40298
|
-
this.text += `
|
|
40299
|
-
ldr r1, =${this.variaveis.get(nomeVar)}
|
|
40300
|
-
mov r2, #256
|
|
40301
|
-
mov r0, #0 @ stdin
|
|
40302
|
-
mov r7, #3 @ sys_read
|
|
40608
|
+
this.text += `
|
|
40609
|
+
ldr r1, =${this.variaveis.get(nomeVar)}
|
|
40610
|
+
mov r2, #256
|
|
40611
|
+
mov r0, #0 @ stdin
|
|
40612
|
+
mov r7, #3 @ sys_read
|
|
40303
40613
|
swi 0`;
|
|
40304
40614
|
}
|
|
40305
40615
|
traduzirDeclaracaoPara(declaracao) {
|
|
@@ -40314,12 +40624,12 @@ ${nomeFuncao}:
|
|
|
40314
40624
|
this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
40315
40625
|
}
|
|
40316
40626
|
}
|
|
40317
|
-
this.text += `
|
|
40627
|
+
this.text += `
|
|
40318
40628
|
${labelInicio}:`;
|
|
40319
40629
|
if (declaracao.condicao) {
|
|
40320
40630
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
40321
|
-
this.text += `
|
|
40322
|
-
cmp ${condicao}, #0
|
|
40631
|
+
this.text += `
|
|
40632
|
+
cmp ${condicao}, #0
|
|
40323
40633
|
beq ${labelFim}`;
|
|
40324
40634
|
}
|
|
40325
40635
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
@@ -40330,8 +40640,8 @@ ${labelInicio}:`;
|
|
|
40330
40640
|
this.dicionarioConstrutos[declaracao.incrementar.constructor.name](declaracao.incrementar);
|
|
40331
40641
|
}
|
|
40332
40642
|
}
|
|
40333
|
-
this.text += `
|
|
40334
|
-
b ${labelInicio}
|
|
40643
|
+
this.text += `
|
|
40644
|
+
b ${labelInicio}
|
|
40335
40645
|
${labelFim}:`;
|
|
40336
40646
|
}
|
|
40337
40647
|
traduzirDeclaracaoParaCada(declaracao) {
|
|
@@ -40347,55 +40657,56 @@ ${labelFim}:`;
|
|
|
40347
40657
|
if (vetor instanceof construtos_1.Vetor) {
|
|
40348
40658
|
tamanhoVetor = vetor.tamanho || 0;
|
|
40349
40659
|
}
|
|
40350
|
-
this.text += `
|
|
40351
|
-
mov r4, #0 @ counter
|
|
40352
|
-
${labelInicio}:
|
|
40353
|
-
cmp r4, #${tamanhoVetor}
|
|
40660
|
+
this.text += `
|
|
40661
|
+
mov r4, #0 @ counter
|
|
40662
|
+
${labelInicio}:
|
|
40663
|
+
cmp r4, #${tamanhoVetor}
|
|
40354
40664
|
bge ${labelFim}`;
|
|
40355
40665
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
40356
40666
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
40357
40667
|
}
|
|
40358
|
-
this.text += `
|
|
40359
|
-
add r4, r4, #1
|
|
40360
|
-
b ${labelInicio}
|
|
40668
|
+
this.text += `
|
|
40669
|
+
add r4, r4, #1
|
|
40670
|
+
b ${labelInicio}
|
|
40361
40671
|
${labelFim}:`;
|
|
40362
40672
|
}
|
|
40363
40673
|
traduzirDeclaracaoRetorna(declaracao) {
|
|
40364
40674
|
if (declaracao.valor) {
|
|
40365
40675
|
const valor = this.dicionarioConstrutos[declaracao.valor.constructor.name](declaracao.valor);
|
|
40366
|
-
this.text += `
|
|
40676
|
+
this.text += `
|
|
40367
40677
|
ldr r0, =${valor}`;
|
|
40368
40678
|
}
|
|
40369
|
-
this.text += `
|
|
40370
|
-
mov sp, fp
|
|
40679
|
+
this.text += `
|
|
40680
|
+
mov sp, fp
|
|
40371
40681
|
pop {fp, pc}`;
|
|
40372
40682
|
}
|
|
40373
40683
|
traduzirDeclaracaoSe(declaracao) {
|
|
40374
40684
|
const labelSenao = this.gerarLabel();
|
|
40375
40685
|
const labelFim = this.gerarLabel();
|
|
40376
40686
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
40377
|
-
this.text += `
|
|
40378
|
-
cmp ${condicao}, #0
|
|
40687
|
+
this.text += `
|
|
40688
|
+
cmp ${condicao}, #0
|
|
40379
40689
|
beq ${labelSenao}`;
|
|
40380
40690
|
if (this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name]) {
|
|
40381
40691
|
this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name](declaracao.caminhoEntao);
|
|
40382
40692
|
}
|
|
40383
|
-
this.text += `
|
|
40384
|
-
b ${labelFim}
|
|
40693
|
+
this.text += `
|
|
40694
|
+
b ${labelFim}
|
|
40385
40695
|
${labelSenao}:`;
|
|
40386
|
-
if (declaracao.caminhoSenao &&
|
|
40696
|
+
if (declaracao.caminhoSenao &&
|
|
40697
|
+
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name]) {
|
|
40387
40698
|
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name](declaracao.caminhoSenao);
|
|
40388
40699
|
}
|
|
40389
|
-
this.text += `
|
|
40700
|
+
this.text += `
|
|
40390
40701
|
${labelFim}:`;
|
|
40391
40702
|
}
|
|
40392
40703
|
traduzirDeclaracaoClasse(declaracao) {
|
|
40393
40704
|
var _a;
|
|
40394
|
-
this.text += `
|
|
40705
|
+
this.text += `
|
|
40395
40706
|
@ Classe: ${((_a = declaracao.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) || 'unknown'}`;
|
|
40396
40707
|
}
|
|
40397
40708
|
traduzirDeclaracaoTente(declaracao) {
|
|
40398
|
-
this.text += `
|
|
40709
|
+
this.text += `
|
|
40399
40710
|
@ Tente-pegue`;
|
|
40400
40711
|
if (declaracao.caminhoTente && Array.isArray(declaracao.caminhoTente)) {
|
|
40401
40712
|
declaracao.caminhoTente.forEach((decl) => {
|
|
@@ -40434,9 +40745,9 @@ ${labelFim}:`;
|
|
|
40434
40745
|
}
|
|
40435
40746
|
else if (this.dicionarioConstrutos[tipoInicializador]) {
|
|
40436
40747
|
const valor = this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
40437
|
-
this.text += `
|
|
40438
|
-
ldr r0, =${valor}
|
|
40439
|
-
ldr r1, =${varLabel}
|
|
40748
|
+
this.text += `
|
|
40749
|
+
ldr r0, =${valor}
|
|
40750
|
+
ldr r1, =${varLabel}
|
|
40440
40751
|
str r0, [r1]`;
|
|
40441
40752
|
}
|
|
40442
40753
|
}
|
|
@@ -40463,20 +40774,20 @@ ${labelFim}:`;
|
|
|
40463
40774
|
// Para ambos linux-arm e android, continuamos usando a convenção
|
|
40464
40775
|
// de syscall Linux ARM (write). Em Android típico, esse binário
|
|
40465
40776
|
// seria executado via adb/Termux, onde essa convenção ainda é válida.
|
|
40466
|
-
this.text += `
|
|
40467
|
-
ldr r1, =${nome_string_literal}
|
|
40468
|
-
mov r2, #${tam_string_literal}
|
|
40469
|
-
mov r0, #1 @ fd stdout
|
|
40470
|
-
mov r7, #4 @ sys_write
|
|
40777
|
+
this.text += `
|
|
40778
|
+
ldr r1, =${nome_string_literal}
|
|
40779
|
+
mov r2, #${tam_string_literal}
|
|
40780
|
+
mov r0, #1 @ fd stdout
|
|
40781
|
+
mov r7, #4 @ sys_write
|
|
40471
40782
|
swi 0`;
|
|
40472
40783
|
}
|
|
40473
40784
|
saidaSistema() {
|
|
40474
40785
|
// Mesmo comentário da função Escreva: usamos sys_exit Linux.
|
|
40475
40786
|
// Em um futuro modo Android "NDK/JNI", esta função deveria
|
|
40476
40787
|
// apenas retornar ao chamador em vez de fazer syscall direta.
|
|
40477
|
-
this.text += `
|
|
40478
|
-
mov r0, #1 @ exit status
|
|
40479
|
-
mov r7, #1 @ sys_exit
|
|
40788
|
+
this.text += `
|
|
40789
|
+
mov r0, #1 @ exit status
|
|
40790
|
+
mov r7, #1 @ sys_exit
|
|
40480
40791
|
swi 0`;
|
|
40481
40792
|
}
|
|
40482
40793
|
traduzir(declaracoes) {
|
|
@@ -40551,13 +40862,14 @@ class TradutorAssemblyX64 {
|
|
|
40551
40862
|
Escreva: this.traduzirDeclaracaoEscreva.bind(this),
|
|
40552
40863
|
};
|
|
40553
40864
|
this.indentacao = 0;
|
|
40554
|
-
this.text = `
|
|
40555
|
-
section .text
|
|
40556
|
-
${this.alvo === 'linux' ? 'global _start' : 'global main'}
|
|
40865
|
+
this.text = `
|
|
40866
|
+
section .text
|
|
40867
|
+
${this.alvo === 'linux' ? 'global _start' : 'global main'}
|
|
40557
40868
|
${this.alvo === 'linux' ? '_start:' : 'main:'}`;
|
|
40558
40869
|
if (this.alvo === 'windows') {
|
|
40559
|
-
this.text =
|
|
40560
|
-
|
|
40870
|
+
this.text =
|
|
40871
|
+
`
|
|
40872
|
+
extern printf
|
|
40561
40873
|
` + this.text;
|
|
40562
40874
|
}
|
|
40563
40875
|
}
|
|
@@ -40619,8 +40931,8 @@ extern printf
|
|
|
40619
40931
|
}
|
|
40620
40932
|
const indice = this.dicionarioConstrutos[construto.indice.constructor.name](construto.indice);
|
|
40621
40933
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
40622
|
-
this.text += `
|
|
40623
|
-
mov rax, ${valor}
|
|
40934
|
+
this.text += `
|
|
40935
|
+
mov rax, ${valor}
|
|
40624
40936
|
mov [${nomeVar} + ${indice} * 8], rax`;
|
|
40625
40937
|
}
|
|
40626
40938
|
traduzirConstrutoAtribuir(construto) {
|
|
@@ -40639,8 +40951,8 @@ extern printf
|
|
|
40639
40951
|
this.bss += ` ${varLabel} resq 1\n`;
|
|
40640
40952
|
this.variaveis.set(nomeVar, varLabel);
|
|
40641
40953
|
}
|
|
40642
|
-
this.text += `
|
|
40643
|
-
mov rax, ${valor}
|
|
40954
|
+
this.text += `
|
|
40955
|
+
mov rax, ${valor}
|
|
40644
40956
|
mov [${this.variaveis.get(nomeVar)}], rax`;
|
|
40645
40957
|
}
|
|
40646
40958
|
traduzirConstrutoBinario(construto) {
|
|
@@ -40648,35 +40960,35 @@ extern printf
|
|
|
40648
40960
|
const direita = this.dicionarioConstrutos[construto.direita.constructor.name](construto.direita);
|
|
40649
40961
|
const operador = construto.operador.lexema;
|
|
40650
40962
|
const reg = this.obterRegistrador();
|
|
40651
|
-
this.text += `
|
|
40652
|
-
mov rax, ${esquerda}
|
|
40963
|
+
this.text += `
|
|
40964
|
+
mov rax, ${esquerda}
|
|
40653
40965
|
mov ${reg}, ${direita}`;
|
|
40654
40966
|
switch (operador) {
|
|
40655
40967
|
case '+':
|
|
40656
|
-
this.text += `
|
|
40968
|
+
this.text += `
|
|
40657
40969
|
add rax, ${reg}`;
|
|
40658
40970
|
break;
|
|
40659
40971
|
case '-':
|
|
40660
|
-
this.text += `
|
|
40972
|
+
this.text += `
|
|
40661
40973
|
sub rax, ${reg}`;
|
|
40662
40974
|
break;
|
|
40663
40975
|
case '*':
|
|
40664
|
-
this.text += `
|
|
40976
|
+
this.text += `
|
|
40665
40977
|
imul rax, ${reg}`;
|
|
40666
40978
|
break;
|
|
40667
40979
|
case '/':
|
|
40668
|
-
this.text += `
|
|
40669
|
-
xor rdx, rdx
|
|
40980
|
+
this.text += `
|
|
40981
|
+
xor rdx, rdx
|
|
40670
40982
|
idiv ${reg}`;
|
|
40671
40983
|
break;
|
|
40672
40984
|
case '%':
|
|
40673
|
-
this.text += `
|
|
40674
|
-
xor rdx, rdx
|
|
40675
|
-
idiv ${reg}
|
|
40985
|
+
this.text += `
|
|
40986
|
+
xor rdx, rdx
|
|
40987
|
+
idiv ${reg}
|
|
40676
40988
|
mov rax, rdx`;
|
|
40677
40989
|
break;
|
|
40678
40990
|
default:
|
|
40679
|
-
this.text += `
|
|
40991
|
+
this.text += `
|
|
40680
40992
|
; Operador ${operador} não implementado`;
|
|
40681
40993
|
}
|
|
40682
40994
|
this.liberarRegistrador(reg);
|
|
@@ -40695,28 +41007,28 @@ extern printf
|
|
|
40695
41007
|
construto.argumentos.forEach((arg, index) => {
|
|
40696
41008
|
if (index < registrosArgs.length) {
|
|
40697
41009
|
const valorArg = this.dicionarioConstrutos[arg.constructor.name](arg);
|
|
40698
|
-
this.text += `
|
|
41010
|
+
this.text += `
|
|
40699
41011
|
mov ${registrosArgs[index]}, ${valorArg}`;
|
|
40700
41012
|
}
|
|
40701
41013
|
else {
|
|
40702
41014
|
// TODO: push extra args on stack according to target ABI
|
|
40703
41015
|
}
|
|
40704
41016
|
});
|
|
40705
|
-
this.text += `
|
|
41017
|
+
this.text += `
|
|
40706
41018
|
call ${nomeFuncao}`;
|
|
40707
41019
|
}
|
|
40708
41020
|
traduzirConstrutoDefinirValor(construto) {
|
|
40709
41021
|
const objeto = this.dicionarioConstrutos[construto.objeto.constructor.name](construto.objeto);
|
|
40710
41022
|
const valor = this.dicionarioConstrutos[construto.valor.constructor.name](construto.valor);
|
|
40711
|
-
this.text += `
|
|
40712
|
-
mov rax, ${valor}
|
|
41023
|
+
this.text += `
|
|
41024
|
+
mov rax, ${valor}
|
|
40713
41025
|
mov [${objeto}], rax`;
|
|
40714
41026
|
}
|
|
40715
41027
|
traduzirFuncaoConstruto(construto) {
|
|
40716
41028
|
const labelFuncao = `func_${this.gerarDigitoAleatorio()}`;
|
|
40717
|
-
this.text += `
|
|
40718
|
-
${labelFuncao}:
|
|
40719
|
-
push rbp
|
|
41029
|
+
this.text += `
|
|
41030
|
+
${labelFuncao}:
|
|
41031
|
+
push rbp
|
|
40720
41032
|
mov rbp, rsp`;
|
|
40721
41033
|
// Traduzir corpo da função
|
|
40722
41034
|
if (construto.corpo && Array.isArray(construto.corpo)) {
|
|
@@ -40726,8 +41038,8 @@ ${labelFuncao}:
|
|
|
40726
41038
|
}
|
|
40727
41039
|
});
|
|
40728
41040
|
}
|
|
40729
|
-
this.text += `
|
|
40730
|
-
pop rbp
|
|
41041
|
+
this.text += `
|
|
41042
|
+
pop rbp
|
|
40731
41043
|
ret`;
|
|
40732
41044
|
}
|
|
40733
41045
|
traduzirConstrutoLiteral(construto) {
|
|
@@ -40742,29 +41054,29 @@ ${labelFuncao}:
|
|
|
40742
41054
|
const operador = construto.operador.lexema;
|
|
40743
41055
|
const labelVerdadeiro = this.gerarLabel();
|
|
40744
41056
|
const labelFim = this.gerarLabel();
|
|
40745
|
-
this.text += `
|
|
40746
|
-
mov rax, ${esquerda}
|
|
41057
|
+
this.text += `
|
|
41058
|
+
mov rax, ${esquerda}
|
|
40747
41059
|
cmp rax, 0`;
|
|
40748
41060
|
if (operador === 'e' || operador === '&&') {
|
|
40749
|
-
this.text += `
|
|
40750
|
-
je ${labelFim}
|
|
40751
|
-
mov rax, ${direita}
|
|
40752
|
-
cmp rax, 0
|
|
40753
|
-
je ${labelFim}
|
|
40754
|
-
${labelVerdadeiro}:
|
|
40755
|
-
mov rax, 1
|
|
41061
|
+
this.text += `
|
|
41062
|
+
je ${labelFim}
|
|
41063
|
+
mov rax, ${direita}
|
|
41064
|
+
cmp rax, 0
|
|
41065
|
+
je ${labelFim}
|
|
41066
|
+
${labelVerdadeiro}:
|
|
41067
|
+
mov rax, 1
|
|
40756
41068
|
${labelFim}:`;
|
|
40757
41069
|
}
|
|
40758
41070
|
else if (operador === 'ou' || operador === '||') {
|
|
40759
|
-
this.text += `
|
|
40760
|
-
jne ${labelVerdadeiro}
|
|
40761
|
-
mov rax, ${direita}
|
|
40762
|
-
cmp rax, 0
|
|
40763
|
-
jne ${labelVerdadeiro}
|
|
40764
|
-
mov rax, 0
|
|
40765
|
-
jmp ${labelFim}
|
|
40766
|
-
${labelVerdadeiro}:
|
|
40767
|
-
mov rax, 1
|
|
41071
|
+
this.text += `
|
|
41072
|
+
jne ${labelVerdadeiro}
|
|
41073
|
+
mov rax, ${direita}
|
|
41074
|
+
cmp rax, 0
|
|
41075
|
+
jne ${labelVerdadeiro}
|
|
41076
|
+
mov rax, 0
|
|
41077
|
+
jmp ${labelFim}
|
|
41078
|
+
${labelVerdadeiro}:
|
|
41079
|
+
mov rax, 1
|
|
40768
41080
|
${labelFim}:`;
|
|
40769
41081
|
}
|
|
40770
41082
|
return 'rax';
|
|
@@ -40777,16 +41089,16 @@ ${labelFim}:`;
|
|
|
40777
41089
|
traduzirConstrutoUnario(construto) {
|
|
40778
41090
|
const operando = this.dicionarioConstrutos[construto.operando.constructor.name](construto.operando);
|
|
40779
41091
|
const operador = construto.operador.lexema;
|
|
40780
|
-
this.text += `
|
|
41092
|
+
this.text += `
|
|
40781
41093
|
mov rax, ${operando}`;
|
|
40782
41094
|
if (operador === '-') {
|
|
40783
|
-
this.text += `
|
|
41095
|
+
this.text += `
|
|
40784
41096
|
neg rax`;
|
|
40785
41097
|
}
|
|
40786
41098
|
else if (operador === '!' || operador === 'nao') {
|
|
40787
|
-
this.text += `
|
|
40788
|
-
cmp rax, 0
|
|
40789
|
-
sete al
|
|
41099
|
+
this.text += `
|
|
41100
|
+
cmp rax, 0
|
|
41101
|
+
sete al
|
|
40790
41102
|
movzx rax, al`;
|
|
40791
41103
|
}
|
|
40792
41104
|
return 'rax';
|
|
@@ -40808,8 +41120,8 @@ ${labelFim}:`;
|
|
|
40808
41120
|
construto.valores.forEach((valor, index) => {
|
|
40809
41121
|
if (this.dicionarioConstrutos[valor.constructor.name]) {
|
|
40810
41122
|
const valorTraduzido = this.dicionarioConstrutos[valor.constructor.name](valor);
|
|
40811
|
-
this.text += `
|
|
40812
|
-
mov rax, ${valorTraduzido}
|
|
41123
|
+
this.text += `
|
|
41124
|
+
mov rax, ${valorTraduzido}
|
|
40813
41125
|
mov [${labelVetor} + ${index * 8}], rax`;
|
|
40814
41126
|
}
|
|
40815
41127
|
});
|
|
@@ -40829,17 +41141,17 @@ ${labelFim}:`;
|
|
|
40829
41141
|
traduzirDeclaracaoEnquanto(declaracao) {
|
|
40830
41142
|
const labelInicio = this.gerarLabel();
|
|
40831
41143
|
const labelFim = this.gerarLabel();
|
|
40832
|
-
this.text += `
|
|
41144
|
+
this.text += `
|
|
40833
41145
|
${labelInicio}:`;
|
|
40834
41146
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
40835
|
-
this.text += `
|
|
40836
|
-
cmp ${condicao}, 0
|
|
41147
|
+
this.text += `
|
|
41148
|
+
cmp ${condicao}, 0
|
|
40837
41149
|
je ${labelFim}`;
|
|
40838
41150
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
40839
41151
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
40840
41152
|
}
|
|
40841
|
-
this.text += `
|
|
40842
|
-
jmp ${labelInicio}
|
|
41153
|
+
this.text += `
|
|
41154
|
+
jmp ${labelInicio}
|
|
40843
41155
|
${labelFim}:`;
|
|
40844
41156
|
}
|
|
40845
41157
|
traduzirDeclaracaoEscolha(declaracao) {
|
|
@@ -40850,9 +41162,9 @@ ${labelFim}:`;
|
|
|
40850
41162
|
const labelProximo = this.gerarLabel();
|
|
40851
41163
|
if (caminho.condicoes && caminho.condicoes[0]) {
|
|
40852
41164
|
const valorCaso = this.dicionarioConstrutos[caminho.condicoes[0].constructor.name](caminho.condicoes[0]);
|
|
40853
|
-
this.text += `
|
|
40854
|
-
mov rax, ${valorEscolha}
|
|
40855
|
-
cmp rax, ${valorCaso}
|
|
41165
|
+
this.text += `
|
|
41166
|
+
mov rax, ${valorEscolha}
|
|
41167
|
+
cmp rax, ${valorCaso}
|
|
40856
41168
|
jne ${labelProximo}`;
|
|
40857
41169
|
if (caminho.declaracoes && Array.isArray(caminho.declaracoes)) {
|
|
40858
41170
|
caminho.declaracoes.forEach((decl) => {
|
|
@@ -40861,23 +41173,24 @@ ${labelFim}:`;
|
|
|
40861
41173
|
}
|
|
40862
41174
|
});
|
|
40863
41175
|
}
|
|
40864
|
-
this.text += `
|
|
40865
|
-
jmp ${labelFim}
|
|
41176
|
+
this.text += `
|
|
41177
|
+
jmp ${labelFim}
|
|
40866
41178
|
${labelProximo}:`;
|
|
40867
41179
|
}
|
|
40868
41180
|
});
|
|
40869
41181
|
}
|
|
40870
|
-
this.text += `
|
|
41182
|
+
this.text += `
|
|
40871
41183
|
${labelFim}:`;
|
|
40872
41184
|
}
|
|
40873
41185
|
traduzirDeclaracaoExpressao(declaracao) {
|
|
40874
|
-
if (declaracao.expressao &&
|
|
41186
|
+
if (declaracao.expressao &&
|
|
41187
|
+
this.dicionarioConstrutos[declaracao.expressao.constructor.name]) {
|
|
40875
41188
|
this.dicionarioConstrutos[declaracao.expressao.constructor.name](declaracao.expressao);
|
|
40876
41189
|
}
|
|
40877
41190
|
}
|
|
40878
41191
|
traduzirDeclaracaoFazer(declaracao) {
|
|
40879
41192
|
const labelInicio = this.gerarLabel();
|
|
40880
|
-
this.text += `
|
|
41193
|
+
this.text += `
|
|
40881
41194
|
${labelInicio}:`;
|
|
40882
41195
|
// Em Delégua, fazer-enquanto tem caminhoFazer que é um Bloco
|
|
40883
41196
|
if (declaracao.caminhoFazer && declaracao.caminhoFazer.declaracoes) {
|
|
@@ -40889,60 +41202,66 @@ ${labelInicio}:`;
|
|
|
40889
41202
|
}
|
|
40890
41203
|
if (declaracao.condicaoEnquanto) {
|
|
40891
41204
|
const condicao = this.dicionarioConstrutos[declaracao.condicaoEnquanto.constructor.name](declaracao.condicaoEnquanto);
|
|
40892
|
-
this.text += `
|
|
40893
|
-
cmp ${condicao}, 0
|
|
41205
|
+
this.text += `
|
|
41206
|
+
cmp ${condicao}, 0
|
|
40894
41207
|
jne ${labelInicio}`;
|
|
40895
41208
|
}
|
|
40896
41209
|
}
|
|
40897
41210
|
traduzirDeclaracaoFalhar(declaracao) {
|
|
40898
41211
|
let mensagem = '"Erro"';
|
|
40899
|
-
if (declaracao.explicacao &&
|
|
41212
|
+
if (declaracao.explicacao &&
|
|
41213
|
+
typeof declaracao.explicacao === 'object' &&
|
|
41214
|
+
'constructor' in declaracao.explicacao) {
|
|
40900
41215
|
const explicacao = declaracao.explicacao;
|
|
40901
41216
|
if (explicacao.constructor && this.dicionarioConstrutos[explicacao.constructor.name]) {
|
|
40902
41217
|
mensagem = this.dicionarioConstrutos[explicacao.constructor.name](explicacao);
|
|
40903
41218
|
}
|
|
40904
41219
|
}
|
|
40905
41220
|
if (this.alvo === 'linux') {
|
|
40906
|
-
this.text += `
|
|
40907
|
-
; Falhar com mensagem: ${mensagem}
|
|
40908
|
-
mov eax, 1
|
|
40909
|
-
mov ebx, 1
|
|
41221
|
+
this.text += `
|
|
41222
|
+
; Falhar com mensagem: ${mensagem}
|
|
41223
|
+
mov eax, 1
|
|
41224
|
+
mov ebx, 1
|
|
40910
41225
|
int 0x80`;
|
|
40911
41226
|
}
|
|
40912
41227
|
else {
|
|
40913
|
-
this.text += `
|
|
40914
|
-
; Falhar com mensagem: ${mensagem}
|
|
40915
|
-
mov eax, 1
|
|
41228
|
+
this.text += `
|
|
41229
|
+
; Falhar com mensagem: ${mensagem}
|
|
41230
|
+
mov eax, 1
|
|
40916
41231
|
ret`;
|
|
40917
41232
|
}
|
|
40918
41233
|
}
|
|
40919
41234
|
traduzirDeclaracaoFuncao(declaracao) {
|
|
40920
41235
|
var _a;
|
|
40921
41236
|
const nomeFuncao = ((_a = declaracao.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) || 'funcao';
|
|
40922
|
-
this.text += `
|
|
40923
|
-
${nomeFuncao}:
|
|
40924
|
-
push rbp
|
|
41237
|
+
this.text += `
|
|
41238
|
+
${nomeFuncao}:
|
|
41239
|
+
push rbp
|
|
40925
41240
|
mov rbp, rsp`;
|
|
40926
|
-
if (declaracao.funcao &&
|
|
41241
|
+
if (declaracao.funcao &&
|
|
41242
|
+
declaracao.funcao.corpo &&
|
|
41243
|
+
Array.isArray(declaracao.funcao.corpo)) {
|
|
40927
41244
|
declaracao.funcao.corpo.forEach((decl) => {
|
|
40928
41245
|
if (this.dicionarioDeclaracoes[decl.constructor.name]) {
|
|
40929
41246
|
this.dicionarioDeclaracoes[decl.constructor.name](decl);
|
|
40930
41247
|
}
|
|
40931
41248
|
});
|
|
40932
41249
|
}
|
|
40933
|
-
this.text += `
|
|
40934
|
-
pop rbp
|
|
41250
|
+
this.text += `
|
|
41251
|
+
pop rbp
|
|
40935
41252
|
ret`;
|
|
40936
41253
|
}
|
|
40937
41254
|
traduzirDeclaracaoImportar(declaracao) {
|
|
40938
41255
|
// Importação é tratada em tempo de linkagem
|
|
40939
|
-
this.text += `
|
|
41256
|
+
this.text += `
|
|
40940
41257
|
; Importar: ${declaracao.caminho || 'unknown'}`;
|
|
40941
41258
|
}
|
|
40942
41259
|
traduzirDeclaracaoLeia(declaracao) {
|
|
40943
41260
|
var _a;
|
|
40944
41261
|
let nomeVar;
|
|
40945
|
-
if (declaracao.argumentos &&
|
|
41262
|
+
if (declaracao.argumentos &&
|
|
41263
|
+
declaracao.argumentos[0] &&
|
|
41264
|
+
declaracao.argumentos[0] instanceof construtos_1.Variavel) {
|
|
40946
41265
|
nomeVar = (_a = declaracao.argumentos[0].simbolo) === null || _a === void 0 ? void 0 : _a.lexema;
|
|
40947
41266
|
}
|
|
40948
41267
|
if (!nomeVar)
|
|
@@ -40952,11 +41271,11 @@ ${nomeFuncao}:
|
|
|
40952
41271
|
this.bss += ` ${varLabel} resb 256\n`;
|
|
40953
41272
|
this.variaveis.set(nomeVar, varLabel);
|
|
40954
41273
|
}
|
|
40955
|
-
this.text += `
|
|
40956
|
-
mov eax, 3
|
|
40957
|
-
mov ebx, 0
|
|
40958
|
-
mov ecx, ${this.variaveis.get(nomeVar)}
|
|
40959
|
-
mov edx, 256
|
|
41274
|
+
this.text += `
|
|
41275
|
+
mov eax, 3
|
|
41276
|
+
mov ebx, 0
|
|
41277
|
+
mov ecx, ${this.variaveis.get(nomeVar)}
|
|
41278
|
+
mov edx, 256
|
|
40960
41279
|
int 0x80`;
|
|
40961
41280
|
}
|
|
40962
41281
|
traduzirDeclaracaoPara(declaracao) {
|
|
@@ -40972,12 +41291,12 @@ ${nomeFuncao}:
|
|
|
40972
41291
|
this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
40973
41292
|
}
|
|
40974
41293
|
}
|
|
40975
|
-
this.text += `
|
|
41294
|
+
this.text += `
|
|
40976
41295
|
${labelInicio}:`;
|
|
40977
41296
|
if (declaracao.condicao) {
|
|
40978
41297
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
40979
|
-
this.text += `
|
|
40980
|
-
cmp ${condicao}, 0
|
|
41298
|
+
this.text += `
|
|
41299
|
+
cmp ${condicao}, 0
|
|
40981
41300
|
je ${labelFim}`;
|
|
40982
41301
|
}
|
|
40983
41302
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
@@ -40988,8 +41307,8 @@ ${labelInicio}:`;
|
|
|
40988
41307
|
this.dicionarioConstrutos[declaracao.incrementar.constructor.name](declaracao.incrementar);
|
|
40989
41308
|
}
|
|
40990
41309
|
}
|
|
40991
|
-
this.text += `
|
|
40992
|
-
jmp ${labelInicio}
|
|
41310
|
+
this.text += `
|
|
41311
|
+
jmp ${labelInicio}
|
|
40993
41312
|
${labelFim}:`;
|
|
40994
41313
|
}
|
|
40995
41314
|
traduzirDeclaracaoParaCada(declaracao) {
|
|
@@ -41005,57 +41324,58 @@ ${labelFim}:`;
|
|
|
41005
41324
|
if (vetor instanceof construtos_1.Vetor) {
|
|
41006
41325
|
tamanhoVetor = vetor.tamanho || 0;
|
|
41007
41326
|
}
|
|
41008
|
-
this.text += `
|
|
41009
|
-
xor rcx, rcx
|
|
41010
|
-
${labelInicio}:
|
|
41011
|
-
cmp rcx, ${tamanhoVetor}
|
|
41327
|
+
this.text += `
|
|
41328
|
+
xor rcx, rcx
|
|
41329
|
+
${labelInicio}:
|
|
41330
|
+
cmp rcx, ${tamanhoVetor}
|
|
41012
41331
|
jge ${labelFim}`;
|
|
41013
41332
|
if (this.dicionarioDeclaracoes[declaracao.corpo.constructor.name]) {
|
|
41014
41333
|
this.dicionarioDeclaracoes[declaracao.corpo.constructor.name](declaracao.corpo);
|
|
41015
41334
|
}
|
|
41016
|
-
this.text += `
|
|
41017
|
-
inc rcx
|
|
41018
|
-
jmp ${labelInicio}
|
|
41335
|
+
this.text += `
|
|
41336
|
+
inc rcx
|
|
41337
|
+
jmp ${labelInicio}
|
|
41019
41338
|
${labelFim}:`;
|
|
41020
41339
|
}
|
|
41021
41340
|
traduzirDeclaracaoRetorna(declaracao) {
|
|
41022
41341
|
if (declaracao.valor) {
|
|
41023
41342
|
const valor = this.dicionarioConstrutos[declaracao.valor.constructor.name](declaracao.valor);
|
|
41024
|
-
this.text += `
|
|
41343
|
+
this.text += `
|
|
41025
41344
|
mov rax, ${valor}`;
|
|
41026
41345
|
}
|
|
41027
|
-
this.text += `
|
|
41028
|
-
pop rbp
|
|
41346
|
+
this.text += `
|
|
41347
|
+
pop rbp
|
|
41029
41348
|
ret`;
|
|
41030
41349
|
}
|
|
41031
41350
|
traduzirDeclaracaoSe(declaracao) {
|
|
41032
41351
|
const labelSenao = this.gerarLabel();
|
|
41033
41352
|
const labelFim = this.gerarLabel();
|
|
41034
41353
|
const condicao = this.dicionarioConstrutos[declaracao.condicao.constructor.name](declaracao.condicao);
|
|
41035
|
-
this.text += `
|
|
41036
|
-
cmp ${condicao}, 0
|
|
41354
|
+
this.text += `
|
|
41355
|
+
cmp ${condicao}, 0
|
|
41037
41356
|
je ${labelSenao}`;
|
|
41038
41357
|
if (this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name]) {
|
|
41039
41358
|
this.dicionarioDeclaracoes[declaracao.caminhoEntao.constructor.name](declaracao.caminhoEntao);
|
|
41040
41359
|
}
|
|
41041
|
-
this.text += `
|
|
41042
|
-
jmp ${labelFim}
|
|
41360
|
+
this.text += `
|
|
41361
|
+
jmp ${labelFim}
|
|
41043
41362
|
${labelSenao}:`;
|
|
41044
|
-
if (declaracao.caminhoSenao &&
|
|
41363
|
+
if (declaracao.caminhoSenao &&
|
|
41364
|
+
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name]) {
|
|
41045
41365
|
this.dicionarioDeclaracoes[declaracao.caminhoSenao.constructor.name](declaracao.caminhoSenao);
|
|
41046
41366
|
}
|
|
41047
|
-
this.text += `
|
|
41367
|
+
this.text += `
|
|
41048
41368
|
${labelFim}:`;
|
|
41049
41369
|
}
|
|
41050
41370
|
traduzirDeclaracaoClasse(declaracao) {
|
|
41051
41371
|
var _a;
|
|
41052
41372
|
// Classes em assembly são complexas - implementação básica
|
|
41053
|
-
this.text += `
|
|
41373
|
+
this.text += `
|
|
41054
41374
|
; Classe: ${((_a = declaracao.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) || 'unknown'}`;
|
|
41055
41375
|
}
|
|
41056
41376
|
traduzirDeclaracaoTente(declaracao) {
|
|
41057
41377
|
// Try-catch em assembly requer handler complexo
|
|
41058
|
-
this.text += `
|
|
41378
|
+
this.text += `
|
|
41059
41379
|
; Tente-pegue`;
|
|
41060
41380
|
if (declaracao.caminhoTente && Array.isArray(declaracao.caminhoTente)) {
|
|
41061
41381
|
declaracao.caminhoTente.forEach((decl) => {
|
|
@@ -41094,8 +41414,8 @@ ${labelFim}:`;
|
|
|
41094
41414
|
}
|
|
41095
41415
|
else if (this.dicionarioConstrutos[tipoInicializador]) {
|
|
41096
41416
|
const valor = this.dicionarioConstrutos[tipoInicializador](declaracao.inicializador);
|
|
41097
|
-
this.text += `
|
|
41098
|
-
mov rax, ${valor}
|
|
41417
|
+
this.text += `
|
|
41418
|
+
mov rax, ${valor}
|
|
41099
41419
|
mov [${varLabel}], rax`;
|
|
41100
41420
|
}
|
|
41101
41421
|
}
|
|
@@ -41118,32 +41438,32 @@ ${labelFim}:`;
|
|
|
41118
41438
|
tam_string_literal = this.criaTamanhoNaMemoriaReferenteAVar(nome_string_literal);
|
|
41119
41439
|
}
|
|
41120
41440
|
if (this.alvo === 'linux') {
|
|
41121
|
-
this.text += `
|
|
41122
|
-
mov edx, ${tam_string_literal}
|
|
41123
|
-
mov ecx, ${nome_string_literal}
|
|
41124
|
-
mov ebx, 1 ; fd stdout
|
|
41125
|
-
mov eax, 4 ; sys_write
|
|
41441
|
+
this.text += `
|
|
41442
|
+
mov edx, ${tam_string_literal}
|
|
41443
|
+
mov ecx, ${nome_string_literal}
|
|
41444
|
+
mov ebx, 1 ; fd stdout
|
|
41445
|
+
mov eax, 4 ; sys_write
|
|
41126
41446
|
int 0x80`;
|
|
41127
41447
|
}
|
|
41128
41448
|
else {
|
|
41129
41449
|
// Windows: prototype `extern printf` and follow Win64 calling convention
|
|
41130
41450
|
// RCX = format pointer; here we use the literal directly as a C string
|
|
41131
|
-
this.text += `
|
|
41132
|
-
lea rcx, [rel ${nome_string_literal}]
|
|
41451
|
+
this.text += `
|
|
41452
|
+
lea rcx, [rel ${nome_string_literal}]
|
|
41133
41453
|
call printf`;
|
|
41134
41454
|
}
|
|
41135
41455
|
}
|
|
41136
41456
|
saidaSistema() {
|
|
41137
41457
|
if (this.alvo === 'linux') {
|
|
41138
|
-
this.text += `
|
|
41139
|
-
mov eax, 1 ; sys_exit
|
|
41140
|
-
xor ebx, ebx ; status 0
|
|
41458
|
+
this.text += `
|
|
41459
|
+
mov eax, 1 ; sys_exit
|
|
41460
|
+
xor ebx, ebx ; status 0
|
|
41141
41461
|
int 0x80`;
|
|
41142
41462
|
}
|
|
41143
41463
|
else {
|
|
41144
41464
|
// Windows: return from main with 0 in EAX
|
|
41145
|
-
this.text += `
|
|
41146
|
-
xor eax, eax
|
|
41465
|
+
this.text += `
|
|
41466
|
+
xor eax, eax
|
|
41147
41467
|
ret`;
|
|
41148
41468
|
}
|
|
41149
41469
|
}
|
|
@@ -41611,7 +41931,7 @@ class TradutorAssemblyScript {
|
|
|
41611
41931
|
return resultado;
|
|
41612
41932
|
}
|
|
41613
41933
|
traduzirDeclaracaoVarMultiplo(declaracaoVarMultiplo) {
|
|
41614
|
-
const variaveis = declaracaoVarMultiplo.simbolos.map(s => s.lexema).join(', ');
|
|
41934
|
+
const variaveis = declaracaoVarMultiplo.simbolos.map((s) => s.lexema).join(', ');
|
|
41615
41935
|
let resultado = 'let ';
|
|
41616
41936
|
resultado += variaveis;
|
|
41617
41937
|
resultado += this.resolveTipoDeclaracaoVarEContante(declaracaoVarMultiplo.tipo);
|
|
@@ -41630,7 +41950,7 @@ class TradutorAssemblyScript {
|
|
|
41630
41950
|
return resultado;
|
|
41631
41951
|
}
|
|
41632
41952
|
traduzirDeclaracaoConstMultiplo(declaracaoConstMultiplo) {
|
|
41633
|
-
const constantes = declaracaoConstMultiplo.simbolos.map(s => s.lexema).join(', ');
|
|
41953
|
+
const constantes = declaracaoConstMultiplo.simbolos.map((s) => s.lexema).join(', ');
|
|
41634
41954
|
let resultado = 'const ';
|
|
41635
41955
|
resultado += constantes;
|
|
41636
41956
|
resultado += this.resolveTipoDeclaracaoVarEContante(declaracaoConstMultiplo.tipo);
|
|
@@ -41785,7 +42105,9 @@ class TradutorAssemblyScript {
|
|
|
41785
42105
|
const declaracoesCorpo = corpoBloco.declaracoes || [];
|
|
41786
42106
|
let resultadoCorpo = '{\n';
|
|
41787
42107
|
this.indentacao += 4;
|
|
41788
|
-
resultadoCorpo +=
|
|
42108
|
+
resultadoCorpo +=
|
|
42109
|
+
' '.repeat(this.indentacao) +
|
|
42110
|
+
`const ${nomeVariavel} = ${nomeVetor}[__i_${nomeVariavel}];\n`;
|
|
41789
42111
|
for (const declaracaoOuConstruto of declaracoesCorpo) {
|
|
41790
42112
|
resultadoCorpo += ' '.repeat(this.indentacao);
|
|
41791
42113
|
const nomeConstrutor = declaracaoOuConstruto.constructor.name;
|
|
@@ -42006,7 +42328,9 @@ class TradutorAssemblyScript {
|
|
|
42006
42328
|
if (typeof chave === 'string') {
|
|
42007
42329
|
chaveStr = `"${chave}"`;
|
|
42008
42330
|
}
|
|
42009
|
-
else if (chave &&
|
|
42331
|
+
else if (chave &&
|
|
42332
|
+
chave.constructor &&
|
|
42333
|
+
this.dicionarioConstrutos[chave.constructor.name]) {
|
|
42010
42334
|
// Se for um Construto, traduzi-lo
|
|
42011
42335
|
chaveStr = this.dicionarioConstrutos[chave.constructor.name](chave);
|
|
42012
42336
|
}
|
|
@@ -42101,7 +42425,7 @@ class TradutorAssemblyScript {
|
|
|
42101
42425
|
return `[${primeiro}, ${segundo}, ${terceiro}, ${quarto}, ${quinto}, ${sexto}, ${setimo}, ${oitavo}, ${nono}, ${decimo}]`;
|
|
42102
42426
|
}
|
|
42103
42427
|
traduzirConstrutoTuplaN(tuplaN) {
|
|
42104
|
-
const elementos = tuplaN.elementos.map(elemento => this.dicionarioConstrutos[elemento.constructor.name](elemento));
|
|
42428
|
+
const elementos = tuplaN.elementos.map((elemento) => this.dicionarioConstrutos[elemento.constructor.name](elemento));
|
|
42105
42429
|
return `[${elementos.join(', ')}]`;
|
|
42106
42430
|
}
|
|
42107
42431
|
traduzirConstrutoSeTernario(seTernario) {
|
|
@@ -42180,7 +42504,7 @@ class TradutorAssemblyScript {
|
|
|
42180
42504
|
// Check if this is a native library function call
|
|
42181
42505
|
if (chamada.entidadeChamada instanceof construtos_1.Variavel) {
|
|
42182
42506
|
const nomeVariavel = chamada.entidadeChamada.simbolo.lexema;
|
|
42183
|
-
const argumentosTexto = chamada.argumentos.map(arg => this.dicionarioConstrutos[arg.constructor.name](arg));
|
|
42507
|
+
const argumentosTexto = chamada.argumentos.map((arg) => this.dicionarioConstrutos[arg.constructor.name](arg));
|
|
42184
42508
|
const funcaoNativa = this.traduzirFuncaoNativaGlobal(nomeVariavel, argumentosTexto);
|
|
42185
42509
|
if (funcaoNativa) {
|
|
42186
42510
|
return funcaoNativa;
|
|
@@ -42527,7 +42851,7 @@ class TradutorElixir {
|
|
|
42527
42851
|
async extrairCamposStruct(declaracao) {
|
|
42528
42852
|
const campos = new Set();
|
|
42529
42853
|
// Procurar pelo construtor
|
|
42530
|
-
const construtor = declaracao.metodos.find(m => m.simbolo.lexema === 'construtor' || m.simbolo.lexema === 'inicializar');
|
|
42854
|
+
const construtor = declaracao.metodos.find((m) => m.simbolo.lexema === 'construtor' || m.simbolo.lexema === 'inicializar');
|
|
42531
42855
|
if (!construtor) {
|
|
42532
42856
|
return [];
|
|
42533
42857
|
}
|
|
@@ -42536,7 +42860,7 @@ class TradutorElixir {
|
|
|
42536
42860
|
this.extrairCamposDeDeclaracao(declaracaoCorpo, campos);
|
|
42537
42861
|
}
|
|
42538
42862
|
// Converter para atoms do Elixir
|
|
42539
|
-
return Array.from(campos).map(c => `:${this.converterIdentificador(c)}`);
|
|
42863
|
+
return Array.from(campos).map((c) => `:${this.converterIdentificador(c)}`);
|
|
42540
42864
|
}
|
|
42541
42865
|
/**
|
|
42542
42866
|
* Extrai campos de uma declaração recursivamente
|
|
@@ -42578,7 +42902,7 @@ class TradutorElixir {
|
|
|
42578
42902
|
// Construtor vira função new/N
|
|
42579
42903
|
if (metodo.simbolo.lexema === 'construtor' || metodo.simbolo.lexema === 'inicializar') {
|
|
42580
42904
|
resultado += `def new(`;
|
|
42581
|
-
const parametros = metodo.funcao.parametros.map(p => this.converterIdentificador(p.nome.lexema));
|
|
42905
|
+
const parametros = metodo.funcao.parametros.map((p) => this.converterIdentificador(p.nome.lexema));
|
|
42582
42906
|
resultado += parametros.join(', ');
|
|
42583
42907
|
resultado += ') do\n';
|
|
42584
42908
|
this.aumentarIndentacao();
|
|
@@ -42596,7 +42920,7 @@ class TradutorElixir {
|
|
|
42596
42920
|
resultado += `def ${nomeMetodo}(`;
|
|
42597
42921
|
const nomeParametroStruct = this.converterIdentificador(nomeModulo.toLowerCase());
|
|
42598
42922
|
this.nomeParametroStruct = nomeParametroStruct;
|
|
42599
|
-
const parametros = [nomeParametroStruct].concat(metodo.funcao.parametros.map(p => this.converterIdentificador(p.nome.lexema)));
|
|
42923
|
+
const parametros = [nomeParametroStruct].concat(metodo.funcao.parametros.map((p) => this.converterIdentificador(p.nome.lexema)));
|
|
42600
42924
|
resultado += parametros.join(', ');
|
|
42601
42925
|
resultado += ') do\n';
|
|
42602
42926
|
this.aumentarIndentacao();
|
|
@@ -42686,7 +43010,7 @@ class TradutorElixir {
|
|
|
42686
43010
|
let resultado = this.adicionarIndentacao();
|
|
42687
43011
|
resultado += `def ${nomeFuncao}(`;
|
|
42688
43012
|
// Parâmetros
|
|
42689
|
-
const parametros = declaracao.funcao.parametros.map(p => this.converterIdentificador(p.nome.lexema));
|
|
43013
|
+
const parametros = declaracao.funcao.parametros.map((p) => this.converterIdentificador(p.nome.lexema));
|
|
42690
43014
|
resultado += parametros.join(', ');
|
|
42691
43015
|
resultado += ') do\n';
|
|
42692
43016
|
// Corpo
|
|
@@ -42963,7 +43287,9 @@ class TradutorElixir {
|
|
|
42963
43287
|
case 'ordenar':
|
|
42964
43288
|
return `Enum.sort(${objeto})`;
|
|
42965
43289
|
case 'juntar':
|
|
42966
|
-
return argumentos.length > 0
|
|
43290
|
+
return argumentos.length > 0
|
|
43291
|
+
? `Enum.join(${objeto}, ${argumentos[0]})`
|
|
43292
|
+
: `Enum.join(${objeto})`;
|
|
42967
43293
|
case 'fatiar':
|
|
42968
43294
|
if (argumentos.length >= 2) {
|
|
42969
43295
|
return `Enum.slice(${objeto}, ${argumentos[0]}, ${argumentos[1]})`;
|
|
@@ -43102,7 +43428,7 @@ class TradutorElixir {
|
|
|
43102
43428
|
async visitarExpressaoFuncaoConstruto(expressao) {
|
|
43103
43429
|
let resultado = 'fn ';
|
|
43104
43430
|
// Parâmetros
|
|
43105
|
-
const parametros = expressao.parametros.map(p => this.converterIdentificador(p.nome.lexema));
|
|
43431
|
+
const parametros = expressao.parametros.map((p) => this.converterIdentificador(p.nome.lexema));
|
|
43106
43432
|
resultado += parametros.join(', ');
|
|
43107
43433
|
resultado += ' ->';
|
|
43108
43434
|
// Corpo - se for uma única expressão, inline; se for bloco, multi-linha
|
|
@@ -43868,7 +44194,8 @@ class TradutorJavaScript {
|
|
|
43868
44194
|
if (argumento instanceof construtos_1.Variavel) {
|
|
43869
44195
|
return argumento.simbolo.lexema;
|
|
43870
44196
|
}
|
|
43871
|
-
if (argumento instanceof construtos_1.ReferenciaFuncao ||
|
|
44197
|
+
if (argumento instanceof construtos_1.ReferenciaFuncao ||
|
|
44198
|
+
argumento instanceof construtos_1.ArgumentoReferenciaFuncao) {
|
|
43872
44199
|
return argumento.simboloFuncao.lexema;
|
|
43873
44200
|
}
|
|
43874
44201
|
return (_c = (_b = (_a = this.dicionarioConstrutos)[argumento.constructor.name]) === null || _b === void 0 ? void 0 : _b.call(_a, argumento)) !== null && _c !== void 0 ? _c : '';
|
|
@@ -44109,7 +44436,7 @@ class TradutorMermaidJs {
|
|
|
44109
44436
|
var _a, _b;
|
|
44110
44437
|
const nomeClasse = declaracao.simbolo.lexema;
|
|
44111
44438
|
const superClasse = declaracao.superClasse
|
|
44112
|
-
? ((
|
|
44439
|
+
? ((_a = declaracao.superClasse.simbolo) === null || _a === void 0 ? void 0 : _a.lexema) || ((_b = declaracao.superClasse.nome) === null || _b === void 0 ? void 0 : _b.lexema)
|
|
44113
44440
|
: undefined;
|
|
44114
44441
|
const linha = declaracao.linha;
|
|
44115
44442
|
// Cria arestas de entrada e saída para a classe
|
|
@@ -44370,9 +44697,7 @@ class TradutorMermaidJs {
|
|
|
44370
44697
|
// Caminho então, normalmente um `Bloco`.
|
|
44371
44698
|
const verticesEntao = await declaracao.caminhoEntao.aceitar(this);
|
|
44372
44699
|
vertices = vertices.concat(verticesEntao);
|
|
44373
|
-
const ultimaArestaEntao = verticesEntao.length > 0
|
|
44374
|
-
? verticesEntao[verticesEntao.length - 1].destino
|
|
44375
|
-
: aresta;
|
|
44700
|
+
const ultimaArestaEntao = verticesEntao.length > 0 ? verticesEntao[verticesEntao.length - 1].destino : aresta;
|
|
44376
44701
|
if (declaracao.caminhoSenao) {
|
|
44377
44702
|
this.anteriores = [];
|
|
44378
44703
|
// Verifica se é "senão se" ou apenas "senão"
|
|
@@ -44420,9 +44745,7 @@ class TradutorMermaidJs {
|
|
|
44420
44745
|
verticesTente.push(...verticesDeclaracao);
|
|
44421
44746
|
}
|
|
44422
44747
|
vertices = vertices.concat(verticesTente);
|
|
44423
|
-
const ultimaArestaTente = verticesTente.length > 0
|
|
44424
|
-
? verticesTente[verticesTente.length - 1].destino
|
|
44425
|
-
: aresta;
|
|
44748
|
+
const ultimaArestaTente = verticesTente.length > 0 ? verticesTente[verticesTente.length - 1].destino : aresta;
|
|
44426
44749
|
const anterioresAposTente = [];
|
|
44427
44750
|
// Caminho pegue (catch) - se existir
|
|
44428
44751
|
if (declaracao.caminhoPegue) {
|
|
@@ -44608,7 +44931,7 @@ class TradutorMermaidJs {
|
|
|
44608
44931
|
async visitarExpressaoFuncaoConstruto(expressao) {
|
|
44609
44932
|
let texto = 'função anônima';
|
|
44610
44933
|
if (expressao.parametros && expressao.parametros.length > 0) {
|
|
44611
|
-
const parametros = expressao.parametros.map(p => p.nome.lexema).join(', ');
|
|
44934
|
+
const parametros = expressao.parametros.map((p) => p.nome.lexema).join(', ');
|
|
44612
44935
|
texto += `(${parametros})`;
|
|
44613
44936
|
}
|
|
44614
44937
|
else {
|
|
@@ -45150,7 +45473,7 @@ class TradutorPython {
|
|
|
45150
45473
|
}
|
|
45151
45474
|
const funcao = argumento;
|
|
45152
45475
|
// Extrai os nomes dos parâmetros
|
|
45153
|
-
const parametros = funcao.parametros.map(param => param.nome.lexema).join(', ');
|
|
45476
|
+
const parametros = funcao.parametros.map((param) => param.nome.lexema).join(', ');
|
|
45154
45477
|
// Python lambdas suportam apenas uma expressão
|
|
45155
45478
|
// Assumimos que a função tem um corpo simples com uma declaração de retorno
|
|
45156
45479
|
let expressao = '';
|
|
@@ -46895,7 +47218,7 @@ class TradutorRuby {
|
|
|
46895
47218
|
}
|
|
46896
47219
|
const funcao = argumento;
|
|
46897
47220
|
// Extrai os nomes dos parâmetros
|
|
46898
|
-
const parametros = funcao.parametros.map(param => param.nome.lexema).join(', ');
|
|
47221
|
+
const parametros = funcao.parametros.map((param) => param.nome.lexema).join(', ');
|
|
46899
47222
|
// Assumimos que a função tem um corpo simples com uma declaração de retorno
|
|
46900
47223
|
let expressao = '';
|
|
46901
47224
|
if (funcao.corpo.length > 0) {
|