-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackend-cxx-ast.rkt
68 lines (52 loc) · 1.86 KB
/
backend-cxx-ast.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#lang racket/base
#|
|#
(require "ir-ast.rkt"
"ast-repr.rkt"
"util.rkt")
;;;
;;; type expressions
;;;
(define-ast* ConstT (Ast Type)
((#:none annos) (#:just t)))
(define-ast* RefT (Ast Type)
((#:none annos) (#:just t)))
;;;
;;; declarations and directives
;;;
;; kind is either 'user or 'system.
(define-ast* Include (Ast) ((#:none annos) (#:none kind) (#:none s)))
;; `rtype` is the return type, only. `s` is the body statement, which
;; should be a `SeqStat` for printing, or it can be `NoBody` also.
(define-ast* CxxDefun (Ast Def) ((#:none annos) (#:none id)
(#:none modifs) (#:just rtype)
(#:many params) (#:just s)))
;; A C++ function prototype declaration. No body, and some modifiers
;; may have to be different compared to the function definition.
(define-ast* Proto (Ast Def) ((#:none annos) (#:none id)
(#:none modifs) (#:just rtype)
(#:many params)))
;; Top-level verbatim string.
(define-ast* TlVerbatim (Ast)
((#:none annos) (#:none s)))
;;;
;;; statements
;;;
(define-ast* ReturnStat (Ast Stat)
((#:none annos) (#:just e)))
;;;
;;; expressions
;;;
;; An expression whose value is given by variable `id`, and assigned
;; to by the statement sequence `ss`, except where the expression has
;; unit type. The variable will be automatically declared upon
;; lifting, and the statements will be lifted to a suitable context.
;; The result should always get assigned to by the statements, at
;; least if the lifted expression is ever to be evaluated.
(define-ast* LiftStatExpr (Ast Expr SeqCont)
((#:none annos) (#:none id) (#:many ss)))
;; Parenthesized expression. For pretty printing only.
(define-ast* Parens (Expr Ast)
((#:none annos) (#:just e)))
(define-ast* VoidCast (Expr Ast)
((#:none annos) (#:just e)))