Skip to content

Commit

Permalink
Fix heuristic for include path search. Warn users if multiple candida…
Browse files Browse the repository at this point in the history
…tes are found
  • Loading branch information
sorig committed Aug 10, 2016
1 parent 68f8710 commit 44a65aa
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions examples/meta/generator/translate.py
Expand Up @@ -11,6 +11,7 @@
set
except NameError:
from sets import Set as set
import warnings


def find(key, dictionary):
Expand Down Expand Up @@ -261,14 +262,30 @@ def getIncludePathForClass(self, type_):
translatedType = self.translateType({"ObjectType": type_})
template_parameter_matcher = '\<[0-9a-zA-Z_]*\>'
variants = [
translatedType,
'C' + translatedType,
re.sub(template_parameter_matcher, '', translatedType),
'C' + re.sub(template_parameter_matcher, '', translatedType)
translatedType,
'C' + re.sub(template_parameter_matcher, '', translatedType),
re.sub(template_parameter_matcher, '', translatedType)
]

candidates = []
for variant in variants:
if variant in self.tags:
return self.tags[variant]
candidates.append(self.tags[variant])

unique_candidates = [path for i, path in enumerate(candidates)
if candidates.index(path) == i]

if len(unique_candidates) == 1:
return unique_candidates[0]

elif len(unique_candidates) > 1:
msg = "Several possible include paths for type {}.\n"\
"Candidate paths: {}\nChosen: {}"
warnings.warn(msg.format(type_,
unique_candidates,
unique_candidates[0]))
return unique_candidates[0]

raise TranslationFailure('Failed to obtain include path for %s' %
(' or '.join(variants)))
Expand Down

0 comments on commit 44a65aa

Please sign in to comment.