Esempio n. 1
0
 def annotations(self) -> str:
     annotations = ""
     for name, value in self.__dict__.items():
         if name in self.hidden_annotations:
             pass
         elif name == "type":
             pass  # Handled below
         elif name == "depends_on" and value:
             annotations += f"{_annotation_prefix}{name}({', '.join(value)});\n"
         elif not name.startswith(
                 "_") and value != default_annotations.get(name):
             if isinstance(value, bool):
                 if value:
                     annotations += f"{_annotation_prefix}{name};\n"
             else:
                 if value:
                     annotations += f"{_annotation_prefix}{name}({value});\n"
     annotations += self.type.annotations
     if annotations:
         if self.ret:
             return f"{_annotation_prefix}return_value {{ {annotations} }}"
         else:
             return f"{_annotation_prefix}argument({self.name}) {{ {annotations} }}"
     else:
         return ""
Esempio n. 2
0
 def annotations(self) -> str:
     annotations = ""
     late_annotations = ""
     for name, value in self.__dict__.items():
         if name in self.hidden_annotations:
             pass
         elif name == "pointee":
             anns = self.pointee.annotations
             if self.transfer not in ("NW_HANDLE", "NW_OPAQUE") and anns:
                 late_annotations += f"{_annotation_prefix}element {{ {anns} }}\n"
         elif name == "fields":
             for fname, field in self.fields.items():
                 anns = field.annotations
                 if anns:
                     late_annotations += f"{_annotation_prefix}field({fname}) {{ {anns} }}\n"
         elif name == "transfer" and value in self.transfer_spellings and value != default_annotations.get(
                 name):
             if value in ("NW_CALLBACK", "NW_CALLBACK_REGISTRATION"):
                 annotations += f"{_annotation_prefix}{self.transfer_spellings[value]}({self.callback_stub_function});\n"
             elif self.transfer_spellings[value]:
                 annotations += f"{_annotation_prefix}{self.transfer_spellings[value]};\n"
         elif name == "lifetime" and value in self.lifetime_spellings and value != default_annotations.get(
                 name):
             if self.lifetime_spellings[value]:
                 annotations += f"{_annotation_prefix}lifetime_{self.lifetime_spellings[value]};\n"
         elif name == "buffer":
             if self.transfer == "NW_BUFFER":
                 annotations += f"{_annotation_prefix}{name}({value});\n"
         elif name == "buffer_allocator" and value != default_annotations.get(
                 name):
             annotations += f"{_annotation_prefix}{name}({value}, {self.buffer_deallocator});\n"
         elif name.endswith("allocates_resources") and value:
             for resource, amount in value.items():
                 annotations += f"{_annotation_prefix}{name}({resource}, {amount});\n"
         elif not name.startswith(
                 "_") and value != default_annotations.get(name):
             if isinstance(value, bool):
                 if value:
                     annotations += f"{_annotation_prefix}{name};\n"
             else:
                 if value:
                     annotations += f"{_annotation_prefix}{name}({value});\n"
     annotations += late_annotations
     return annotations
Esempio n. 3
0
    def __str__(self):
        annotations = ""
        for name, value in self.__dict__.items():
            if name in self.hidden_annotations:
                pass
            elif name == "synchrony" and value in self.synchrony_spellings:
                annotations += f"{_annotation_prefix}{self.synchrony_spellings[value]};\n"
            elif name == "consumes_resources" and value:
                for resource, amount in value.items():
                    annotations += f"{_annotation_prefix}{name}({resource}, {amount});\n"
            elif name == "supported":
                if not value:
                    annotations += f"{_annotation_prefix}unsupported;\n"
            elif not name.startswith(
                    "_") and value != default_annotations.get(name):
                if isinstance(value, bool):
                    if value:
                        annotations += f"{_annotation_prefix}{name};\n"
                else:
                    if value:
                        annotations += f"{_annotation_prefix}{name}({value});\n"

        args = ", ".join(str(a) for a in self.real_arguments)
        decl = self.return_value.type.attach_to(f"{self.name}({args})")
        if self.return_value.type.is_void:
            ret_assignment = f"{_annotation_prefix}execute()"
        else:
            ret_assignment = self.return_value.type.attach_to(
                f"ret = {_annotation_prefix}execute()")
        body = f"""{{\
            {annotations}
            {lines(a.annotations for a in self.arguments)}
            {self.return_value.annotations}
            {lines(str(a) + ";" for a in self.implicit_arguments)}
            {lines(str(a) + ";" for a in self.logue_declarations)}\
            {lines(self.prologue)}\
            {ret_assignment};\
            {lines(self.epilogue)}\
        }}"""
        return f"""{decl}{body}"""