コード例 #1
0
ファイル: return_.py プロジェクト: sandymerida/tytus
 def execute(self, environment):
     try:
         tab = ""
         cd = ""
         tab1 = False
         if isinstance(environment, Environment):
             tab += "\t"
             tab1 = True
         if self.exp:
             e = self.exp.execute(environment)
             cd += tab + "stack.append(" + e.temp + ")\n"
             grammar.optimizer_.addIgnoreString(
                 str("stack.append(" + e.temp + ")"), self.row, tab1)
             cd += tab + "goto .endLabel\n"
             grammar.optimizer_.addGoto(str("endLabel"), self.row, tab1)
             return code.C3D(e.value + cd, "return", self.row, self.column)
         cd = tab + "stack.append(None)\n"
         grammar.optimizer_.addIgnoreString(str("stack.append(None)"),
                                            self.row, tab1)
         cd += tab + "goto .endLabel\n"
         grammar.optimizer_.addGoto(str("endLabel"), self.row, tab1)
         return code.C3D(cd, "return", self.row, self.column)
     except:
         grammar.PL_errors.append(
             "Error P0000: plpgsql fatal error \n Hint---> Return Expresion"
         )
コード例 #2
0
ファイル: elseif_stmt.py プロジェクト: Odra99/tytus
 def execute(self, environment):
     try:
         cod3d = self.p_fev()
         self.p_if_sum()
         boolCode = self.expBool.execute(environment)
         cod3d += boolCode.value
         cod3d += ("\tif " + str(boolCode.temp) + ": goto .etiv" +
                   str(grammar.current_etiq + 1) + "\n")
         grammar.optimizer_.addIF(
             str(boolCode.temp),
             str("etiv" + str(grammar.current_etiq + 1)), self.row)
         cod3d += "\tgoto .etif" + str(grammar.current_etiq + 2) + "\n"
         grammar.optimizer_.addGoto(
             str("etif" + str(grammar.current_etiq + 2)), self.row)
         grammar.back_fill.insert_true(grammar.current_etiq + 1)
         grammar.back_fill.insert_false(grammar.current_etiq + 2)
         grammar.current_etiq += 2
         cod3d += self.p_iev()
         for stmt in self.stmts:
             cod3d += stmt.execute(environment).value
         cod3d += self.p_fef()
         self.p_if_rest()
         return code.C3D(cod3d, "elseif", self.row, self.column)
     except:
         grammar.PL_errors.append(
             "Error P0000: plpgsql fatal error \n Hint---> Else If Statement"
         )
コード例 #3
0
 def execute(self, environment):
     try:
         out = "fase1.execution(dbtemp + "
         out += '" '
         out += "UPDATE "
         out += self.fromcl + " SET "
         i = 0
         # values
         for id, value in self.values:
             value = value.execute(environment)
             t = id + " = " + value.temp
             out += t
             if i < len(self.values) - 1:
                 out += ", "
             else:
                 out += " "
             i += 1
         # where
         pval = self.wherecl.execute(environment)
         if pval.temp != "":
             out += "WHERE " + pval.temp + " "
         parVal = pval.value
         out = out.rstrip() + ';")\n'
         if isinstance(environment, Environment):
             grammar.optimizer_.addIgnoreString(out, self.row, True)
             out = "\t" + out
         else:
             grammar.optimizer_.addIgnoreString(out, self.row, False)
         return code.C3D(parVal + out, "update", self.row, self.column)
     except:
         grammar.PL_errors.append(
             "Error P0000: Plpgsql Fatal error \n Hint---> Update")
コード例 #4
0
    def execute(self, environment):
        try:
            out = "fase1.execution(dbtemp + "
            out += '" '
            out += "CREATE "
            out += "TYPE "
            out += self.exists + " "
            out += self.name + " AS ENUM ("

            j = 0
            for i in range(len(self.values) - 1):
                j = i + 1
                pval = self.values[i].execute(environment)
                out += pval.temp + ", "
            pval = self.values[j].execute(environment)
            out += pval.temp
            out += ");"
            out += '")\n'
            if isinstance(environment, Environment):
                grammar.optimizer_.addIgnoreString(out, self.row, True)
                out = "\t" + out
            else:
                grammar.optimizer_.addIgnoreString(out, self.row, False)
            return code.C3D(out, "create_type", self.row, self.column)
        except:
            grammar.PL_errors.append(
                "Error P0000: plpgsql fatal error \n Hint---> Create Type"
            )
