; IR definitions and manipulation functions (in-package "VERRAZANO") ; base class for IR types (defclass annotable () ((notes :accessor annotable-notes :initform (make-hash-table)))) ; defines a node in the graph (defclass node (annotable) ((edges :accessor node-edges :initform nil) (mark :accessor node-mark :initform nil))) ; root of entire tree, defines root namespace (defclass library (node) ()) ; base type for all C++ types (defclass cpp-type (node) ((name :accessor cpp-type-name :initform nil))) ; definition for a namespace (defclass namespace-type (cpp-type) ()) ; definition for types like 'int' (defclass fundamental-type (cpp-type) ()) ; definition for a qualification of another type (defclass qualified-type (cpp-type) ((const :accessor qualified-type-const :initform nil))) ; definition for a pointer to another type (defclass pointer-type (cpp-type) ()) ; definition for an array of another type (defclass array-type (cpp-type) ((size :accessor array-type-size :initform 0))) ; definition for an enumeration type (defclass enum-type (cpp-type) ()) ; definition for structures (or classes) (defclass struct-type (cpp-type) ()) ; definition for unions (defclass union-type (cpp-type) ()) ; definition for classes (or structures) (defclass class-type (cpp-type) ()) ; definition for function prototypes (defclass function-type (cpp-type) ()) ; definition for aliases (defclass alias-type (cpp-type) ()) ; pseudo-type to indicate varargs (defclass ellipsis-type (cpp-type) ()) ; represents edges in the graph (defclass edge (annotable) ((target :accessor edge-target :initarg :target))) ; source returns object of type target (defclass returns (edge) ()) ; source receives object of type target as argument (defclass receives (edge) ((name :accessor receives-edge-name :initform nil) (value :accessor allocates-edge-value :initform nil))) ; source defines an object of type target (defclass defines (edge) ()) ; source allocates an object of type target (defclass allocates (edge) ((name :accessor allocates-edge-name :initform nil) (value :accessor allocates-edge-value :initform nil))) ; definition of source extends definition of target (defclass extends (edge) ()) ; unmark a graph (defun unmark-graph (node) (let ((seen (make-hash-table))) (unmark-graph-helper node seen))) ; helper function for unmarking a graph (defun unmark-graph-helper (node seen) (when (not (gethash node seen)) (unmark-node node) (setf (gethash node seen) t) (dolist (edge (node-edges node)) (unmark-graph-helper (edge-target edge) seen)))) ; mark a node as visited (defun mark-node (node) (setf (node-mark node) t)) ; unmark a node (defun unmark-node (node) (setf (node-mark node) nil)) ; add an edge to a node (defun add-edge (from edg) (push edg (slot-value from 'edges))) ; set a slot in an IR node (defun set-slot (irelt slot value &optional default) (let ((val (if value value default))) (when val (setf (slot-value irelt slot) val)))) ; set the annotation on an element (defun set-note (irelt name value &optional default) (let ((val (if value value default))) (when val (setf (gethash name (annotable-notes irelt)) val)))) ; get the annotation on an element (defun get-note (irelt name) (gethash name (annotable-notes irelt)))