def analyze_solution(raw_solution, statistics):
    solution_string = raw_solution.replace("\\n", "\n")

    try:
        ast_tree = ast.parse(solution_string)
        tree = Parser.parse_tree(ast_tree, raw=solution_string)
        statistics.add_tree(tree)
    except SyntaxError:
        return
 def calc_distance(self, tree):
     return Parser.calculate_distance(self.base_tree, tree)
Beispiel #3
0
	def __init__(self):
		self.my = ASTParser()
def main():
	if ( (len(sys.argv) != 3) or (sys.argv[1] == "-help") or (sys.argv[1] == "--help") ):
		sys.exit("Usage:  python " + sys.argv[0] + " [name of input file that runs the cryptosystem] [name of .bls output file]")

	inputFileName = sys.argv[1]
	outputFileName = sys.argv[2]

	if (len(inputFileName) == 0):
		sys.exit("AutoBatch_Parser->main:  input file name passed in is of length zero.")

	if (len(outputFileName) == 0):
		sys.exit("AutoBatch_Parser->main:  output file name passed in is of length zero.")

	myASTParser = ASTParser()
	rootNode = myASTParser.getASTNodeFromFile(inputFileName)
	if (rootNode == None):
		sys.exit("AutoBatch_Parser->main:  root node obtained from ASTParser->getASTNodeFromFile is of None type.")

	functionNames = myASTParser.getFunctionNames(rootNode)
	if (functionNames == None):
		sys.exit("AutoBatch_Parser->main:  function names obtained from ASTParser->getFunctionNames is of None type.")

	(functionArgNames, lenFunctionArgDefaults) = myASTParser.getFunctionArgNamesAndDefaultLen(rootNode)
	if ( (functionArgNames == None) or (lenFunctionArgDefaults == None) ):
		sys.exit("AutoBatch_Parser->main:  problem with either functionArgNames or lenFunctionArgDefaults returned from getFunctionArgNamesAndDefaultLen.")

	for funcName in con.funcNamesNotToTest:
		if (funcName in functionNames):
			del functionNames[funcName]
		if (funcName in functionArgNames):
			del functionArgNames[funcName]
		if (funcName in lenFunctionArgDefaults):
			del lenFunctionArgDefaults[funcName]

	functionArgMappings = getFunctionArgMappings(functionNames, functionArgNames, lenFunctionArgDefaults, myASTParser)
	if (functionArgMappings == None):
		sys.exit("AutoBatch_Parser->main:  mappings of variables passed between functions from getFunctionArgMappings is of None type.")

	returnNodes = getReturnNodes(functionNames, myASTParser)
	if ( (returnNodes == None) or (type(returnNodes).__name__ != con.dictTypePython) or (len(returnNodes) == 0) ):
		sys.exit("AutoBatch_Parser->main:  problem with value returned from getReturnNodes.")

	verifyFuncNodeList = myASTParser.getFunctionNode(rootNode, con.verifyFuncName)
	if (verifyFuncNodeList == None):
		sys.exit("AutoBatch_Parser->main:  could not locate a function with name " + con.verifyFuncName)
	if (len(verifyFuncNodeList) > 1):
		sys.exit("AutoBatch_Parser->main:  located more than one function with the name " + con.verifyFuncName)

	verifyFuncNode = verifyFuncNodeList[0]

	verifyEqNode = myASTParser.getLastEquation(verifyFuncNode)
	if (verifyEqNode == None):
		sys.exit("AutoBatch_Parser->main:  could not locate the verify equation within the " + con.verifyFuncName + " function.")

	origVerifyEq = myASTParser.getSourceLineOfNode(verifyEqNode)
	cleanVerifyEqLn = cleanVerifyEq(origVerifyEq)

	varsVerifyEq = getAllVariableNamesFromVerifyEq(verifyEqNode, myASTParser)
	if ( (varsVerifyEq == None) or (type(varsVerifyEq).__name__ != con.listTypePython) or (len(varsVerifyEq) == 0) ):
		sys.exit("AutoBatch_Parser->main:  problem with the value returned from getAllVariableNamesFromVerifyEq on the verify equation node.")

	varAssignments = getVarAssignments(rootNode, functionNames, myASTParser)
	if (varAssignments == None):
		sys.exit("AutoBatch_Parser->main:  getVarAssignments returned None when trying to get the variable assignments.")
	
	precomputeList = {}
	index = 0
	for _var in varAssignments[con.verifyFuncName]:
		_leftVar = _var.getName().getStringVarName()
		# JAA: means a variable assignment and doesn't constitute as something that needs precomputing by definition
		if (type(_var.getValue()).__name__ == con.subscriptName):
			continue
		for v in varsVerifyEq:
#			print("varsVerifyEq: ", v.getStringVarName())
			if _leftVar == v.getStringVarName():
				precomputeList[index] = _var
				index += 1
				#print("Found stmt: ", _var.getName().getStringVarName(), ":=", _var.getValue().getStringVarName())
			
	# write the final .bv file for Batcher
	writeBVFile(myASTParser, varAssignments, inputFileName, outputFileName, varsVerifyEq, functionArgMappings, functionArgNames, returnNodes, precomputeList, cleanVerifyEqLn)
Beispiel #5
0
def main():
	test = ASTParser()
	node = test.getASTNodeFromFile("new.py")
	next = AST_Test()
	next.visit(node)
	N = 4