Skip to content

Commit

Permalink
deploy: 026e2be
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe committed Feb 15, 2024
1 parent 4b599dc commit 902dc09
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 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 @@ -105,7 +105,7 @@
.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>;

<span class="kw">let </span>builder = OperationBuilder::new(operation);
<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>;
<span class="kw">let </span>builder_fn = builder.create_op_builder_fn()<span class="question-mark">?</span>;
<span class="kw">let </span>default_constructor = builder.create_default_constructor()<span class="question-mark">?</span>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<span class="kw">let </span>new = builder.create_new_fn(phantom_arguments.as_slice())<span class="question-mark">?</span>;
<span class="kw">let </span>build = builder.create_build_fn()<span class="question-mark">?</span>;

<span class="kw">let </span>builder_identifier = builder.builder_identifier()<span class="question-mark">?</span>;
<span class="kw">let </span>builder_identifier = builder.identifier();
<span class="kw">let </span>doc = <span class="macro">format!</span>(<span class="string">"Builder for {}"</span>, builder.operation().summary()<span class="question-mark">?</span>);
<span class="kw">let </span>iter_arguments = builder.type_state().parameters();

Expand Down
26 changes: 14 additions & 12 deletions src/melior_macro/dialect/operation/builder.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
<a href="#187" id="187">187</a>
<a href="#188" id="188">188</a>
<a href="#189" id="189">189</a>
<a href="#190" id="190">190</a>
</pre></div><pre class="rust"><code><span class="kw">mod </span>type_state_item;
<span class="kw">mod </span>type_state_list;

Expand All @@ -202,21 +203,27 @@

<span class="kw">pub struct </span>OperationBuilder&lt;<span class="lifetime">'o</span>&gt; {
operation: <span class="kw-2">&amp;</span><span class="lifetime">'o </span>Operation&lt;<span class="lifetime">'o</span>&gt;,
identifier: Ident,
type_state: TypeStateList,
}

<span class="kw">impl</span>&lt;<span class="lifetime">'o</span>&gt; OperationBuilder&lt;<span class="lifetime">'o</span>&gt; {
<span class="kw">pub fn </span>new(operation: <span class="kw-2">&amp;</span><span class="lifetime">'o </span>Operation&lt;<span class="lifetime">'o</span>&gt;) -&gt; <span class="self">Self </span>{
<span class="self">Self </span>{
<span class="kw">pub fn </span>new(operation: <span class="kw-2">&amp;</span><span class="lifetime">'o </span>Operation&lt;<span class="lifetime">'o</span>&gt;) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="self">Self</span>, Error&gt; {
<span class="prelude-val">Ok</span>(<span class="self">Self </span>{
operation,
identifier: <span class="macro">format_ident!</span>(<span class="string">"{}Builder"</span>, operation.class_name()<span class="question-mark">?</span>),
type_state: <span class="self">Self</span>::create_type_state(operation),
}
})
}

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

<span class="kw">pub fn </span>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>.identifier
}

<span class="kw">pub fn </span>type_state(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="kw-2">&amp;</span>TypeStateList {
<span class="kw-2">&amp;</span><span class="self">self</span>.type_state
}
Expand All @@ -227,8 +234,7 @@
phantoms: <span class="kw-2">&amp;</span><span class="lifetime">'a </span>[TokenStream],
) -&gt; <span class="kw">impl </span>Iterator&lt;Item = <span class="prelude-ty">Result</span>&lt;TokenStream, Error&gt;&gt; + <span class="lifetime">'a </span>{
<span class="self">self</span>.operation.fields().map(<span class="kw">move </span>|field| {
<span class="comment">// TODO Initialize a builder identifier out of this closure.
</span><span class="kw">let </span>builder_ident = <span class="self">self</span>.builder_identifier()<span class="question-mark">?</span>;
<span class="kw">let </span>builder_ident = <span class="self">self</span>.identifier();
<span class="kw">let </span>name = sanitize_snake_case_name(field.name())<span class="question-mark">?</span>;
<span class="kw">let </span>parameter_type = field.parameter_type();
<span class="kw">let </span>argument = <span class="macro">quote! </span>{ #name: #parameter_type };
Expand Down Expand Up @@ -275,7 +281,7 @@
}

<span class="kw">pub fn </span>create_build_fn(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="prelude-ty">Result</span>&lt;TokenStream, Error&gt; {
<span class="kw">let </span>builder_ident = <span class="self">self</span>.builder_identifier()<span class="question-mark">?</span>;
<span class="kw">let </span>builder_ident = <span class="self">self</span>.identifier();
<span class="kw">let </span>arguments = <span class="self">self</span>.type_state.arguments_all_set(<span class="bool-val">true</span>);
<span class="kw">let </span>class_name = <span class="macro">format_ident!</span>(<span class="string">"{}"</span>, <span class="kw-2">&amp;</span><span class="self">self</span>.operation.class_name()<span class="question-mark">?</span>);
<span class="kw">let </span>error = <span class="macro">format!</span>(<span class="string">"should be a valid {class_name}"</span>);
Expand All @@ -294,7 +300,7 @@
}

<span class="kw">pub fn </span>create_new_fn(<span class="kw-2">&amp;</span><span class="self">self</span>, phantoms: <span class="kw-2">&amp;</span>[TokenStream]) -&gt; <span class="prelude-ty">Result</span>&lt;TokenStream, Error&gt; {
<span class="kw">let </span>builder_ident = <span class="self">self</span>.builder_identifier()<span class="question-mark">?</span>;
<span class="kw">let </span>builder_ident = <span class="self">self</span>.identifier();
<span class="kw">let </span>name = <span class="kw-2">&amp;</span><span class="self">self</span>.operation.full_name()<span class="question-mark">?</span>;
<span class="kw">let </span>arguments = <span class="self">self</span>.type_state.arguments_all_set(<span class="bool-val">false</span>);

Expand All @@ -312,7 +318,7 @@
}

<span class="kw">pub fn </span>create_op_builder_fn(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="prelude-ty">Result</span>&lt;TokenStream, Error&gt; {
<span class="kw">let </span>builder_ident = <span class="self">self</span>.builder_identifier()<span class="question-mark">?</span>;
<span class="kw">let </span>builder_ident = <span class="self">self</span>.identifier();
<span class="kw">let </span>arguments = <span class="self">self</span>.type_state.arguments_all_set(<span class="bool-val">false</span>);

<span class="prelude-val">Ok</span>(<span class="macro">quote! </span>{
Expand Down Expand Up @@ -372,9 +378,5 @@
.collect(),
)
}

<span class="kw">pub fn </span>builder_identifier(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; <span class="prelude-ty">Result</span>&lt;Ident, Error&gt; {
<span class="prelude-val">Ok</span>(<span class="macro">format_ident!</span>(<span class="string">"{}Builder"</span>, <span class="self">self</span>.operation.class_name()<span class="question-mark">?</span>))
}
}
</code></pre></div></section></main></body></html>

0 comments on commit 902dc09

Please sign in to comment.