本文整理匯總了Python中SymbolTable.SymbolTable.getFirstRelevantScopeName方法的典型用法代碼示例。如果您正苦於以下問題:Python SymbolTable.getFirstRelevantScopeName方法的具體用法?Python SymbolTable.getFirstRelevantScopeName怎麽用?Python SymbolTable.getFirstRelevantScopeName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SymbolTable.SymbolTable
的用法示例。
在下文中一共展示了SymbolTable.getFirstRelevantScopeName方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TypeChecker
# 需要導入模塊: from SymbolTable import SymbolTable [as 別名]
# 或者: from SymbolTable.SymbolTable import getFirstRelevantScopeName [as 別名]
#.........這裏部分代碼省略.........
except:
self.error("bad argument in funcall",node.line)
return funSymbol.type
def visit_ExprList(self,node):
# print "visiting ExprList"
toReturn = []
for element in node.list:
toReturn.append(element.accept(self))
return toReturn
def visit_FunDefs(self,node):
# print "visiting FunDefs"
for element in node.list :
element.accept(self)
def visit_FunDef(self,node):
# print "visiting FunDef"
self.symbolTable = SymbolTable(self.symbolTable,node.id.value)
self.symbolTable.getParentScope().put(node.id.value,FunSymbol(node.typeOrId, node.id.value, map(lambda x: x.accept(self),node.argList.list)))
node.compoundInstr.accept(self)
self.symbolTable = self.symbolTable.getParentScope()
return node.id.value
def visit_ArgList(self,node):
# print "visiting ArgList"
toReturn = []
for element in node.list:
toReturn.append(element.accept(self))
return toReturn
def visit_Arg(self,node):
# print "visiting Arg"
self.symbolTable.put(node.id.value,node.typeOrId)
return node.typeOrId
def visit_ClassDefs(self,node):
# print "visiting ClassDefs"
for element in node.list :
element.accept(self)
def visit_ClassDef(self,node):
# print "visiting ClassDef"
self.symbolTable = SymbolTable(self.symbolTable if node.parentId == None else self.classTables[node.parentId.value], node.id.value)
classSymbol = ClassSymbol(node.accessmodificator, node.id.value, node.parentId if node.parentId == None else node.parentId.accept(self),node.classcontent.accept(self))
self.classTables[node.id.value]=self.symbolTable
while self.symbolTable.parent!=None:
self.symbolTable = self.symbolTable.getParentScope()
self.symbolTable.put(node.id.value,classSymbol)
def visit_Access(self,node):
# print "visiting Access"
accessedObject = node.list[0].accept(self)
if(isinstance(accessedObject, ClassSymbol)):
if(accessedObject.hasAccess(self.symbolTable.getFirstRelevantScopeName(),node.list[1].value)):
classContentName = self.makeClassContentName(accessedObject.id,node.list[0].value,node.list[1].value)
if self.symbolTable.getIncludingParents(classContentName):
accessedObject=self.symbolTable.getIncludingParents(classContentName)
else:
self.error("cannot find class content "+classContentName,0)
else:
self.error("trying to access field that is not visible", 0)
return accessedObject
def visit_Fielddefs(self, node):
# print "visiting Fielddefs"
toReturn=[]
for element in node.list:
for accessAndId in element.accept(self):
toReturn.append(accessAndId)
return toReturn
def visit_Fielddef(self, node):
# print "visiting Fielddef"
toReturn=[]
for element in node.declaration.accept(self):
toReturn.append((element,node.accessmodificator))
return toReturn
def visit_Classcontent(self, node):
# print "visiting Classcontent"
toReturn={}
for element in node.fielddefs.accept(self):
toReturn[element[0]]=element[1]
for element in node.methoddefs.accept(self):
toReturn[element[0]]=element[1]
return toReturn
def visit_Methoddefs(self, node):
# print "visiting Methoddefs"
toReturn=[]
for element in node.list:
toReturn.append(element.accept(self))
return toReturn
def visit_Methoddef(self, node):
# print "visiting Methoddef"
return (node.fundef.accept(self), node.accessmodificator)