コード例 #5
0
ファイル: operation.py プロジェクト: Sohanyuuu/tytus
 def execute(self, environment):
     tab = ""
     if isinstance(environment, Environment):
         tab = "\t"
     exp = self.exp.execute(environment)
     if self.operator == "+":
         exp = exp.value + tab + self.temp + " = " + str(exp.temp) + "\n"
     elif self.operator == "-":
         exp = exp.value + tab + self.temp + " = -1 * " + str(
             exp.temp) + "\n"
     elif self.operator == "NOTNULL":
         exp = (exp.value + tab + self.temp + " = " + str(exp.temp) +
                " != None " + "\n")
     elif self.operator == "NOT":
         exp = exp.value + tab + self.temp + " = not " + str(
             exp.temp) + "\n"
     else:
         if "NOT" in self.operator:
             exp2 = self.operator[5:]
             self.operator = " != "
         else:
             exp2 = self.operator[2:]
             self.operator = " == "
         grammar.optimizer_.addAritOp(self.temp, exp.temp, exp2,
                                      self.operator, self.row)
         exp2 = values.get(exp2, exp2)
         exp = (exp.value + tab + self.temp + " = " + str(exp.temp) +
                self.operator + exp2 + "\n")
     return code.C3D(exp, self.temp, self.row, self.column)
コード例 #6
0
 def execute(self, environment):
     try:
         if not self.params:
             self.params = []
         environment.globalEnv.addFunction(self.proc, self.id, self.returns,
                                           len(self.params))
         cd = "\n@with_goto\ndef " + self.id + "():\n"
         grammar.optimizer_.addIgnoreString(str(cd), self.row, False)
         for p in self.params:
             t = p.execute(environment).temp
             temp = t + " = stack.pop()\n"
             cd += "\t" + t + " = stack.pop()\n"
             fix = ("\t" + "if isinstance(" + t + ", str): " + t +
                    ' = "\'"+' + t + '+"\'"' + "\n")
             cd += fix
             temp += fix
             grammar.optimizer_.addIgnoreString(str(temp), self.row, True)
         if self.params:
             for p in self.params:
                 p.execute(environment)
         return code.C3D(cd, self.id, self.row, self.column)
     except:
         grammar.PL_errors.append(
             "Error P0000: plpgsql fatal error \n Hint---> Function " +
             self.id)
コード例 #7
0
ファイル: insert_.py プロジェクト: sandymerida/tytus
 def execute(self, environment):
     try:
         out = "fase1.execution(dbtemp + "
         out += '" '
         out += "INSERT INTO "
         out += self.tabla + " "
         out += self.columns
         out += "VALUES ("
         parVal = ""
         j = 0
         for i in range(len(self.parametros) - 1):
             j = i + 1
             pval = self.parametros[i].execute(environment)
             parVal += pval.value
             out += pval.temp + ", "
         pval = self.parametros[j].execute(environment)
         parVal += pval.value
         out += pval.temp
         out += ");"
         out += '")\n'
         cod = out
         if isinstance(environment, Environment):
             out = "\t" + out
         out = parVal + out
         if isinstance(environment, Environment):
             grammar.optimizer_.addIgnoreString(cod, self.row, True)
         else:
             grammar.optimizer_.addIgnoreString(cod, self.row, False)
         return code.C3D(out, "insert", self.row, self.column)
     except:
         grammar.PL_errors.append(
             "Error P0000: Plpgsql fatal error \n Hint---> Insert ")
コード例 #8
0
 def execute(self, environment):
     tab = ""
     tab1 = False
     if isinstance(environment, Environment):
         tab = "\t"
         tab1 = True
     exp1 = self.exp1.execute(environment)
     exp2 = self.exp2.execute(environment)
     if self.operator == "<>":
         self.operator = "!="
     elif self.operator == "=":
         self.operator = "=="
     elif self.operator == "||":
         self.operator = "+"
     exp1.temp = values.get(exp1.temp, exp1.temp)
     exp2.temp = values.get(exp2.temp, exp2.temp)
     exp = (
         exp1.value
         + exp2.value
         + tab
         + self.temp
         + " = "
         + str(exp1.temp)
         + " "
         + self.operator.lower()
         + " "
         + str(exp2.temp)
         + "\n"
     )
     grammar.optimizer_.addAritOp(
         self.temp, str(exp1.temp), exp2.temp, self.operator.lower(), self.row, tab1
     )
     return code.C3D(exp, self.temp, self.row, self.column)
