public static Nodo generarC3DAcceso(ParseTreeNode acceso, Tipo tipo, Nodo nExp) { actual = null; Nodo nodo = null; String puntero = "P"; String estructura = "Stack"; foreach (ParseTreeNode objeto in acceso.ChildNodes) { if (objeto.Term.Name.Equals("id")) { GeneradorC3D.instrucciones.Add(new C3D((int)C3D.TipoC3D.COMENTARIO, "// Accediendo a un id " + objeto.Token.Text)); nodo = generarC3DID(objeto.Token.Text, tipo, puntero, estructura); } else if (objeto.Term.Name.Equals("NARREGLO")) { GeneradorC3D.instrucciones.Add(new C3D((int)C3D.TipoC3D.COMENTARIO, "// Accediendo a un arreglo")); nodo = Arreglo.generarAsignacionC3D(objeto.ChildNodes[0].Token.Text, objeto.ChildNodes[1], tipo); } else { // llamada con retorno GeneradorC3D.instrucciones.Add(new C3D((int)C3D.TipoC3D.COMENTARIO, "// Accediendo a una llamada")); nodo = Llamada.llamadaC3D(objeto, tipo); } tipo = Tipo.ESTE; if (nodo != null) { estructura = nodo.estructura; puntero = nodo.cadena; } } if (nExp != null) { // Asignar el valor a la variable! GeneradorC3D.instrucciones.Add(new C3D((int)C3D.TipoC3D.COMENTARIO, "// Asignar el valor a la variable del acceso")); GeneradorC3D.instrucciones.Add(new C3D((int)C3D.TipoC3D.VALOR, nodo.estructura, nodo.referencia, nExp.cadena)); } return(nodo); }
private static void generarC3DThis(Clase clase, String puntero, String estructura) { Simbolo sclase = TablaSimbolos.getInstance.getClase(clase.nombre); if (sclase != null) { String t1 = getTemporal(); instrucciones.Add(new C3D((int)C3D.TipoC3D.COMENTARIO, "// Guardar apuntador del this")); instrucciones.Add(new C3D((int)C3D.TipoC3D.ASIGNACION, t1, puntero, "+", "0")); instrucciones.Add(new C3D((int)C3D.TipoC3D.COMENTARIO, "// Guardar apuntador donde incia el this")); instrucciones.Add(new C3D((int)C3D.TipoC3D.VALOR, estructura, t1, "H")); instrucciones.Add(new C3D((int)C3D.TipoC3D.COMENTARIO, "// Reservar espacio para globales de " + clase.nombre)); aumentarHeap(Convert.ToString(sclase.tam)); // Recorrer las variables globales y asignarles foreach (Atributo atr in clase.atributos) { if (atr.esArreglo) { Arreglo.guardarC3D(atr.nombre, atr.valor, Acceso.Tipo.ESTE); } else { if (atr.valor != null) { instrucciones.Add(new C3D((int)C3D.TipoC3D.COMENTARIO, "// Obtener valor del atributo " + atr.nombre)); Nodo exp = Expresion.expresionC3D(atr.valor); Acceso.actual = null; instrucciones.Add(new C3D((int)C3D.TipoC3D.COMENTARIO, "// Obtener posicion del atributo " + atr.nombre)); Nodo nodo = Acceso.generarC3DID(atr.nombre, Acceso.Tipo.ESTE, "P", "Stack"); if (nodo != null) { // Asignar la expresion instrucciones.Add(new C3D((int)C3D.TipoC3D.COMENTARIO, "// Asignar expresion al atributo " + atr.nombre)); instrucciones.Add(new C3D((int)C3D.TipoC3D.VALOR, nodo.estructura, nodo.referencia, exp.cadena)); } } } } } }
private static void generarC3DSuper(Clase clase, String puntero, String estructura) { Simbolo sclase = TablaSimbolos.getInstance.getClase(clase.nombre); if (sclase != null) { String t1 = getTemporal(); instrucciones.Add(new C3D((int)C3D.TipoC3D.COMENTARIO, "// Guardar apuntador del super")); instrucciones.Add(new C3D((int)C3D.TipoC3D.ASIGNACION, t1, puntero, "+", "1")); instrucciones.Add(new C3D((int)C3D.TipoC3D.COMENTARIO, "// Guardar posicion donde empieza super")); instrucciones.Add(new C3D((int)C3D.TipoC3D.VALOR, estructura, t1, "H")); // Buscar clase padre Clase padre; if (clase.padre != null) { padre = getClasePadre(clase.padre); if (padre == null) { return; } } else { return; } sclase = TablaSimbolos.getInstance.getClase(clase.padre); if (sclase == null) { return; } instrucciones.Add(new C3D((int)C3D.TipoC3D.COMENTARIO, "// Reservar espacio para la clase padre" + sclase.nombre)); aumentarHeap(Convert.ToString(sclase.tam)); // Recorrer las variables globales y asignarles foreach (Atributo atr in padre.atributos) { if (atr.visibilidad == (int)Simbolo.Visibilidad.PUBLICO || atr.visibilidad == (int)Simbolo.Visibilidad.PROTEGIDO) { if (atr.esArreglo) { Arreglo.guardarC3D(atr.nombre, atr.valor, Acceso.Tipo.SUPER); } else { if (atr.valor != null) { instrucciones.Add(new C3D((int)C3D.TipoC3D.COMENTARIO, "// Obtener valor del atributo " + atr.nombre)); Nodo exp = Expresion.expresionC3D(atr.valor); Acceso.actual = null; instrucciones.Add(new C3D((int)C3D.TipoC3D.COMENTARIO, "// Obtener posicion del atributo " + atr.nombre)); Nodo nodo = Acceso.generarC3DID(atr.nombre, Acceso.Tipo.SUPER, "P", "Stack"); if (nodo != null) { // Asignar la expresion instrucciones.Add(new C3D((int)C3D.TipoC3D.COMENTARIO, "// Guardar valor del atributo " + atr.nombre)); instrucciones.Add(new C3D((int)C3D.TipoC3D.VALOR, nodo.estructura, nodo.referencia, exp.cadena)); } } } } } } }