def dimensionStringFromDeclaration(symbolName, declaration): from models.symbol import dimensionStringFromSpecification from machinery.commons import parseSpecification return dimensionStringFromSpecification( symbolName, parseSpecification(declaration) )
def dimensionStringFromDeclaration(symbolName, declaration): from models.symbol import dimensionStringFromSpecification from machinery.commons import parseSpecification return dimensionStringFromSpecification( symbolName, parseSpecification(declaration) )
def symbolNamesFromDeclaration(declaration): from models.symbol import symbolNamesFromSpecificationTuple from machinery.commons import parseSpecification return symbolNamesFromSpecificationTuple( parseSpecification(declaration) )
def testSpecificationParsing(self): from machinery.commons import parseSpecification self.assertEqual( parseSpecification(""), (None, None, None) ) self.assertEqual( parseSpecification("blub blib"), (None, None, None) ) self.assertEqual( parseSpecification("real a"), ("real", (("a", None),), "") ) self.assertEqual( parseSpecification("real, attribute a"), ("real, attribute", (("a", None),), "") ) self.assertEqual( parseSpecification("real, attribute a(m, n)"), ("real, attribute", (("a", "m, n"),), "") ) self.assertEqual( parseSpecification("real, attribute a(m * (n + 1))"), ("real, attribute", (("a", "m * (n + 1)"),), "") ) self.assertEqual( parseSpecification("real, attribute a (m * (n + 1))"), ("real, attribute", (("a", "m * (n + 1)"),), "") ) self.assertEqual( parseSpecification("real, attribute(m, n) a"), ("real, attribute(m, n)", (("a", None),), "") ) self.assertEqual( parseSpecification("real, attribute(m * (n + 1)) a"), ("real, attribute(m * (n + 1))", (("a", None),), "") ) self.assertEqual( parseSpecification("real, attribute (m * (n + 1)) a"), ("real, attribute (m * (n + 1))", (("a", None),), "") ) self.assertEqual( parseSpecification("real, attribute :: a, b"), ("real, attribute", (("a", None), ("b", None)), "") ) self.assertEqual( parseSpecification("real, attribute :: a(m, n), b"), ("real, attribute", (("a", "m, n"), ("b", None)), "") ) self.assertEqual( parseSpecification("real, attribute a = 1.0d0"), ("real, attribute", (("a", None),), "= 1.0d0") ) self.assertEqual( parseSpecification("real, attribute a= 1.0d0"), ("real, attribute", (("a", None),), "= 1.0d0") ) self.assertEqual( parseSpecification("real, attribute :: a= 1.0d0"), ("real, attribute", (("a", None),), "= 1.0d0") ) self.assertEqual( parseSpecification("real, attribute::a= 1.0d0"), ("real, attribute", (("a", None),), "= 1.0d0") ) self.assertEqual( parseSpecification("double precision a"), ("double precision", (("a", None),), "") ) self.assertEqual( parseSpecification("double precision :: a"), ("double precision", (("a", None),), "") ) self.assertEqual( parseSpecification("double precision, attribute :: a = 1.0d0"), ("double precision, attribute", (("a", None),), "= 1.0d0") ) self.assertEqual( parseSpecification("double precision, attribute a = 1.0d0"), ("double precision, attribute", (("a", None),), "= 1.0d0") )
def processInsideDeclarationsState(self, line): '''process everything that happens per h90 declaration line''' subProcCallMatch = self.patterns.subprocCallPattern.match(line) parallelRegionMatch = self.patterns.parallelRegionPattern.match(line) domainDependantMatch = self.patterns.domainDependantPattern.match(line) subProcEndMatch = self.patterns.subprocEndPattern.match(line) templateMatch = self.patterns.templatePattern.match(line) templateEndMatch = self.patterns.templateEndPattern.match(line) branchMatch = self.patterns.branchPattern.match(line) dataStatementMatch = self.patterns.dataStatementPattern.match(line) if dataStatementMatch: self.processDataStatementMatch(dataStatementMatch) return if branchMatch: self.processBranchMatch(branchMatch) return if subProcCallMatch: self.switchToNewRegion("CallRegion") self.processCallMatch(subProcCallMatch) self.switchToNewRegion() return if subProcEndMatch: self.processProcEndMatch(subProcEndMatch) if self.state == "inside_branch": self.stateBeforeBranch = 'inside_module_body' else: self.state = 'inside_module_body' return if parallelRegionMatch: raise UsageError("parallel region without parallel dependants") if self.patterns.subprocBeginPattern.match(line): raise UsageError("subprocedure within subprocedure not allowed") if templateMatch: raise UsageError( "template directives are only allowed outside of subroutines") if templateEndMatch: raise UsageError( "template directives are only allowed outside of subroutines") if domainDependantMatch: if self.state == "inside_branch": self.stateBeforeBranch = 'inside_domainDependantRegion' else: self.state = 'inside_domainDependantRegion' self.switchToNewRegion() self.processDomainDependantMatch(domainDependantMatch) return importMatch1 = self.patterns.importPattern.match(line) importMatch2 = self.patterns.singleMappedImportPattern.match(line) importMatch3 = self.patterns.importAllPattern.match(line) specTuple = parseSpecification(line) specificationStatementMatch = self.patterns.specificationStatementPattern.match( line) if not ( \ line.strip() == "" \ or importMatch1 \ or importMatch2 \ or importMatch3 \ or specTuple[0] \ or specificationStatementMatch \ ): if self.state == "inside_branch": self.stateBeforeBranch = "inside_subroutine_body" else: self.state = "inside_subroutine_body" self.switchToNewRegion() self.processInsideSubroutineBodyState(line) return self.analyseSymbolInformationOnCurrentLine(line) #we are never calling super and every match that would have prepared a line, would already have been covered #with a return -> safe to call prepareLine here. self.prepareLine(line, self.tab_insideSub)
def symbolNamesFromDeclaration(declaration): from models.symbol import symbolNamesFromSpecificationTuple from machinery.commons import parseSpecification return symbolNamesFromSpecificationTuple( parseSpecification(declaration) )
def testSpecificationParsing(self): from machinery.commons import parseSpecification self.assertEqual( parseSpecification(""), (None, None, None) ) self.assertEqual( parseSpecification("blub blib"), (None, None, None) ) self.assertEqual( parseSpecification("real a"), ("real", (("a", None),), "") ) self.assertEqual( parseSpecification("real, attribute a"), ("real, attribute", (("a", None),), "") ) self.assertEqual( parseSpecification("real, attribute a(m, n)"), ("real, attribute", (("a", "m, n"),), "") ) self.assertEqual( parseSpecification("real, attribute a(m * (n + 1))"), ("real, attribute", (("a", "m * (n + 1)"),), "") ) self.assertEqual( parseSpecification("real, attribute a (m * (n + 1))"), ("real, attribute", (("a", "m * (n + 1)"),), "") ) self.assertEqual( parseSpecification("real, attribute(m, n) a"), ("real, attribute(m, n)", (("a", None),), "") ) self.assertEqual( parseSpecification("real, attribute(m * (n + 1)) a"), ("real, attribute(m * (n + 1))", (("a", None),), "") ) self.assertEqual( parseSpecification("real, attribute (m * (n + 1)) a"), ("real, attribute (m * (n + 1))", (("a", None),), "") ) self.assertEqual( parseSpecification("real, attribute :: a, b"), ("real, attribute", (("a", None), ("b", None)), "") ) self.assertEqual( parseSpecification("real, attribute :: a(m, n), b"), ("real, attribute", (("a", "m, n"), ("b", None)), "") ) self.assertEqual( parseSpecification("real, attribute a = 1.0d0"), ("real, attribute", (("a", None),), "= 1.0d0") ) self.assertEqual( parseSpecification("real, attribute a= 1.0d0"), ("real, attribute", (("a", None),), "= 1.0d0") ) self.assertEqual( parseSpecification("real, attribute :: a= 1.0d0"), ("real, attribute", (("a", None),), "= 1.0d0") ) self.assertEqual( parseSpecification("real, attribute::a= 1.0d0"), ("real, attribute", (("a", None),), "= 1.0d0") ) self.assertEqual( parseSpecification("double precision a"), ("double precision", (("a", None),), "") ) self.assertEqual( parseSpecification("double precision :: a"), ("double precision", (("a", None),), "") ) self.assertEqual( parseSpecification("double precision, attribute :: a = 1.0d0"), ("double precision, attribute", (("a", None),), "= 1.0d0") ) self.assertEqual( parseSpecification("double precision, attribute a = 1.0d0"), ("double precision, attribute", (("a", None),), "= 1.0d0") )
def processInsideDeclarationsState(self, line): '''process everything that happens per h90 declaration line''' subProcCallMatch = self.patterns.subprocCallPattern.match(line) parallelRegionMatch = self.patterns.parallelRegionPattern.match(line) domainDependantMatch = self.patterns.domainDependantPattern.match(line) subProcEndMatch = self.patterns.subprocEndPattern.match(line) templateMatch = self.patterns.templatePattern.match(line) templateEndMatch = self.patterns.templateEndPattern.match(line) branchMatch = self.patterns.branchPattern.match(line) dataStatementMatch = self.patterns.dataStatementPattern.match(line) if dataStatementMatch: self.processDataStatementMatch(dataStatementMatch) return if branchMatch: self.processBranchMatch(branchMatch) return if subProcCallMatch: self.switchToNewRegion("CallRegion") self.processCallMatch(subProcCallMatch) self.switchToNewRegion() return if subProcEndMatch: self.processProcEndMatch(subProcEndMatch) if self.state == "inside_branch": self.stateBeforeBranch = 'inside_module_body' else: self.state = 'inside_module_body' return if parallelRegionMatch: raise UsageError("parallel region without parallel dependants") if self.patterns.subprocBeginPattern.match(line): raise UsageError("subprocedure within subprocedure not allowed") if templateMatch: raise UsageError("template directives are only allowed outside of subroutines") if templateEndMatch: raise UsageError("template directives are only allowed outside of subroutines") if domainDependantMatch: if self.state == "inside_branch": self.stateBeforeBranch = 'inside_domainDependantRegion' else: self.state = 'inside_domainDependantRegion' self.switchToNewRegion() self.processDomainDependantMatch(domainDependantMatch) return importMatch1 = self.patterns.importPattern.match(line) importMatch2 = self.patterns.singleMappedImportPattern.match(line) importMatch3 = self.patterns.importAllPattern.match(line) specTuple = parseSpecification(line) specificationStatementMatch = self.patterns.specificationStatementPattern.match(line) if not ( \ line.strip() == "" \ or importMatch1 \ or importMatch2 \ or importMatch3 \ or specTuple[0] \ or specificationStatementMatch \ ): if self.state == "inside_branch": self.stateBeforeBranch = "inside_subroutine_body" else: self.state = "inside_subroutine_body" self.switchToNewRegion() self.processInsideSubroutineBodyState(line) return self.analyseSymbolInformationOnCurrentLine(line) #we are never calling super and every match that would have prepared a line, would already have been covered #with a return -> safe to call prepareLine here. self.prepareLine(line, self.tab_insideSub)