コード例 #9
0
ファイル: assignment.py プロジェクト: sandymerida/tytus
    def execute(self, environment):
        try:
            exp = self.value.execute(environment)
            # TODO: Error
            if environment.getVar(self.id) != None:
                self.value = exp.value + "\t" + self.id + " = " + str(
                    exp.temp) + "\n"
                """
                fix = (
                    "\t"
                    + "if isinstance("
                    + self.id
                    + ", str): "
                    + self.id
                    + ' = "\'"+'
                    + self.id
                    + '+"\'"'
                    + "\n"
                )
                self.value += fix
                """
                grammar.optimizer_.addScalarAsig(self.id, exp.temp, self.row,
                                                 True)
                # grammar.optimizer_.addIgnoreString(str(fix), self.row, False)

                return code.C3D(self.value, self.id, self.row, self.column)
            else:
                grammar.PL_errors.append("Error P0000: La variable " +
                                         self.id +
                                         " no esta declarada en la linea: " +
                                         self.row)
        except:
            grammar.PL_errors.append(
                "Error P0000: Error en la asignacion de valor")
コード例 #10
0
 def execute(self, environment):
     global environments
     newEnv = Environment(environment)
     environments.append([self.function.id, newEnv])
     decl = ""
     bl = ""
     defFunc = self.function.execute(newEnv).value
     for d in self.declaration:
         decl += d.execute(newEnv).value
     if self.function.proc == "PROCEDURE":
         for b in self.blocks:
             if isinstance(b, return_.Return):
                 if b.exp:
                     print("no se puede return")
                     # TODO: Error no puede venir return en procedure
                     pass
                 else:
                     bl += b.execute(newEnv).value
             else:
                 bl += b.execute(newEnv).value
     else:
         for b in self.blocks:
             bl += b.execute(newEnv).value
     grammar.optimizer_.addIgnoreString(str("stack.append(None)"), self.row,
                                        True)
     grammar.optimizer_.addLabel(str("endLabel"), self.row, True)
     return code.C3D(
         defFunc + decl + bl + "\tstack.append(None)\n" +
         "\tlabel .endLabel\n\n",
         "block",
         self.row,
         self.column,
     )
コード例 #11
0
 def execute(self, environment):
     cod3d = self.p_fev()
     for stmt in self.stmts:
         cod3d += stmt.execute(environment).value
     cod3d += self.p_fef()
     cod3d += self.p_write_next_etiq()
     cod3d += self.p_fev()
     return code.C3D(cod3d, "else", self.row, self.column)
コード例 #12
0
ファイル: assignment.py プロジェクト: Sohanyuuu/tytus
 def execute(self, environment):
     exp = self.value.execute(environment)
     # TODO: Error
     if environment.getVar(self.id) != None:
         self.value = exp.value + "\t" + self.id + " = " + str(
             exp.temp) + "\n"
         grammar.optimizer_.addScalarAsig(self.id, exp.temp, self.row)
         return code.C3D(self.value, self.id, self.row, self.column)
コード例 #13
0
 def execute(self, environment):
     cd = "\n"
     p = self.procedures
     temp = p.execute(environment).value
     cd += temp
     cd += "\n"
     grammar.optimizer_.addIgnoreString(str(temp), self.row, False)
     return code.C3D(cd, "execute", self.row, self.column)
コード例 #14
0
ファイル: operation.py プロジェクト: Odra99/tytus
 def execute(self, environment):
     try:
         tab = ""
         tab1 =False
         if isinstance(environment, Environment):
             tab = "\t"
             tab1=True
         exp = self.exp.execute(environment)
         if self.operator == "+":
             grammar.optimizer_.addScalarAsig(
                 self.temp, str(exp.temp), None, "=", self.row,tab1
             )
             exp = exp.value + tab + self.temp + " = " + str(exp.temp) + "\n"
             
         elif self.operator == "-":
             grammar.optimizer_.addAritOp(
                 self.temp, "-1 ", exp.temp, "*", self.row,tab1
             )
             exp = exp.value + tab + self.temp + " = -1 * " + str(exp.temp) + "\n"
             
         elif self.operator == "NOTNULL":
             grammar.optimizer_.addAritOp(
                 self.temp, str(exp.temp), "None", "!=", self.row,tab1
             )
             exp = (
                 exp.value + tab + self.temp + " = " + str(exp.temp) + " != None " + "\n"
             )
             
         elif self.operator == "NOT":
             grammar.optimizer_.addScalarAsig(
                 self.temp, str(exp.temp), None, "= not", self.row,tab1
             )
             exp = exp.value + tab + self.temp + " = not " + str(exp.temp) + "\n"
             
         else:
             if "NOT" in self.operator:
                 exp2 = self.operator[5:]
                 self.operator = " != "
             else:
                 exp2 = self.operator[2:]
                 self.operator = " == "
             grammar.optimizer_.addAritOp(
                 self.temp, exp.temp, exp2, self.operator, self.row,tab1
             )
             exp2 = values.get(exp2, exp2)
             exp = (
                 exp.value
                 + tab
                 + self.temp
                 + " = "
                 + str(exp.temp)
                 + self.operator
                 + exp2
                 + "\n"
             )
         return code.C3D(exp, self.temp, self.row, self.column)
     except:
         grammar.PL_errors.append("Error P0000: plpgsql fatal error \n Hint---> Unary Expression")
