Skip to content

Commit

Permalink
Merge pull request #3241 from sorig/meta_fix_static_imports
Browse files Browse the repository at this point in the history
Meta Language fix static call import
  • Loading branch information
karlnapf committed Jun 6, 2016
2 parents 8638ce1 + 458ba78 commit 4fb6397
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
4 changes: 2 additions & 2 deletions examples/meta/generator/targets/python.json
@@ -1,8 +1,8 @@
{
"Program": "$dependencies$program$testing",
"Dependencies": {
"AllDependencies": "$constructedClassDependencies$enumDependencies\n",
"ConstructedClassDependencies": "from modshogun import $classlist\n",
"AllDependencies": "$interfacedClassDependencies$enumDependencies\n",
"InterfacedClassDependencies": "from modshogun import $classlist\n",
"EnumDependencies": "from modshogun import $enums\n",
"DependencyListElementEnum": "$value",
"DependencyListSeparator": ", "
Expand Down
25 changes: 17 additions & 8 deletions examples/meta/generator/translate.py
Expand Up @@ -14,8 +14,15 @@
class Translator:
def __init__(self, targetDict):
self.dependencies = {
# All object types used throughout the program
"AllClasses":set(),
"ConstructedClasses":set(),

# All classes where the class interface has been used explicitly.
# I.e. classes used to construct objects and classes where static
# methods are called
"InterfacedClasses":set(),

# All enum types used throughout the program
"Enums":set()
}

Expand All @@ -30,7 +37,7 @@ def translateProgram(self, program, programName=None,
"""
# reset dependencies
self.dependencies["AllClasses"] = set()
self.dependencies["ConstructedClasses"] = set()
self.dependencies["InterfacedClasses"] = set()
self.dependencies["Enums"] = set()
self.tags = tags
self.storeVars = storeVars
Expand Down Expand Up @@ -109,7 +116,7 @@ def dependenciesString(self):
# a list of all explicitly constructed classes,
# and list of all enums used. All are optional.
allClassDependencies = ""
constructedClassDependencies = ""
interfacedClassDependencies = ""
enumDependencies = ""
dependenciesExist = False

Expand All @@ -118,10 +125,10 @@ def dependenciesString(self):
template = Template(self.targetDict["Dependencies"]["AllClassDependencies"])
allClassDependencies = template.substitute(classlist=self.seperatedClassDependencies("AllClasses"))

if len(self.dependencies["ConstructedClasses"]) > 0 and "ConstructedClassDependencies" in self.targetDict["Dependencies"]:
if len(self.dependencies["InterfacedClasses"]) > 0 and "InterfacedClassDependencies" in self.targetDict["Dependencies"]:
dependenciesExist = True
template = Template(self.targetDict["Dependencies"]["ConstructedClassDependencies"])
constructedClassDependencies = template.substitute(classlist=self.seperatedClassDependencies("ConstructedClasses"))
template = Template(self.targetDict["Dependencies"]["InterfacedClassDependencies"])
interfacedClassDependencies = template.substitute(classlist=self.seperatedClassDependencies("InterfacedClasses"))

if len(self.dependencies["Enums"]) > 0 and "EnumDependencies" in self.targetDict["Dependencies"]:
dependenciesExist = True
Expand All @@ -133,7 +140,7 @@ def dependenciesString(self):

allDependenciesTemplate = Template(self.targetDict["Dependencies"]["AllDependencies"])
return allDependenciesTemplate.substitute(allClassDependencies=allClassDependencies,
constructedClassDependencies=constructedClassDependencies,
interfacedClassDependencies=interfacedClassDependencies,
enumDependencies=enumDependencies)

def seperatedClassDependencies(self, type):
Expand Down Expand Up @@ -264,7 +271,7 @@ def translateInit(self, init):
exprString = self.translateExpr(initialisation["Expr"])
return template.substitute(name=nameString, type=typeString, expr=exprString)
elif list(initialisation.keys())[0] == "ArgumentList":
self.dependencies["ConstructedClasses"].add(typeString)
self.dependencies["InterfacedClasses"].add(typeString)
template = Template(self.targetDict["Init"]["Construct"])
argsString = self.translateArgumentList(initialisation["ArgumentList"])
return template.substitute(name=nameString, type=typeString, arguments=argsString)
Expand Down Expand Up @@ -303,6 +310,8 @@ def translateExpr(self, expr):
pass
translatedArgsList = self.translateArgumentList(argsList)

self.dependencies["InterfacedClasses"].add(type_)

return template.substitute(type=type_, method=method, arguments=translatedArgsList)

elif key == "BoolLiteral":
Expand Down

0 comments on commit 4fb6397

Please sign in to comment.