예제 #1
0
def hacerUnSoloCambio(func, entry_lower, temps_array, contador_funciones):
    newString = ''  #viendo nada mas como queda armado
    if func in entry_lower:
        type_return = Procedures().getReturnType(func)
        #separando string
        split = entry_lower.split(func, 1)
        #recibiendo retorno de la funcion
        temp = temps_array[contador_funciones]
        newValue = temp
        #aumentando contador para obtener el temporal correspondiente
        contador_funciones += 1
        temp_ant = ''
        for idx, val in enumerate(split):
            #Quitando parametros
            if idx > 0 and "(" in val and ")" in val:
                i = val.index("(")
                j = val.index(")")
                str1 = val[:i]
                str2 = val[j + 1:]
                val = str1 + str2
            if (idx < len(split) - 1):
                temp_ant = temp
                temp = ThreeAddressCode().newTemp()
                # newValue = temp
                #METIENDO COMILLAS
                if type_return == ColumnsTypes.TEXT or type_return == ColumnsTypes.VARCHAR:
                    ThreeAddressCode().addCode(
                        f"{temp} = \"{val}\" + \'\\\"\'")
                    temp = ThreeAddressCode().newTemp()
                    ThreeAddressCode().addCode(
                        f"{temp} = str({temp_ant}) + \'\\\"\'")
                else:
                    ThreeAddressCode().addCode(
                        f"{temp} = \"{val}\" + str({temp_ant})")
            newString += f"{val}"
        if len(split) > 1:
            print("val", val)
            contiene_reemplazo = True
            funciones = Procedures().getProceduresIDs()

            for func in funciones:
                if func in val:
                    contiene_reemplazo = False
                    break
            if contiene_reemplazo:
                temp = ThreeAddressCode().newTemp()
                ThreeAddressCode().addCode(f"{temp} = \"{val}\"")
            return hacerUnSoloCambio(func, val, temps_array,
                                     contador_funciones)

    return contador_funciones
예제 #2
0
    def compile(self, environment):
        params = len(self.params)
        if self.isNew:
            self.environment = environment  # TODO verificar
            if Procedures().saveProcedure(self.id, self, None, self.line, self.column):
                var_array = self.print(environment)
                self.setVariables(var_array, environment)
        else:
            var_array = Procedures().getProcedure(self.id, params, self.line, self.column)
            if var_array:
                self.setVariables(var_array, environment)

            fun = ThreeAddressCode().searchFunction(self.id)
            if fun:
                
                self.setVariables(fun['variables'], environment)
예제 #3
0
 def process(self, environment):
     for name in self.id:
         name = name['value']
         drop = Procedures().dropProcedure(name, self.line, self.column)
         if not drop and not self.ifExists:
             desc = f": Function {name} does not exist"
             ErrorController().add(39, 'Execution', desc, self.line,
                                   self.column)
예제 #4
0
def putVarValues(entry: str, temps_array: list, environment: Ambito):
    # entry = entry.replace("))", ")")
    variables = environment.getAllVarIds()
    temp = None
    entry_lower = entry
    diccionario = {}
    hay_variables = False
    for variable in variables:

        if variable in entry_lower:
            first_letter = entry_lower.index(variable)
            next_last_letter = first_letter + len(variable)

            if first_letter - 1 > 0:
                if entry_lower[first_letter - 1].isalpha():
                    continue
            if next_last_letter < len(entry_lower):
                if entry_lower[next_last_letter].isalpha():
                    continue
            hay_variables = True
            print(f"variable: {variable}")
            newValue = environment.getVar(variable)
            #OBTENIENDO VALOR Y PASARLO A UN TEMPORAL
            temp = ThreeAddressCode().newTemp()
            ThreeAddressCode().addCode(f"{temp} = Stack[{newValue.position}]")
            diccionario[variable] = temp

    if hay_variables:
        contador_temporales = ThreeAddressCode().tempCounter
        for variable in variables:
            cambiarVariable(variable, entry_lower, diccionario)
        numbers = int(temp[1:])
        temp = f"t{numbers+1}"
        for r in range(contador_temporales,
                       ThreeAddressCode().tempCounter - 1):
            temp_ant = temp
            temp = ThreeAddressCode().newTemp()
            if temp_ant is None:
                ThreeAddressCode().addCode(f"{temp} = t{r} + t{r+1}")
            else:
                ThreeAddressCode().addCode(f"{temp} = {temp_ant} + t{r+1}")

        if temp is None:
            dif = ThreeAddressCode().tempCounter - contador_temporales
            if dif > 0:
                temp = f"t{contador_temporales + 1}"

    if len(temps_array) > 0:
        funciones = Procedures().getProceduresIDs()
        contador_funciones = 0
        for func in funciones:
            print(f"funcion: {func}")
            # func = func.lower()

            if func in entry_lower:
                contador_temporales = ThreeAddressCode().tempCounter
                #separando string
                contador_funciones = hacerUnSoloCambio(func, entry_lower,
                                                       temps_array,
                                                       contador_funciones)

                for r in range(contador_temporales,
                               ThreeAddressCode().tempCounter - 1):
                    temp_ant = temp
                    temp = ThreeAddressCode().newTemp()
                    if temp_ant is None:
                        ThreeAddressCode().addCode(f"{temp} = t{r} + t{r+1}")
                    else:
                        ThreeAddressCode().addCode(
                            f"{temp} = {temp_ant} + t{r+1}")

                if temp is None:
                    dif = ThreeAddressCode().tempCounter - contador_temporales
                    if dif > 0:
                        temp = f"t{contador_temporales + 1}"

    if temp is None: return entry
    else: return temp
