From 0cb193d0245e6c0c61acdb9693612483956c1e58 Mon Sep 17 00:00:00 2001
From: Henrique Margotte <henriquemargotte@gmail.com>
Date: Sun, 1 Dec 2024 11:41:40 -0300
Subject: [PATCH] tabela de simbolos com pf

---
 ts/ts.c | 79 +++++++++++++++++++++++++++++++++++++++------------------
 ts/ts.h | 12 +++++++++
 2 files changed, 66 insertions(+), 25 deletions(-)

diff --git a/ts/ts.c b/ts/ts.c
index 6eda21d..c546593 100644
--- a/ts/ts.c
+++ b/ts/ts.c
@@ -28,6 +28,10 @@ void insere_ts(char *ident, int categ, int nivel, info_t info, ts_t *ts){
             new->info.pr.param[i][0] = info.pr.param[i][0];
             new->info.pr.param[i][1] = info.pr.param[i][1];
         }
+    } else if (categ == PF) {
+        new->info.pf.tipo = info.pf.tipo;
+        new->info.pf.desloc = info.pf.desloc;
+        new->info.pf.passagem = info.pf.passagem;
     }
 
 	new->prox = ts->topo;
@@ -70,7 +74,10 @@ void atualiza_tipo(int n, int tipo, ts_t *ts){
 
 	simb_t *p = ts->topo;
 	for (int i = 0; i < n; ++i){
-		p->info.vs.tipo = tipo;
+		if (p->categ == VS)
+            p->info.vs.tipo = tipo;
+        else if (p->categ == PF)
+            p->info.pf.tipo = tipo;
 		p = p->prox;
 	}
 }
@@ -89,40 +96,62 @@ void mostra_ts(ts_t *ts) {
 
     simb_t *p = ts->topo;
     while (p != NULL) {
-        // Identificar a categoria
-        const char *categStr;
+        const char *categStr = "Outro";
         const char *tipoStr = "-";
         char deslocStr[10] = "-";
         char detalhes[50] = "-";
 
-        if (p->categ == VS) {
-            categStr = "VS";
-            // Determina o tipo como Inteiro, Boolean ou Indefinido
-            switch (p->info.vs.tipo) {
-                case INTEIRO:
-                    tipoStr = "Inteiro";
-                    break;
-                case BOOLEAN:
-                    tipoStr = "Boolean";
-                    break;
-                default:
-                    tipoStr = "NSEI";
-                    break;
+        switch (p->categ) {
+            case VS: {
+                categStr = "VS";
+                // Tipo (Inteiro, Boolean, Indefinido)
+                switch (p->info.vs.tipo) {
+                    case INTEIRO:
+                        tipoStr = "Inteiro";
+                        break;
+                    case BOOLEAN:
+                        tipoStr = "Boolean";
+                        break;
+                    default:
+                        tipoStr = "NSEI";
+                        break;
+                }
+                sprintf(deslocStr, "%d", p->info.vs.desloc);
+                break;
             }
-            sprintf(deslocStr, "%d", p->info.vs.desloc);
-        } else if (p->categ == PR) {
-            categStr = "PR";
-            tipoStr = "-";
-            sprintf(detalhes, "%s, Params: %d", p->info.pr.rot, p->info.pr.quant);
-        } else {
-            categStr = "Outro";
+            case PR: {
+                categStr = "PR";
+                tipoStr = "-";
+                sprintf(detalhes, "%s, Params: %d", p->info.pr.rot, p->info.pr.quant);
+                break;
+            }
+            case PF: {
+                categStr = "PF";
+                // Tipo (Inteiro, Boolean, Indefinido)
+                switch (p->info.pf.tipo) {
+                    case INTEIRO:
+                        tipoStr = "Inteiro";
+                        break;
+                    case BOOLEAN:
+                        tipoStr = "Boolean";
+                        break;
+                    default:
+                        tipoStr = "NSEI";
+                        break;
+                }
+                sprintf(deslocStr, "%d", p->info.pf.desloc);
+                // Passagem por valor ou referĂȘncia
+                sprintf(detalhes, "Passagem: %s", p->info.pf.passagem == VLR ? "Valor" : "ReferĂȘncia");
+                break;
+            }
+            default:
+                categStr = "Outro";
         }
 
-        // Imprime a entrada
         printf("| %-10s | %-8s | %-8d | %-10s | %-10s | %-20s |\n", 
                p->ident, categStr, p->nivel, tipoStr, deslocStr, detalhes);
 
         p = p->prox;
     }
     printf("----------------------------------------------------------------------------------\n");
-}
\ No newline at end of file
+}
diff --git a/ts/ts.h b/ts/ts.h
index 02271bd..c2c5825 100644
--- a/ts/ts.h
+++ b/ts/ts.h
@@ -12,9 +12,16 @@ typedef struct pr_t {
     int **param;
 } pr_t;
 
+typedef struct pf_t {
+    int tipo;
+    int desloc;
+    int passagem;
+} pf_t;
+
 typedef union info_t {
     vs_t vs;
     pr_t pr;
+    pf_t pf;
 } info_t;
 
 typedef struct simb_t {
@@ -38,6 +45,11 @@ typedef struct ts_t {
 // enum categorias
 #define VS 0
 #define PR 1
+#define PF 2
+
+// enum passagem
+#define VLR 0
+#define REF 1
 
 void inicializa_ts(ts_t *ts);
 
-- 
GitLab