Skip to content

Commit

Permalink
deploy: e6da400
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe committed Feb 17, 2024
1 parent 8e3e9a0 commit 0fb23d4
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/melior_macro/dialect/generation.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
<span class="kw">let </span>attribute_accessors = operation
.attributes()
.map(generate_attribute_accessors)
.collect::&lt;<span class="prelude-ty">Result</span>&lt;Vec&lt;<span class="kw">_</span>&gt;, <span class="kw">_</span>&gt;&gt;()<span class="question-mark">?</span>;
.collect::&lt;Vec&lt;<span class="kw">_</span>&gt;&gt;();

<span class="kw">let </span>builder = OperationBuilder::new(operation)<span class="question-mark">?</span>;
<span class="kw">let </span>builder_tokens = generate_operation_builder(<span class="kw-2">&amp;</span>builder)<span class="question-mark">?</span>;
Expand Down
48 changes: 20 additions & 28 deletions src/melior_macro/dialect/generation/attribute_accessor.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,31 +76,23 @@
<a href="#75" id="75">75</a>
<a href="#76" id="76">76</a>
<a href="#77" id="77">77</a>
<a href="#78" id="78">78</a>
<a href="#79" id="79">79</a>
<a href="#80" id="80">80</a>
<a href="#81" id="81">81</a>
</pre></div><pre class="rust"><code><span class="kw">use </span><span class="kw">crate</span>::dialect::{
error::Error,
operation::{Attribute, OperationField},
utility::sanitize_snake_case_identifier,
};
</pre></div><pre class="rust"><code><span class="kw">use </span><span class="kw">crate</span>::dialect::operation::{Attribute, OperationField};
<span class="kw">use </span>proc_macro2::TokenStream;
<span class="kw">use </span>quote::quote;

