Skip to content

Commit

Permalink
Adds implementatio to all nodes that we're considering
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorato committed Nov 18, 2017
1 parent f7deacf commit 68659a7
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 2 deletions.
23 changes: 23 additions & 0 deletions ast/conditionalnodes.py
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
from ast.nodes import *


class IfThenElseNode(ChildfulNode):
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


# A SwitchNode's child are its CaseNodes
class SwitchNode(ChildfulNode):
def __init__(self, kind, test, body):
ChildfulNode.__init__(self, kind, body)
self.test = test


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


2 changes: 1 addition & 1 deletion ast/cyclenodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class CycleNode(ChildfulNode):
def __init__(self, kind, children, test):
ChildfulNode.__init__(kind, children)
self.test = test
self.test = test # Its an ExpressionNode


class WhileNode(CycleNode):
Expand Down
66 changes: 66 additions & 0 deletions ast/expressionnodes.py
Original file line number Diff line number Diff line change
@@ -1 +1,67 @@
from ast.nodes import *


class ExpressionNode(Node):
def __init__(self, kind):
Node.__init__(self, kind)


class AttributionNode(ExpressionNode):
def __init__(self, kind, left_expr, right_expr):
ExpressionNode.__init__(self, kind)
self.left_expr = left_expr
self.right_expr = 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


class BinaryExpression(ExpressionNode):
def __init__(self, kind, type, left_expr, right_expr):
ExpressionNode.__init__(self, kind)
self.type = type # The operator, like '+' or '*'
self.left_expr = left_expr # Every binary expression has a left expr and a..
self.right_expr = right_expr # right expression!


class TernaryExpression(ExpressionNode):
def __init__(self, kind, test, true_expr, false_expr):
ExpressionNode.__init__(self, kind)
self.test = test
self.true_expr = true_expr
self.false_expr = false_expr


# FIXME assumption - an indexation is a variable
# so $a[1] is a variable node
class VariableNode(ExpressionNode):
def __init__(self, kind, name):
ExpressionNode.__init__(self, kind)
self.name = name


# FIXME assumption - we're not handling indexation calls
# so $a[1]("ha"); isn't handled
class FunctionCallNode(ExpressionNode):
def __init__(self, kind, name, arguments):
ExpressionNode.__init__(self, kind)
self.name = name
self.arguments = arguments # arguments is a list of VariableNodes


# Stuff like $_GET and $_POST
class EntryPointNode(VariableNode):
def __init__(self, kind, name):
VariableNode.__init__(self, kind, name)
self.tainted = True
self.visited = True


class ConstantNode(ExpressionNode):
def __init__(self, kind, value):
ExpressionNode.__init__(self, kind)
self.value = value
8 changes: 8 additions & 0 deletions ast/functionnodes.py
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
from ast.nodes import *


# FIXME assumption, we're ignoring type hinting
class FunctionDefinitionNode(ChildfulNode):
def __init__(self, kind, name, arguments, children):
ChildfulNode.__init__(self, kind, children)
self.name = name
self.arguments = arguments # arguments is a list of VariableNodes
5 changes: 4 additions & 1 deletion ast/nodes.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
class Node:
def __init__(self, kind):
self.kind = kind # This node's kind
self.kind = kind # This node's kind
self.tainted = True # FIXME assuming its good until an entry point is found
self.visited = False # has this node been visited already?

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


# This is just a fancy name for an abstraction of a node that has child nodes
# i.e. children somewhere, like inside a body
class ChildfulNode(Node):
def __init__(self, kind, children):
Node.__init__(self, kind)
Expand Down

0 comments on commit 68659a7

Please sign in to comment.