Beispiel #1
0
 def printVars(self, model):
     self.clock.tick("printing")
     self.printStartDelimeter()
     ph = PrintHierarchy.PrintHierarchy(self, model)
     Visitor.visit(ph, self.module)
     ph.printTree()
     standard_print("")
     self.printEndDelimeter()
     standard_print("")
     self.clock.tack("printing")
Beispiel #2
0
def adjustAbstractsFixedPoint(cfr):
    hasChanged = True
    while hasChanged:
        hasChanged = setAbstractScopes(cfr)
        for i in cfr.cfr_sorts.values():
            if i.element.isAbstract:  
                adj = AdjustAbstracts(cfr)
                Visitor.visit(adj, i.element)
                if adj.hasChanged:
                    hasChanged = True
Beispiel #3
0
def adjustAbstractsFixedPoint(cfr):
    hasChanged = True
    while hasChanged:
        hasChanged = setAbstractScopes(cfr)
        for i in cfr.cfr_sorts.values():
            if i.element.isAbstract:
                adj = AdjustAbstracts(cfr)
                Visitor.visit(adj, i.element)
                if adj.hasChanged:
                    hasChanged = True
Beispiel #4
0
 def setScopes(self):
     if Options.SCOPE_FILE != "" or Options.SCOPE_MAP_FILE != "":
         if Options.SCOPE_FILE == "" or Options.SCOPE_MAP_FILE == "":
             sys.exit("--scopemapfile requires --scopefile, and vice versa.")
         scopeJSON = Common.readJSONFile(Options.SCOPE_FILE)
         scopeDict = {}
         for i in scopeJSON:
             scopeDict[i["lpqName"]] = i["scope"]
         scopeMapJSON = Common.readJSONFile(Options.SCOPE_MAP_FILE)
         scopeMapDict = {}
         for i in scopeMapJSON:
             scopeMapDict[i["uid"]] = i["lpqName"]
         for i in self.cfr_sorts.values():
             uid = i.element.uid
             scope = scopeDict.get(scopeMapDict[uid],1)
             (glower, _) = i.element.glCard
             i.element.glCard = (glower, IntegerLiteral(scope))
     else:
         Visitor.visit(SetScopes.SetScopes(self), self.module)
         AdjustAbstracts.adjustAbstractsFixedPoint(self)
Beispiel #5
0
def getNumBracketedConstraintsOperators(cfr_inst):
    module = cfr_inst.module
    constraintsStatsVisitor = GetBracketedConstraintsStats()
    Visitor.visit(constraintsStatsVisitor, module)
    counts = sorted(constraintsStatsVisitor.counts)
    return counts
Beispiel #6
0
def model_to_string(cfr, model):
    ph = PrintHierarchy.PrintHierarchy(cfr, model)
    Visitor.visit(ph, cfr.module)
    ph.printTree()
    return ph.get_pickled()
Beispiel #7
0
def model_to_string(cfr, model):
    ph = PrintHierarchy.PrintHierarchy(cfr, model)
    Visitor.visit(ph, cfr.module)
    ph.printTree()
    return ph.get_pickled()
Beispiel #8
0
 def translate(self):
     '''
     Converts Clafer constraints to Z3 constraints.
     '''
     #TODO caching for ASIL subexpressions. Do set equals first. Cache nonsupered joins.
     try:
         self.clock.tick("translation")
         
         """ Create a ClaferSort associated with each Clafer. """  
         Visitor.visit(CreateSorts.CreateSorts(self), self.module)
         
         """ Resolve any 'parent' or 'this' ClaferID's. """
         Visitor.visit(ResolveClaferIds.ResolveClaferIds(self), self.module)
         
         """ Add subclafers to the *fields* variable in the corresponding parent clafer. Also handles supers and refs. """
         Visitor.visit(CreateHierarchy.CreateHierarchy(self), self.module)
         
         debug_print("Mapping colon clafers.")
         self.mapColonClafers()
       
         debug_print("Adjusting instances for scopes.")
         self.setScopes()
         
         """ Initializing ClaferSorts and their instances. """
         #TODO Clean this up.
         Visitor.visit(Initialize.Initialize(self), self.module)
         self.fixSubSortIndices()
         self.createInstancesConstraintsAndFunctions()
           
         #for i in self.cfr_sorts.values():
         #    standard_print(str(i) + " : "+ str(i.numInstances))
         
         debug_print("Creating cardinality constraints.")
         self.createCardinalityConstraints()
         
         debug_print("Creating ref constraints.")
         self.createRefConstraints()
         
         debug_print("Adding subsort constraints.")
         self.addSubSortConstraints()
         self.setTopLevelIndices()
         
         debug_print("Creating group cardinality constraints.")
         self.createGroupCardConstraints()
         
         #debug_print("Creating bracketed constraints.")
         #self.bracketedConstraintsPreview = CreateSimpleBracketedConstraints.CreateSimpleBracketedConstraints(self)
         #Visitor.visit(self.bracketedConstraintsPreview, self.module)  
                   
         debug_print("Creating bracketed constraints.")
         bcVisitor = CreateBracketedConstraints.CreateBracketedConstraints(self)
         #for i in self.bracketedConstraintsPreview.setEqualityConstraints:
         #    bcVisitor.constraintVisit(None, i)
         #print("ABOVE")
         #for i in self.join_cache.keys():
         #    print(str(i))# + " : " + str(self.join_cache[i]))
         #print("BELOW")
         #bcVisitor.constraintVisit(None, self.bracketedConstraintsPreview.otherConstraints[3])
         #sys.exit("ABOVE!!!!!!!!")
         #for i in self.bracketedConstraintsPreview.otherConstraints:
             #print(i.stringRep)    
             #bcVisitor.constraintVisit(None, i)
         Visitor.visit(CreateBracketedConstraints.CreateBracketedConstraints(self), self.module)
         
         
         debug_print("Checking for goals.")
         if not Options.IGNORE_GOALS:
             Visitor.visit(CheckForGoals.CheckForGoals(self), self.module)
         
         self.clock.tock("translation")
         
     except UnusedAbstractException as e:
         print(str(e))
         return 0
Beispiel #9
0
def getNumBracketedConstraintsOperators(cfr_inst):
    module = cfr_inst.module
    constraintsStatsVisitor = GetBracketedConstraintsStats()
    Visitor.visit(constraintsStatsVisitor, module)
    counts = sorted(constraintsStatsVisitor.counts)
    return counts
Beispiel #10
0
from antlr4 import *
from PhpLexer import PhpLexer
from PhpParser import PhpParser
from visitors import Visitor
from time import time
import timeit
import sys

input_file = sys.argv[1] if len(sys.argv) > 1 else "example.php"
input_ = FileStream(input_file)
lexer = PhpLexer(input_)
stream = CommonTokenStream(lexer)
parser = PhpParser(stream)
e = parser.phpBlock()
v = Visitor()
t = v.visit(e)