Skip to content

Commit

Permalink
Merge pull request #2 from rodrigorato/dev
Browse files Browse the repository at this point in the history
Domain specific objects done from the JSON representation
  • Loading branch information
rodrigorato authored Nov 19, 2017
2 parents ab14e0f + d853869 commit 6ff112d
Show file tree
Hide file tree
Showing 12 changed files with 320 additions and 24 deletions.
22 changes: 20 additions & 2 deletions ast/conditionalnodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ def __init__(self, kind, test, body, alternate=None):
ChildfulNode.__init__(self, kind, body)
self.test = test # An expression
self.body = body # A list of Nodes
self.alternate = alternate # A IfThenElse node or None
self.alternate = alternate # A IfThenElse node, an ElseNode or None

def __repr__(self):
return '<kind:' + self.kind + ',' \
'children:' + pretty_format(self.children) + ',' \
+ (pretty_format(self.alternate) if self.alternate else '') + '>'


class ElseNode(ChildfulNode):
def __init__(self, kind, children):
ChildfulNode.__init__(self, kind, children)


# A SwitchNode's child are its CaseNodes
Expand All @@ -15,10 +25,18 @@ def __init__(self, kind, test, body):
ChildfulNode.__init__(self, kind, body)
self.test = test

def __repr__(self):
return '<kind:' + self.kind + ',' \
'test: ' + pretty_format(self.test) + ',' \
'body: ' + pretty_format(self.children) + '>'


class CaseNode(ChildfulNode):
def __init__(self, kind, test, body):
ChildfulNode.__init__(self, kind, body)
self.test = test


def __repr__(self):
return '<kind:' + self.kind + ',' \
'test: ' + pretty_format(self.test) + ',' \
'body: ' + pretty_format(self.children) + '>'
16 changes: 14 additions & 2 deletions ast/cyclenodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@

class CycleNode(ChildfulNode):
def __init__(self, kind, children, test):
ChildfulNode.__init__(kind, children)
ChildfulNode.__init__(self, kind, children)
self.test = test # Its an ExpressionNode

def __repr__(self):
return '<kind:' + self.kind + ',' \
'test: ' + pretty_format(self.test) + ',' \
'children: ' + pretty_format(self.children) + '>'


class WhileNode(CycleNode):
def __init__(self, kind, children, test):
Expand All @@ -21,4 +26,11 @@ class ForNode(CycleNode):
def __init__(self, kind, children, test, init, increment):
CycleNode.__init__(self, kind, children, test)
self.init = init
self.increment = increment
self.increment = increment

def __repr__(self):
return '<kind:' + self.kind + ',' \
'init: ' + pretty_format(self.init) + ',' \
'test: ' + pretty_format(self.test) + ',' \
'increment: ' + pretty_format(self.increment) + ',' + \
'children: ' + pretty_format(self.children) + '>'
48 changes: 47 additions & 1 deletion ast/expressionnodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@ def __init__(self, kind, left_expr, right_expr):
self.left_expr = left_expr
self.right_expr = right_expr

def __repr__(self):
return '<kind:' + self.kind + ',' \
'left_expr: ' + pretty_format(self.left_expr) + ',' \
'right_expr: ' + pretty_format(self.right_expr) + '>'


class UnaryExpression(ExpressionNode):
def __init__(self, kind, type, expr):
ExpressionNode.__init__(self, kind)
self.type = type # The Unary operator, like '!' and '++'
self.expr = expr # Every Unary expression has an expression associated with it

def __repr__(self):
return '<kind:' + self.kind + ',' \
'type: ' + pretty_format(self.type) + ',' \
'expr: ' + pretty_format(self.expr) + '>'


class BinaryExpression(ExpressionNode):
def __init__(self, kind, type, left_expr, right_expr):
Expand All @@ -27,6 +37,12 @@ def __init__(self, kind, type, left_expr, right_expr):
self.left_expr = left_expr # Every binary expression has a left expr and a..
self.right_expr = right_expr # right expression!

def __repr__(self):
return '<kind:' + self.kind + ',' \
'type: ' + pretty_format(self.type) + ',' \
'left_expr: ' + pretty_format(self.left_expr) + ',' \
'right_expr: ' + pretty_format(self.right_expr) + '>'


class TernaryExpression(ExpressionNode):
def __init__(self, kind, test, true_expr, false_expr):
Expand All @@ -35,6 +51,12 @@ def __init__(self, kind, test, true_expr, false_expr):
self.true_expr = true_expr
self.false_expr = false_expr

def __repr__(self):
return '<kind:' + self.kind + ',' \
'test: ' + pretty_format(self.test) + ',' \
'true_expr: ' + pretty_format(self.true_expr) + ',' \
'false_expr: ' + pretty_format(self.false_expr) + '>'


# FIXME assumption - an indexation is a variable
# so $a[1] is a variable node
Expand All @@ -43,6 +65,10 @@ def __init__(self, kind, name):
ExpressionNode.__init__(self, kind)
self.name = name

def __repr__(self):
return '<kind:' + self.kind + ',' \
'name: ' + self.name + '>'


# FIXME assumption - we're not handling indexation calls
# so $a[1]("ha"); isn't handled
Expand All @@ -52,6 +78,11 @@ def __init__(self, kind, name, arguments):
self.name = name
self.arguments = arguments # arguments is a list of VariableNodes

def __repr__(self):
return '<kind:' + self.kind + ',' \
'name: ' + self.name + ',' \
'arguments: ' + pretty_format(self.arguments) + '>'


# Stuff like $_GET and $_POST
class EntryPointNode(VariableNode):
Expand All @@ -60,8 +91,23 @@ def __init__(self, kind, name):
self.tainted = True
self.visited = True

def __repr__(self):
return '<kind:' + self.kind + ',' \
'name: ' + self.name + '>'


class ConstantNode(ExpressionNode):
def __init__(self, kind, value):
ExpressionNode.__init__(self, kind)
self.value = value
self.value = value

def __repr__(self):
return '<kind:' + self.kind + ',' \
'value: ' + pretty_format(self.value) + '>'


class EncapsedStringNode(ExpressionNode):
def __init__(self, kind, value, type):
ExpressionNode.__init__(self, kind)
self.value = value # Value is a list of ExpressionNodes
self.type = type # FIXME assuming only string is possible
19 changes: 19 additions & 0 deletions ast/functionnodes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from ast.nodes import *
from ast.expressionnodes import *


# FIXME assumption, we're ignoring type hinting
Expand All @@ -7,3 +8,21 @@ def __init__(self, kind, name, arguments, children):
ChildfulNode.__init__(self, kind, children)
self.name = name
self.arguments = arguments # arguments is a list of VariableNodes

def __repr__(self):
return '<kind:' + self.kind + ',' \
'name: ' + self.name + ',' \
'arguments: ' + pretty_format(self.arguments) + ',' \
'children: ' + pretty_format(self.children) + '>'


# TODO not considering byref arguments
class FunctionDefinitionArgumentsNode(VariableNode):
def __init__(self, kind, name, value_expr=None):
VariableNode.__init__(self, kind, name)
self.value_expr = value_expr

def __repr__(self):
return '<kind:' + self.kind + ',' \
'name: ' + self.name + ',' \
'value_expr: ' + pretty_format(self.value_expr) + '>'
Loading

0 comments on commit 6ff112d

Please sign in to comment.