当前位置: 首页>>代码示例>>Python>>正文


Python G.typeMap方法代码示例

本文整理汇总了Python中oodle.G.G.typeMap方法的典型用法代码示例。如果您正苦于以下问题:Python G.typeMap方法的具体用法?Python G.typeMap怎么用?Python G.typeMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oodle.G.G的用法示例。


在下文中一共展示了G.typeMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import typeMap [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())
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:27,代码来源:Oodle.py

示例2: outAAssignStmt

# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import typeMap [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)
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:27,代码来源:SemanticChecker.py

示例3: outACall

# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import typeMap [as 别名]
	def outACall(self, node):
		'''Generate method 'call' code
		   Error Conditions
			* NONE'''
		self.printFunc(self.outACall, node)
		src = node.toString().strip()
		ln = node.getId().getLine()
		nm = node.getId().getText()
		klass = None
		if node.getExpr():
			pass
			#id_nm = node.getExpr().getId().getText()
			#klass = self.typeMap[node.getExpr()]
		if klass:
			klass = klass.typeName()
		else:
			klass = self.curClass()
		decl = G.typeMap().method(klass, nm) #FIXME - only allows calls to methods within the same class
		if not decl:
			decl = G.typeMap().func(nm)
		if not decl:
			decl = G.typeMap().extern(nm)
		self.writeAsmTextComment(src, ln)
		self.writeAsmText('call ' + nm)
		
		#FIXME - HACK FOR REMOVING/NOT REMOVING PARAMETERS
		if len(decl.params()) == 1 and decl.typeName()[0] == Type.VOID.typeName():
			pass 
		else: 
			self.writeAsmText('addl $' + str(len(decl.params()) * 4 ) + ', %esp')
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:32,代码来源:CodeGenx86.py

示例4: outACall

# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import typeMap [as 别名]
	def outACall(self, node):
		'''Manage a method 'call'
		   Error Conditions
		    * object does not contain method id
		    * method id does not exist in 'me'
		    * wrong number of parameters
		    * wrong parameter types'''
		self.printFunc(self.outACall, node)
		tp_map = G.typeMap()
		ln = node.getId().getLine()
		nm = node.getId().getText()
		klass = None
		if node.getExpr():
			klass = self.typeMap[node.getExpr()]
		if klass:
			klass = klass.typeName()
		else:
			klass = self.curClass()
		decl = G.typeMap().method(klass, nm) #FIXME - only allows calls to methods within the same class
		if not decl:
			decl = G.typeMap().func(nm)
		if not decl:
			decl = G.typeMap().extern(nm)
		ls_args = [self.typeMap[a] for a in node.getArgs()]

		tp_ret = Type.NONE
		#id does not exist or is not a method id
		if decl == None or not isinstance(decl, (MethodDecl, ExternDecl, FuncDecl)):
			G.errors().semantic().add("method '" + nm + "' does not exist", ln)
		#check for correct number and type of parameters
		elif len(ls_args) > 0:
			params = [tp_map.klass(p.typeName()) for p in decl.params()]
			if len(params) != len(ls_args):
				G.errors().semantic().add("method '" + nm + "' expects " +
										  str(len(params)) +
										  " parameter(s) but was given " +
										  str(len(ls_args)), ln)
			elif ls_args != params:
				G.errors().semantic().add("method '" + nm +
										  "' expects parameters " +
										  str([str(p) for p in params]) +
										  " but was given " +
										  str([str(a) for a in ls_args]), ln)
		#get method return type
		if decl != None:
			tp_ret = G.typeMap().klass(decl.typeName())
		
		self.typeMap[node] = tp_ret
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:50,代码来源:SemanticChecker.py

示例5: inAXtern

# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import typeMap [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
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:31,代码来源:TypeMapBuilder.py

示例6: inAMethodSig

# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import typeMap [as 别名]
	def inAMethodSig(self, node):
		''''''
		self.printFunc(self.inAMethodSig, node)

		klass = G.typeMap().klass(self.curClass())
		nm = node.getId().getText()
		if klass.exists(nm):
			G.errors().semantic().add("method '" + nm + "' already exists", ln)
		else:
			klass.addMethod(MethodDecl(nm))
			self.setCurMethod(nm)

		ln = node.getId().getLine()
		
		meth = G.typeMap().klass(self.curClass()).method(self.curMethod())
		if node.getRet():
			tp = node.getRet().getTp().getText()
			meth.setTypeName(tp) #set the return type name
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:20,代码来源:TypeMapBuilder.py