<span class="kw">pub fn </span>generate_attribute_accessors(attribute: <span class="kw-2">&amp;</span>Attribute) -&gt; <span class="prelude-ty">Result</span>&lt;TokenStream, Error&gt; {
<span class="kw">let </span>getter = generate_getter(attribute)<span class="question-mark">?</span>;
<span class="kw">let </span>setter = generate_setter(attribute)<span class="question-mark">?</span>;
<span class="kw">let </span>remover = generate_remover(attribute)<span class="question-mark">?</span>;
<span class="kw">pub fn </span>generate_attribute_accessors(attribute: <span class="kw-2">&amp;</span>Attribute) -&gt; TokenStream {
<span class="kw">let </span>getter = generate_getter(attribute);
<span class="kw">let </span>setter = generate_setter(attribute);
<span class="kw">let </span>remover = generate_remover(attribute);

<span class="prelude-val">Ok</span>(<span class="macro">quote! </span>{
<span class="macro">quote! </span>{
#getter
#setter
#remover
})
}
}

<span class="kw">fn </span>generate_getter(attribute: <span class="kw-2">&amp;</span>Attribute) -&gt; <span class="prelude-ty">Result</span>&lt;TokenStream, Error&gt; {
<span class="kw">fn </span>generate_getter(attribute: <span class="kw-2">&amp;</span>Attribute) -&gt; TokenStream {
<span class="kw">let </span>name = attribute.name();

<span class="kw">let </span>identifier = attribute.singular_identifier();
Expand All @@ -112,15 +104,15 @@
</span><span class="macro">quote! </span>{ <span class="prelude-val">Ok</span>(<span class="self">self</span>.operation.attribute(#name)<span class="question-mark">?</span>.try_into()<span class="question-mark">?</span>) }
};

<span class="prelude-val">Ok</span>(<span class="macro">quote! </span>{
<span class="macro">quote! </span>{
<span class="attr">#[allow(clippy::needless_question_mark)]
</span><span class="kw">pub fn </span>#identifier(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; #return_type {
#body
}
})
}
}

<span class="kw">fn </span>generate_setter(attribute: <span class="kw-2">&amp;</span>Attribute) -&gt; <span class="prelude-ty">Result</span>&lt;TokenStream, Error&gt; {
<span class="kw">fn </span>generate_setter(attribute: <span class="kw-2">&amp;</span>Attribute) -&gt; TokenStream {
<span class="kw">let </span>name = attribute.name();

<span class="kw">let </span>body = <span class="kw">if </span>attribute.is_unit() {
Expand All @@ -137,28 +129,28 @@
}
};

<span class="kw">let </span>ident = sanitize_snake_case_identifier(<span class="kw-2">&amp;</span><span class="macro">format!</span>(<span class="string">"set_{}"</span>, attribute.name()))<span class="question-mark">?</span>;
<span class="kw">let </span>identifier = attribute.set_identifier();
<span class="kw">let </span>r#type = attribute.parameter_type();

<span class="prelude-val">Ok</span>(<span class="macro">quote! </span>{
<span class="kw">pub fn </span>#ident(<span class="kw-2">&amp;mut </span><span class="self">self</span>, context: <span class="kw-2">&amp;</span><span class="lifetime">'c </span>::melior::Context, value: #r#type) {
<span class="macro">quote! </span>{
<span class="kw">pub fn </span>#identifier(<span class="kw-2">&amp;mut </span><span class="self">self</span>, context: <span class="kw-2">&amp;</span><span class="lifetime">'c </span>::melior::Context, value: #r#type) {
#body
}
})
}
}

<span class="kw">fn </span>generate_remover(attribute: <span class="kw-2">&amp;</span>Attribute) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="prelude-ty">Option</span>&lt;TokenStream&gt;, Error&gt; {
<span class="prelude-val">Ok</span>(<span class="kw">if </span>attribute.is_unit() || attribute.is_optional() {
<span class="kw">fn </span>generate_remover(attribute: <span class="kw-2">&amp;</span>Attribute) -&gt; <span class="prelude-ty">Option</span>&lt;TokenStream&gt; {
<span class="kw">if </span>attribute.is_unit() || attribute.is_optional() {
<span class="kw">let </span>name = attribute.name();
<span class="kw">let </span>ident = sanitize_snake_case_identifier(<span class="kw-2">&amp;</span><span class="macro">format!</span>(<span class="string">"remove_{}"</span>, attribute.name()))<span class="question-mark">?</span>;
<span class="kw">let </span>identifier = attribute.remove_identifier();

<span class="prelude-val">Some</span>(<span class="macro">quote! </span>{
<span class="kw">pub fn </span>#ident(<span class="kw-2">&amp;mut </span><span class="self">self</span>, context: <span class="kw-2">&amp;</span><span class="lifetime">'c </span>::melior::Context) -&gt; <span class="prelude-ty">Result</span>&lt;(), ::melior::Error&gt; {
<span class="kw">pub fn </span>#identifier(<span class="kw-2">&amp;mut </span><span class="self">self</span>, context: <span class="kw-2">&amp;</span><span class="lifetime">'c </span>::melior::Context) -&gt; <span class="prelude-ty">Result</span>&lt;(), ::melior::Error&gt; {
<span class="self">self</span>.operation.remove_attribute(#name)
}
})
} <span class="kw">else </span>{
<span class="prelude-val">None
</span>})
</span>}
}
</code></pre></div></section></main></body></html>
24 changes: 24 additions & 0 deletions src/melior_macro/dialect/operation/attribute.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,18 @@
<a href="#158" id="158">158</a>
<a href="#159" id="159">159</a>
<a href="#160" id="160">160</a>
<a href="#161" id="161">161</a>
<a href="#162" id="162">162</a>
<a href="#163" id="163">163</a>
<a href="#164" id="164">164</a>
<a href="#165" id="165">165</a>
<a href="#166" id="166">166</a>
<a href="#167" id="167">167</a>
<a href="#168" id="168">168</a>
<a href="#169" id="169">169</a>
<a href="#170" id="170">170</a>
<a href="#171" id="171">171</a>
<a href="#172" id="172">172</a>
</pre></div><pre class="rust"><code><span class="kw">use </span><span class="kw">crate</span>::dialect::{
error::Error,
operation::operation_field::OperationField,
Expand Down Expand Up @@ -223,6 +235,8 @@
name: <span class="kw-2">&amp;</span><span class="lifetime">'a </span>str,
singular_identifier: Ident,
storage_type_string: String,
set_identifier: Ident,
remove_identifier: Ident,
storage_type: Type,
optional: bool,
default: bool,
Expand All @@ -235,6 +249,8 @@
<span class="prelude-val">Ok</span>(<span class="self">Self </span>{
name,
singular_identifier: sanitize_snake_case_identifier(name)<span class="question-mark">?</span>,
set_identifier: sanitize_snake_case_identifier(<span class="kw-2">&amp;</span><span class="macro">format!</span>(<span class="string">"set_{name}"</span>))<span class="question-mark">?</span>,
remove_identifier: sanitize_snake_case_identifier(<span class="kw-2">&amp;</span><span class="macro">format!</span>(<span class="string">"remove_{name}"</span>))<span class="question-mark">?</span>,
storage_type: syn::parse_str(
ATTRIBUTE_TYPES
.get(storage_type_string.trim())
Expand All @@ -257,6 +273,14 @@
})
}

<span class="kw">pub fn </span>set_identifier(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>Ident {
<span class="kw-2">&amp;</span><span class="self">self</span>.set_identifier
}

<span class="kw">pub fn </span>remove_identifier(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>Ident {
<span class="kw-2">&amp;</span><span class="self">self</span>.remove_identifier
}

<span class="kw">pub fn </span>is_optional(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; bool {
<span class="self">self</span>.optional
}
Expand Down

0 comments on commit 0fb23d4

Please sign in to comment.