Removed comment mapping completely

This commit is contained in:
2026-06-20 19:21:10 +02:00
parent 0dd1016980
commit 8f115353bb
4 changed files with 22 additions and 23 deletions
+7 -11
View File
@@ -2,7 +2,7 @@ use std::collections::HashMap;
use mist_parser::ast::*;
use crate::{Context, GenRust, GetRust, RustCodegen};
use crate::{Context, GenRust, GenSpanTranslation, GetRust, RustCodegen};
pub struct ClassProcessedData {
visibility: Visibility,
@@ -117,7 +117,7 @@ impl ClassProcessedData {
}
for field in &self.fields {
cg.add_indentedln(&field.get_comment());
field.gen_span(cg);
cg.add_indentedln(&field.item.decl.get_rust());
}
@@ -269,7 +269,7 @@ impl ClassProcessedData {
}
if let TypeExpr::Ref { mutable, .. } = params.remove(0) {
cg.add_indentedln(&method.get_comment());
method.gen_span(cg);
cg.add_indented(&format!("{}::__m_", target_rust_path));
cg.add(&method.item.name.get_rust());
cg.add(" as ");
@@ -302,7 +302,7 @@ impl ClassProcessedData {
for (override_tier, v) in &self.override_v_table {
if let Some(path) = &override_tier.0 {
cg.add_indentedln(&v.get_comment());
v.gen_span(cg);
// This forces the compiler to statically verify that &Self can Deref into &Target
cg.add_indentedln(&format!("let _: &{} = this;", path.get_rust()));
}
@@ -319,10 +319,8 @@ impl ClassProcessedData {
ctx: &mut Context,
cg: &mut RustCodegen,
) {
let constructor_comment = constructor.get_comment();
cg.add_indentedln("#[allow(invalid_value)]");
cg.add_indentedln(&constructor_comment);
constructor.gen_span(cg);
cg.add_indented(&format!(
"{}fn new{}(",
@@ -357,10 +355,8 @@ impl ClassProcessedData {
cg.add_indentedln("this._vptr = &Self::__V_TABLE;");
for field in &self.fields {
let comment = field.get_comment();
if let Some(init) = &field.item.init {
cg.add_indentedln(&comment);
field.gen_span(cg);
cg.add_indentedln(&format!("this.{} = ", field.item.decl.name.get_rust()));
init.gen_rust(ctx, cg);
}
@@ -378,7 +374,7 @@ impl ClassProcessedData {
cg.add_indentedln("this._vptr = &Self::__V_TABLE;");
cg.add_indentedln(&constructor_comment);
constructor.gen_span(cg);
cg.add_indentedln("this");
cg.indent -= 1;
+13 -4
View File
@@ -142,6 +142,18 @@ impl GenRust for Attribute {
}
}
pub trait GenSpanTranslation {
fn gen_span(&self, _cg: &mut RustCodegen);
}
impl<T> GenSpanTranslation for Spanned<T> {
fn gen_span(&self, cg: &mut RustCodegen) {
cg.mapping
.map
.insert((cg.position, MistMap(self.line, self.column)));
}
}
impl<T: GetRust> GenRust for T {
fn gen_rust(&self, _: &mut Context, cg: &mut RustCodegen) {
cg.add(&self.get_rust());
@@ -150,10 +162,7 @@ impl<T: GetRust> GenRust for T {
impl<T: GenRust> GenRust for Spanned<T> {
fn gen_rust(&self, ctx: &mut Context, cg: &mut RustCodegen) {
cg.mapping
.map
.insert((cg.position, MistMap(self.line, self.column)));
self.gen_span(cg);
self.item.gen_rust(ctx, cg);
}
}
+2 -2
View File
@@ -1,6 +1,6 @@
use mist_parser::ast::*;
use crate::Context;
use crate::{Context, GenSpanTranslation};
use crate::{GenRust, GetRust, RustCodegen};
@@ -55,7 +55,7 @@ impl GenRust for Statement {
cg.indent += 1;
for match_item in match_items {
cg.add_indentedln(&match_item.get_comment());
match_item.gen_span(cg);
let MatchItem(pat, body) = &match_item.item;