/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package API; import ast.AbstractSyntaxTree; import ast.Node; import java.util.ArrayList; import java.util.HashMap; /** * * @author Eugenio */ public class Constantes { public static AbstractSyntaxTree ast; public static HashMap consts; public static HashMap types; public static HashMap> scopes; private static String currentKey; public static void _init() { if (consts != null) { return; } types = new HashMap<>(); consts = new HashMap<>(); scopes = new HashMap<>(); } public static void Add(String id, Node constant) { constant.S("public", Base.IsPublic(id) ? "true" : "false"); consts.put(id, constant); } public static Node Get(String id) { return consts.get(id); } public static boolean Defined(String id) { return consts.containsKey(id); } public static void List() { System.out.println("Constants:\n" + consts.keySet()); } /** * Metodos velhos */ // /** // * Adiciona uma constante // * // * @param nome nome da constante // * @param type // * @param valor valor da constante // * @param scope // */ // public static void add(String nome, String type, String valor, String scope) { // String key = nome + ":" + scope; // consts.put(key, valor); // types.put(key, type); // } // // /** // * Retorna verdadeiro se o constante existir // * // * @param name nome da constante // * @param scope local da definicao da constante // * @return true se o tipo existe // */ // public static boolean exist(String name, String scope) { // if (name.contains(".")) { // return false; // } // // boolean end = scope.equals("global"); // currentKey = name + ":" + scope; // // if (consts.containsKey(currentKey)) { // return true; // } // // String[] path = scope.split(",", 2); // // return end ? false : exist(name, path[path.length - 1]); // } // // /** // * Retorna o tipo da constante // * // * @param name nome da constante // * @return tipo da constante // * @throws Exception caso não encontre a constante // */ // public static String type(String name, String scope) { // if (exist(name, scope)) { // return types.get(currentKey); // } // return "undefined"; // } // // /** // * Retorna o valor de uma constante na forma de string // * // * @param text // * @param scope // * @return // */ // public static String val(String text, String scope) { // if (exist(text, scope)) { // return consts.get(currentKey); // } // return "undefined"; // } // // public static String val(Node var) { // return val(var.getText(), var.get("scope")); // } // // public static int intVal(Node var) throws Exception { // String v = val(var); // if (UtilsCompiler.isNumber(v)) { // return UtilsCompiler.parseInt(v); // } // throw new Exception("O valor " + v + " não é um numero!"); // } }