Skip to content

Commit

Permalink
Removing whitespace for C/CPP codegen
Browse files Browse the repository at this point in the history
Signed-off-by: jongyong <[email protected]>
  • Loading branch information
quic-jongyong committed Sep 11, 2024
1 parent 03496de commit 033ff24
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 104 deletions.
13 changes: 7 additions & 6 deletions idlc_codegen/src/documentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ impl Documentation {
Some('*') => {
// User needs asterisk to be the first alignment so lets
// substitute it with a space
documentation.push(' ');
documentation.push_str(&docstring[1..]);
if !docstring[1..].is_empty() {
documentation.push(' ');
documentation.push_str(&docstring[1..]);
}
}
Some(_) => {
// User probably means to keep this content in there, pad it
Expand All @@ -88,7 +90,6 @@ impl Documentation {
}
None => {}
}

documentation.push('\n');
}
documentation.push_str(style.end());
Expand Down Expand Up @@ -132,7 +133,7 @@ starts with nothing
/// b
/// c
/// starts with nothing
///
///
///</pre>"
);
}
Expand All @@ -155,7 +156,7 @@ starts with nothing
* b
* c
* starts with nothing
*
*
*/"
);
}
Expand All @@ -179,7 +180,7 @@ starts with nothing
* b
* c
* starts with nothing
*
*
*/"
);
}
Expand Down
38 changes: 19 additions & 19 deletions idlc_codegen_c/src/interface/functions/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl idlc_codegen::functions::ParameterVisitor for Implementation {
let bi_embedded = packer.bi_embedded();
self.initializations.push(format!(
r#"{definition} i;
{0}{1}"#,
{0}{1}"#,
bi_embedded,
packer.bi_assignments(),
));
Expand Down Expand Up @@ -187,8 +187,8 @@ impl idlc_codegen::functions::ParameterVisitor for Implementation {
let name = format!("{}_ptr", ident);
let ty = change_primitive(ty);
self.post_call.push(format!(
r#"*{ident}_lenout = {ARGS}[{idx}].b.size / sizeof({ty});
"#
r#"
*{ident}_lenout = {ARGS}[{idx}].b.size / sizeof({ty});"#
));
self.args.push(format!(
r#"
Expand All @@ -201,8 +201,8 @@ impl idlc_codegen::functions::ParameterVisitor for Implementation {
let name = format!("{}_ptr", ident);
let ty = ty.ident.to_string();
self.post_call.push(format!(
r#"*{ident}_lenout = {ARGS}[{idx}].b.size / sizeof({ty});
"#
r#"
*{ident}_lenout = {ARGS}[{idx}].b.size / sizeof({ty});"#
));
self.args.push(format!(
r#"
Expand All @@ -224,8 +224,8 @@ impl idlc_codegen::functions::ParameterVisitor for Implementation {
.to_string(),
);
self.post_call.push(format!(
r#"(*{ident}_ptr)[{i}] = a[{idx}].o;
"#,
r#"
(*{ident}_ptr)[{i}] = a[{idx}].o;"#,
));
}
}
Expand Down Expand Up @@ -257,7 +257,7 @@ impl idlc_codegen::functions::ParameterVisitor for Implementation {

self.initializations.push(format!(
r#"{definition} o = {{{initialization}}};
"#
"#
));
self.post_call.push(packer.post_bo_assignments());
self.args.push(format!(
Expand Down Expand Up @@ -307,8 +307,8 @@ impl idlc_codegen::functions::ParameterVisitor for Implementation {
name = format!("*{name}");
}
self.post_call.push(format!(
r#"{name} = {ARGS}[{idx}].o;
"#
r#"
{name} = {ARGS}[{idx}].o;"#
));
self.args.push(
r#"
Expand Down Expand Up @@ -342,8 +342,7 @@ pub fn emit(
if total > 0 {
object_args = format!(
r#"ObjectArg a[] = {{{args}
}};
"#
}};"#
);
}

Expand All @@ -359,7 +358,7 @@ pub fn emit(
{documentation}
static inline int32_t {current_iface_ident}_{ident}(Object self{params})
{{
return Object_invoke(self, {iface_ident}_{OP}_{ident}, 0, 0);;
return Object_invoke(self, {iface_ident}_{OP}_{ident}, 0, 0);
}}
"#
);
Expand All @@ -370,28 +369,29 @@ static inline int32_t {current_iface_ident}_{ident}(Object self{params})
{documentation}
static inline int32_t {current_iface_ident}_{ident}(Object self{params})
{{
{0}{1}{2}int32_t result = {returns}
{3}
{0}{1}{2}
int32_t result = {returns}
{3}
return result;
}}
"#,
if !initializations.is_empty() {
format!("{initializations}\n ")
format!(" {initializations}\n")
} else {
"".to_string()
},
if !object_args.is_empty() {
format!("{object_args}\n ")
format!(" {object_args}\n")
} else {
"".to_string()
},
if !pre_call_assignments.is_empty() {
format!("{pre_call_assignments}\n ")
format!(" {pre_call_assignments}\n")
} else {
"".to_string()
},
if !post_call_assignments.is_empty() {
format!("{post_call_assignments} ")
post_call_assignments.to_string()
} else {
"".to_string()
}
Expand Down
4 changes: 2 additions & 2 deletions idlc_codegen_c/src/interface/functions/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl idlc_codegen::functions::ParameterVisitor for Invoke {
} else {
self.pre.push(format!(
r#" \
{CONST} {ty_ident} *{name} = ({CONST} {ty_ident}*){ARGS}[{idx}].b.ptr;"#
{CONST} {ty_ident} *{name} = ({CONST} {ty_ident}*){ARGS}[{idx}].b.ptr;"#
));
}
}
Expand Down Expand Up @@ -312,7 +312,7 @@ impl idlc_codegen::functions::ParameterVisitor for Invoke {
} else {
self.pre.push(format!(
r#" \
{ty_ident} *{name} = ({ty_ident}*){ARGS}[{idx}].b.ptr;"#
{ty_ident} *{name} = ({ty_ident}*){ARGS}[{idx}].b.ptr;"#
));
}
}
Expand Down
20 changes: 10 additions & 10 deletions idlc_codegen_c/src/interface/functions/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ impl<'a> PackedPrimitives<'a> {
self.0.inputs_by_idents().for_each(|(ident, ty)| match ty {
Type::Primitive(_) => {
assignments += &format!(
r#"i.m_{ident} = {ident}_val;
"#
r#"
i.m_{ident} = {ident}_val;"#
);
}
Type::SmallStruct(_s) => {
assignments += &format!(
r#"i.m_{ident} = *{ident}_ptr;
"#
r#"
i.m_{ident} = *{ident}_ptr;"#
);
}
});
Expand All @@ -63,8 +63,8 @@ impl<'a> PackedPrimitives<'a> {
let ty = s.ident.to_string();

assignments += &format!(
r#"{ty} {ident}_cpy = *{ident}_ptr;
"#
r#"
{ty} {ident}_cpy = *{ident}_ptr;"#
);
}
}
Expand All @@ -86,14 +86,14 @@ impl<'a> PackedPrimitives<'a> {
self.0.outputs_by_idents().for_each(|(ident, ty)| match ty {
Type::Primitive(_) => {
assignments += &format!(
r"*{ident}_ptr = o.m_{ident};
"
r"
*{ident}_ptr = o.m_{ident};"
);
}
Type::SmallStruct(_) => {
assignments += &format!(
r"*{ident}_ptr = o.m_{ident};
"
r"
*{ident}_ptr = o.m_{ident};"
);
}
});
Expand Down
48 changes: 24 additions & 24 deletions idlc_codegen_cpp/src/interface/functions/implementation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ impl idlc_codegen::functions::ParameterVisitor for Implementation {
let _idx = self.0.idx();
let bi_embedded = packer.bi_embedded();
self.0.initializations.push(format!(
r#"{definition} i;
{0}{1}"#,
r#"{definition} i;{0}{1}"#,
bi_embedded,
packer.bi_assignments(),
));
Expand All @@ -72,8 +71,8 @@ impl idlc_codegen::functions::ParameterVisitor for Implementation {
let ty_ident = ty.ident.to_string();
if ty.contains_interfaces() {
self.0.initializations.push(format!(
r#"{ty_ident} {ident}_cpy = {name};
"#
r#"
{ty_ident} {ident}_cpy = {name};"#
));
self.0.args.push(format!(
r#"{{.bi = ({OBJECTBUFIN}) {{ &{ident}_cpy, sizeof({ty_ident}) }} }},
Expand Down Expand Up @@ -152,9 +151,9 @@ impl idlc_codegen::functions::ParameterVisitor for Implementation {
}

self.0.post_call.push(format!(
r#"for(size_t arg_idx=0;arg_idx<{cnt};arg_idx++)
({ident}_ref)[arg_idx].consume(a[{idx}+arg_idx].o);
"#,
r#"
for(size_t arg_idx=0;arg_idx<{cnt};arg_idx++)
({ident}_ref)[arg_idx].consume(a[{idx}+arg_idx].o);"#,
));

for _ in 1..cnt.into() {
Expand Down Expand Up @@ -182,8 +181,8 @@ impl idlc_codegen::functions::ParameterVisitor for Implementation {
let _idx = self.0.idx();

self.0.initializations.push(format!(
r#"{definition} o = {{{initialization}}};
"#
r#"
{definition} o = {{{initialization}}};"#
));
self.0.args.push(format!(
r#"
Expand All @@ -210,8 +209,8 @@ impl idlc_codegen::functions::ParameterVisitor for Implementation {
.collect::<Vec<String>>()
.join(".");
self.0.initializations.push(format!(
r#"{name}.{path} = Object_NULL;
"#
r#"
{name}.{path} = Object_NULL;"#
));
self.visit_output_object(
&idlc_mir::Ident {
Expand All @@ -236,13 +235,13 @@ impl idlc_codegen::functions::ParameterVisitor for Implementation {
);
if ident.contains('.') || ident.contains("->") {
self.0.post_call.push(format!(
r#"{ident} = {ARGS}[{idx}].o;
"#
r#"
{ident} = {ARGS}[{idx}].o;"#
));
} else {
self.0.post_call.push(format!(
r#"{ident}.consume({ARGS}[{idx}].o);
"#
r#"
{ident}.consume({ARGS}[{idx}].o);"#
));
}
}
Expand Down Expand Up @@ -276,9 +275,9 @@ pub fn emit(

if total > 0 {
object_args = format!(
r#"ObjectArg a[] = {{{args}
}};
"#
r#"
ObjectArg a[] = {{{args}
}};"#
);
}

Expand All @@ -298,24 +297,25 @@ pub fn emit(
r#"
{documentation}
virtual int32_t {ident}({params}) {{
{0}{1}{2}int32_t result = {returns}
{0}{1}{2}
int32_t result = {returns}
if (Object_OK != result) {{ return result; }}
{post_call_assignments}
{post_call_assignments}
return result;
}}
"#,
"#,
if !initializations.is_empty() {
format!("{initializations}\n ")
format!(" {initializations}\n")
} else {
"".to_string()
},
if !object_args.is_empty() {
format!("{object_args}\n ")
format!("{object_args}\n")
} else {
"".to_string()
},
if !pre_call_assignments.is_empty() {
format!("{pre_call_assignments}\n ")
format!(" {pre_call_assignments}\n")
} else {
"".to_string()
},
Expand Down
Loading

0 comments on commit 033ff24

Please sign in to comment.