예제 #5
0
파일: shared.py 프로젝트: sandymerida/tytus
def putVarValues(entry: str, temps_array: [], environment: Ambito):
    entry = entry.replace("))", ")")
    variables = environment.getAllVarIds()
    temp = None
    entry_lower = entry
    for variable in variables:
        print(f"variable: {variable}")
        # variable = f" {variable} "
        if variable in entry_lower:
            first_letter = entry_lower.index(variable)
            next_last_letter = first_letter + len(variable)

            if first_letter - 1 > 0:
                if entry_lower[first_letter - 1].isalpha():
                    continue
            if next_last_letter < len(entry_lower):
                if entry_lower[next_last_letter].isalpha():
                    continue

            split = entry_lower.split(variable)
            newValue = environment.getVar(variable)
            temp = ThreeAddressCode().newTemp()
            newString = ''
            #OBTENIENDO VALOR Y PASARLO A UN TEMPORAL
            ThreeAddressCode().addCode(f"{temp} = Stack[{newValue.position}]")
            temp_ant = ''
            for idx, val in enumerate(split):

                if (idx < len(split) - 1):
                    temp_ant = temp
                    temp = ThreeAddressCode().newTemp()
                    ThreeAddressCode().addCode(
                        f"{temp} = \"{val}\" + str({temp_ant})")
                    newString += f"{val}{newValue.value}"

            temp_ant = temp
            temp = ThreeAddressCode().newTemp()
            ThreeAddressCode().addCode(f"{temp} = {temp_ant} + \";\"")
            newString += ';'

            print("valor nuevo string: ", newString)

    if len(temps_array) > 0:
        funciones = Procedures().getProceduresIDs()
        contador_funciones = 0
        for func in funciones:
            print(f"funcion: {func}")
            # func = func.lower()

            if func in entry_lower:
                contador_temporales = ThreeAddressCode().tempCounter
                #separando string
                contador_funciones = hacerUnSoloCambio(func, entry_lower,
                                                       temps_array,
                                                       contador_funciones)

                for r in range(contador_temporales,
                               ThreeAddressCode().tempCounter - 1):
                    temp_ant = temp
                    temp = ThreeAddressCode().newTemp()
                    if temp_ant is None:
                        ThreeAddressCode().addCode(f"{temp} = t{r} + t{r+1}")
                    else:
                        ThreeAddressCode().addCode(
                            f"{temp} = {temp_ant} + t{r+1}")

                if temp is None:
                    dif = ThreeAddressCode().tempCounter - contador_temporales
                    if dif > 0:
                        temp = f"t{contador_temporales + 1}"

                # temp_ant = temp
                # temp = ThreeAddressCode().newTemp()
                # ThreeAddressCode().addCode(f"{temp} = {temp_ant} + \";\"")
                # newString +=  f"{val}"
                # entry_lower = newString.lower()

                # print("valor nuevo string: ", newString)

    if temp is None: return entry
    else: return temp