Transpile predefined functions to an `Expr`
@@ -50,29 +50,28 @@ func transpileCharacterLiteral(n *ast.CharacterLiteral) *goast.BasicLit {
}
}
-func transpilePredefinedExpr(n *ast.PredefinedExpr, p *program.Program) (*goast.BasicLit, string, error) {
+func transpilePredefinedExpr(n *ast.PredefinedExpr, p *program.Program) (goast.Expr, string, error) {
// A predefined expression is a literal that is not given a value until
// compile time.
//
// TODO: Predefined expressions are not evaluated
// https://github.com/elliotchance/c2go/issues/81
- var value string
-
switch n.Name {
case "__PRETTY_FUNCTION__":
- value = "[]byte(\"void print_number(int *)\")"
+ return util.NewCallExpr(
+ "[]byte",
+ util.NewStringLit(`"void print_number(int *)"`),
+ ), "const char*", nil
case "__func__":
- value = fmt.Sprintf("[]byte(\"%s\")", p.Function.Name)
+ return util.NewCallExpr(
+ "[]byte",
+ util.NewStringLit(strconv.Quote(p.Function.Name)),
+ ), "const char*", nil
default:
// There are many more.
panic(fmt.Sprintf("unknown PredefinedExpr: %s", n.Name))
}
-
- return &goast.BasicLit{
- Kind: token.STRING,
- Value: value,
- }, "const char*", nil
}
