Skip to content

Commit

Permalink
Renomear isVariable para getTypeIfVariable
Browse files Browse the repository at this point in the history
  • Loading branch information
erickolisveira committed Jun 10, 2020
1 parent 5c2c0e5 commit f3cf464
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/SemanticVisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def isValidNumber(number):
return False

def isTypePrimitive(type):
if(type in st.Number or type == st.BOOL or type == st.ARRAY):
if(type in st.Number or type == st.BOOL or type == st.ARRAY or type == st.STRING):
return True
return False

def isVariable(self, exprType):
def getTypeIfVariable(self, exprType):
if type(exprType) is dict:
return exprType[st.TYPE]
return exprType
Expand Down Expand Up @@ -158,8 +158,8 @@ def visitExpr_Plus(self, exprPlus):
type1 = exprPlus.expr1.accept(self)
type2 = exprPlus.expr2.accept(self)

type1 = isVariable(self, type1)
type2 = isVariable(self, type2)
type1 = getTypeIfVariable(self, type1)
type2 = getTypeIfVariable(self, type2)

c = coercion(type1, type2)
if (c == None):
Expand All @@ -170,8 +170,8 @@ def visitExpr_Minus(self, exprMinus):
type1 = exprMinus.expr1.accept(self)
type2 = exprMinus.expr2.accept(self)

type1 = isVariable(self, type1)
type2 = isVariable(self, type2)
type1 = getTypeIfVariable(self, type1)
type2 = getTypeIfVariable(self, type2)

c = coercion(type1, type2)
if (c == None):
Expand All @@ -182,8 +182,8 @@ def visitExpr_Times(self, exprTimes):
type1 = exprTimes.expr1.accept(self)
type2 = exprTimes.expr2.accept(self)

type1 = isVariable(self, type1)
type2 = isVariable(self, type2)
type1 = getTypeIfVariable(self, type1)
type2 = getTypeIfVariable(self, type2)

c = coercion(type1, type2)
if (c == None):
Expand All @@ -194,14 +194,14 @@ def visitExpr_Divide(self, exprDivide):
type1 = exprDivide.expr1.accept(self)
type2 = exprDivide.expr2.accept(self)

type1 = isVariable(self, type1)
type2 = isVariable(self, type2)
type1 = getTypeIfVariable(self, type1)
type2 = getTypeIfVariable(self, type2)

c = coercion(type1, type2)
if (c == None):
el.ExpressionTypeError(self, exprDivide, type1, type2)
return c

def visitExpr_Mod(self, exprMod):
type1 = exprMod.expr1.accept(self)
type2 = exprMod.expr2.accept(self)
Expand All @@ -216,8 +216,9 @@ def visitExpr_Mod(self, exprMod):

def visitExpr_Uminus(self, exprUminus):
exprType = exprUminus.expr.accept(self)
if type(exprType) is dict:
exprType = exprType[st.TYPE]

exprType = getTypeIfVariable(self, exprType)

if(exprType in st.Number):
return exprType
else:
Expand Down Expand Up @@ -303,7 +304,7 @@ def visitExpr_AssignExpr(self, assignExpr):
bindable = assignExpr.variable.accept(self)
exprType = assignExpr.expr.accept(self)

exprType = isVariable(self, exprType)
exprType = getTypeIfVariable(self, exprType)

if exprType == None:
el.AttributionTypeError(self, assignExpr, exprType)
Expand All @@ -314,7 +315,7 @@ def visitExpr_AddAssignExpr(self, assignExpr):
bindable = assignExpr.variable.accept(self)
exprType = assignExpr.expr.accept(self)

exprType = isVariable(self, exprType)
exprType = getTypeIfVariable(self, exprType)

if exprType == None:
el.AttributionTypeError(self, assignExpr, exprType)
Expand Down Expand Up @@ -399,7 +400,7 @@ def visitExpr_PosDecrement(self, exprPosDecrement):
variable = exprPosDecrement.variable.accept(self)
if variable[st.TYPE] not in st.Number:
el.DecrementVariableError(variable)

def visitExpr_ArrayDeclaration(self, exprArrayDecl):
exprArrayDecl.arrayDecl.accept(self)
return st.ARRAY
Expand All @@ -424,7 +425,7 @@ def visitVariable_Single(self, variable):
if(bindable == None):
return st.addVar(variable.token)
return bindable

def visitVariable_Array(self, variable):
bindable = st.getBindable(variable.token)
if(bindable == None):
Expand Down

0 comments on commit f3cf464

Please sign in to comment.