示例7: outAUdtType

# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import typeMap [as 别名]
	def outAUdtType(self, node):
		'''Manage 'user defined types' (classes types) type
		   Error Conditions:'''
		self.printFunc(self.outAUdtType, node)
		err = False
		nm = node.getTp().getText()
		ln = node.getTp().getLine()

		tp = Type.NONE
		#invalid/undeclared type name
		if not G.typeMap().klassExists(nm):
			G.errors().semantic().add("invalid/undeclared type name", ln)
		else:
			tp = G.typeMap().klass(nm)
		self.typeMap[node] = tp
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:17,代码来源:SemanticChecker.py

示例8: inAKlassInherits

# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import typeMap [as 别名]
	def inAKlassInherits(self, node):
		''''''
		self.printFunc(self.inAKlassInherits, node)
		ln = node.getId().getLine()
		
		tp_map = G.typeMap()
		nm = node.getId().getText()
		tp_map.klass(self.curClass()).setParent(nm)
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:10,代码来源:TypeMapBuilder.py

示例9: outANewExpr

# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import typeMap [as 别名]
	def outANewExpr(self, node):
		'''Manage 'new' expression
		   Error Conditions
		    * HACK MiniOodle: new is unsupported'''
		self.printFunc(self.outANewExpr, node)
		ln = node.getValue().getLine()
		nm = node.getTp().getTp().getText()
		tp = G.typeMap().klass(nm)
		if not tp:
			tp = Type.NONE
		self.typeMap[node] = tp
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:13,代码来源:SemanticChecker.py

示例10: inAVarToplevel

# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import typeMap [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
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:15,代码来源:TypeMapBuilder.py

示例11: outAMethodSig

# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import typeMap [as 别名]
	def outAMethodSig(self, node):
		'''class method signature'''
		self.printFunc(self.outAMethodSig, node)
		mem = -4
		vars = node.parent().getVars()
		if len(vars) > 0:
			mem = G.typeMap().method(self.curClass(), self.curMethod()).vars()[-1].offset()

		self.writeAsmText('pushl %ebp')
		self.writeAsmText('movl %esp, %ebp')
		self.writeAsmText('addl $(' + str(mem) + '), %esp')
		for v in range(-4, mem - 4, -4):
			self.writeAsmText('movl $0, ' + str(v) + '(%ebp)')
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:15,代码来源:CodeGenx86.py

示例12: outAFuncSig

# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import typeMap [as 别名]
	def outAFuncSig(self, node):
		'''global function signature'''
		self.printFunc(self.outAFuncSig, node)
		mem = -4
		vars = node.parent().getVars()
		if len(vars) > 0:
			mem = G.typeMap().func(self.curMethod()).vars()[-1].offset()
			#mem = G.symMap()[vars[-1]].decl().offset()
		self.writeAsmText('pushl %ebp')
		self.writeAsmText('movl %esp, %ebp')
		self.writeAsmText('addl $(' + str(mem) + '), %esp')
		for v in range(-4, mem - 4, -4):
			self.writeAsmText('movl $0, ' + str(v) + '(%ebp)')
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:15,代码来源:CodeGenx86.py

示例13: inAFuncArg

# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import typeMap [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
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:15,代码来源:TypeMapBuilder.py

示例14: outAIdExpr

# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import typeMap [as 别名]
	def outAIdExpr(self, node):
		'''Manage 'id' expression
		   Error Conditions
		    * Undefined id
		    * HACK MiniOodle 'out' and 'in' are allowed'''
		self.printFunc(self.outAIdExpr, node)
		nm = node.getId().getText()
		decl = G.typeMap().var(self.curClass(), self.curMethod(), nm)
		if not decl:
			decl = G.typeMap().glbVar(nm)
		ln = node.getId().getLine()
		
		tp = Type.NONE
		#HACK - MiniOodle classes of 'in' and 'out'
		if nm in ['in', 'out']:
			pass
		#id is undefined
		elif decl == None:
			G.errors().semantic().add("undefined variable '" + nm + "'", ln)
		else:
			tp = G.typeMap().klass(decl.typeName())
		self.typeMap[node] = tp #assign this nodes type
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:24,代码来源:SemanticChecker.py

示例15: inAKlassHeader

# 需要导入模块: from oodle.G import G [as 别名]
# 或者: from oodle.G.G import typeMap [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)
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:16,代码来源:TypeMapBuilder.py


注:本文中的oodle.G.G.typeMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。