コード例 #15
0
ファイル: show_.py プロジェクト: Sohanyuuu/tytus
 def execute(self, environment):
     out = "fase1.execution("
     out += '"'
     out += "SHOW DATABASES"
     out += self.like + ";"
     out += '")\n'
     if isinstance(environment, Environment):
         out = "\t" + out
     return code.C3D(out, "show_databases", self.row, self.column)
コード例 #16
0
ファイル: truncate_.py プロジェクト: Sohanyuuu/tytus
 def execute(self, environment):
     out = "fase1.execution(dbtemp + "
     out += '" '
     out += "TRUNCATE "
     out += self.name + ";"
     out += '")\n'
     if isinstance(environment, Environment):
         out = "\t" + out
     return code.C3D(out, "truncate_database", self.row, self.column)
コード例 #17
0
ファイル: use_.py プロジェクト: Sohanyuuu/tytus
 def execute(self, environment):
     out = "dbtemp = "
     out += '"'
     out += "USE "
     out += self.db + ";"
     out += '"\n'
     if isinstance(environment, Environment):
         out = "\t" + out
     return code.C3D(out, "use_database", self.row, self.column)
コード例 #18
0
 def execute(self, environment):
     out = "fase1.execution(dbtemp + "
     out += '" '
     out += "DROP INDEX "
     out += self.exists + " "
     out += self.idList + ";"
     out += '")\n'
     if isinstance(environment, Environment):
         out = "\t" + out
     return code.C3D(out, "drop_index", self.row, self.column)
コード例 #19
0
ファイル: declaration.py プロジェクト: Sohanyuuu/tytus
    def execute(self, environment: Environment):
        environment.addVar(self.id, self.id, self.type, self.row, self.column)
        val = ""
        tmp = self.id
        if self.ass:
            a = self.ass.execute(environment)
            val = a.value
            tmp = a.temp

        return code.C3D(val, tmp, self.row, self.column)
コード例 #20
0
 def execute(self, environment):
     tab = ""
     cd = ""
     if isinstance(environment, Environment):
         tab += "\t"
     if self.exp:
         e = self.exp.execute(environment)
         cd += tab + "stack.append(" + e.temp + ")\n"
         grammar.optimizer_.addIgnoreString(
             str("stack.append(" + str(e.temp) + ")"), self.row
         )
         cd += tab + "goto .endLabel\n"
         grammar.optimizer_.addGoto(str("endLabel"), self.row)
         return code.C3D(e.value + cd, "return", self.row, self.column)
     cd = tab + "stack.append(None)\n"
     grammar.optimizer_.addIgnoreString(str("stack.append(Nonen"), self.row)
     cd += tab + "goto .endLabel\n"
     grammar.optimizer_.addGoto(str("endLabel"), self.row)
     return code.C3D(cd, "return", self.row, self.column)
コード例 #21
0
ファイル: drop_database.py プロジェクト: Sohanyuuu/tytus
 def execute(self, environment):
     out = "fase1.execution("
     out += '"'
     out += "DROP DATABASE "
     out += self.exists
     out += self.name + ";"
     out += '")\n'
     if isinstance(environment, Environment):
         out = "\t" + out
     return code.C3D(out, "drop_db", self.row, self.column)
