Attribute codegen
This commit is contained in:
+29
-3
@@ -1,7 +1,7 @@
|
|||||||
use parser::ast::{
|
use parser::ast::{
|
||||||
BinaryOp, Block, Expression, IfStmt, Literal, Path, Postfix, Prefix, Statement, TopLevel,
|
Attribute, BinaryOp, Block, Expression, IfStmt, Literal, Path, Postfix, Prefix, Statement,
|
||||||
TopLevelKind, TypeExpr, TypeExprKind, TypePostfix, VarAssignStmt, VarDecl, VarDeclStmt,
|
TopLevel, TopLevelKind, TypeExpr, TypeExprKind, TypePostfix, VarAssignStmt, VarDecl,
|
||||||
WhileStmt,
|
VarDeclStmt, WhileStmt,
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -228,10 +228,36 @@ impl ToRust for Block {
|
|||||||
|
|
||||||
impl ToRust for TopLevel {
|
impl ToRust for TopLevel {
|
||||||
fn to_rust(&self, cg: &mut RustCodegen) {
|
fn to_rust(&self, cg: &mut RustCodegen) {
|
||||||
|
for attr in &self.1 {
|
||||||
|
cg.addln(&format!("#[{}]", attr.get_rust()));
|
||||||
|
}
|
||||||
|
|
||||||
self.0.to_rust(cg);
|
self.0.to_rust(cg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl GetRust for Attribute {
|
||||||
|
fn get_rust(&self) -> String {
|
||||||
|
match self {
|
||||||
|
Self::Path(path) => path.get_rust(),
|
||||||
|
Self::NameValue { path, value } => {
|
||||||
|
format!("{} = {}", path.get_rust(), value.get_rust())
|
||||||
|
}
|
||||||
|
Self::List { path, items } => {
|
||||||
|
format!(
|
||||||
|
"{}({})",
|
||||||
|
path.get_rust(),
|
||||||
|
items
|
||||||
|
.iter()
|
||||||
|
.map(Attribute::get_rust)
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(", ")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ToRust for TopLevelKind {
|
impl ToRust for TopLevelKind {
|
||||||
fn to_rust(&self, cg: &mut RustCodegen) {
|
fn to_rust(&self, cg: &mut RustCodegen) {
|
||||||
match self {
|
match self {
|
||||||
|
|||||||
@@ -3,3 +3,9 @@ public struct ApiCall {
|
|||||||
i32 x,
|
i32 x,
|
||||||
i32 y,
|
i32 y,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
ApiCall call = ApiCall { x: 10, y: 12 };
|
||||||
|
|
||||||
|
println!("{call:?}");
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user