|
@@ -19,6 +19,9 @@ VALID_OPS = list(['*', '-', '/', '+', '%', '++', '--', 'p--', 'p++'])
|
|
VALID_OPS.extend(VALID_LOGIC_OPS)
|
|
VALID_OPS.extend(VALID_LOGIC_OPS)
|
|
VALID_OPS.extend(VALID_REL_OPS)
|
|
VALID_OPS.extend(VALID_REL_OPS)
|
|
|
|
|
|
|
|
+PRINT_COUNT = 0
|
|
|
|
+SCAN_COUNT = 0
|
|
|
|
+
|
|
def normalizeType(type):
|
|
def normalizeType(type):
|
|
if type in INT_TYPES:
|
|
if type in INT_TYPES:
|
|
return 'int'
|
|
return 'int'
|
|
@@ -35,13 +38,13 @@ class DeclarationInfo:
|
|
|
|
|
|
def isVector (self) :
|
|
def isVector (self) :
|
|
return self.dimensions == 1
|
|
return self.dimensions == 1
|
|
-
|
|
+
|
|
def isMatrix (self):
|
|
def isMatrix (self):
|
|
return self.dimensions == 2
|
|
return self.dimensions == 2
|
|
-
|
|
+
|
|
def isMultiDimension (self):
|
|
def isMultiDimension (self):
|
|
return self.dimensions > 2
|
|
return self.dimensions > 2
|
|
-
|
|
+
|
|
def isArray (self):
|
|
def isArray (self):
|
|
return self.dimensions > 0
|
|
return self.dimensions > 0
|
|
|
|
|
|
@@ -52,7 +55,7 @@ class CommandInfo:
|
|
self.numLogicOps = numLogicOps
|
|
self.numLogicOps = numLogicOps
|
|
self.numRelOps = numRelOps
|
|
self.numRelOps = numRelOps
|
|
self.opList = opList
|
|
self.opList = opList
|
|
-
|
|
+
|
|
def __str__(self):
|
|
def __str__(self):
|
|
return "Type:%s LogicOpCount:%d RelOpCount:%d OpList:%s"%( self.condType, self.numLogicOps, self.numRelOps, self.opList)
|
|
return "Type:%s LogicOpCount:%d RelOpCount:%d OpList:%s"%( self.condType, self.numLogicOps, self.numRelOps, self.opList)
|
|
|
|
|
|
@@ -61,7 +64,7 @@ class ForCommandInfo (CommandInfo):
|
|
CommandInfo.__init__(self, cmdCount, condType, numLogicOps, numRelOps, opList)
|
|
CommandInfo.__init__(self, cmdCount, condType, numLogicOps, numRelOps, opList)
|
|
self.useAssignment = useAssignment
|
|
self.useAssignment = useAssignment
|
|
self.useNext = useNext
|
|
self.useNext = useNext
|
|
-
|
|
+
|
|
def __str__(self):
|
|
def __str__(self):
|
|
return "hasInit:%s hasNext:%s Type:%s LogicOpCount:%d RelOpCount:%d OpList:%s"%(self.useAssignment, self.useNext, self.condType, self.numLogicOps, self.numRelOps, self.opList)
|
|
return "hasInit:%s hasNext:%s Type:%s LogicOpCount:%d RelOpCount:%d OpList:%s"%(self.useAssignment, self.useNext, self.condType, self.numLogicOps, self.numRelOps, self.opList)
|
|
|
|
|
|
@@ -87,10 +90,10 @@ class ASTAnalyser:
|
|
self.declarationsPointers = dict()
|
|
self.declarationsPointers = dict()
|
|
self.declarationsVectors = dict()
|
|
self.declarationsVectors = dict()
|
|
self.declarationsMatrixes = dict()
|
|
self.declarationsMatrixes = dict()
|
|
-
|
|
+
|
|
def conditionCommandStr (self) :
|
|
def conditionCommandStr (self) :
|
|
return [ s.__str__() for s in self.conditionCommandData]
|
|
return [ s.__str__() for s in self.conditionCommandData]
|
|
-
|
|
+
|
|
def forCommandStr (self) :
|
|
def forCommandStr (self) :
|
|
return [ s.__str__() for s in self.forCommandData]
|
|
return [ s.__str__() for s in self.forCommandData]
|
|
|
|
|
|
@@ -139,7 +142,7 @@ class ASTAnalyser:
|
|
self.declarations[type] += 1
|
|
self.declarations[type] += 1
|
|
else:
|
|
else:
|
|
self.declarations[type] = 1
|
|
self.declarations[type] = 1
|
|
-
|
|
+
|
|
def proccessDecl (self, node):
|
|
def proccessDecl (self, node):
|
|
type = node.type
|
|
type = node.type
|
|
dimensions = 0
|
|
dimensions = 0
|
|
@@ -160,7 +163,7 @@ class ASTAnalyser:
|
|
self.constantInitCount[init.value] += 1
|
|
self.constantInitCount[init.value] += 1
|
|
else:
|
|
else:
|
|
self.constantInitCount[init.value] = 1
|
|
self.constantInitCount[init.value] = 1
|
|
-
|
|
+
|
|
def proccessFuncDef (self, node):
|
|
def proccessFuncDef (self, node):
|
|
name = node.__class__.__name__
|
|
name = node.__class__.__name__
|
|
self.incCmdCount(name)
|
|
self.incCmdCount(name)
|
|
@@ -169,24 +172,29 @@ class ASTAnalyser:
|
|
self.proccessCommand(cmd)
|
|
self.proccessCommand(cmd)
|
|
|
|
|
|
def proccessFuncCall (self, node):
|
|
def proccessFuncCall (self, node):
|
|
|
|
+ global PRINT_COUNT, SCAN_COUNT
|
|
name = node.__class__.__name__
|
|
name = node.__class__.__name__
|
|
|
|
+ if node.name.name == "printf":
|
|
|
|
+ PRINT_COUNT = PRINT_COUNT + 1
|
|
|
|
+ elif node.name.name == "scanf":
|
|
|
|
+ SCAN_COUNT = SCAN_COUNT + 1
|
|
self.incCmdCount(name)
|
|
self.incCmdCount(name)
|
|
epxrs = node.args.exprs
|
|
epxrs = node.args.exprs
|
|
for e in epxrs:
|
|
for e in epxrs:
|
|
self.countOperators(e)
|
|
self.countOperators(e)
|
|
-
|
|
+
|
|
def proccessAssignment (self, node):
|
|
def proccessAssignment (self, node):
|
|
name = node.__class__.__name__
|
|
name = node.__class__.__name__
|
|
self.incCmdCount(name)
|
|
self.incCmdCount(name)
|
|
epxr = node.rvalue
|
|
epxr = node.rvalue
|
|
self.countOperators(epxr)
|
|
self.countOperators(epxr)
|
|
-
|
|
+
|
|
def proccessReturn (self, node):
|
|
def proccessReturn (self, node):
|
|
name = node.__class__.__name__
|
|
name = node.__class__.__name__
|
|
self.incCmdCount(name)
|
|
self.incCmdCount(name)
|
|
epxr = node.expr
|
|
epxr = node.expr
|
|
self.countOperators(epxr)
|
|
self.countOperators(epxr)
|
|
-
|
|
+
|
|
def proccessSwitch (self, node):
|
|
def proccessSwitch (self, node):
|
|
name = node.__class__.__name__
|
|
name = node.__class__.__name__
|
|
self.incCmdCount(name)
|
|
self.incCmdCount(name)
|
|
@@ -195,7 +203,7 @@ class ASTAnalyser:
|
|
cmdList = node.stmt.block_items
|
|
cmdList = node.stmt.block_items
|
|
for cmd in cmdList:
|
|
for cmd in cmdList:
|
|
self.proccessCommand(cmd)
|
|
self.proccessCommand(cmd)
|
|
-
|
|
+
|
|
def proccessDoWhile (self, name, node):
|
|
def proccessDoWhile (self, name, node):
|
|
self.incCmdCount(name)
|
|
self.incCmdCount(name)
|
|
epxr = node.cond
|
|
epxr = node.cond
|
|
@@ -216,7 +224,7 @@ class ASTAnalyser:
|
|
else:
|
|
else:
|
|
self.proccessCommand(cmdList)
|
|
self.proccessCommand(cmdList)
|
|
self.conditionCommandData.append(CommandInfo(self.cmdCountStack.pop(), condType,logicCount, relCount, opList))
|
|
self.conditionCommandData.append(CommandInfo(self.cmdCountStack.pop(), condType,logicCount, relCount, opList))
|
|
-
|
|
+
|
|
def proccessFor (self, node):
|
|
def proccessFor (self, node):
|
|
name = node.__class__.__name__
|
|
name = node.__class__.__name__
|
|
self.incCmdCount(name)
|
|
self.incCmdCount(name)
|
|
@@ -233,7 +241,7 @@ class ASTAnalyser:
|
|
hasInit = node.init.__class__.__name__ != 'NoneType'
|
|
hasInit = node.init.__class__.__name__ != 'NoneType'
|
|
if hasInit:
|
|
if hasInit:
|
|
self.proccessCommand(node.init)
|
|
self.proccessCommand(node.init)
|
|
-
|
|
+
|
|
hasNext = node.next.__class__.__name__ != 'NoneType'
|
|
hasNext = node.next.__class__.__name__ != 'NoneType'
|
|
if hasNext:
|
|
if hasNext:
|
|
self.proccessCommand(node.next)
|
|
self.proccessCommand(node.next)
|
|
@@ -249,7 +257,7 @@ class ASTAnalyser:
|
|
elif name != 'NoneType':
|
|
elif name != 'NoneType':
|
|
self.proccessCommand(cmdList)
|
|
self.proccessCommand(cmdList)
|
|
self.forCommandData.append(ForCommandInfo(hasInit, hasNext, self.cmdCountStack.pop(), condType, logicCount, relCount, opList))
|
|
self.forCommandData.append(ForCommandInfo(hasInit, hasNext, self.cmdCountStack.pop(), condType, logicCount, relCount, opList))
|
|
-
|
|
+
|
|
def proccessIf (self, node):
|
|
def proccessIf (self, node):
|
|
name = node.__class__.__name__
|
|
name = node.__class__.__name__
|
|
self.incCmdCount(name)
|
|
self.incCmdCount(name)
|
|
@@ -271,17 +279,21 @@ class ASTAnalyser:
|
|
self.proccessCommand(cmd)
|
|
self.proccessCommand(cmd)
|
|
else:
|
|
else:
|
|
self.proccessCommand(iftrue)
|
|
self.proccessCommand(iftrue)
|
|
-
|
|
|
|
iffalse = node.iffalse
|
|
iffalse = node.iffalse
|
|
ifCompound = iffalse.__class__.__name__
|
|
ifCompound = iffalse.__class__.__name__
|
|
if ifCompound == 'Compound':
|
|
if ifCompound == 'Compound':
|
|
|
|
+
|
|
|
|
+ self.cmdCountStack.append(0)
|
|
|
|
+ self.incCmdCount('Else')
|
|
cmdList = iffalse.block_items
|
|
cmdList = iffalse.block_items
|
|
for cmd in cmdList:
|
|
for cmd in cmdList:
|
|
self.proccessCommand(cmd)
|
|
self.proccessCommand(cmd)
|
|
- elif name != 'NoneType':
|
|
+ elif iffalse != None and name != 'NoneType':
|
|
|
|
+ self.cmdCountStack.append(0)
|
|
|
|
+ self.incCmdCount('Else')
|
|
self.proccessCommand(iffalse)
|
|
self.proccessCommand(iffalse)
|
|
self.conditionCommandData.append(CommandInfo(self.cmdCountStack.pop(), condType, logicCount, relCount, opList))
|
|
self.conditionCommandData.append(CommandInfo(self.cmdCountStack.pop(), condType, logicCount, relCount, opList))
|
|
-
|
|
+
|
|
def proccessCase (self, node):
|
|
def proccessCase (self, node):
|
|
try:
|
|
try:
|
|
epxr = node.expr
|
|
epxr = node.expr
|
|
@@ -335,7 +347,7 @@ class ASTAnalyser:
|
|
self.commandCount[cmd] += 1
|
|
self.commandCount[cmd] += 1
|
|
else:
|
|
else:
|
|
self.commandCount[cmd] = 1
|
|
self.commandCount[cmd] = 1
|
|
-
|
|
+
|
|
def checkCondType (self, expr):
|
|
def checkCondType (self, expr):
|
|
name = expr.__class__.__name__
|
|
name = expr.__class__.__name__
|
|
if name == 'BinaryOp':
|
|
if name == 'BinaryOp':
|
|
@@ -385,4 +397,4 @@ class ASTAnalyser:
|
|
self.proccessFor(node)
|
|
self.proccessFor(node)
|
|
else:
|
|
else:
|
|
self.cmdCountStack[-1] -= 1
|
|
self.cmdCountStack[-1] -= 1
|
|
-
|
|
+
|