コード例 #22
0
    def execute(self, environment):
        parVal = ""
        out = "fase1.execution(dbtemp + "
        out += '" '
        out += "SELECT "
        out += self.distinct + " "
        # SelectParams
        j = 0
        for i in range(len(self.params) - 1):
            j = i + 1
            pval = self.params[i].execute(environment)
            parVal += pval.value
            out += pval.temp + ", "
        pval = self.params[j].execute(environment)
        parVal += pval.value
        out += pval.temp
        # From
        out += " " + self.fromcl + " "
        # where
        pval = self.wherecl.execute(environment)
        if pval.temp != "":
            out += "WHERE " + pval.temp + " "
        parVal += pval.value
        # group by
        if self.groupbyCl:
            groupbyCl = ""
            for g in self.groupbyCl[0]:
                groupbyCl += ", "
                if type(g) == int:
                    groupbyCl += str(g)
                else:
                    groupbyCl += g.id

            out += "GROUP BY " + groupbyCl[2:] + self.groupbyCl[1] + " "
        # limit
        out += self.limitCl + " "
        # order by
        if self.orderByCl:
            orderbyCl = ""
            for o in self.orderByCl:
                orderbyCl += ", "
                if type(o[0]) == int:
                    orderbyCl += str(o[0]) + o[1] + o[2]
                else:
                    orderbyCl += o[0].id + o[1] + o[2]
            out += "ORDER BY " + orderbyCl[2:]
        out = out.rstrip() + ";"
        out += '")\n'
        # TODO: optimizacion
        if isinstance(environment, Environment):
            grammar.optimizer_.addIgnoreString(out, self.row, True)
            out = "\t" + out
        else:
            grammar.optimizer_.addIgnoreString(out, self.row, False)
        return code.C3D(parVal + out, "select", self.row, self.column)
コード例 #23
0
 def execute(self, environment):
     out = "fase1.execution("
     out += '"'
     out += "ALTER DATABASE "
     out += self.name + " "
     out += self.option + " TO "
     out += self.newname + ";"
     out += '")\n'
     if isinstance(environment, Environment):
         out = "\t" + out
     return code.C3D(out, "alter_db", self.row, self.column)
コード例 #24
0
ファイル: drop_func.py プロジェクト: Sohanyuuu/tytus
 def execute(self, environment):
     c3d = ""
     tab = ""
     if isinstance(environment, Environment):
         tab += "\t"
         func = environment.globalEnv.dropFunction(self.id)
     else:
         func = environment.dropFunction(self.id)
     if func:
         c3d += tab + "del " + self.id + "\n"
     return code.C3D(c3d, "drop_func", self.row, self.column)
コード例 #25
0
ファイル: insert_.py プロジェクト: Sohanyuuu/tytus
 def execute(self, environment):
     out = "fase1.execution(dbtemp + "
     out += '" '
     out += "INSERT "
     out += self.exists + " "
     out += self.name + " ("
     out += self.columns + " )"
     out += self.inherits + ";"
     out += '")\n'
     if isinstance(environment, Environment):
         out = "\t" + out
     return code.C3D(out, "insert", self.row, self.column)
コード例 #26
0
 def execute(self, environment):
     out = "dbtemp = "
     out += '"'
     out += "USE "
     out += self.db + ";"
     out += '"\n'
     if isinstance(environment, Environment):
         grammar.optimizer_.addIgnoreString(out, self.row, True)
         out = "\t" + out
     else:
         grammar.optimizer_.addIgnoreString(out, self.row, False)
     return code.C3D(out, "use_database", self.row, self.column)
コード例 #27
0
 def execute(self, environment):
     out = "fase1.execution(dbtemp + "
     out += '" '
     out += "TRUNCATE "
     out += self.name + ";"
     out += '")\n'
     if isinstance(environment, Environment):
         grammar.optimizer_.addIgnoreString(out, self.row, True)
         out = "\t" + out
     else:
         grammar.optimizer_.addIgnoreString(out, self.row, False)
     return code.C3D(out, "truncate_database", self.row, self.column)
コード例 #28
0
 def execute(self, environment):
     out = "fase1.execution(dbtemp + "
     out += '" '
     out += "CREATE "
     out += "TYPE "
     out += self.exists + " "
     out += self.name + " AS ENUM ("
     out += self.values + ");"
     out += '")\n'
     if isinstance(environment, Environment):
         out = "\t" + out
     return code.C3D(out, "create_type", self.row, self.column)
コード例 #29
0
ファイル: else_stmt.py プロジェクト: sandymerida/tytus
 def execute(self, environment):
     try:
         cod3d = self.p_fev()
         for stmt in self.stmts:
             cod3d += stmt.execute(environment).value
         cod3d += self.p_fef()
         cod3d += self.p_write_next_etiq()
         cod3d += self.p_fev()
         return code.C3D(cod3d, "else", self.row, self.column)
     except:
         grammar.PL_errors.append(
             "Error P0000: plpgsql fatal error \n Hint---> Else Statement")
コード例 #30
0
 def execute(self, environment):
     out = "fase1.execution("
     out += '"'
     out += "SHOW DATABASES"
     out += self.like + ";"
     out += '")\n'
     if isinstance(environment, Environment):
         grammar.optimizer_.addIgnoreString(out, self.row, True)
         out = "\t" + out
     else:
         grammar.optimizer_.addIgnoreString(out, self.row, False)
     return code.C3D(out, "show_databases", self.row, self.column)