def clear(self): """Clear all registrations in this application. """ RegRegistry.clear(self) MountRegistry.clear(self) PredicateRegistry.clear(self) Configurable.clear(self) ConverterRegistry.clear(self) TweenRegistry.clear(self) TemplateEngineRegistry.clear(self) self.traject = Traject()
def __init__(self, name, bases, testing_config): self.name = name bases = [base.registry for base in bases if hasattr(base, 'registry')] RegRegistry.__init__(self) MountRegistry.__init__(self) PredicateRegistry.__init__(self) Configurable.__init__(self, bases, testing_config) ConverterRegistry.__init__(self) TweenRegistry.__init__(self) TemplateEngineRegistry.__init__(self) self.settings = SettingSectionContainer() self.clear()
class Traject(Node): def __init__(self): super(Traject, self).__init__() # XXX caching is not enabled # also could this really be registering things in the main # application registry instead? if it did and we solve caching # for that this would get it automatically. but this would # require each traject base to have its own lookup self._inverse = Registry() def add_pattern(self, path, value): node = self known_variables = set() for segment in reversed(parse_path(path)): step = Step(segment) node = node.add(step) variables = set(step.names) if known_variables.intersection(variables): raise TrajectError("Duplicate variables") known_variables.update(variables) node.value = value def inverse(self, model_class, path, get_variables): # XXX should we do checking for duplicate variables here too? path = Path(path) self._inverse.register('inverse', [model_class], (path.interpolation_str(), get_variables)) def __call__(self, stack): stack = stack[:] node = self variables = {} while stack: segment = stack.pop() if segment.startswith(VIEW_PREFIX): stack.append(segment) return node.value, stack, variables new_node, new_variables = node.get(segment) if new_node is None: stack.append(segment) return node.value, stack, variables node = new_node variables.update(new_variables) return node.value, stack, variables def path(self, model): path, get_variables = self._inverse.component('inverse', [model]) variables = get_variables(model) assert isinstance(variables, dict) return path % variables
def makeRegistry(self): try: import lxml.etree as etree HAS_LXML = True except ImportError: HAS_LXML = False if not HAS_LXML: return super().makeRegistry() registryFile = str(SPECIFICATION_DIR / 'registry/xr.xml') registry = Registry() registry.filename = registryFile registry.loadElementTree(etree.parse(registryFile)) return registry
def __init__(self): super(Traject, self).__init__() # XXX caching is not enabled # also could this really be registering things in the main # application registry instead? if it did and we solve caching # for that this would get it automatically. but this would # require each traject base to have its own lookup self._inverse = Registry()
def makeRegistry(self): # This tries to override and use lxml instead of the built-in etree. # lxml isn't suitable for generation, but it's fine for this checking, # and it provides file line info which is useful in messages. try: import lxml.etree as etree HAS_LXML = True except ImportError: HAS_LXML = False if not HAS_LXML: return super().makeRegistry() registryFile = str(SPECIFICATION_DIR / 'registry/xr.xml') registry = Registry() registry.filename = registryFile registry.loadElementTree(etree.parse(registryFile)) return registry
def __init__(self): super(Traject, self).__init__() # XXX caching is not enabled # also could this really be registering things in the main # application registry instead? if it did and we solve caching # for that this would get it automatically. self._root = Node() self._inverse = Registry()
metavar='target', nargs='?', help='Specify target') parser.add_argument('-quiet', action='store_true', default=False, help='Suppress script output during normal execution.') args = parser.parse_args() # This splits arguments which are space-separated lists args.feature = [name for arg in args.feature for name in arg.split()] args.extension = [name for arg in args.extension for name in arg.split()] # Load & parse registry reg = Registry() startTimer(args.time) reg.loadFile(args.registry) endTimer(args.time, '* Time to make and parse ElementTree =') if args.validate: reg.validateGroups() if args.dump: write('* Dumping registry to regdump.txt', file=sys.stderr) reg.dumpReg(filehandle=open('regdump.txt', 'w', encoding='utf-8')) # create error/warning & diagnostic files errWarn = open(args.errfile, 'w', encoding='utf-8') if args.errfile else sys.stderr
baseDir = results.baseDir # Dictionary of pages & aliases pages = {} for file in results.files: d = genRef(file, baseDir) pages.update(d) # Now figure out which pages *weren't* generated from the spec. # This relies on the dictionaries of API constructs in the api module. if not results.noauto: registry = Registry() registry.loadFile(results.registry) if conventions.write_refpage_include: # Only extensions with a supported="..." attribute in this set # will be considered for extraction/generation. supported_strings = set((conventions.xml_supported_name_of_api, )) ext_names = set(k for k, v in registry.extdict.items() if v.supported in supported_strings) desired_extensions = ext_names.intersection(set(results.extension)) for prefix in conventions.extension_index_prefixes: # Splits up into chunks, sorted within each chunk. filtered_extensions = sorted([ name for name in desired_extensions if name.startswith(prefix) and name not in extensions
def makeRegistry(self): root = Path(__file__).resolve().parent.parent.parent registryFile = str(root / 'specification/registry/xr.xml') registry = Registry() registry.loadFile(registryFile) return registry
import filecmp import optparse import os import platform import sys from os import path from string import Template from subprocess import call vulkan_reg_path = path.join(path.dirname(__file__), "..", "..", "third_party", "vulkan_headers", "registry") sys.path.append(vulkan_reg_path) from reg import Registry registry = Registry() registry.loadFile(open(path.join(vulkan_reg_path, "vk.xml"))) VULKAN_REQUIRED_API_VERSION = 'VK_API_VERSION_1_1' VULKAN_UNASSOCIATED_FUNCTIONS = [{ 'functions': [ # vkGetInstanceProcAddr belongs here but is handled specially. 'vkEnumerateInstanceVersion', 'vkCreateInstance', 'vkEnumerateInstanceExtensionProperties', 'vkEnumerateInstanceLayerProperties', ] }] VULKAN_INSTANCE_FUNCTIONS = [
def makeRegistry(self): registryFile = str(ROOT / 'xml/vk.xml') registry = Registry() registry.loadFile(registryFile) return registry
def __init__(self): self._step_matchers = set() self._conflicting_steps = set() self._variable_matchers = {} self._model_factories = {} self._inverse = Registry() # XXX caching?
class Traject(object): def __init__(self): self._step_matchers = set() self._conflicting_steps = set() self._variable_matchers = {} self._model_factories = {} self._inverse = Registry() # XXX caching? def register(self, path, model_factory, base_argument=False, conflicting=False): pattern = parse(path) seen_names = set() for p in subpatterns(pattern): variable_matcher = VariableMatcher(p[-1], p) if variable_matcher.has_variables(): for name in variable_matcher.names: if name in seen_names: raise TrajectError( "path '%s' has a duplicate variable: %s" % (path, name)) seen_names.add(name) variable_pattern = p[:-1] + (VARIABLE, ) variable_matchers = self._variable_matchers.setdefault( variable_pattern, set()) for m in variable_matchers: if variable_matcher.conflicts(m): raise TrajectError( "path '%s' conflicts with path '%s'" % (path, create(m.pattern))) variable_matchers.add(variable_matcher) else: if conflicting and p in self._step_matchers: raise TrajectError("path '%s' conflicts with another" % path) if p in self._conflicting_steps: raise TrajectError("path '%s' conflicts with another" % path) self._step_matchers.add(p) if conflicting: self._conflicting_steps.add(p) v = self._model_factories.get(pattern) if v is not None: existing_model_factory, base_argument = v raise TrajectError( "path '%s' is already used to register model %r" % (path, existing_model_factory)) self._model_factories[pattern] = model_factory, base_argument def register_inverse(self, model_class, path, get_variables): path = interpolation_path(path) self._inverse.register('inverse', [model_class], (path, get_variables)) def match(self, pattern, step): step_pattern = self.match_step(pattern, step) if step_pattern is not None: return step_pattern, {} return self.match_variables(pattern, step) def match_step(self, pattern, step): pattern = pattern + (step, ) if pattern in self._step_matchers: return pattern else: return None def match_variables(self, pattern, step): variable_pattern = pattern + (VARIABLE, ) for variable_matcher in self._variable_matchers.get( variable_pattern, []): matched = variable_matcher(step) if matched: break else: return None, {} return pattern + (variable_matcher.step, ), matched def get_model(self, base, pattern, variables): v = self._model_factories.get(pattern) if v is None: return None model_factory, base_argument = v if base_argument: variables['base'] = base return model_factory(**variables) def get_path(self, model): # XXX what if path cannot be found? path, get_variables = self._inverse.component('inverse', [model]) variables = get_variables(model) assert isinstance(variables, dict) return path % variables
if args.errfile: errWarn = open(args.errfile, 'w', encoding='utf-8') else: errWarn = sys.stderr if args.diagfile: diag = open(args.diagfile, 'w', encoding='utf-8') else: diag = None # Create the API generator & generator options (gen, options) = genTarget(args) # Create the registry object with the specified generator and generator # options. The options are set before XML loading as they may affect it. reg = Registry(gen, options) # Parse the specified registry XML into an ElementTree object startTimer(args.time) tree = etree.parse(args.registry) endTimer(args.time, '* Time to make ElementTree =') # Load the XML tree into the registry object startTimer(args.time) reg.loadElementTree(tree) endTimer(args.time, '* Time to parse ElementTree =') if args.validate: reg.validateGroups() if args.dump:
class Traject(object): def __init__(self): self._step_matchers = set() self._conflicting_steps = set() self._variable_matchers = {} self._model_factories = {} self._inverse = Registry() # XXX caching? def register(self, path, model_factory, base_argument=False, conflicting=False): pattern = parse(path) seen_names = set() for p in subpatterns(pattern): variable_matcher = VariableMatcher(p[-1], p) if variable_matcher.has_variables(): for name in variable_matcher.names: if name in seen_names: raise TrajectError( "path '%s' has a duplicate variable: %s" % (path, name) ) seen_names.add(name) variable_pattern = p[:-1] + (VARIABLE,) variable_matchers = self._variable_matchers.setdefault( variable_pattern, set()) for m in variable_matchers: if variable_matcher.conflicts(m): raise TrajectError( "path '%s' conflicts with path '%s'" % (path, create(m.pattern))) variable_matchers.add(variable_matcher) else: if conflicting and p in self._step_matchers: raise TrajectError( "path '%s' conflicts with another" % path) if p in self._conflicting_steps: raise TrajectError( "path '%s' conflicts with another" % path) self._step_matchers.add(p) if conflicting: self._conflicting_steps.add(p) v = self._model_factories.get(pattern) if v is not None: existing_model_factory, base_argument = v raise TrajectError( "path '%s' is already used to register model %r" % (path, existing_model_factory)) self._model_factories[pattern] = model_factory, base_argument def register_inverse(self, model_class, path, get_variables): path = interpolation_path(path) self._inverse.register('inverse', [model_class], (path, get_variables)) def match(self, pattern, step): step_pattern = self.match_step(pattern, step) if step_pattern is not None: return step_pattern, {} return self.match_variables(pattern, step) def match_step(self, pattern, step): pattern = pattern + (step,) if pattern in self._step_matchers: return pattern else: return None def match_variables(self, pattern, step): variable_pattern = pattern + (VARIABLE,) for variable_matcher in self._variable_matchers.get(variable_pattern, []): matched = variable_matcher(step) if matched: break else: return None, {} return pattern + (variable_matcher.step,), matched def get_model(self, base, pattern, variables): v = self._model_factories.get(pattern) if v is None: return None model_factory, base_argument = v if base_argument: variables['base'] = base return model_factory(**variables) def get_path(self, model): # XXX what if path cannot be found? path, get_variables = self._inverse.component('inverse', [model]) variables = get_variables(model) assert isinstance(variables, dict) return path % variables
buildList = [ DGeneratorOptions( filename=path.join(srcDir, "vk.d"), module="{}.vk".format(pack), apiname="vulkan", regFile=path.join(regDir, "vk.xml"), versions=featuresPat, addExtensions=addPlatformExtensionsRE, removeExtensions=None, emitExtensions=emitPlatformExtensionsRE, ), ] for opts in buildList: gen = DGenerator() reg = Registry() reg.loadElementTree(etree.parse(opts.regFile)) reg.setGenerator(gen) reg.apiGen(opts) files.append(opts.filename) import platform libname = '' if platform.system() == 'Windows': libname = 'vkd.lib' else: libname = 'libvkd.a' with open(path.join(rootDir, 'dmd_args.txt'), "w") as argfile: argfile.write('-lib\n') argfile.write('-I' + args.dest + '\n')
class Traject(object): def __init__(self): super(Traject, self).__init__() # XXX caching is not enabled # also could this really be registering things in the main # application registry instead? if it did and we solve caching # for that this would get it automatically. self._root = Node() self._inverse = Registry() def add_pattern(self, path, value, converters=None): node = self._root known_variables = set() for segment in reversed(parse_path(path)): step = Step(segment, converters) node = node.add(step) variables = set(step.names) if known_variables.intersection(variables): raise TrajectError("Duplicate variables") known_variables.update(variables) node.value = value def inverse(self, model_class, path, get_variables, converters, parameter_names): # XXX should we do checking for duplicate variables here too? path = Path(path) self._inverse.register('inverse', [model_class], (path.interpolation_str(), get_variables, converters, parameter_names)) def consume(self, stack): stack = stack[:] node = self._root variables = {} while stack: segment = stack.pop() if segment.startswith(VIEW_PREFIX): stack.append(segment) return node.value, stack, variables new_node, new_variables = node.get(segment) if new_node is None: stack.append(segment) return node.value, stack, variables node = new_node variables.update(new_variables) return node.value, stack, variables def path(self, model): (path, get_variables, converters, parameter_names) = self._inverse.component( 'inverse', [model]) all_variables = get_variables(model) assert isinstance(all_variables, dict) variables = { name: converters.get(name, IDENTITY_CONVERTER).encode(value) for name, value in all_variables.items() if name not in parameter_names} parameters = { name: converters.get(name, IDENTITY_CONVERTER).encode(value) for name, value in all_variables.items() if (name in parameter_names and value is not None) } return path % variables, parameters
setLogFile(True, True, results.logFile) setLogFile(True, False, results.diagFile) setLogFile(False, True, results.warnFile) baseDir = results.baseDir for file in results.files: genRef(file, baseDir) # Now figure out which pages *weren't* generated from the spec. # This relies on the dictionaries of API constructs in the api module. if not results.noauto: registry = Registry() registry.loadFile(results.registry) if conventions.write_refpage_include: # Only extensions with a supported="..." attribute in this set # will be considered for extraction/generation. supported_strings = set((conventions.xml_supported_name_of_api,)) ext_names = set(k for k, v in registry.extdict.items() if v.supported in supported_strings) desired_extensions = ext_names.intersection(set(results.extension)) for prefix in conventions.extension_index_prefixes: # Splits up into chunks, sorted within each chunk. filtered_extensions = sorted( [name for name in ext_names if name.startswith(prefix) and name not in extensions])