| 792 | } |
| 793 | |
| 794 | void OpInfo::WriteClassDecl(WritableFile* h) const { |
| 795 | string class_decl = comment; |
| 796 | strings::StrAppend(&class_decl, "class ", op_name, " {\n"); |
| 797 | strings::StrAppend(&class_decl, " public:\n"); |
| 798 | if (has_optional_attrs) { |
| 799 | strings::StrAppend(&class_decl, GetOpAttrStruct()); |
| 800 | } |
| 801 | strings::StrAppend(&class_decl, " ", |
| 802 | GetConstructorDecl("", /* include_attr */ false), ";\n"); |
| 803 | if (has_optional_attrs) { |
| 804 | strings::StrAppend(&class_decl, " ", |
| 805 | GetConstructorDecl("", /* include_attr */ true), ";\n"); |
| 806 | } |
| 807 | if (output_types.empty()) { |
| 808 | // Allow casting this class to Operation. |
| 809 | strings::StrAppend(&class_decl, |
| 810 | " operator ::tensorflow::Operation() const { " |
| 811 | "return operation; }\n"); |
| 812 | } else if (output_types.size() == 1) { |
| 813 | if (is_list_output[0]) { |
| 814 | // Write the subscript operator, allowing out[i] for the list-typed |
| 815 | // output. |
| 816 | strings::StrAppend(&class_decl, |
| 817 | " ::tensorflow::Output operator[](size_t index) " |
| 818 | "const { return ", |
| 819 | output_names[0], "[index]; }\n\n"); |
| 820 | |
| 821 | } else { |
| 822 | // Write type cast functions, allowing casting this class to Input and |
| 823 | // Output. |
| 824 | strings::StrAppend(&class_decl, |
| 825 | " operator ::tensorflow::Output() const { return ", |
| 826 | output_names[0], "; }\n"); |
| 827 | strings::StrAppend(&class_decl, |
| 828 | " operator ::tensorflow::Input() const { return ", |
| 829 | output_names[0], "; }\n"); |
| 830 | // Write node() to get the Node* directly. |
| 831 | strings::StrAppend(&class_decl, |
| 832 | " ::tensorflow::Node* node() const { return ", |
| 833 | output_names[0], ".node(); }\n"); |
| 834 | } |
| 835 | } |
| 836 | // Add the static functions to set optional attrs |
| 837 | if (has_optional_attrs) { |
| 838 | strings::StrAppend(&class_decl, "\n"); |
| 839 | for (int i = 0; i < graph_op_def.attr_size(); ++i) { |
| 840 | const auto& attr(graph_op_def.attr(i)); |
| 841 | const auto& api_def_attr(api_def.attr(i)); |
| 842 | if ((inferred_input_attrs.find(attr.name()) != |
| 843 | inferred_input_attrs.end()) || |
| 844 | !api_def_attr.has_default_value()) { |
| 845 | continue; |
| 846 | } |
| 847 | const auto entry = AttrTypeName(attr.type()); |
| 848 | const auto attr_type_name = entry.first; |
| 849 | const bool use_const = entry.second; |
| 850 | const string camel_case_name = ToCamelCase(api_def_attr.rename_to()); |
| 851 | const string suffix = |
no test coverage detected