def compile(self): """ This method will compile and prepare everything to start evaluation the configuration specification. This method will: - load all namespaces - compile the __config__ namespace - start resolving it and importing unknown namespaces """ project = Project.get() self.__root_ns = project.get_root_namespace() project.load() statements, blocks = project.get_complete_ast() # load plugins for name, cls in PluginMeta.get_functions().items(): mod_ns = cls.__module__.split(".") if mod_ns[0] != "inmanta_plugins": raise Exception( "All plugin modules should be loaded in the impera_plugins package not in %s" % cls.__module__) mod_ns = mod_ns[1:] ns = self.__root_ns for part in mod_ns: if ns is None: break ns = ns.get_child(part) if ns is None: raise Exception( "Unable to find namespace for plugin module %s" % (cls.__module__)) cls.namespace = ns name = name.split("::")[-1] statement = PluginStatement(ns, name, cls) statements.append(statement) # add the entity type (hack?) entity = DefineEntity(self.__root_ns.get_child_or_create("std"), "Entity", "The entity all other entities inherit from.", [], []) requires_rel = DefineRelation( ("std::Entity", "requires", [0, None], False), ("std::Entity", "provides", [0, None], False)) requires_rel.namespace = self.__root_ns.get_ns_from_string("std") statements.append(entity) statements.append(requires_rel) return (statements, blocks)
def p_entity_extends(p: YaccProduction) -> None: "entity_def : ENTITY CID EXTENDS class_ref_list ':' entity_body_outer" assert namespace p[0] = DefineEntity(namespace, p[2], p[6][0], p[4], p[6][1]) attach_lnr(p)
def p_entity(p: YaccProduction) -> None: "entity_def : ENTITY CID ':' entity_body_outer" assert namespace p[0] = DefineEntity(namespace, p[2], p[4][0], [], p[4][1]) attach_lnr(p)
def compile(self) -> Tuple[List["Statement"], List["BasicBlock"]]: """ This method will parse and prepare everything to start evaluation the configuration specification. This method will: - load all modules using Project.get().get_complete_ast() - add all plugins - create std::Entity """ project = module.Project.get() self.__root_ns = project.get_root_namespace() project.load() statements, blocks = project.get_complete_ast() # load plugins for name, cls in PluginMeta.get_functions().items(): mod_ns = cls.__module__.split(".") if mod_ns[0] != const.PLUGINS_PACKAGE: raise Exception( "All plugin modules should be loaded in the %s package not in %s" % (const.PLUGINS_PACKAGE, cls.__module__) ) mod_ns = mod_ns[1:] ns: Optional[Namespace] = self.__root_ns for part in mod_ns: if ns is None: break ns = ns.get_child(part) if ns is None: raise Exception("Unable to find namespace for plugin module %s" % (cls.__module__)) name = name.split("::")[-1] statement = PluginStatement(ns, name, cls) statements.append(statement) # add the entity type (hack?) ns = self.__root_ns.get_child_or_create("std") nullrange = Range("internal", 1, 0, 0, 0) entity = DefineEntity( ns, LocatableString("Entity", nullrange, 0, ns), LocatableString("The entity all other entities inherit from.", nullrange, 0, ns), [], [], ) str_std_entity = LocatableString("std::Entity", nullrange, 0, ns) requires_rel = DefineRelation( (str_std_entity, LocatableString("requires", nullrange, 0, ns), (0, None)), (str_std_entity, LocatableString("provides", nullrange, 0, ns), (0, None)), ) requires_rel.namespace = self.__root_ns.get_ns_from_string("std") statements.append(entity) statements.append(requires_rel) return (statements, blocks)
def p_entity_extends(p): "entity_def : ENTITY CID EXTENDS class_ref_list ':' entity_body_outer " p[0] = DefineEntity(namespace, p[2], p[6][0], p[4], p[6][1]) attach_lnr(p)
def p_entity(p): "entity_def : ENTITY CID ':' entity_body_outer " p[0] = DefineEntity(namespace, p[2], p[4][0], [], p[4][1]) attach_lnr(p)