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


Python G.G类代码示例

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


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

示例1: main

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,代码行数:25,代码来源:Oodle.py

示例2: outACall

	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,代码行数:30,代码来源:CodeGenx86.py

示例3: outAVar

	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
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:30,代码来源:SemanticChecker.py

示例4: inAKlassInherits

	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)
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:7,代码来源:SemanticChecker.py

示例5: inAXtern

	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,代码行数:29,代码来源:TypeMapBuilder.py

示例6: outAArrayType

	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
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:8,代码来源:SemanticChecker.py

示例7: outAArrayExpr

	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
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:8,代码来源:SemanticChecker.py

示例8: outAStrExpr

	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
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:8,代码来源:SemanticChecker.py

示例9: isVarNameUsed

	def isVarNameUsed(self, nm):
		'''Check whether var name is already used'''
		ret = False
		sym = G.symTab().lookup(nm)
		if sym != None:
			ret = ret or isinstance(sym.decl(), ClassDecl)
			#ret = ret or isinstance(sym.decl(), MethodDecl) #FIXME - probably need this
			ret = ret or (isinstance(sym.decl(), VarDecl) and sym.scope() == G.symTab().getScope())
		return ret
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:9,代码来源:CodeGenx86.py

示例10: outALoopStmt

	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)
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:10,代码来源:SemanticChecker.py

示例11: inAKlassBody

	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)
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:12,代码来源:SemanticChecker.py

示例12: outAFunc

	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("")
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:12,代码来源:SemanticChecker.py

示例13: inAVarToplevel

	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,代码行数:13,代码来源:TypeMapBuilder.py

示例14: inAFuncArg

	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,代码行数:13,代码来源:TypeMapBuilder.py

示例15: outANotExpr

	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
开发者ID:sundrythoughts,项目名称:JyOodle,代码行数:14,代码来源:SemanticChecker.py


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