summaryrefslogtreecommitdiff
path: root/src/bin/eolian_mono/eolian/mono/alias_definition.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/eolian_mono/eolian/mono/alias_definition.hh')
-rw-r--r--src/bin/eolian_mono/eolian/mono/alias_definition.hh103
1 files changed, 99 insertions, 4 deletions
diff --git a/src/bin/eolian_mono/eolian/mono/alias_definition.hh b/src/bin/eolian_mono/eolian/mono/alias_definition.hh
index 5d275a3..d7fda07 100644
--- a/src/bin/eolian_mono/eolian/mono/alias_definition.hh
+++ b/src/bin/eolian_mono/eolian/mono/alias_definition.hh
@@ -1,3 +1,18 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#ifndef EOLIAN_MONO_ALIAS_DEFINITION_HH 16#ifndef EOLIAN_MONO_ALIAS_DEFINITION_HH
2#define EOLIAN_MONO_ALIAS_DEFINITION_HH 17#define EOLIAN_MONO_ALIAS_DEFINITION_HH
3 18
@@ -41,14 +56,20 @@ struct alias_definition_generator
41 alias_type_doc = utils::replace_all(alias_type, "<", "&lt;"); 56 alias_type_doc = utils::replace_all(alias_type, "<", "&lt;");
42 alias_type_doc = utils::replace_all(alias_type_doc, ">", "&gt;"); 57 alias_type_doc = utils::replace_all(alias_type_doc, ">", "&gt;");
43 58
59 std::string alias_since;
60 if (!documentation_helpers::generate_since_tag_line(std::back_inserter(alias_since), alias.documentation, scope_tab, context))
61 return false;
62
44 std::string const alias_name = utils::remove_all(alias.eolian_name, '_'); 63 std::string const alias_name = utils::remove_all(alias.eolian_name, '_');
45 if (!as_generator( 64 if (!as_generator(
46 documentation 65 documentation
47 << "public struct " << alias_name << "\n" 66 << "public struct " << alias_name << " : IEquatable<" << alias_name << ">\n"
48 << "{\n" 67 << "{\n"
49 << scope_tab << "private " << alias_type << " payload;\n\n" 68 << scope_tab << "private " << alias_type << " payload;\n\n"
50 69
51 << scope_tab << "/// <summary>Converts an instance of " << alias_type_doc << " to this struct.</summary>\n" 70 << scope_tab << "/// <summary>Converts an instance of " << alias_type_doc << " to this struct.\n"
71 << alias_since
72 << scope_tab << "/// </summary>\n"
52 << scope_tab << "/// <param name=\"value\">The value to be converted.</param>\n" 73 << scope_tab << "/// <param name=\"value\">The value to be converted.</param>\n"
53 << scope_tab << "/// <returns>A struct with the given value.</returns>\n" 74 << scope_tab << "/// <returns>A struct with the given value.</returns>\n"
54 << scope_tab << "public static implicit operator " << alias_name << "(" << alias_type << " value)\n" 75 << scope_tab << "public static implicit operator " << alias_name << "(" << alias_type << " value)\n"
@@ -56,14 +77,88 @@ struct alias_definition_generator
56 << scope_tab << scope_tab << "return new " << alias_name << "{payload=value};\n" 77 << scope_tab << scope_tab << "return new " << alias_name << "{payload=value};\n"
57 << scope_tab << "}\n\n" 78 << scope_tab << "}\n\n"
58 79
59 << scope_tab << "/// <summary>Converts an instance of this struct to " << alias_type_doc << ".</summary>\n" 80 << scope_tab << "/// <summary>Converts an instance of this struct to " << alias_type_doc << ".\n"
81 << alias_since
82 << scope_tab << "/// </summary>\n"
60 << scope_tab << "/// <param name=\"value\">The value to be converted packed in this struct.</param>\n" 83 << scope_tab << "/// <param name=\"value\">The value to be converted packed in this struct.</param>\n"
61 << scope_tab << "/// <returns>The actual value the alias is wrapping.</returns>\n" 84 << scope_tab << "/// <returns>The actual value the alias is wrapping.</returns>\n"
62 << scope_tab << "public static implicit operator " << alias_type << "(" << alias_name << " value)\n" 85 << scope_tab << "public static implicit operator " << alias_type << "(" << alias_name << " value)\n"
63 << scope_tab << "{\n" 86 << scope_tab << "{\n"
64 << scope_tab << scope_tab << "return value.payload;\n" 87 << scope_tab << scope_tab << "return value.payload;\n"
65 << scope_tab << "}\n" 88 << scope_tab << "}\n"
66 << "}\n" 89
90 << scope_tab << "/// <summary>Converts an instance of " << alias_type_doc << " to this struct.</summary>\n"
91 << scope_tab << "/// <param name=\"value\">The value to be converted.</param>\n"
92 << scope_tab << "/// <returns>A struct with the given value.</returns>\n"
93 << scope_tab << "public static " << alias_name << " From" << name_helpers::translate_value_type(alias_type) << "(" << alias_type << " value)\n"
94 << scope_tab << "{\n"
95 << scope_tab << scope_tab << "return value;\n"
96 << scope_tab << "}\n\n"
97
98 << scope_tab << "/// <summary>Converts an instance of this struct to " << alias_type_doc << ".</summary>\n"
99 << scope_tab << "/// <returns>The actual value the alias is wrapping.</returns>\n"
100 << scope_tab << "public " << alias_type << " To" << name_helpers::translate_value_type(alias_type) << "()\n"
101 << scope_tab << "{\n"
102 << scope_tab << scope_tab << "return this;\n"
103 << scope_tab << "}\n"
104 ).generate(sink, alias, context))
105 return false;
106
107 std::string since_line;
108 if (!alias.documentation.since.empty())
109 if (!as_generator(scope_tab << "/// <para>Since EFL " + alias.documentation.since + ".</para>\n"
110 ).generate(std::back_inserter(since_line), attributes::unused, context))
111 return false;
112
113 // GetHashCode (needed by the equality comparisons)
114 if (!as_generator(
115 scope_tab << "/// <summary>Get a hash code for this item.\n"
116 << since_line
117 << scope_tab << "/// </summary>\n"
118 << scope_tab << "public override int GetHashCode() => payload.GetHashCode();\n"
119 ).generate(sink, attributes::unused, context))
120 return false;
121
122 // IEquatble<T> Equals
123 if (!as_generator(
124 scope_tab << "/// <summary>Equality comparison.\n"
125 << since_line
126 << scope_tab << "/// </summary>\n"
127 << scope_tab << "public bool Equals(" << alias_name << " other) => payload == other.payload;\n"
128 ).generate(sink, attributes::unused, context))
129 return false;
130
131 // ValueType.Equals
132 if (!as_generator(
133 scope_tab << "/// <summary>Equality comparison.\n"
134 << since_line
135 << scope_tab << "/// </summary>\n"
136 << scope_tab << "public override bool Equals(object other)\n"
137 << scope_tab << scope_tab << "=> ((other is " << alias_name << ") ? Equals((" << alias_name << ")other) : false);\n"
138 ).generate(sink, attributes::unused, context))
139 return false;
140
141 // Equality operators
142 if (!as_generator(
143 scope_tab << "/// <summary>Equality comparison.\n"
144 << since_line
145 << scope_tab << "/// </summary>\n"
146 << scope_tab << "public static bool operator ==(" << alias_name << " lhs, " << alias_name << " rhs)\n"
147 << scope_tab << scope_tab << "=> lhs.payload == rhs.payload;\n"
148 ).generate(sink, attributes::unused, context))
149 return false;
150
151 if (!as_generator(
152 scope_tab << "/// <summary>Equality comparison.\n"
153 << since_line
154 << scope_tab << "/// </summary>\n"
155 << scope_tab << "public static bool operator !=(" << alias_name << " lhs, " << alias_name << " rhs)\n"
156 << scope_tab << scope_tab << "=> lhs.payload != rhs.payload;\n"
157 ).generate(sink, attributes::unused, context))
158 return false;
159
160 if (!as_generator(
161 "}\n"
67 ).generate(sink, alias, context)) 162 ).generate(sink, alias, context))
68 return false; 163 return false;
69 164