Skip to content

Commit

Permalink
[C2HEXA] Detect NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
PeyTy committed Jul 20, 2024
1 parent 566bdd2 commit bfafca6
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions source/toHexa/clang/clangGenerator.hexa
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,21 @@ class ClangGenerator {
return nodeToNode(node.inner[0])
case CStyleCastExpr:
// TODO "castKind": "BitCast"
return Node.Parenthesis(Node.As(nodeToNode(node.inner[0]), Token.KNot, typeToType(node.type)))
let e = nodeToNode(node.inner[0])
let to = typeToType(node.type)

switch e {
case Int(value): if value == 0 {
switch to {
case ParametricType(name, params):
if name == 'ArrayPointer' {
return Node.Null
}
}
}
}

return Node.Parenthesis(Node.As(e, Token.KNot, to))
case DeclRefExpr:
if let referencedDecl = node.referencedDecl {
return Node.Ident(toCamelCase(referencedDecl.name), null)
Expand Down Expand Up @@ -750,7 +764,7 @@ class ClangGenerator {

fun stringifyWithoutDecorators(node Node?) String {
switch node {
case Bool(b): return b? "true" : "false"
case Bool(b): return b ? "true": "false"
case String(s): return JSON.stringify(s)
case Ident(name, params):
// TODO generate in parser `if let x {}` form bruh
Expand Down

0 comments on commit bfafca6

Please sign in to comment.