本文整理汇总了Python中oodle.G.G.errors方法的典型用法代码示例。如果您正苦于以下问题:Python G.errors方法的具体用法?Python G.errors怎么用?Python G.errors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oodle.G.G
的用法示例。
在下文中一共展示了G.errors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: inAXtern
# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import errors [as 别名]
def inAXtern(self, node):
''''''
self.printFunc(self.inAXtern, node)
ln = node.getId().getLine()
nm = node.getId().getText()
tp_map = G.typeMap()
if tp_map.externExists(nm):
G.errors().semantic().add("extern '" + nm + "' already exists", ln)
else:
tp_map.addExtern(ExternDecl(nm))
ex = tp_map.extern(nm)
if node.getRet():
tp = node.getRet().getTp().getText()
ex.setTypeName(tp) #set the return type name
args = node.getArgs()
for a in args:
ln = a.getId().getLine()
nm = a.getId().getText()
tp = ""
if a.getTp():
tp = a.getTp().getTp().getText()
if ex.exists(nm):
G.errors().semantic().add("parameter '" + nm + "' already exists", ln)
else:
par_decl = LocalVarDecl(nm, tp)
ex.addParam(par_decl) #add param to TypeMap
示例2: outAAssignStmt
# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import errors [as 别名]
def outAAssignStmt(self, node):
'''Manage 'assignment' statement
Error Conditions:
* rhs id must exist and be a VarDecl or (return type) MethodDecl
* lhs and rhs must have equal types'''
self.printFunc(self.outAAssignStmt, node)
ln = node.getId().getLine()
nm = node.getId().getText()
decl = G.typeMap().var(self.curClass(), self.curMethod(), nm)
if not decl:
decl = G.typeMap().glbVar(nm)
tp_lhs = Type.NONE
tp_rhs = self.typeMap[node.getExpr()]
#id does not exist or is not a variable or method
if decl == None or not isinstance(decl, (VarDecl, MethodDecl, FuncDecl)):
G.errors().semantic().add("'" + nm + "' does not exist", ln)
#id exists and is a variable or method
elif isinstance(decl, (VarDecl, MethodDecl, FuncDecl)):
tp_lhs = G.typeMap().klass(decl.typeName())
#check for equivalent types
if decl != None and tp_lhs != tp_rhs:
G.errors().semantic().add("'" + node.toString().strip() +
"' assignment requires 2 operands of the same type", ln)
示例3: inAKlassInherits
# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import errors [as 别名]
def inAKlassInherits(self, node):
'''Manage inheritance
Error Conditions:
* HACK MiniOodle: inheritance is an unsupported feature'''
self.printFunc(self.inAKlassInherits, node)
ln = node.getKwFrom().getLine() #get the line number
G.errors().semantic().addUnsupportedFeature("'inherits from'", ln)
示例4: outAVar
# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import errors [as 别名]
def outAVar(self, node):
'''Manage 'var' declarations
Error Conditions:
* var type is not declared
* var type is mismatched'''
self.printFunc(self.outAVar, node)
err = False #set if error is detected
id = node.getId() #TId node
nm = id.getText() #variable name
ln = id.getLine() #line number
#check assignment type
tp_assign = Type.NONE
if node.getExpr() != None:
tp_assign = self.typeMap[node.getExpr()]
#check declared type
tp_decl = Type.NONE
if node.getTp() == None:
G.errors().semantic().add("variable '" + nm + "' must have a type", ln)
else:
tp_decl = self.typeMap[node.getTp()] #get the variable type from the child node
#compare declared and assigned types
if tp_assign != Type.NONE and tp_decl != Type.NONE and tp_assign != tp_decl:
G.errors().semantic().add("type mismatch '" + tp_decl.name() +
"' := '" + tp_assign.name(), ln)
#store this nodes type
self.typeMap[node] = tp_decl
示例5: main
# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import errors [as 别名]
def main():
if len(sys.argv) < 2:
print "usage:"
print " java Oodle filename"
return
#HACK - add readint() and writeint() declarations
G.typeMap().addExtern(ExternDecl('readint', 'int'))
G.typeMap().addExtern(ExternDecl('writeint')).addParam(LocalVarDecl('i', 'int'))
G.options().parseArgs(sys.argv[1:])
flist = G.fileConcat ()
for f in G.options().getFileList():
flist.appendFile(f)
st_node = None
print 'Lexing...'
lex = Lexer(flist.getConcatFile().getAbsolutePath())
print 'Parsing...'
par = Parser(lex)
try:
st_node = par.parse()
except ParserException, e:
G.errors().syntax().add(e.getMessage())
示例6: outAStrExpr
# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import errors [as 别名]
def outAStrExpr(self, node):
'''Manage 'string' expr9 expression
Error Conditions
* HACK MiniOodle: string is unsupported'''
self.printFunc(self.outAStrExpr, node)
ln = node.getValue().getLine()
G.errors().semantic().addUnsupportedFeature("string", ln)
self.typeMap[node] = Type.STRING
示例7: outAArrayType
# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import errors [as 别名]
def outAArrayType(self, node):
'''Manage 'array' type
Error Conditions:
* Unsupported Feature'''
self.printFunc(self.outAArrayType, node)
ln = node.getLBrack().getLine()
G.errors().semantic().addUnsupportedFeature('array', ln)
self.typeMap[node] = Type.NONE
示例8: outAArrayExpr
# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import errors [as 别名]
def outAArrayExpr(self, node):
'''Manage 'array' expression
Error Conditions
* HACK MiniOodle: me is unsupported'''
self.printFunc(self.outAArrayExpr, node)
ln = node.getId().getLine()
G.errors().semantic().addUnsupportedFeature('array', ln)
self.typeMap[node] = Type.NONE
示例9: outALoopStmt
# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import errors [as 别名]
def outALoopStmt(self, node):
'''Manage 'loop while' statement
Error Conditions:
* expr type != Type.BOOLEAN'''
self.printFunc(self.outALoopStmt)
ln = node.getWhile().getLine()
tp = self.typeMap[node.getExpr()]
if tp != Type.BOOLEAN:
G.errors().semantic().add("loops must evaluate on type " +
Type.BOOLEAN.name(), ln)
示例10: inAKlassBody
# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import errors [as 别名]
def inAKlassBody(self, node):
'''Manage class variables
Error Conditions:
* HACK MiniOodle: no class variable initialization'''
self.printFunc(self.inAKlassBody)
vars = node.getVars()
#class variable init is unsupported in MiniOodle
for v in vars:
if v.getExpr() != None:
ln = v.getId().getLine() #line number
G.errors().semantic().addUnsupportedFeature("class variable initialization", ln)
示例11: outAFunc
# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import errors [as 别名]
def outAFunc(self, node):
''''''
self.printFunc(self.outAFunc)
vars = node.getVars()
#HACK - local variable init is unsupported in MiniOodle
sloc = -8
for v in vars:
ln = v.getId().getLine() #line number
if v.getExpr() != None:
G.errors().semantic().addUnsupportedFeature("local variable initialization", ln)
self.setCurMethod("")
示例12: inAVarToplevel
# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import errors [as 别名]
def inAVarToplevel(self, node):
''''''
self.printFunc(self.inAVarToplevel, node)
ln = node.getVar().getId().getLine()
tp_map = G.typeMap()
nm = node.getVar().getId().getText()
tp = node.getVar().getTp().getTp().getText()
if tp_map.glbVarExists(nm):
G.errors().semantic().add("global variable '" + nm + "' already exists", ln)
else:
var_decl = GlobalVarDecl(nm, tp)
tp_map.addGlbVar(var_decl) #add var to TypeMap
示例13: inAFuncArg
# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import errors [as 别名]
def inAFuncArg(self, node):
''''''
self.printFunc(self.inAFuncArg, node)
ln = node.getId().getLine()
tp_map = G.typeMap()
func = tp_map.func(self.curMethod())
nm = node.getId().getText()
tp = node.getTp().getTp().getText()
if func.exists(nm):
G.errors().semantic().add("variable '" + nm + "' already exists", ln)
else:
var_decl = LocalVarDecl(nm, tp)
func.addParam(var_decl) #add var to TypeMap
示例14: outANotExpr
# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import errors [as 别名]
def outANotExpr(self, node):
'''Manage 'not' expression
Error Conditions
* expression type not boolean'''
self.printFunc(self.outANotExpr, node)
ln = node.getOp().getLine()
tp = self.typeMap[node.getExpr()]
tp_ret = Type.BOOLEAN
if tp != Type.BOOLEAN:
tp_ret = Type.NONE
G.errors().semantic().add("'" + node.toString().strip() +
"' operation requires type " +
Type.BOOLEAN.name(), ln)
self.typeMap[node] = tp_ret
示例15: inAKlassHeader
# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import errors [as 别名]
def inAKlassHeader(self, node):
''''''
self.printFunc(self.inAKlassHeader, node)
ln = node.getId().getLine()
tp_map = G.typeMap()
nm = node.getId().getText() #class name
if tp_map.klassExists(nm):
G.errors().semantic().add("class '" + nm + "' already exists", ln)
else:
tp_map.addKlass(ClassDecl(nm)) #add class to TypeMap
self.setCurClass(nm)