website

Website contents
git clone git://git.reagancfischer.dev/website.git
Log | Files | Refs

ast.html (93188B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta charset="utf-8">
      5 <title>AST code</title>
      6 <script>
      7 !function(){var q=null;window.PR_SHOULD_USE_CONTINUATION=!0;
      8 (function(){function R(a){function d(e){var b=e.charCodeAt(0);if(b!==92)return b;var a=e.charAt(1);return(b=r[a])?b:"0"<=a&&a<="7"?parseInt(e.substring(1),8):a==="u"||a==="x"?parseInt(e.substring(2),16):e.charCodeAt(1)}function g(e){if(e<32)return(e<16?"\\x0":"\\x")+e.toString(16);e=String.fromCharCode(e);return e==="\\"||e==="-"||e==="]"||e==="^"?"\\"+e:e}function b(e){var b=e.substring(1,e.length-1).match(/\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\[0-3][0-7]{0,2}|\\[0-7]{1,2}|\\[\S\s]|[^\\]/g),e=[],a=
      9 b[0]==="^",c=["["];a&&c.push("^");for(var a=a?1:0,f=b.length;a<f;++a){var h=b[a];if(/\\[bdsw]/i.test(h))c.push(h);else{var h=d(h),l;a+2<f&&"-"===b[a+1]?(l=d(b[a+2]),a+=2):l=h;e.push([h,l]);l<65||h>122||(l<65||h>90||e.push([Math.max(65,h)|32,Math.min(l,90)|32]),l<97||h>122||e.push([Math.max(97,h)&-33,Math.min(l,122)&-33]))}}e.sort(function(e,a){return e[0]-a[0]||a[1]-e[1]});b=[];f=[];for(a=0;a<e.length;++a)h=e[a],h[0]<=f[1]+1?f[1]=Math.max(f[1],h[1]):b.push(f=h);for(a=0;a<b.length;++a)h=b[a],c.push(g(h[0])),
     10 h[1]>h[0]&&(h[1]+1>h[0]&&c.push("-"),c.push(g(h[1])));c.push("]");return c.join("")}function s(e){for(var a=e.source.match(/\[(?:[^\\\] ]|\\[\S\s])*]|\\u[\dA-Fa-f]{4}|\\x[\dA-Fa-f]{2}|\\\d+|\\[^\dux]|\(\?[!:=]|[()^]|[^()[\\^]+/g),c=a.length,d=[],f=0,h=0;f<c;++f){var l=a[f];l==="("?++h:"\\"===l.charAt(0)&&(l=+l.substring(1))&&(l<=h?d[l]=-1:a[f]=g(l))}for(f=1;f<d.length;++f)-1===d[f]&&(d[f]=++x);for(h=f=0;f<c;++f)l=a[f],l==="("?(++h,d[h]||(a[f]="(?:")):"\\"===l.charAt(0)&&(l=+l.substring(1))&&l<=h&&
     11 (a[f]="\\"+d[l]);for(f=0;f<c;++f)"^"===a[f]&&"^"!==a[f+1]&&(a[f]="");if(e.ignoreCase&&m)for(f=0;f<c;++f)l=a[f],e=l.charAt(0),l.length>=2&&e==="["?a[f]=b(l):e!=="\\"&&(a[f]=l.replace(/[A-Za-z]/g,function(a){a=a.charCodeAt(0);return"["+String.fromCharCode(a&-33,a|32)+"]"}));return a.join("")}for(var x=0,m=!1,j=!1,k=0,c=a.length;k<c;++k){var i=a[k];if(i.ignoreCase)j=!0;else if(/[a-z]/i.test(i.source.replace(/\\u[\da-f]{4}|\\x[\da-f]{2}|\\[^UXux]/gi,""))){m=!0;j=!1;break}}for(var r={b:8,t:9,n:10,v:11,
     12 f:12,r:13},n=[],k=0,c=a.length;k<c;++k){i=a[k];if(i.global||i.multiline)throw Error(""+i);n.push("(?:"+s(i)+")")}return RegExp(n.join("|"),j?"gi":"g")}function S(a,d){function g(a){var c=a.nodeType;if(c==1){if(!b.test(a.className)){for(c=a.firstChild;c;c=c.nextSibling)g(c);c=a.nodeName.toLowerCase();if("br"===c||"li"===c)s[j]="\n",m[j<<1]=x++,m[j++<<1|1]=a}}else if(c==3||c==4)c=a.nodeValue,c.length&&(c=d?c.replace(/\r\n?/g,"\n"):c.replace(/[\t\n\r ]+/g," "),s[j]=c,m[j<<1]=x,x+=c.length,m[j++<<1|1]=
     13 a)}var b=/(?:^|\s)nocode(?:\s|$)/,s=[],x=0,m=[],j=0;g(a);return{a:s.join("").replace(/\n$/,""),d:m}}function H(a,d,g,b){d&&(a={a:d,e:a},g(a),b.push.apply(b,a.g))}function T(a){for(var d=void 0,g=a.firstChild;g;g=g.nextSibling)var b=g.nodeType,d=b===1?d?a:g:b===3?U.test(g.nodeValue)?a:d:d;return d===a?void 0:d}function D(a,d){function g(a){for(var j=a.e,k=[j,"pln"],c=0,i=a.a.match(s)||[],r={},n=0,e=i.length;n<e;++n){var z=i[n],w=r[z],t=void 0,f;if(typeof w==="string")f=!1;else{var h=b[z.charAt(0)];
     14 if(h)t=z.match(h[1]),w=h[0];else{for(f=0;f<x;++f)if(h=d[f],t=z.match(h[1])){w=h[0];break}t||(w="pln")}if((f=w.length>=5&&"lang-"===w.substring(0,5))&&!(t&&typeof t[1]==="string"))f=!1,w="src";f||(r[z]=w)}h=c;c+=z.length;if(f){f=t[1];var l=z.indexOf(f),B=l+f.length;t[2]&&(B=z.length-t[2].length,l=B-f.length);w=w.substring(5);H(j+h,z.substring(0,l),g,k);H(j+h+l,f,I(w,f),k);H(j+h+B,z.substring(B),g,k)}else k.push(j+h,w)}a.g=k}var b={},s;(function(){for(var g=a.concat(d),j=[],k={},c=0,i=g.length;c<i;++c){var r=
     15 g[c],n=r[3];if(n)for(var e=n.length;--e>=0;)b[n.charAt(e)]=r;r=r[1];n=""+r;k.hasOwnProperty(n)||(j.push(r),k[n]=q)}j.push(/[\S\s]/);s=R(j)})();var x=d.length;return g}function v(a){var d=[],g=[];a.tripleQuotedStrings?d.push(["str",/^(?:'''(?:[^'\\]|\\[\S\s]|''?(?=[^']))*(?:'''|$)|"""(?:[^"\\]|\\[\S\s]|""?(?=[^"]))*(?:"""|$)|'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$))/,q,"'\""]):a.multiLineStrings?d.push(["str",/^(?:'(?:[^'\\]|\\[\S\s])*(?:'|$)|"(?:[^"\\]|\\[\S\s])*(?:"|$)|`(?:[^\\`]|\\[\S\s])*(?:`|$))/,
     16 q,"'\"`"]):d.push(["str",/^(?:'(?:[^\n\r'\\]|\\.)*(?:'|$)|"(?:[^\n\r"\\]|\\.)*(?:"|$))/,q,"\"'"]);a.verbatimStrings&&g.push(["str",/^@"(?:[^"]|"")*(?:"|$)/,q]);var b=a.hashComments;b&&(a.cStyleComments?(b>1?d.push(["com",/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,q,"#"]):d.push(["com",/^#(?:(?:define|e(?:l|nd)if|else|error|ifn?def|include|line|pragma|undef|warning)\b|[^\n\r]*)/,q,"#"]),g.push(["str",/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h(?:h|pp|\+\+)?|[a-z]\w*)>/,q])):d.push(["com",
     17 /^#[^\n\r]*/,q,"#"]));a.cStyleComments&&(g.push(["com",/^\/\/[^\n\r]*/,q]),g.push(["com",/^\/\*[\S\s]*?(?:\*\/|$)/,q]));if(b=a.regexLiterals){var s=(b=b>1?"":"\n\r")?".":"[\\S\\s]";g.push(["lang-regex",RegExp("^(?:^^\\.?|[+-]|[!=]=?=?|\\#|%=?|&&?=?|\\(|\\*=?|[+\\-]=|->|\\/=?|::?|<<?=?|>>?>?=?|,|;|\\?|@|\\[|~|{|\\^\\^?=?|\\|\\|?=?|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*("+("/(?=[^/*"+b+"])(?:[^/\\x5B\\x5C"+b+"]|\\x5C"+s+"|\\x5B(?:[^\\x5C\\x5D"+b+"]|\\x5C"+
     18 s+")*(?:\\x5D|$))+/")+")")])}(b=a.types)&&g.push(["typ",b]);b=(""+a.keywords).replace(/^ | $/g,"");b.length&&g.push(["kwd",RegExp("^(?:"+b.replace(/[\s,]+/g,"|")+")\\b"),q]);d.push(["pln",/^\s+/,q," \r\n\t\u00a0"]);b="^.[^\\s\\w.$@'\"`/\\\\]*";a.regexLiterals&&(b+="(?!s*/)");g.push(["lit",/^@[$_a-z][\w$@]*/i,q],["typ",/^(?:[@_]?[A-Z]+[a-z][\w$@]*|\w+_t\b)/,q],["pln",/^[$_a-z][\w$@]*/i,q],["lit",/^(?:0x[\da-f]+|(?:\d(?:_\d+)*\d*(?:\.\d*)?|\.\d\+)(?:e[+-]?\d+)?)[a-z]*/i,q,"0123456789"],["pln",/^\\[\S\s]?/,
     19 q],["pun",RegExp(b),q]);return D(d,g)}function J(a,d,g){function b(a){var c=a.nodeType;if(c==1&&!x.test(a.className))if("br"===a.nodeName)s(a),a.parentNode&&a.parentNode.removeChild(a);else for(a=a.firstChild;a;a=a.nextSibling)b(a);else if((c==3||c==4)&&g){var d=a.nodeValue,i=d.match(m);if(i)c=d.substring(0,i.index),a.nodeValue=c,(d=d.substring(i.index+i[0].length))&&a.parentNode.insertBefore(j.createTextNode(d),a.nextSibling),s(a),c||a.parentNode.removeChild(a)}}function s(a){function b(a,c){var d=
     20 c?a.cloneNode(!1):a,e=a.parentNode;if(e){var e=b(e,1),g=a.nextSibling;e.appendChild(d);for(var i=g;i;i=g)g=i.nextSibling,e.appendChild(i)}return d}for(;!a.nextSibling;)if(a=a.parentNode,!a)return;for(var a=b(a.nextSibling,0),d;(d=a.parentNode)&&d.nodeType===1;)a=d;c.push(a)}for(var x=/(?:^|\s)nocode(?:\s|$)/,m=/\r\n?|\n/,j=a.ownerDocument,k=j.createElement("li");a.firstChild;)k.appendChild(a.firstChild);for(var c=[k],i=0;i<c.length;++i)b(c[i]);d===(d|0)&&c[0].setAttribute("value",d);var r=j.createElement("ol");
     21 r.className="linenums";for(var d=Math.max(0,d-1|0)||0,i=0,n=c.length;i<n;++i)k=c[i],k.className="L"+(i+d)%10,k.firstChild||k.appendChild(j.createTextNode("\u00a0")),r.appendChild(k);a.appendChild(r)}function p(a,d){for(var g=d.length;--g>=0;){var b=d[g];F.hasOwnProperty(b)?E.console&&console.warn("cannot override language handler %s",b):F[b]=a}}function I(a,d){if(!a||!F.hasOwnProperty(a))a=/^\s*</.test(d)?"default-markup":"default-code";return F[a]}function K(a){var d=a.h;try{var g=S(a.c,a.i),b=g.a;
     22 a.a=b;a.d=g.d;a.e=0;I(d,b)(a);var s=/\bMSIE\s(\d+)/.exec(navigator.userAgent),s=s&&+s[1]<=8,d=/\n/g,x=a.a,m=x.length,g=0,j=a.d,k=j.length,b=0,c=a.g,i=c.length,r=0;c[i]=m;var n,e;for(e=n=0;e<i;)c[e]!==c[e+2]?(c[n++]=c[e++],c[n++]=c[e++]):e+=2;i=n;for(e=n=0;e<i;){for(var p=c[e],w=c[e+1],t=e+2;t+2<=i&&c[t+1]===w;)t+=2;c[n++]=p;c[n++]=w;e=t}c.length=n;var f=a.c,h;if(f)h=f.style.display,f.style.display="none";try{for(;b<k;){var l=j[b+2]||m,B=c[r+2]||m,t=Math.min(l,B),A=j[b+1],G;if(A.nodeType!==1&&(G=x.substring(g,
     23 t))){s&&(G=G.replace(d,"\r"));A.nodeValue=G;var L=A.ownerDocument,o=L.createElement("span");o.className=c[r+1];var v=A.parentNode;v.replaceChild(o,A);o.appendChild(A);g<l&&(j[b+1]=A=L.createTextNode(x.substring(t,l)),v.insertBefore(A,o.nextSibling))}g=t;g>=l&&(b+=2);g>=B&&(r+=2)}}finally{if(f)f.style.display=h}}catch(u){E.console&&console.log(u&&u.stack||u)}}var E=window,y=["break,continue,do,else,for,if,return,while"],C=[[y,"auto,case,char,const,default,double,enum,extern,float,goto,inline,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"],
     24 "catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"],M=[C,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,delegate,dynamic_cast,explicit,export,friend,generic,late_check,mutable,namespace,nullptr,property,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"],V=[C,"abstract,assert,boolean,byte,extends,final,finally,implements,import,instanceof,interface,null,native,package,strictfp,super,synchronized,throws,transient"],
     25 N=[C,"abstract,as,base,bool,by,byte,checked,decimal,delegate,descending,dynamic,event,finally,fixed,foreach,from,group,implicit,in,interface,internal,into,is,let,lock,null,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var,virtual,where"],C=[C,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"],O=[y,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"],
     26 P=[y,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"],W=[y,"as,assert,const,copy,drop,enum,extern,fail,false,fn,impl,let,log,loop,match,mod,move,mut,priv,pub,pure,ref,self,static,struct,true,trait,type,unsafe,use"],y=[y,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"],Q=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)\b/,
     27 U=/\S/,X=v({keywords:[M,N,C,"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",O,P,y],hashComments:!0,cStyleComments:!0,multiLineStrings:!0,regexLiterals:!0}),F={};p(X,["default-code"]);p(D([],[["pln",/^[^<?]+/],["dec",/^<!\w[^>]*(?:>|$)/],["com",/^<\!--[\S\s]*?(?:--\>|$)/],["lang-",/^<\?([\S\s]+?)(?:\?>|$)/],["lang-",/^<%([\S\s]+?)(?:%>|$)/],["pun",/^(?:<[%?]|[%?]>)/],["lang-",
     28 /^<xmp\b[^>]*>([\S\s]+?)<\/xmp\b[^>]*>/i],["lang-js",/^<script\b[^>]*>([\S\s]*?)(<\/script\b[^>]*>)/i],["lang-css",/^<style\b[^>]*>([\S\s]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i] ]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);p(D([["pln",/^\s+/,q," \t\r\n"],["atv",/^(?:"[^"]*"?|'[^']*'?)/,q,"\"'"] ],[["tag",/^^<\/?[a-z](?:[\w-.:]*\w)?|\/?>$/i],["atn",/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^\s"'>]*(?:[^\s"'/>]|\/(?=\s)))/],["pun",/^[/<->]+/],
     29 ["lang-js",/^on\w+\s*=\s*"([^"]+)"/i],["lang-js",/^on\w+\s*=\s*'([^']+)'/i],["lang-js",/^on\w+\s*=\s*([^\s"'>]+)/i],["lang-css",/^style\s*=\s*"([^"]+)"/i],["lang-css",/^style\s*=\s*'([^']+)'/i],["lang-css",/^style\s*=\s*([^\s"'>]+)/i] ]),["in.tag"]);p(D([],[["atv",/^[\S\s]+/] ]),["uq.val"]);p(v({keywords:M,hashComments:!0,cStyleComments:!0,types:Q}),["c","cc","cpp","cxx","cyc","m"]);p(v({keywords:"null,true,false"}),["json"]);p(v({keywords:N,hashComments:!0,cStyleComments:!0,verbatimStrings:!0,types:Q}),
     30 ["cs"]);p(v({keywords:V,cStyleComments:!0}),["java"]);p(v({keywords:y,hashComments:!0,multiLineStrings:!0}),["bash","bsh","csh","sh"]);p(v({keywords:O,hashComments:!0,multiLineStrings:!0,tripleQuotedStrings:!0}),["cv","py","python"]);p(v({keywords:"caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END",hashComments:!0,multiLineStrings:!0,regexLiterals:2}),["perl","pl","pm"]);p(v({keywords:P,
     31 hashComments:!0,multiLineStrings:!0,regexLiterals:!0}),["rb","ruby"]);p(v({keywords:C,cStyleComments:!0,regexLiterals:!0}),["javascript","js"]);p(v({keywords:"all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,throw,true,try,unless,until,when,while,yes",hashComments:3,cStyleComments:!0,multilineStrings:!0,tripleQuotedStrings:!0,regexLiterals:!0}),["coffee"]);p(v({keywords:W,cStyleComments:!0,multilineStrings:!0}),["rc","rs","rust"]);
     32 p(D([],[["str",/^[\S\s]+/] ]),["regex"]);var Y=E.PR={createSimpleLexer:D,registerLangHandler:p,sourceDecorator:v,PR_ATTRIB_NAME:"atn",PR_ATTRIB_VALUE:"atv",PR_COMMENT:"com",PR_DECLARATION:"dec",PR_KEYWORD:"kwd",PR_LITERAL:"lit",PR_NOCODE:"nocode",PR_PLAIN:"pln",PR_PUNCTUATION:"pun",PR_SOURCE:"src",PR_STRING:"str",PR_TAG:"tag",PR_TYPE:"typ",prettyPrintOne:E.prettyPrintOne=function(a,d,g){var b=document.createElement("div");b.innerHTML="<pre>"+a+"</pre>";b=b.firstChild;g&&J(b,g,!0);K({h:d,j:g,c:b,i:1});
     33 return b.innerHTML},prettyPrint:E.prettyPrint=function(a,d){function g(){for(var b=E.PR_SHOULD_USE_CONTINUATION?c.now()+250:Infinity;i<p.length&&c.now()<b;i++){for(var d=p[i],j=h,k=d;k=k.previousSibling;){var m=k.nodeType,o=(m===7||m===8)&&k.nodeValue;if(o?!/^\??prettify\b/.test(o):m!==3||/\S/.test(k.nodeValue))break;if(o){j={};o.replace(/\b(\w+)=([\w%+\-.:]+)/g,function(a,b,c){j[b]=c});break}}k=d.className;if((j!==h||e.test(k))&&!v.test(k)){m=!1;for(o=d.parentNode;o;o=o.parentNode)if(f.test(o.tagName)&&
     34 o.className&&e.test(o.className)){m=!0;break}if(!m){d.className+=" prettyprinted";m=j.lang;if(!m){var m=k.match(n),y;if(!m&&(y=T(d))&&t.test(y.tagName))m=y.className.match(n);m&&(m=m[1])}if(w.test(d.tagName))o=1;else var o=d.currentStyle,u=s.defaultView,o=(o=o?o.whiteSpace:u&&u.getComputedStyle?u.getComputedStyle(d,q).getPropertyValue("white-space"):0)&&"pre"===o.substring(0,3);u=j.linenums;if(!(u=u==="true"||+u))u=(u=k.match(/\blinenums\b(?::(\d+))?/))?u[1]&&u[1].length?+u[1]:!0:!1;u&&J(d,u,o);r=
     35 {h:m,c:d,j:u,i:o};K(r)}}}i<p.length?setTimeout(g,250):"function"===typeof a&&a()}for(var b=d||document.body,s=b.ownerDocument||document,b=[b.getElementsByTagName("pre"),b.getElementsByTagName("code"),b.getElementsByTagName("xmp")],p=[],m=0;m<b.length;++m)for(var j=0,k=b[m].length;j<k;++j)p.push(b[m][j]);var b=q,c=Date;c.now||(c={now:function(){return+new Date}});var i=0,r,n=/\blang(?:uage)?-([\w.]+)(?!\S)/,e=/\bprettyprint\b/,v=/\bprettyprinted\b/,w=/pre|xmp/i,t=/^code$/i,f=/^(?:pre|code|xmp)$/i,
     36 h={};g()}};typeof define==="function"&&define.amd&&define("google-code-prettify",[],function(){return Y})})();}()
     37 </script>
     38 <style>
     39 .pln{color:#1b181b}.str{color:#918b3b}.kwd{color:#7b59c0}.com{color:#9e8f9e}.typ{color:#516aec}.lit{color:#a65926}.clo,.opn,.pun{color:#1b181b}.tag{color:#ca402b}.atn{color:#a65926}.atv{color:#159393}.dec{color:#a65926}.var{color:#ca402b}.fun{color:#516aec}pre.prettyprint{background:#f7f3f7;color:#ab9bab;font-family:Menlo,Consolas,"Bitstream Vera Sans Mono","DejaVu Sans Mono",Monaco,monospace;font-size:12px;line-height:1.5;border:1px solid #d8cad8;padding:10px}ol.linenums{margin-top:0;margin-bottom:0}
     40 body{min-width:200px;max-width:850px;margin:0 auto;padding:30px;}.chapter-nav{font-size: 10pt;}a:link,a:visited{color:#00f}.codeblock_name,code,pre.prettyprint{font-family:Monaco,"Lucida Console",monospace}body{font-size:14pt}.codeblock_name,.math,.seealso,code{font-size:10pt}.codeblock{page-break-inside:avoid;padding-bottom:15px}.math{text-indent:0}pre.prettyprint{font-size:10pt;padding:10px;border-radius:10px;border:none;white-space:pre-wrap}.codeblock_name{margin-top:1.25em;display:block}a:link{text-decoration:none}a:link:not(.lit):hover{color:#00f;text-decoration:underline}a:link:active{color:red}h4{padding-right:1.25em}h4.noheading{margin-bottom:0}h1{text-align:center}code{padding:2px}pre{-moz-tab-size:4;-o-tab-size:4;tab-size:4}p:not(.notp){margin:0;text-indent:2em}.two-col{list-style-type:none}.two-col li:before{content:'-';padding:5px;margin-right:5px;color:orange;background-color:#fff;display:inline-block}@media print{body{font-size:10pt}pre.prettyprint{font-size:8pt}.seealso{font-size:9pt}.codeblock_name,.math,code{font-size:8pt}.math{text-indent:0}}
     41 /* code blocks (Style from jmeiners.com/lc3-vm, CC BY-NC-SA 4.0, used with attribution) */
     42 
     43 /* Quotes and Block Quotes */
     44 blockquote {
     45     margin: 1.5em 10px;
     46     padding: 0.5em 10px;
     47     border-left: 5px solid #ccc;
     48     color: #666;
     49     background-color: #f9f9f9;
     50     font-style: italic;
     51 }
     52 
     53 blockquote p {
     54     margin: 0;
     55     font-size: 1.2em;
     56 }
     57 
     58 q {
     59     quotes: "“" "”" "‘" "’";
     60     font-style: italic;
     61 }
     62 
     63 q::before {
     64     content: open-quote;
     65 }
     66 
     67 q::after {
     68     content: close-quote;
     69 }
     70 
     71 /*! Color themes for Google Code Prettify | MIT License | github.com/jmblog/color-themes-for-google-code-prettify */
     72 .prettyprint {
     73     background: #f5f7ff;
     74     font-family: Menlo, "Bitstream Vera Sans Mono", "DejaVu Sans Mono", Monaco, Consolas, monospace;
     75     border: 0 !important;
     76 }
     77 
     78 .pln {
     79     color: #202746;
     80 }
     81 
     82 /* Specify class=linenums on a pre to get line numbering */
     83 ol.linenums {
     84     margin-top: 0;
     85     margin-bottom: 0;
     86     color: #202746;
     87 }
     88 
     89 li.L0,
     90 li.L1,
     91 li.L2,
     92 li.L3,
     93 li.L4,
     94 li.L5,
     95 li.L6,
     96 li.L7,
     97 li.L8,
     98 li.L9 {
     99     padding-left: 1em;
    100     background-color: #f5f7ff;
    101     list-style-type: decimal;
    102 }
    103 
    104 @media screen {
    105 
    106     /* string content */
    107 
    108     .str {
    109         color: #ac9739;
    110     }
    111 
    112     /* keyword */
    113 
    114     .kwd {
    115         color: #6679cc;
    116     }
    117 
    118     /* comment */
    119 
    120     .com {
    121         color: #202746;
    122     }
    123 
    124     /* type name */
    125 
    126     .typ {
    127         color: #3d8fd1;
    128     }
    129 
    130     /* literal value */
    131 
    132     .lit {
    133         color: #c76b29;
    134     }
    135 
    136     /* punctuation */
    137 
    138     .pun {
    139         color: #202746;
    140     }
    141 
    142     /* lisp open bracket */
    143 
    144     .opn {
    145         color: #202746;
    146     }
    147 
    148     /* lisp close bracket */
    149 
    150     .clo {
    151         color: #202746;
    152     }
    153 
    154     /* markup tag name */
    155 
    156     .tag {
    157         color: #c94922;
    158     }
    159 
    160     /* markup attribute name */
    161 
    162     .atn {
    163         color: #c76b29;
    164     }
    165 
    166     /* markup attribute value */
    167 
    168     .atv {
    169         color: #22a2c9;
    170     }
    171 
    172     /* declaration */
    173 
    174     .dec {
    175         color: #c76b29;
    176     }
    177 
    178     /* variable name */
    179 
    180     .var {
    181         color: #c94922;
    182     }
    183 
    184     /* function name */
    185 
    186     .fun {
    187         color: #3d8fd1;
    188     }
    189 }</style>
    190 </head>
    191 <body onload="prettyPrint()">
    192 <section>
    193 <h1>AST code</h1>
    194 <a name="1:1"><div class="section"><h4 class="noheading">1. </h4></a>
    195 <p>This is the AST code. There's no important logic here, this is just accessors and constructors for the AST nodes
    196 </p>
    197 
    198 </div>
    199 <a name="1:2"><div class="section"><h4>2. The AST Interface - Node Types</h4></a>
    200 
    201 <div class="codeblock">
    202 <span class="codeblock_name">{Node Types <a href="ast.html#1:2">2</a>}</span>
    203 <pre class="prettyprint lang-c">
    204 typedef struct ast_node ast_node_t;
    205 
    206 typedef enum {
    207     // Expression nodes
    208     AST_INTU32,
    209     AST_INTU64,
    210     AST_INTS32,
    211     AST_INTS64,
    212     AST_FLOAT,
    213     AST_DOUBLE,
    214     AST_STRING,
    215     AST_CHAR,
    216     AST_VAR,
    217     AST_SUBSCRIPT,
    218     AST_DIRECT_COMPONENT_SELECTION,
    219     AST_INDIRECT_COMPONENT_SELECTION,
    220     AST_FUNCTION_CALL,
    221     AST_POSTFIX_INC,
    222     AST_POSTFIX_DEC,
    223     AST_UNARY_PLUS,
    224     AST_UNARY_MINUS,
    225     AST_LOGICAL_NOT,
    226     AST_BITWISE_NOT,
    227     AST_ADDRESS_OF,
    228     AST_INDIRECTION,
    229     AST_SIZEOF,
    230     AST_PRE_INC,
    231     AST_PRE_DEC,
    232     AST_CAST,
    233     AST_MUL,
    234     AST_DIV,
    235     AST_MOD,
    236     AST_ADD,
    237     AST_SUB,
    238     AST_LEFT_SHIFT,
    239     AST_RIGHT_SHIFT,
    240     AST_LESS_THAN,
    241     AST_GREATER_THAN,
    242     AST_LESS_THAN_OR_EQUAL,
    243     AST_GREATER_THAN_OR_EQUAL,
    244     AST_EQUAL,
    245     AST_NOT_EQUAL,
    246     AST_BITWISE_AND,
    247     AST_BITWISE_XOR,
    248     AST_BITWISE_OR,
    249     AST_LOGICAL_AND,
    250     AST_LOGICAL_OR,
    251     AST_CONDITIONAL,
    252     AST_ASSIGN,
    253     AST_ADD_ASSIGN,
    254     AST_SUB_ASSIGN,
    255     AST_MUL_ASSIGN,
    256     AST_DIV_ASSIGN,
    257     AST_MOD_ASSIGN,
    258     AST_LEFT_SHIFT_ASSIGN,
    259     AST_RIGHT_SHIFT_ASSIGN,
    260     AST_AND_ASSIGN,
    261     AST_XOR_ASSIGN,
    262     AST_OR_ASSIGN,
    263     AST_COMMA,
    264     // Statement nodes
    265     AST_EXPRESSION_STATEMENT,
    266     AST_LABEL_STATEMENT,
    267     AST_CASE_STATEMENT,
    268     AST_DEFAULT_STATEMENT,
    269     AST_COMPOUND_STATEMENT,
    270     AST_IF_STATEMENT,
    271     AST_WHILE_STATEMENT,
    272     AST_DO_WHILE_STATEMENT,
    273     AST_FOR_STATEMENT,
    274     AST_GOTO_STATEMENT,
    275     AST_CONTINUE_STATEMENT,
    276     AST_BREAK_STATEMENT,
    277     AST_RETURN_STATEMENT,
    278     AST_SWITCH_STATEMENT,
    279     AST_NULL_STATEMENT,
    280     // Declaration nodes
    281     AST_VAR_DECL,
    282     AST_FUN_DECL,
    283     AST_PARAM,
    284     AST_FUN_DEF,
    285     AST_STRUCT_DECL,
    286     AST_UNION_DECL,
    287     AST_ENUM_DECL,
    288     AST_TYPEDEF,
    289     AST_TYPE,
    290     AST_MEMBER,
    291     AST_ENUM_MEMBER,
    292     // Translation unit
    293     AST_TRANSLATION_UNIT
    294 } ast_node_type_t;
    295 </pre>
    296 
    297 
    298 <p class="seealso">Used in section <a href="ast.html#1:15">15</a></p>
    299 </div>
    300 </div>
    301 <a name="1:3"><div class="section"><h4>3. The AST Interface - Creating Nodes</h4></a>
    302 <p>These functions create nodes for the AST.
    303 </p>
    304 <p>The order of functions here partly follows the order of the grammar rules from the bottom up, I.E primary -> postfix -> unary -> multiplicative -> additive -> relational -> equality -> assignment -> expression -> statement -> declaration.
    305 </p>
    306 
    307 <div class="codeblock">
    308 <span class="codeblock_name">{Node Creation (Expression Nodes) <a href="ast.html#1:3">3</a>}</span>
    309 <pre class="prettyprint lang-c">
    310 // Expression nodes (primary)
    311 ast_node_t *ast_create_ints32_node(int32_t value, int line, int column); // 1
    312 ast_node_t *ast_create_ints64_node(int64_t value, int line, int column); // 1L
    313 ast_node_t *ast_create_intu32_node(uint32_t value, int line, int column); // 1u
    314 ast_node_t *ast_create_intu64_node(uint64_t value, int line, int column); // 1ul
    315 ast_node_t *ast_create_float_node(float value, int line, int column); // 1.0f
    316 ast_node_t *ast_create_double_node(double value, int line, int column); // 1.0
    317 ast_node_t *ast_create_string_node(char *value, int line, int column); // "string"
    318 ast_node_t *ast_create_char_node(char value, int line, int column); // 'c'
    319 ast_node_t *ast_create_var_node(char *value, int line, int column); // Variable
    320 // Nothing needed for paren as the child can just be placed in the parent node directly
    321 // Expression nodes (postfix)
    322 ast_node_t *ast_create_subscript_node(ast_node_t *expr, ast_node_t *subscript, int line, int column); // expr[subscript]
    323 ast_node_t *ast_create_direct_component_selection_node(ast_node_t *expr, char *component, int line, int column); // .component
    324 ast_node_t *ast_create_indirect_component_selection_node(ast_node_t *expr, char *component, int line, int column); // -&gt;component
    325 ast_node_t *ast_create_function_call_node(ast_node_t *expr, ast_node_t **args, size_t num_args, int line, int column); // expr(arg1, arg2, ...)
    326 ast_node_t  *ast_create_postfix_inc_node(ast_node_t *expr, int line, int column); // expr++
    327 ast_node_t  *ast_create_postfix_dec_node(ast_node_t *expr, int line, int column); // expr--
    328 // Expression nodes (unary)
    329 ast_node_t *ast_create_unary_plus_node(ast_node_t *expr, int line, int column); // +expr
    330 ast_node_t *ast_create_unary_minus_node(ast_node_t *expr, int line, int column); // -expr
    331 ast_node_t *ast_create_logical_not_node(ast_node_t *expr, int line, int column); // !expr
    332 ast_node_t *ast_create_bitwise_not_node(ast_node_t *expr, int line, int column); // ~expr
    333 ast_node_t *ast_create_address_of_node(ast_node_t *expr, int line, int column); // &amp;expr
    334 ast_node_t *ast_create_indirection_node(ast_node_t *expr, int line, int column); // *expr
    335 ast_node_t *ast_create_sizeof_node(ast_node_t *expr, int line, int column); // sizeof(expr)
    336 ast_node_t *ast_create_pre_inc_node(ast_node_t *expr, int line, int column); // ++expr
    337 ast_node_t *ast_create_pre_dec_node(ast_node_t *expr, int line, int column); // --expr
    338 // Expression nodes (cast)
    339 ast_node_t *ast_create_cast_node(ast_node_t *type, ast_node_t *expr, int line, int column); // (type)expr
    340 // Expression nodes (multiplicative)
    341 ast_node_t *ast_create_mul_node(ast_node_t *left, ast_node_t *right, int line, int column); // left * right
    342 ast_node_t *ast_create_div_node(ast_node_t *left, ast_node_t *right, int line, int column); // left / right
    343 ast_node_t *ast_create_mod_node(ast_node_t *left, ast_node_t *right, int line, int column); // left % right
    344 // Expression nodes (additive)
    345 ast_node_t *ast_create_add_node(ast_node_t *left, ast_node_t *right, int line, int column); // left + right
    346 ast_node_t *ast_create_sub_node(ast_node_t *left, ast_node_t *right, int line, int column); // left - right
    347 // Expression nodes (shift)
    348 ast_node_t *ast_create_left_shift_node(ast_node_t *left, ast_node_t *right, int line, int column); // left &lt;&lt; right
    349 ast_node_t *ast_create_right_shift_node(ast_node_t *left, ast_node_t *right, int line, int column); // left &gt;&gt; right
    350 // Expression nodes (relational)
    351 ast_node_t *ast_create_less_than_node(ast_node_t *left, ast_node_t *right, int line, int column); // left &lt; right
    352 ast_node_t *ast_create_greater_than_node(ast_node_t *left, ast_node_t *right, int line, int column); // left &gt; right
    353 ast_node_t *ast_create_less_than_or_equal_node(ast_node_t *left, ast_node_t *right, int line, int column); // left &lt;= right
    354 ast_node_t *ast_create_greater_than_or_equal_node(ast_node_t *left, ast_node_t *right, int line, int column); // left &gt;= right
    355 // Expression nodes (equality)
    356 ast_node_t *ast_create_equal_node(ast_node_t *left, ast_node_t *right, int line, int column); // left == right
    357 ast_node_t *ast_create_not_equal_node(ast_node_t *left, ast_node_t *right, int line, int column); // left != right
    358 // Expression nodes (bitwise and)
    359 ast_node_t *ast_create_bitwise_and_node(ast_node_t *left, ast_node_t *right, int line, int column); // left &amp; right
    360 // Expression nodes (bitwise xor)
    361 ast_node_t *ast_create_bitwise_xor_node(ast_node_t *left, ast_node_t *right, int line, int column); // left ^ right
    362 // Expression nodes (bitwise or)
    363 ast_node_t *ast_create_bitwise_or_node(ast_node_t *left, ast_node_t *right, int line, int column); // left | right
    364 // Expression nodes (logical and)
    365 ast_node_t *ast_create_logical_and_node(ast_node_t *left, ast_node_t *right, int line, int column); // left &amp;&amp; right
    366 // Expression nodes (logical or)
    367 ast_node_t *ast_create_logical_or_node(ast_node_t *left, ast_node_t *right, int line, int column); // left || right
    368 // Expression nodes (conditional)
    369 ast_node_t *ast_create_conditional_node(ast_node_t *condition, ast_node_t *true_expr, ast_node_t *false_expr, int line, int column); // condition ? true_expr : false_expr
    370 // Expression nodes (assignment)
    371 ast_node_t *ast_create_assign_node(ast_node_t *left, ast_node_t *right, int line, int column); // left = right
    372 ast_node_t *ast_create_add_assign_node(ast_node_t *left, ast_node_t *right, int line, int column); // left += right
    373 ast_node_t *ast_create_sub_assign_node(ast_node_t *left, ast_node_t *right, int line, int column); // left -= right
    374 ast_node_t *ast_create_mul_assign_node(ast_node_t *left, ast_node_t *right, int line, int column); // left *= right
    375 ast_node_t *ast_create_div_assign_node(ast_node_t *left, ast_node_t *right, int line, int column); // left /= right
    376 ast_node_t *ast_create_mod_assign_node(ast_node_t *left, ast_node_t *right, int line, int column); // left %= right
    377 ast_node_t *ast_create_left_shift_assign_node(ast_node_t *left, ast_node_t *right, int line, int column); // left &lt;&lt;= right
    378 ast_node_t *ast_create_right_shift_assign_node(ast_node_t *left, ast_node_t *right, int line, int column); // left &gt;&gt;= right
    379 ast_node_t *ast_create_and_assign_node(ast_node_t *left, ast_node_t *right, int line, int column); // left &amp;= right
    380 ast_node_t *ast_create_xor_assign_node(ast_node_t *left, ast_node_t *right, int line, int column); // left ^= right
    381 ast_node_t *ast_create_or_assign_node(ast_node_t *left, ast_node_t *right, int line, int column); // left |= right
    382 // Expression nodes (comma)
    383 ast_node_t *ast_create_comma_node(ast_node_t *left, ast_node_t *right, int line, int column); // left, right
    384 </pre>
    385 
    386 
    387 <p class="seealso">Used in section <a href="ast.html#1:15">15</a></p>
    388 </div>
    389 </div>
    390 <a name="1:4"><div class="section"><h4 class="noheading">4. </h4></a>
    391 <p>Here we define functions for creating statement nodes.
    392 </p>
    393 
    394 <div class="codeblock">
    395 <span class="codeblock_name">{Node Creation (Statement Nodes) <a href="ast.html#1:4">4</a>}</span>
    396 <pre class="prettyprint lang-c">
    397 // Statement nodes (expression)
    398 ast_node_t *ast_create_expression_statement_node(ast_node_t *expr); // expr;
    399 // Statement nodes (label)
    400 ast_node_t *ast_create_label_statement_node(char *label, int line, int column); // label:
    401 ast_node_t *ast_create_case_statement_node(ast_node_t *expr, int line, int column); // case expr:
    402 ast_node_t *ast_create_default_statement_node(int line, int column); // default:
    403 // Statement nodes (compound)
    404 ast_node_t *ast_create_compound_statement_node(ast_node_t **decls_and_stmts, size_t num_decls_and_stmts, int line, int column); // { decls_and_stmts }
    405 // Statement nodes (conditional)
    406 ast_node_t *ast_create_if_statement_node(ast_node_t *condition, ast_node_t *true_stmt, ast_node_t *false_stmt, int line, int column); // if (condition) true_stmt else false_stmt
    407 // Statement nodes (iteration)
    408 ast_node_t *ast_create_while_statement_node(ast_node_t *condition, ast_node_t *stmt, int line, int column); // while (condition) stmt
    409 ast_node_t *ast_create_do_while_statement_node(ast_node_t *stmt, ast_node_t *condition, int line, int column); // do stmt while (condition)
    410 ast_node_t *ast_create_for_statement_node(ast_node_t *init, ast_node_t *condition, ast_node_t *update, ast_node_t *stmt, int line, int column); // for (init; condition; update) stmt
    411 // Statement nodes (jump)
    412 ast_node_t *ast_create_goto_statement_node(char *label, int line, int column); // goto label;
    413 ast_node_t *ast_create_continue_statement_node(int line, int column); // continue;
    414 ast_node_t *ast_create_break_statement_node(int line, int column); // break;
    415 ast_node_t *ast_create_return_statement_node(ast_node_t *expr, int line, int column); // return expr;
    416 // Statement nodes (multiway branch)
    417 ast_node_t *ast_create_switch_statement_node(ast_node_t *expr, ast_node_t *stmt, int line, int column); // switch (expr) stmt
    418 // Statement nodes (null)
    419 ast_node_t *ast_create_null_statement_node(int line, int column); // ;
    420 </pre>
    421 
    422 
    423 <p class="seealso">Used in section <a href="ast.html#1:15">15</a></p>
    424 </div>
    425 </div>
    426 <a name="1:5"><div class="section"><h4 class="noheading">5. </h4></a>
    427 <p>Here we define functions for creating declaration nodes. Types are passed as a raw list of tokens, which will be used in the semantic analysis phase to build a type. In this way, we're kind of offsetting type parsing.
    428 </p>
    429 <p>An example call for a declaration would be <code>ast_node_t *type = ast_create_type_node((token_t *[]){ptr to TOK_VOLATILE, ptr to TOK_CONST, ptr to TOK_INT}, 3);</code>, <code>ast_node_t *decl = ast_create_var_decl_node(type, "x");</code>.
    430 </p>
    431 <p>A special AST node is created for parameters, struct/union members, and enum members. The enum member node can hold a value, but the others are just for the type.
    432 A special AST node also exists for types.
    433 </p>
    434 
    435 <div class="codeblock">
    436 <span class="codeblock_name">{Node Creation (Declaration Nodes) <a href="ast.html#1:5">5</a>}</span>
    437 <pre class="prettyprint lang-c">
    438 // Declaration nodes (simple)
    439 ast_node_t *ast_create_var_decl_node(ast_node_t *type, char *id, int line, int column); // type id
    440 ast_node_t *ast_create_fun_decl_node(ast_node_t *type, char *id, ast_node_t **params, size_t num_params, int line, int column); // type id(params)
    441 // Declaration nodes (parameter)
    442 ast_node_t *ast_create_param_node(ast_node_t *type, char *id, int line, int column); // type id
    443 // Declaration nodes (function)
    444 ast_node_t *ast_create_fun_def_node(ast_node_t *type, char *id, ast_node_t **params, size_t num_params, ast_node_t *stmt, int line, int column); // type id(params) stmt
    445 // Declaration nodes (struct) 
    446 ast_node_t *ast_create_struct_decl_node(char *id, ast_node_t **members, size_t num_members, int line, int column); // struct id { members } (reuses param node for members)
    447 // Declaration nodes (union)
    448 ast_node_t *ast_create_union_decl_node(char *id, ast_node_t **members, size_t num_members, int line, int column); // union id { members } (reuses param node for members)
    449 // Declaration nodes (enum)
    450 ast_node_t *ast_create_enum_decl_node(char *id, ast_node_t **enums, size_t num_enums, int line, int column); // enum id { enums }
    451 // Declaration nodes (Typedef)
    452 ast_node_t *ast_create_typedef_node(ast_node_t *type, char *id, int line, int column); // typedef type id
    453 // Types/members
    454 ast_node_t *ast_create_type_node(token_t *type[], size_t num_type, int line, int column); // type
    455 ast_node_t *ast_create_member_node(ast_node_t *type, char *id, int line, int column); // type id
    456 ast_node_t *ast_create_enum_member_node(char *id, ast_node_t *value, int line, int column); // id = value
    457 </pre>
    458 
    459 
    460 <p class="seealso">Used in section <a href="ast.html#1:15">15</a></p>
    461 </div>
    462 </div>
    463 <a name="1:6"><div class="section"><h4>6. The AST Interface - Translation Unit</h4></a>
    464 <p>The translation unit is the root of the AST. It's a list of nodes, which can be declarations or statements. This is the only function that will be called from the parser.
    465 </p>
    466 
    467 <div class="codeblock">
    468 <span class="codeblock_name">{Node Creation (Translation Unit) <a href="ast.html#1:6">6</a>}</span>
    469 <pre class="prettyprint lang-c">
    470 ast_node_t *ast_create_translation_unit(ast_node_t **nodes, size_t num_nodes, int line, int column);
    471 </pre>
    472 
    473 
    474 <p class="seealso">Used in section <a href="ast.html#1:15">15</a></p>
    475 </div>
    476 </div>
    477 <a name="1:7"><div class="section"><h4>7. The AST Interface - Destroying Nodes</h4></a>
    478 <p>A single function is defined to destroy an AST node and all its children.
    479 </p>
    480 
    481 <div class="codeblock">
    482 <span class="codeblock_name">{Node Destruction <a href="ast.html#1:7">7</a>}</span>
    483 <pre class="prettyprint lang-c">
    484 void ast_destroy_node(ast_node_t *node);
    485 </pre>
    486 
    487 
    488 <p class="seealso">Used in section <a href="ast.html#1:15">15</a></p>
    489 </div>
    490 </div>
    491 <a name="1:8"><div class="section"><h4>8. The AST Interface - Getting Node Information</h4></a>
    492 <p>These functions get information from the AST nodes. They will do on-the-fly type checking to ensure the node is the correct type, so we need to have separate functions for each type of node.
    493 </p>
    494 
    495 </div>
    496 <a name="1:9"><div class="section"><h4 class="noheading">9. </h4></a>
    497 
    498 <div class="codeblock">
    499 <span class="codeblock_name">{Node Information (General) <a href="ast.html#1:9">9</a>}</span>
    500 <pre class="prettyprint lang-c">
    501 ast_node_type_t ast_get_node_type(ast_node_t *node);
    502 int ast_get_node_line(ast_node_t *node);
    503 int ast_get_node_column(ast_node_t *node);
    504 </pre>
    505 
    506 
    507 <p class="seealso">Used in section <a href="ast.html#1:15">15</a></p>
    508 </div>
    509 </div>
    510 <a name="1:10"><div class="section"><h4 class="noheading">10. </h4></a>
    511 
    512 <div class="codeblock">
    513 <span class="codeblock_name">{Node Information (Expression Nodes) <a href="ast.html#1:10">10</a>}</span>
    514 <pre class="prettyprint lang-c">
    515 // Expression nodes (primary)
    516 int64_t ast_get_int_value(ast_node_t *node);
    517 double ast_get_double_value(ast_node_t *node);
    518 char *ast_get_string_value(ast_node_t *node);
    519 char ast_get_char_value(ast_node_t *node);
    520 char *ast_get_var_value(ast_node_t *node);
    521 // Expression nodes (postfix)
    522 ast_node_t *ast_get_subscript_expr(ast_node_t *node);
    523 ast_node_t *ast_get_subscript_idx(ast_node_t *node);
    524 char *ast_get_component(ast_node_t *node);
    525 ast_node_t *ast_get_function_call_expr(ast_node_t *node);
    526 ast_node_t **ast_get_function_call_args(ast_node_t *node, size_t *num_args);
    527 ast_node_t *ast_get_postfix_expr(ast_node_t *node);
    528 // Expression nodes (unary)
    529 ast_node_t *ast_get_unary_expr(ast_node_t *node);
    530 // Expression nodes (cast)
    531 ast_node_t *ast_get_cast_type(ast_node_t *node);
    532 ast_node_t *ast_get_cast_expr(ast_node_t *node);
    533 // Expression nodes (binary)
    534 ast_node_t *ast_get_left_expr(ast_node_t *node);
    535 ast_node_t *ast_get_right_expr(ast_node_t *node);
    536 // Expression nodes (conditional)
    537 ast_node_t *ast_get_conditional_condition(ast_node_t *node);
    538 ast_node_t *ast_get_conditional_true_expr(ast_node_t *node);
    539 ast_node_t *ast_get_conditional_false_expr(ast_node_t *node);
    540 </pre>
    541 
    542 
    543 <p class="seealso">Used in section <a href="ast.html#1:15">15</a></p>
    544 </div>
    545 </div>
    546 <a name="1:11"><div class="section"><h4 class="noheading">11. </h4></a>
    547 
    548 <div class="codeblock">
    549 <span class="codeblock_name">{Node Information (Statement Nodes) <a href="ast.html#1:11">11</a>}</span>
    550 <pre class="prettyprint lang-c">
    551 // Statement nodes (expression)
    552 ast_node_t *ast_get_expression_statement_expr(ast_node_t *node);
    553 // Statement nodes (label)
    554 char *ast_get_label_statement_label(ast_node_t *node); // label
    555 ast_node_t *ast_get_case_statement_expr(ast_node_t *node); // expr
    556 // Statement nodes (compound)
    557 ast_node_t **ast_get_compound_statement_contents(ast_node_t *node, size_t *num_contents); // decls_and_stmts
    558 // Statement nodes (conditional)
    559 ast_node_t *ast_get_if_statement_condition(ast_node_t *node); // condition
    560 ast_node_t *ast_get_if_statement_true_stmt(ast_node_t *node); // true_stmt
    561 ast_node_t *ast_get_if_statement_false_stmt(ast_node_t *node); // false_stmt
    562 // Statement nodes (iteration)
    563 ast_node_t *ast_get_iteration_statement_condition(ast_node_t *node); // condition
    564 ast_node_t *ast_get_iteration_statement_stmt(ast_node_t *node); // stmt
    565 ast_node_t *ast_get_for_statement_init(ast_node_t *node); // init
    566 ast_node_t *ast_get_for_statement_update(ast_node_t *node); // update
    567 // Statement nodes (jump)
    568 char *ast_get_goto_statement_label(ast_node_t *node); // label
    569 // Statement nodes (multiway branch)
    570 ast_node_t *ast_get_switch_statement_expr(ast_node_t *node); // expr
    571 ast_node_t *ast_get_switch_statement_stmt(ast_node_t *node); // stmt
    572 </pre>
    573 
    574 
    575 <p class="seealso">Used in section <a href="ast.html#1:15">15</a></p>
    576 </div>
    577 </div>
    578 <a name="1:12"><div class="section"><h4 class="noheading">12. </h4></a>
    579 
    580 <div class="codeblock">
    581 <span class="codeblock_name">{Node Information (Declaration Nodes) <a href="ast.html#1:12">12</a>}</span>
    582 <pre class="prettyprint lang-c">
    583 // Declaration nodes (simple)
    584 ast_node_t *ast_get_var_decl_type(ast_node_t *node);
    585 char *ast_get_var_decl_id(ast_node_t *node);
    586 ast_node_t *ast_get_fun_decl_type(ast_node_t *node);
    587 char *ast_get_fun_decl_id(ast_node_t *node);
    588 ast_node_t **ast_get_fun_decl_params(ast_node_t *node, size_t *num_params);
    589 // Declaration nodes (parameter)
    590 ast_node_t *ast_get_param_type(ast_node_t *node);
    591 char *ast_get_param_id(ast_node_t *node);
    592 // Declaration nodes (function)
    593 ast_node_t *ast_get_fun_def_type(ast_node_t *node);
    594 char *ast_get_fun_def_id(ast_node_t *node);
    595 ast_node_t **ast_get_fun_def_params(ast_node_t *node, size_t *num_params);
    596 ast_node_t *ast_get_fun_def_stmt(ast_node_t *node);
    597 // Declaration nodes (struct)
    598 char *ast_get_struct_decl_id(ast_node_t *node);
    599 ast_node_t **ast_get_struct_decl_members(ast_node_t *node, size_t *num_members);
    600 // Declaration nodes (union)
    601 char *ast_get_union_decl_id(ast_node_t *node);
    602 ast_node_t **ast_get_union_decl_members(ast_node_t *node, size_t *num_members);
    603 // Declaration nodes (enum)
    604 char *ast_get_enum_decl_id(ast_node_t *node);
    605 ast_node_t **ast_get_enum_decl_enums(ast_node_t *node, size_t *num_enums);
    606 // Declaration nodes (Typedef)
    607 ast_node_t *ast_get_typedef_type(ast_node_t *node);
    608 char *ast_get_typedef_id(ast_node_t *node);
    609 // Types/members
    610 token_t **ast_get_type(ast_node_t *node, size_t *num_type);
    611 ast_node_t *ast_get_member_type(ast_node_t *node);
    612 char *ast_get_member_id(ast_node_t *node);
    613 ast_node_t *ast_get_enum_member_expr(ast_node_t *node);
    614 </pre>
    615 
    616 
    617 <p class="seealso">Used in section <a href="ast.html#1:15">15</a></p>
    618 </div>
    619 </div>
    620 <a name="1:13"><div class="section"><h4 class="noheading">13. </h4></a>
    621 
    622 <div class="codeblock">
    623 <span class="codeblock_name">{Node Information (Translation Unit) <a href="ast.html#1:13">13</a>}</span>
    624 <pre class="prettyprint lang-c">
    625 ast_node_t **ast_get_translation_unit(ast_node_t *node, size_t *num_nodes);
    626 </pre>
    627 
    628 
    629 <p class="seealso">Used in section <a href="ast.html#1:15">15</a></p>
    630 </div>
    631 </div>
    632 <a name="1:14"><div class="section"><h4 class="noheading">14. </h4></a>
    633 <p>Having seperate calls for each type makes it very difficult to mess up the tree structure in the parser.
    634 </p>
    635 
    636 </div>
    637 <a name="1:15"><div class="section"><h4 class="noheading">15. </h4></a>
    638 
    639 <div class="codeblock">
    640 <span class="codeblock_name">{<strong>ast.h</strong> <a href="ast.html#1:15">15</a>}</span>
    641 <pre class="prettyprint lang-c">
    642 #ifndef AST_H
    643 #define AST_H
    644 #include "token.h"
    645 #include &lt;stddef.h&gt;
    646 #include &lt;stdint.h&gt;
    647 <span class="nocode pln">{Node Types, <a href="ast.html#1:2">2</a>}</span>
    648 <span class="nocode pln">{Node Creation (Expression Nodes), <a href="ast.html#1:3">3</a>}</span>
    649 <span class="nocode pln">{Node Creation (Statement Nodes), <a href="ast.html#1:4">4</a>}</span>
    650 <span class="nocode pln">{Node Creation (Declaration Nodes), <a href="ast.html#1:5">5</a>}</span>
    651 <span class="nocode pln">{Node Creation (Translation Unit), <a href="ast.html#1:6">6</a>}</span>
    652 <span class="nocode pln">{Node Destruction, <a href="ast.html#1:7">7</a>}</span>
    653 <span class="nocode pln">{Node Information (General), <a href="ast.html#1:9">9</a>}</span>
    654 <span class="nocode pln">{Node Information (Expression Nodes), <a href="ast.html#1:10">10</a>}</span>
    655 <span class="nocode pln">{Node Information (Statement Nodes), <a href="ast.html#1:11">11</a>}</span>
    656 <span class="nocode pln">{Node Information (Declaration Nodes), <a href="ast.html#1:12">12</a>}</span>
    657 <span class="nocode pln">{Node Information (Translation Unit), <a href="ast.html#1:13">13</a>}</span>
    658 #endif
    659 </pre>
    660 
    661 
    662 
    663 </div>
    664 
    665 <div class="codeblock">
    666 <span class="codeblock_name">{Implementation - Common Node Structure <a href="ast.html#1:15">15</a>}</span>
    667 <pre class="prettyprint lang-c">
    668 #define AST_MAGIC 0x4153544E4F44ULL // "ASTNOD"
    669 
    670 struct ast_node {
    671   long magic;
    672   int line;
    673   int column;
    674   int hasdata;
    675   short kind;
    676   long opt_data[0];
    677 };
    678 
    679 static void* ast_get_data(ast_node_t *node)
    680 {
    681   assert(node-&gt;magic == AST_MAGIC);
    682   assert(node-&gt;hasdata);
    683   return node-&gt;opt_data;
    684 }
    685 
    686 ast_node_type_t ast_get_node_type(ast_node_t *node)
    687 {
    688   assert(node-&gt;magic == AST_MAGIC);
    689   return node-&gt;kind;
    690 }
    691 
    692 int ast_get_node_line(ast_node_t *node)
    693 {
    694   assert(node-&gt;magic == AST_MAGIC);
    695   return node-&gt;line;
    696 }
    697 
    698 int ast_get_node_column(ast_node_t *node)
    699 {
    700   assert(node-&gt;magic == AST_MAGIC);
    701   return node-&gt;column;
    702 }
    703 
    704 static ast_node_t *ast_create_node(ast_node_type_t kind, int line, int column, size_t data_size)
    705 {
    706   ast_node_t *node = malloc(sizeof(ast_node_t) + data_size);
    707   node-&gt;magic = AST_MAGIC;
    708   node-&gt;line = line;
    709   node-&gt;column = column;
    710   node-&gt;hasdata = data_size &gt; 0;
    711   node-&gt;kind = kind;
    712   return node;
    713 }
    714 </pre>
    715 
    716 
    717 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
    718 </div>
    719 </div>
    720 <a name="1:16"><div class="section"><h4 class="noheading">16. </h4></a>
    721 
    722 <div class="codeblock">
    723 <span class="codeblock_name">{Implementation - Nodes (Primary) <a href="ast.html#1:16">16</a>}</span>
    724 <pre class="prettyprint lang-c">
    725 struct ast_int_node {
    726   int64_t value;
    727 };
    728 
    729 ast_node_t *ast_create_intu32_node(uint32_t value, int line, int column)
    730 {
    731   ast_node_t *node =
    732       ast_create_node(AST_INTU32, line, column, sizeof(struct ast_int_node));
    733   struct ast_int_node *data = ast_get_data(node);
    734   data-&gt;value = value;
    735   return node;
    736 }
    737 
    738 ast_node_t *ast_create_ints32_node(int32_t value, int line, int column)
    739 {
    740   ast_node_t *node =
    741       ast_create_node(AST_INTS32, line, column, sizeof(struct ast_int_node));
    742   struct ast_int_node *data = ast_get_data(node);
    743   data-&gt;value = value;
    744   return node;
    745 }
    746 
    747 ast_node_t *ast_create_intu64_node(uint64_t value, int line, int column)
    748 {
    749   ast_node_t *node =
    750       ast_create_node(AST_INTU64, line, column, sizeof(struct ast_int_node));
    751   struct ast_int_node *data = ast_get_data(node);
    752   data-&gt;value = value;
    753   return node;
    754 }
    755 
    756 ast_node_t *ast_create_ints64_node(int64_t value, int line, int column)
    757 {
    758   ast_node_t *node =
    759       ast_create_node(AST_INTS64, line, column, sizeof(struct ast_int_node));
    760   struct ast_int_node *data = ast_get_data(node);
    761   data-&gt;value = value;
    762   return node;
    763 }
    764 
    765 int64_t ast_get_int_value(ast_node_t *node) {
    766   assert(ast_get_node_type(node) == AST_INTU32 || ast_get_node_type(node) == AST_INTS32 || ast_get_node_type(node) == AST_INTU64 || ast_get_node_type(node) == AST_INTS64);
    767   struct ast_int_node *data = ast_get_data(node);
    768   return data-&gt;value;
    769 }
    770 
    771 struct ast_double_node {
    772   double value;
    773 };
    774 
    775 struct ast_float_node {
    776     float value;
    777 };
    778 
    779 ast_node_t *ast_create_float_node(float value, int line, int column)
    780 {
    781   ast_node_t *node = ast_create_node(AST_FLOAT, line, column, sizeof(struct ast_float_node));
    782   struct ast_float_node *data = ast_get_data(node);
    783   data-&gt;value = value;
    784   return node;
    785 }
    786 
    787 float ast_get_float_value(ast_node_t *node)
    788 {
    789   assert(ast_get_node_type(node) == AST_FLOAT);
    790   struct ast_float_node *data = ast_get_data(node);
    791   return data-&gt;value;
    792 }
    793 
    794 ast_node_t *ast_create_double_node(double value, int line, int column)
    795 {
    796   ast_node_t *node = ast_create_node(AST_DOUBLE, line, column, sizeof(struct ast_double_node));
    797   struct ast_double_node *data = ast_get_data(node);
    798   data-&gt;value = value;
    799   return node;
    800 }
    801 
    802 double ast_get_double_value(ast_node_t *node)
    803 {
    804   assert(ast_get_node_type(node) == AST_DOUBLE);
    805   struct ast_double_node *data = ast_get_data(node);
    806   return data-&gt;value;
    807 }
    808 
    809 struct ast_string_node {
    810   char *value;
    811 };
    812 
    813 ast_node_t *ast_create_string_node(char *value, int line, int column)
    814 {
    815   ast_node_t *node = ast_create_node(AST_STRING, line, column, sizeof(struct ast_string_node));
    816   struct ast_string_node *data = ast_get_data(node);
    817   data-&gt;value = value; // We don't duplicate here because the string is in the shared string table
    818   return node;
    819 }
    820 
    821 char *ast_get_string_value(ast_node_t *node)
    822 {
    823   assert(ast_get_node_type(node) == AST_STRING);
    824   struct ast_string_node *data = ast_get_data(node);
    825   return data-&gt;value;
    826 }
    827 
    828 struct ast_char_node {
    829   char value;
    830 };
    831 
    832 ast_node_t *ast_create_char_node(char value, int line, int column)
    833 {
    834   ast_node_t *node = ast_create_node(AST_CHAR, line, column, sizeof(struct ast_char_node));
    835   struct ast_char_node *data = ast_get_data(node);
    836   data-&gt;value = value;
    837   return node;
    838 }
    839 
    840 char ast_get_char_value(ast_node_t *node)
    841 {
    842   assert(ast_get_node_type(node) == AST_CHAR);
    843   struct ast_char_node *data = ast_get_data(node);
    844   return data-&gt;value;
    845 }
    846 
    847 ast_node_t *ast_create_var_node(char *value, int line, int column)
    848 {
    849   ast_node_t *node = ast_create_node(AST_VAR, line, column, sizeof(struct ast_string_node));
    850   struct ast_string_node *data = ast_get_data(node);
    851   data-&gt;value = value; // We don't duplicate here because the string is in the shared string table
    852   return node;
    853 }
    854 
    855 char *ast_get_var_value(ast_node_t *node)
    856 {
    857   assert(ast_get_node_type(node) == AST_VAR);
    858   struct ast_string_node *data = ast_get_data(node);
    859   return data-&gt;value;
    860 }
    861 </pre>
    862 
    863 
    864 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
    865 </div>
    866 </div>
    867 <a name="1:17"><div class="section"><h4 class="noheading">17. </h4></a>
    868 
    869 <div class="codeblock">
    870 <span class="codeblock_name">{Implementation - Nodes (Postfix) <a href="ast.html#1:17">17</a>}</span>
    871 <pre class="prettyprint lang-c">
    872 struct ast_subscript_node {
    873   ast_node_t *expr;
    874   ast_node_t *subscript;
    875 };
    876 
    877 ast_node_t *ast_create_subscript_node(ast_node_t *expr, ast_node_t *subscript, int line, int column)
    878 {
    879   ast_node_t *node = ast_create_node(AST_SUBSCRIPT, line, column, sizeof(struct ast_subscript_node));
    880   struct ast_subscript_node *data = ast_get_data(node);
    881   data-&gt;expr = expr;
    882   data-&gt;subscript = subscript;
    883   return node;
    884 }
    885 
    886 ast_node_t *ast_get_subscript_expr(ast_node_t *node)
    887 {
    888   assert(ast_get_node_type(node) == AST_SUBSCRIPT);
    889   struct ast_subscript_node *data = ast_get_data(node);
    890   return data-&gt;expr;
    891 }
    892 
    893 ast_node_t *ast_get_subscript_idx(ast_node_t *node)
    894 {
    895   assert(ast_get_node_type(node) == AST_SUBSCRIPT);
    896   struct ast_subscript_node *data = ast_get_data(node);
    897   return data-&gt;subscript;
    898 }
    899 
    900 struct ast_component_selection_node {
    901   ast_node_t *expr;
    902   char *component;
    903 };
    904 
    905 ast_node_t *ast_create_direct_component_selection_node(ast_node_t *expr, char *component, int line, int column)
    906 {
    907   ast_node_t *node = ast_create_node(AST_DIRECT_COMPONENT_SELECTION, line, column, sizeof(struct ast_component_selection_node));
    908   struct ast_component_selection_node *data = ast_get_data(node);
    909   data-&gt;expr = expr;
    910   data-&gt;component = component;
    911   return node;
    912 }
    913 
    914 char *ast_get_component(ast_node_t *node)
    915 {
    916   assert(ast_get_node_type(node) == AST_DIRECT_COMPONENT_SELECTION);
    917   struct ast_component_selection_node *data = ast_get_data(node);
    918   return data-&gt;component;
    919 }
    920 
    921 ast_node_t *ast_get_component_expr(ast_node_t *node)
    922 {
    923   assert(ast_get_node_type(node) == AST_DIRECT_COMPONENT_SELECTION);
    924   struct ast_component_selection_node *data = ast_get_data(node);
    925   return data-&gt;expr;
    926 }
    927 
    928 ast_node_t *ast_create_indirect_component_selection_node(ast_node_t *expr, char *component, int line, int column)
    929 {
    930   ast_node_t *node = ast_create_node(AST_INDIRECT_COMPONENT_SELECTION, line, column, sizeof(struct ast_component_selection_node));
    931   struct ast_component_selection_node *data = ast_get_data(node);
    932   data-&gt;expr = expr;
    933   data-&gt;component = component;
    934   return node;
    935 }
    936 
    937 struct ast_function_call_node {
    938   ast_node_t *expr;
    939   ast_node_t **args;
    940   size_t num_args;
    941 };
    942 
    943 ast_node_t *ast_create_function_call_node(ast_node_t *expr, ast_node_t **args, size_t num_args, int line, int column)
    944 {
    945   ast_node_t *node = ast_create_node(AST_FUNCTION_CALL, line, column, sizeof(struct ast_function_call_node));
    946   struct ast_function_call_node *data = ast_get_data(node);
    947   data-&gt;expr = expr;
    948   data-&gt;args = args;
    949   data-&gt;num_args = num_args;
    950   return node;
    951 }
    952 
    953 ast_node_t *ast_get_function_call_expr(ast_node_t *node)
    954 {
    955   assert(ast_get_node_type(node) == AST_FUNCTION_CALL);
    956   struct ast_function_call_node *data = ast_get_data(node);
    957   return data-&gt;expr;
    958 }
    959 
    960 ast_node_t **ast_get_function_call_args(ast_node_t *node, size_t *num_args)
    961 {
    962   assert(ast_get_node_type(node) == AST_FUNCTION_CALL);
    963   struct ast_function_call_node *data = ast_get_data(node);
    964   *num_args = data-&gt;num_args;
    965   return data-&gt;args;
    966 }
    967 
    968 ast_node_t *ast_create_postfix_inc_node(ast_node_t *expr, int line, int column)
    969 {
    970   ast_node_t *node = ast_create_node(AST_POSTFIX_INC, line, column, sizeof(ast_node_t *));
    971   ast_node_t **data = ast_get_data(node);
    972   *data = expr;
    973   return node;
    974 }
    975 
    976 ast_node_t *ast_create_postfix_dec_node(ast_node_t *expr, int line, int column)
    977 {
    978   ast_node_t *node = ast_create_node(AST_POSTFIX_DEC, line, column, sizeof(ast_node_t *));
    979   ast_node_t **data = ast_get_data(node);
    980   *data = expr;
    981   return node;
    982 }
    983 
    984 ast_node_t *ast_get_postfix_expr(ast_node_t *node)
    985 {
    986   assert(ast_get_node_type(node) == AST_POSTFIX_INC || ast_get_node_type(node) == AST_POSTFIX_DEC);
    987   ast_node_t **data = ast_get_data(node);
    988   return *data;
    989 }
    990 </pre>
    991 
    992 
    993 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
    994 </div>
    995 </div>
    996 <a name="1:18"><div class="section"><h4 class="noheading">18. </h4></a>
    997 
    998 <div class="codeblock">
    999 <span class="codeblock_name">{Implementation - Nodes (Unary/Cast) <a href="ast.html#1:18">18</a>}</span>
   1000 <pre class="prettyprint lang-c">
   1001 
   1002 #define AST_CREATE_UNARY_NODE(NODE_TYPE, NODE_NAME) \
   1003 ast_node_t *ast_create_##NODE_NAME##_node(ast_node_t *expr, int line, int column) \
   1004 { \
   1005   ast_node_t *node = ast_create_node(NODE_TYPE, line, column, sizeof(ast_node_t *)); \
   1006   ast_node_t **data = ast_get_data(node); \
   1007   *data = expr; \
   1008   return node; \
   1009 }
   1010 
   1011 AST_CREATE_UNARY_NODE(AST_UNARY_PLUS, unary_plus)
   1012 AST_CREATE_UNARY_NODE(AST_UNARY_MINUS, unary_minus)
   1013 AST_CREATE_UNARY_NODE(AST_LOGICAL_NOT, logical_not)
   1014 AST_CREATE_UNARY_NODE(AST_BITWISE_NOT, bitwise_not)
   1015 AST_CREATE_UNARY_NODE(AST_ADDRESS_OF, address_of)
   1016 AST_CREATE_UNARY_NODE(AST_INDIRECTION, indirection)
   1017 AST_CREATE_UNARY_NODE(AST_SIZEOF, sizeof)
   1018 AST_CREATE_UNARY_NODE(AST_PRE_INC, pre_inc)
   1019 AST_CREATE_UNARY_NODE(AST_PRE_DEC, pre_dec)
   1020 
   1021 ast_node_t *ast_create_cast_node(ast_node_t *type, ast_node_t *expr, int line, int column)
   1022 {
   1023   ast_node_t *node = ast_create_node(AST_CAST, line, column, 2 * sizeof(ast_node_t *));
   1024   ast_node_t **data = ast_get_data(node);
   1025   data[0] = type;
   1026   data[1] = expr;
   1027   return node;
   1028 }
   1029 
   1030 ast_node_t *ast_get_unary_expr(ast_node_t *node)
   1031 {
   1032   assert(ast_get_node_type(node) == AST_UNARY_PLUS || ast_get_node_type(node) == AST_UNARY_MINUS || ast_get_node_type(node) == AST_LOGICAL_NOT || ast_get_node_type(node) == AST_BITWISE_NOT || ast_get_node_type(node) == AST_ADDRESS_OF || ast_get_node_type(node) == AST_INDIRECTION || ast_get_node_type(node) == AST_SIZEOF || ast_get_node_type(node) == AST_PRE_INC || ast_get_node_type(node) == AST_PRE_DEC || ast_get_node_type(node) == AST_CAST);
   1033   ast_node_t **data = ast_get_data(node);
   1034   return data[0];
   1035 }
   1036 
   1037 ast_node_t *ast_get_cast_type(ast_node_t *node)
   1038 {
   1039   assert(ast_get_node_type(node) == AST_CAST);
   1040   ast_node_t **data = ast_get_data(node);
   1041   return data[0];
   1042 }
   1043 
   1044 ast_node_t *ast_get_cast_expr(ast_node_t *node)
   1045 {
   1046   assert(ast_get_node_type(node) == AST_CAST);
   1047   ast_node_t **data = ast_get_data(node);
   1048   return data[1];
   1049 }
   1050 
   1051 </pre>
   1052 
   1053 
   1054 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1055 </div>
   1056 </div>
   1057 <a name="1:19"><div class="section"><h4 class="noheading">19. </h4></a>
   1058 
   1059 <div class="codeblock">
   1060 <span class="codeblock_name">{Implementation - Nodes (Binary/Assign/Comma) <a href="ast.html#1:19">19</a>}</span>
   1061 <pre class="prettyprint lang-c">
   1062 struct ast_binary_node {
   1063   ast_node_t *left;
   1064   ast_node_t *right;
   1065 };
   1066 
   1067 // Macro to generate binary AST node creation functions
   1068 #define AST_CREATE_BINARY_NODE(NODE_TYPE, NODE_NAME) \
   1069 ast_node_t *ast_create_##NODE_NAME##_node(ast_node_t *left, ast_node_t *right, int line, int column) \
   1070 { \
   1071   ast_node_t *node = ast_create_node(NODE_TYPE, line, column, sizeof(struct ast_binary_node)); \
   1072   struct ast_binary_node *data = ast_get_data(node); \
   1073   data-&gt;left = left; \
   1074   data-&gt;right = right; \
   1075   return node; \
   1076 }
   1077 
   1078 AST_CREATE_BINARY_NODE(AST_MUL, mul)
   1079 AST_CREATE_BINARY_NODE(AST_DIV, div)
   1080 AST_CREATE_BINARY_NODE(AST_MOD, mod)
   1081 AST_CREATE_BINARY_NODE(AST_ADD, add)
   1082 AST_CREATE_BINARY_NODE(AST_SUB, sub)
   1083 AST_CREATE_BINARY_NODE(AST_LEFT_SHIFT, left_shift)
   1084 AST_CREATE_BINARY_NODE(AST_RIGHT_SHIFT, right_shift)
   1085 AST_CREATE_BINARY_NODE(AST_LESS_THAN, less_than)
   1086 AST_CREATE_BINARY_NODE(AST_GREATER_THAN, greater_than)
   1087 AST_CREATE_BINARY_NODE(AST_LESS_THAN_OR_EQUAL, less_than_or_equal)
   1088 AST_CREATE_BINARY_NODE(AST_GREATER_THAN_OR_EQUAL, greater_than_or_equal)
   1089 AST_CREATE_BINARY_NODE(AST_EQUAL, equal)
   1090 AST_CREATE_BINARY_NODE(AST_NOT_EQUAL, not_equal)
   1091 AST_CREATE_BINARY_NODE(AST_BITWISE_AND, bitwise_and)
   1092 AST_CREATE_BINARY_NODE(AST_BITWISE_XOR, bitwise_xor)
   1093 AST_CREATE_BINARY_NODE(AST_BITWISE_OR, bitwise_or)
   1094 AST_CREATE_BINARY_NODE(AST_LOGICAL_AND, logical_and)
   1095 AST_CREATE_BINARY_NODE(AST_LOGICAL_OR, logical_or)
   1096 AST_CREATE_BINARY_NODE(AST_ASSIGN, assign)
   1097 AST_CREATE_BINARY_NODE(AST_ADD_ASSIGN, add_assign)
   1098 AST_CREATE_BINARY_NODE(AST_SUB_ASSIGN, sub_assign)
   1099 AST_CREATE_BINARY_NODE(AST_MUL_ASSIGN, mul_assign)
   1100 AST_CREATE_BINARY_NODE(AST_DIV_ASSIGN, div_assign)
   1101 AST_CREATE_BINARY_NODE(AST_MOD_ASSIGN, mod_assign)
   1102 AST_CREATE_BINARY_NODE(AST_LEFT_SHIFT_ASSIGN, left_shift_assign)
   1103 AST_CREATE_BINARY_NODE(AST_RIGHT_SHIFT_ASSIGN, right_shift_assign)
   1104 AST_CREATE_BINARY_NODE(AST_AND_ASSIGN, bitwise_and_assign)
   1105 AST_CREATE_BINARY_NODE(AST_XOR_ASSIGN, bitwise_xor_assign)
   1106 AST_CREATE_BINARY_NODE(AST_OR_ASSIGN, bitwise_or_assign)
   1107 AST_CREATE_BINARY_NODE(AST_COMMA, comma)
   1108 
   1109 ast_node_t *ast_get_left_expr(ast_node_t *node)
   1110 {
   1111   assert(ast_get_node_type(node) == AST_MUL || ast_get_node_type(node) == AST_DIV || ast_get_node_type(node) == AST_MOD
   1112   || ast_get_node_type(node) == AST_ADD || ast_get_node_type(node) == AST_SUB || ast_get_node_type(node) == AST_LEFT_SHIFT 
   1113   || ast_get_node_type(node) == AST_RIGHT_SHIFT || ast_get_node_type(node) == AST_LESS_THAN || ast_get_node_type(node) == AST_GREATER_THAN 
   1114   || ast_get_node_type(node) == AST_LESS_THAN_OR_EQUAL || ast_get_node_type(node) == AST_GREATER_THAN_OR_EQUAL 
   1115   || ast_get_node_type(node) == AST_EQUAL || ast_get_node_type(node) == AST_NOT_EQUAL 
   1116   || ast_get_node_type(node) == AST_BITWISE_AND || ast_get_node_type(node) == AST_BITWISE_XOR || ast_get_node_type(node) == AST_BITWISE_OR 
   1117   || ast_get_node_type(node) == AST_LOGICAL_AND || ast_get_node_type(node) == AST_LOGICAL_OR || ast_get_node_type(node) == AST_ASSIGN 
   1118   || ast_get_node_type(node) == AST_ADD_ASSIGN || ast_get_node_type(node) == AST_SUB_ASSIGN || ast_get_node_type(node) == AST_MUL_ASSIGN || ast_get_node_type(node) == AST_DIV_ASSIGN 
   1119   || ast_get_node_type(node) == AST_MOD_ASSIGN || ast_get_node_type(node) == AST_LEFT_SHIFT_ASSIGN || ast_get_node_type(node) == AST_RIGHT_SHIFT_ASSIGN || ast_get_node_type(node) == AST_AND_ASSIGN 
   1120   || ast_get_node_type(node) == AST_XOR_ASSIGN || ast_get_node_type(node) == AST_OR_ASSIGN || ast_get_node_type(node) == AST_COMMA);
   1121   struct ast_binary_node *data = ast_get_data(node);
   1122   return data-&gt;left;
   1123 }
   1124 
   1125 ast_node_t *ast_get_right_expr(ast_node_t *node)
   1126 {
   1127   assert(ast_get_node_type(node) == AST_MUL || ast_get_node_type(node) == AST_DIV || ast_get_node_type(node) == AST_MOD
   1128   || ast_get_node_type(node) == AST_ADD || ast_get_node_type(node) == AST_SUB || ast_get_node_type(node) == AST_LEFT_SHIFT 
   1129   || ast_get_node_type(node) == AST_RIGHT_SHIFT || ast_get_node_type(node) == AST_LESS_THAN || ast_get_node_type(node) == AST_GREATER_THAN 
   1130   || ast_get_node_type(node) == AST_LESS_THAN_OR_EQUAL || ast_get_node_type(node) == AST_GREATER_THAN_OR_EQUAL 
   1131   || ast_get_node_type(node) == AST_EQUAL || ast_get_node_type(node) == AST_NOT_EQUAL 
   1132   || ast_get_node_type(node) == AST_BITWISE_AND || ast_get_node_type(node) == AST_BITWISE_XOR || ast_get_node_type(node) == AST_BITWISE_OR 
   1133   || ast_get_node_type(node) == AST_LOGICAL_AND || ast_get_node_type(node) == AST_LOGICAL_OR || ast_get_node_type(node) == AST_ASSIGN 
   1134   || ast_get_node_type(node) == AST_ADD_ASSIGN || ast_get_node_type(node) == AST_SUB_ASSIGN || ast_get_node_type(node) == AST_MUL_ASSIGN || ast_get_node_type(node) == AST_DIV_ASSIGN 
   1135   || ast_get_node_type(node) == AST_MOD_ASSIGN || ast_get_node_type(node) == AST_LEFT_SHIFT_ASSIGN || ast_get_node_type(node) == AST_RIGHT_SHIFT_ASSIGN || ast_get_node_type(node) == AST_AND_ASSIGN 
   1136   || ast_get_node_type(node) == AST_XOR_ASSIGN || ast_get_node_type(node) == AST_OR_ASSIGN || ast_get_node_type(node) == AST_COMMA);
   1137   struct ast_binary_node *data = ast_get_data(node);
   1138   return data-&gt;right;
   1139 }
   1140 
   1141 </pre>
   1142 
   1143 
   1144 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1145 </div>
   1146 </div>
   1147 <a name="1:20"><div class="section"><h4 class="noheading">20. </h4></a>
   1148 
   1149 <div class="codeblock">
   1150 <span class="codeblock_name">{Implementation - Nodes (Conditional) <a href="ast.html#1:20">20</a>}</span>
   1151 <pre class="prettyprint lang-c">
   1152 struct ast_conditional_node {
   1153   ast_node_t *condition;
   1154   ast_node_t *true_expr;
   1155   ast_node_t *false_expr;
   1156 };
   1157 
   1158 ast_node_t *ast_create_conditional_node(ast_node_t *condition, ast_node_t *true_expr, ast_node_t *false_expr, int line, int column)
   1159 {
   1160   ast_node_t *node = ast_create_node(AST_CONDITIONAL, line, column, sizeof(struct ast_conditional_node));
   1161   struct ast_conditional_node *data = ast_get_data(node);
   1162   data-&gt;condition = condition;
   1163   data-&gt;true_expr = true_expr;
   1164   data-&gt;false_expr = false_expr;
   1165   return node;
   1166 }
   1167 
   1168 ast_node_t *ast_get_conditional_condition(ast_node_t *node)
   1169 {
   1170   assert(ast_get_node_type(node) == AST_CONDITIONAL);
   1171   struct ast_conditional_node *data = ast_get_data(node);
   1172   return data-&gt;condition;
   1173 }
   1174 
   1175 ast_node_t *ast_get_conditional_true_expr(ast_node_t *node)
   1176 {
   1177   assert(ast_get_node_type(node) == AST_CONDITIONAL);
   1178   struct ast_conditional_node *data = ast_get_data(node);
   1179   return data-&gt;true_expr;
   1180 }
   1181 
   1182 ast_node_t *ast_get_conditional_false_expr(ast_node_t *node)
   1183 {
   1184   assert(ast_get_node_type(node) == AST_CONDITIONAL);
   1185   struct ast_conditional_node *data = ast_get_data(node);
   1186   return data-&gt;false_expr;
   1187 }
   1188 
   1189 </pre>
   1190 
   1191 
   1192 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1193 </div>
   1194 </div>
   1195 <a name="1:21"><div class="section"><h4 class="noheading">21. </h4></a>
   1196 
   1197 <div class="codeblock">
   1198 <span class="codeblock_name">{Implementation - Nodes (Expression Statement Nodes) <a href="ast.html#1:21">21</a>}</span>
   1199 <pre class="prettyprint lang-c">
   1200 struct ast_expression_statement_node {
   1201   ast_node_t *expr;
   1202 };
   1203 
   1204 ast_node_t *ast_create_expression_statement_node(ast_node_t *expr)
   1205 {
   1206   ast_node_t *node = ast_create_node(AST_EXPRESSION_STATEMENT, expr-&gt;line, expr-&gt;column, sizeof(struct ast_expression_statement_node));
   1207   struct ast_expression_statement_node *data = ast_get_data(node);
   1208   data-&gt;expr = expr;
   1209   return node;
   1210 }
   1211 
   1212 ast_node_t *ast_get_expression_statement_expr(ast_node_t *node)
   1213 {
   1214   assert(ast_get_node_type(node) == AST_EXPRESSION_STATEMENT);
   1215   struct ast_expression_statement_node *data = ast_get_data(node);
   1216   return data-&gt;expr;
   1217 }
   1218 
   1219 </pre>
   1220 
   1221 
   1222 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1223 </div>
   1224 </div>
   1225 <a name="1:22"><div class="section"><h4 class="noheading">22. </h4></a>
   1226 
   1227 <div class="codeblock">
   1228 <span class="codeblock_name">{Implementation - Nodes (Label/Case Statement Nodes) <a href="ast.html#1:22">22</a>}</span>
   1229 <pre class="prettyprint lang-c">
   1230 struct ast_label_statement_node {
   1231   char *label;
   1232 };
   1233 
   1234 ast_node_t *ast_create_label_statement_node(char *label, int line, int col)
   1235 {
   1236   ast_node_t *node = ast_create_node(AST_LABEL_STATEMENT, line, col, sizeof(struct ast_label_statement_node));
   1237   struct ast_label_statement_node *data = ast_get_data(node);
   1238   data-&gt;label = label;
   1239   return node;
   1240 }
   1241 
   1242 char *ast_get_label_statement_label(ast_node_t *node)
   1243 {
   1244   assert(ast_get_node_type(node) == AST_LABEL_STATEMENT);
   1245   struct ast_label_statement_node *data = ast_get_data(node);
   1246   return data-&gt;label;
   1247 }
   1248 
   1249 ast_node_t *ast_create_case_statement_node(ast_node_t *expr, int line, int col)
   1250 {
   1251   ast_node_t *node = ast_create_node(AST_CASE_STATEMENT, line, col, sizeof(ast_node_t *));
   1252   ast_node_t **data = ast_get_data(node);
   1253   *data = expr;
   1254   return node;
   1255 }
   1256 
   1257 ast_node_t *ast_get_case_statement_expr(ast_node_t *node)
   1258 {
   1259   assert(ast_get_node_type(node) == AST_CASE_STATEMENT);
   1260   ast_node_t **data = ast_get_data(node);
   1261   return *data;
   1262 }
   1263 
   1264 ast_node_t *ast_create_default_statement_node(int line, int col)
   1265 {
   1266   return ast_create_node(AST_DEFAULT_STATEMENT, line, col, 0);
   1267 }
   1268 </pre>
   1269 
   1270 
   1271 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1272 </div>
   1273 </div>
   1274 <a name="1:23"><div class="section"><h4 class="noheading">23. </h4></a>
   1275 
   1276 <div class="codeblock">
   1277 <span class="codeblock_name">{Implementation - Nodes (Compound Statement Nodes) <a href="ast.html#1:23">23</a>}</span>
   1278 <pre class="prettyprint lang-c">
   1279 struct ast_compound_statement_node {
   1280   ast_node_t **decls_and_stmts;
   1281   size_t num_decls_and_stmts;
   1282 };
   1283 
   1284 ast_node_t *ast_create_compound_statement_node(ast_node_t **decls_and_stmts, size_t num_decls_and_stmts, int line, int col)
   1285 {
   1286   ast_node_t *node = ast_create_node(AST_COMPOUND_STATEMENT, line, col, sizeof(struct ast_compound_statement_node));
   1287   struct ast_compound_statement_node *data = ast_get_data(node);
   1288   data-&gt;decls_and_stmts = decls_and_stmts;
   1289   data-&gt;num_decls_and_stmts = num_decls_and_stmts;
   1290   return node;
   1291 }
   1292 
   1293 ast_node_t **ast_get_compound_statement_contents(ast_node_t *node, size_t *num_contents)
   1294 {
   1295   assert(ast_get_node_type(node) == AST_COMPOUND_STATEMENT);
   1296   struct ast_compound_statement_node *data = ast_get_data(node);
   1297   *num_contents = data-&gt;num_decls_and_stmts;
   1298   return data-&gt;decls_and_stmts;
   1299 }
   1300 
   1301 </pre>
   1302 
   1303 
   1304 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1305 </div>
   1306 </div>
   1307 <a name="1:24"><div class="section"><h4 class="noheading">24. </h4></a>
   1308 
   1309 <div class="codeblock">
   1310 <span class="codeblock_name">{Implementation - Nodes (Conditional Statement Nodes) <a href="ast.html#1:24">24</a>}</span>
   1311 <pre class="prettyprint lang-c">
   1312 struct ast_if_statement_node {
   1313   ast_node_t *condition;
   1314   ast_node_t *true_stmt;
   1315   ast_node_t *false_stmt;
   1316 };
   1317 
   1318 ast_node_t *ast_create_if_statement_node(ast_node_t *condition, ast_node_t *true_stmt, ast_node_t *false_stmt, int line, int col)
   1319 {
   1320   ast_node_t *node = ast_create_node(AST_IF_STATEMENT, line, col, sizeof(struct ast_if_statement_node));
   1321   struct ast_if_statement_node *data = ast_get_data(node);
   1322   data-&gt;condition = condition;
   1323   data-&gt;true_stmt = true_stmt;
   1324   data-&gt;false_stmt = false_stmt;
   1325   return node;
   1326 }
   1327 
   1328 ast_node_t *ast_get_if_statement_condition(ast_node_t *node)
   1329 {
   1330   assert(ast_get_node_type(node) == AST_IF_STATEMENT);
   1331   struct ast_if_statement_node *data = ast_get_data(node);
   1332   return data-&gt;condition;
   1333 }
   1334 
   1335 ast_node_t *ast_get_if_statement_true_stmt(ast_node_t *node)
   1336 {
   1337   assert(ast_get_node_type(node) == AST_IF_STATEMENT);
   1338   struct ast_if_statement_node *data = ast_get_data(node);
   1339   return data-&gt;true_stmt;
   1340 }
   1341 
   1342 ast_node_t *ast_get_if_statement_false_stmt(ast_node_t *node)
   1343 {
   1344   assert(ast_get_node_type(node) == AST_IF_STATEMENT);
   1345   struct ast_if_statement_node *data = ast_get_data(node);
   1346   return data-&gt;false_stmt;
   1347 }
   1348 
   1349 </pre>
   1350 
   1351 
   1352 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1353 </div>
   1354 </div>
   1355 <a name="1:25"><div class="section"><h4 class="noheading">25. </h4></a>
   1356 
   1357 <div class="codeblock">
   1358 <span class="codeblock_name">{Implementation - Nodes (Iteration Statement Nodes) <a href="ast.html#1:25">25</a>}</span>
   1359 <pre class="prettyprint lang-c">
   1360 
   1361 struct ast_iteration_statement_node {
   1362   ast_node_t *condition;
   1363   ast_node_t *stmt;
   1364 };
   1365 
   1366 ast_node_t *ast_create_while_statement_node(ast_node_t *condition, ast_node_t *stmt, int line, int col)
   1367 {
   1368   ast_node_t *node = ast_create_node(AST_WHILE_STATEMENT, line, col, sizeof(struct ast_iteration_statement_node));
   1369   struct ast_iteration_statement_node *data = ast_get_data(node);
   1370   data-&gt;condition = condition;
   1371   data-&gt;stmt = stmt;
   1372   return node;
   1373 }
   1374 
   1375 ast_node_t *ast_create_do_while_statement_node(ast_node_t *condition, ast_node_t *stmt, int line, int col)
   1376 {
   1377   ast_node_t *node = ast_create_node(AST_DO_WHILE_STATEMENT, line, col, sizeof(struct ast_iteration_statement_node));
   1378   struct ast_iteration_statement_node *data = ast_get_data(node);
   1379   data-&gt;condition = condition;
   1380   data-&gt;stmt = stmt;
   1381   return node;
   1382 }
   1383 
   1384 // Shares the first two members with ast_iteration_statement_node
   1385 struct ast_for_statement_node {  
   1386   ast_node_t *condition;  
   1387   ast_node_t *stmt;
   1388   ast_node_t *init;
   1389   ast_node_t *update;
   1390 
   1391 };
   1392 
   1393 ast_node_t *ast_create_for_statement_node(ast_node_t *init, ast_node_t *condition, ast_node_t *update, ast_node_t *stmt, int line, int col)
   1394 {
   1395   ast_node_t *node = ast_create_node(AST_FOR_STATEMENT, line, col, sizeof(struct ast_for_statement_node));
   1396   struct ast_for_statement_node *data = ast_get_data(node);
   1397   data-&gt;init = init;
   1398   data-&gt;condition = condition;
   1399   data-&gt;update = update;
   1400   data-&gt;stmt = stmt;
   1401   return node;
   1402 }
   1403 
   1404 ast_node_t *ast_get_iteration_statement_condition(ast_node_t *node)
   1405 {
   1406   assert(ast_get_node_type(node) == AST_WHILE_STATEMENT || ast_get_node_type(node) == AST_DO_WHILE_STATEMENT || ast_get_node_type(node) == AST_FOR_STATEMENT);
   1407   struct ast_iteration_statement_node *data = ast_get_data(node);
   1408   return data-&gt;condition;
   1409 }
   1410 
   1411 ast_node_t *ast_get_iteration_statement_stmt(ast_node_t *node)
   1412 {
   1413   assert(ast_get_node_type(node) == AST_WHILE_STATEMENT || ast_get_node_type(node) == AST_DO_WHILE_STATEMENT || ast_get_node_type(node) == AST_FOR_STATEMENT);
   1414   struct ast_iteration_statement_node *data = ast_get_data(node);
   1415   return data-&gt;stmt;
   1416 }
   1417 
   1418 ast_node_t *ast_get_for_statement_init(ast_node_t *node)
   1419 {
   1420   assert(ast_get_node_type(node) == AST_FOR_STATEMENT);
   1421   struct ast_for_statement_node *data = ast_get_data(node);
   1422   return data-&gt;init;
   1423 }
   1424 
   1425 ast_node_t *ast_get_for_statement_update(ast_node_t *node)
   1426 {
   1427   assert(ast_get_node_type(node) == AST_FOR_STATEMENT);
   1428   struct ast_for_statement_node *data = ast_get_data(node);
   1429   return data-&gt;update;
   1430 }
   1431 </pre>
   1432 
   1433 
   1434 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1435 </div>
   1436 </div>
   1437 <a name="1:26"><div class="section"><h4 class="noheading">26. </h4></a>
   1438 
   1439 <div class="codeblock">
   1440 <span class="codeblock_name">{Implementation - Nodes (Jump Statement Nodes) <a href="ast.html#1:26">26</a>}</span>
   1441 <pre class="prettyprint lang-c">
   1442 struct ast_goto_statement_node {
   1443   char *label;
   1444 };
   1445 
   1446 ast_node_t *ast_create_goto_statement_node(char *label, int line, int col)
   1447 {
   1448   ast_node_t *node = ast_create_node(AST_GOTO_STATEMENT, line, col, sizeof(struct ast_goto_statement_node));
   1449   struct ast_goto_statement_node *data = ast_get_data(node);
   1450   data-&gt;label = label;
   1451   return node;
   1452 }
   1453 
   1454 char *ast_get_goto_statement_label(ast_node_t *node)
   1455 {
   1456   assert(ast_get_node_type(node) == AST_GOTO_STATEMENT);
   1457   struct ast_goto_statement_node *data = ast_get_data(node);
   1458   return data-&gt;label;
   1459 }
   1460 
   1461 ast_node_t *ast_create_continue_statement_node(int line, int col)
   1462 {
   1463   return ast_create_node(AST_CONTINUE_STATEMENT, line, col, 0);
   1464 }
   1465 
   1466 ast_node_t *ast_create_break_statement_node(int line, int col)
   1467 {
   1468   return ast_create_node(AST_BREAK_STATEMENT, line, col, 0);
   1469 }
   1470 
   1471 ast_node_t *ast_create_return_statement_node(ast_node_t *expr, int line, int col)
   1472 {
   1473   ast_node_t *node = ast_create_node(AST_RETURN_STATEMENT, line, col, sizeof(ast_node_t *));
   1474   ast_node_t **data = ast_get_data(node);
   1475   *data = expr;
   1476   return node;
   1477 }
   1478 
   1479 ast_node_t *ast_get_return_statement_expr(ast_node_t *node)
   1480 {
   1481   assert(ast_get_node_type(node) == AST_RETURN_STATEMENT);
   1482   ast_node_t **data = ast_get_data(node);
   1483   return *data;
   1484 }
   1485 
   1486 </pre>
   1487 
   1488 
   1489 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1490 </div>
   1491 </div>
   1492 <a name="1:27"><div class="section"><h4 class="noheading">27. </h4></a>
   1493 
   1494 <div class="codeblock">
   1495 <span class="codeblock_name">{Implementation - Nodes (Switch Statement Nodes) <a href="ast.html#1:27">27</a>}</span>
   1496 <pre class="prettyprint lang-c">
   1497 
   1498 struct ast_switch_statement_node {
   1499   ast_node_t *expr;
   1500   ast_node_t *stmt;
   1501 };
   1502 
   1503 ast_node_t *ast_create_switch_statement_node(ast_node_t *expr, ast_node_t *stmt, int line, int col)
   1504 {
   1505   ast_node_t *node = ast_create_node(AST_SWITCH_STATEMENT, line, col, sizeof(struct ast_switch_statement_node));
   1506   struct ast_switch_statement_node *data = ast_get_data(node);
   1507   data-&gt;expr = expr;
   1508   data-&gt;stmt = stmt;
   1509   return node;
   1510 }
   1511 
   1512 ast_node_t *ast_get_switch_statement_expr(ast_node_t *node)
   1513 {
   1514   assert(ast_get_node_type(node) == AST_SWITCH_STATEMENT);
   1515   struct ast_switch_statement_node *data = ast_get_data(node);
   1516   return data-&gt;expr;
   1517 }
   1518 
   1519 ast_node_t *ast_get_switch_statement_stmt(ast_node_t *node)
   1520 {
   1521   assert(ast_get_node_type(node) == AST_SWITCH_STATEMENT);
   1522   struct ast_switch_statement_node *data = ast_get_data(node);
   1523   return data-&gt;stmt;
   1524 }
   1525 </pre>
   1526 
   1527 
   1528 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1529 </div>
   1530 
   1531 <div class="codeblock">
   1532 <span class="codeblock_name">{Implementation - Nodes (Simple Declaration Nodes) <a href="ast.html#1:27">27</a>}</span>
   1533 <pre class="prettyprint lang-c">
   1534 struct var_decl_data {
   1535   ast_node_t *type;
   1536   char *id;
   1537 };
   1538 
   1539 ast_node_t *ast_create_var_decl_node(ast_node_t *type, char *id, int line, int col)
   1540 {
   1541   ast_node_t *node = ast_create_node(AST_VAR_DECL, line, col, sizeof(struct var_decl_data));
   1542     struct var_decl_data *data = ast_get_data(node);
   1543   data-&gt;type = type;
   1544   data-&gt;id = id;
   1545   return (ast_node_t *)data;
   1546 }
   1547 
   1548 ast_node_t *ast_get_var_decl_type(ast_node_t *node)
   1549 {
   1550   struct var_decl_data *data = ast_get_data(node);
   1551   return data-&gt;type;
   1552 }
   1553 
   1554 char *ast_get_var_decl_id(ast_node_t *node)
   1555 {
   1556   struct var_decl_data *data = ast_get_data(node);
   1557   return data-&gt;id;
   1558 }
   1559 
   1560 struct fun_decl_data {
   1561   ast_node_t *type;
   1562   char *id;
   1563     ast_node_t **params;
   1564   size_t num_params;
   1565 };
   1566 
   1567 ast_node_t *ast_create_fun_decl_node(ast_node_t *type, char *id, ast_node_t **params, size_t num_params, int line, int col)
   1568 {
   1569   ast_node_t *node = ast_create_node(AST_FUN_DECL, line, col, sizeof(struct fun_decl_data));
   1570     struct fun_decl_data *data = ast_get_data(node);
   1571   data-&gt;type = type;
   1572   data-&gt;id = id;
   1573   data-&gt;params = params;
   1574   data-&gt;num_params = num_params;
   1575   return (ast_node_t *)data;
   1576 }
   1577 
   1578 ast_node_t *ast_get_fun_decl_type(ast_node_t *node)
   1579 {
   1580   struct fun_decl_data *data = ast_get_data(node);
   1581   return data-&gt;type;
   1582 }
   1583 
   1584 char *ast_get_fun_decl_id(ast_node_t *node)
   1585 {
   1586   struct fun_decl_data *data = ast_get_data(node);
   1587   return data-&gt;id;
   1588 }
   1589 
   1590 ast_node_t **ast_get_fun_decl_params(ast_node_t *node, size_t *num_params)
   1591 {
   1592   struct fun_decl_data *data = ast_get_data(node);
   1593   *num_params = data-&gt;num_params;
   1594   return data-&gt;params;
   1595 }
   1596 
   1597 </pre>
   1598 
   1599 
   1600 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1601 </div>
   1602 </div>
   1603 <a name="1:28"><div class="section"><h4 class="noheading">28. </h4></a>
   1604 
   1605 <div class="codeblock">
   1606 <span class="codeblock_name">{Implementation - Nodes (Parameter Declaration Nodes) <a href="ast.html#1:28">28</a>}</span>
   1607 <pre class="prettyprint lang-c">
   1608 struct param_data {
   1609   ast_node_t *type;
   1610   char *id;
   1611 };
   1612 
   1613 ast_node_t *ast_create_param_node(ast_node_t *type, char *id, int line, int col)
   1614 {
   1615   ast_node_t *node = ast_create_node(AST_PARAM, line, col, sizeof(struct param_data));
   1616     struct param_data *data = ast_get_data(node);
   1617   data-&gt;type = type;
   1618   data-&gt;id = id;
   1619   return node;
   1620 }
   1621 
   1622 ast_node_t *ast_get_param_type(ast_node_t *node)
   1623 {
   1624   struct param_data *data = ast_get_data(node);
   1625   return data-&gt;type;
   1626 }
   1627 
   1628 char *ast_get_param_id(ast_node_t *node)
   1629 {
   1630   struct param_data *data = ast_get_data(node);
   1631   return data-&gt;id;
   1632 }
   1633 
   1634 </pre>
   1635 
   1636 
   1637 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1638 </div>
   1639 </div>
   1640 <a name="1:29"><div class="section"><h4 class="noheading">29. </h4></a>
   1641 
   1642 <div class="codeblock">
   1643 <span class="codeblock_name">{Implementation - Nodes (Function Definition Nodes) <a href="ast.html#1:29">29</a>}</span>
   1644 <pre class="prettyprint lang-c">
   1645 
   1646 struct fun_def_data {
   1647   ast_node_t *type;
   1648   char *id;
   1649   ast_node_t **params;
   1650   size_t num_params;
   1651   ast_node_t *stmt;
   1652 };
   1653 
   1654 ast_node_t *ast_create_fun_def_node(ast_node_t *type, char *id, ast_node_t **params, size_t num_params, ast_node_t *stmt, int line, int col)
   1655 {
   1656   ast_node_t *node = ast_create_node(AST_FUN_DEF, line, col, sizeof(struct fun_def_data));
   1657     struct fun_def_data *data = ast_get_data(node);
   1658   data-&gt;type = type;
   1659   data-&gt;id = id;
   1660   data-&gt;params = params;
   1661   data-&gt;num_params = num_params;
   1662   data-&gt;stmt = stmt;
   1663   return node;
   1664 }
   1665 
   1666 ast_node_t *ast_get_fun_def_type(ast_node_t *node)
   1667 {
   1668   struct fun_def_data *data = ast_get_data(node);
   1669   return data-&gt;type;
   1670 }
   1671 
   1672 char *ast_get_fun_def_id(ast_node_t *node)
   1673 {
   1674   struct fun_def_data *data = ast_get_data(node);
   1675   return data-&gt;id;
   1676 }
   1677 
   1678 ast_node_t **ast_get_fun_def_params(ast_node_t *node, size_t *num_params)
   1679 {
   1680   struct fun_def_data *data = ast_get_data(node);
   1681   *num_params = data-&gt;num_params;
   1682   return data-&gt;params;
   1683 }
   1684 
   1685 ast_node_t *ast_get_fun_def_stmt(ast_node_t *node)
   1686 {
   1687   struct fun_def_data *data = ast_get_data(node);
   1688   return data-&gt;stmt;
   1689 }
   1690 
   1691 </pre>
   1692 
   1693 
   1694 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1695 </div>
   1696 </div>
   1697 <a name="1:30"><div class="section"><h4 class="noheading">30. </h4></a>
   1698 
   1699 <div class="codeblock">
   1700 <span class="codeblock_name">{Implementation - Nodes (Struct Declaration Nodes) <a href="ast.html#1:30">30</a>}</span>
   1701 <pre class="prettyprint lang-c">
   1702 struct struct_decl_data {
   1703   char *id;
   1704   ast_node_t **members;
   1705   size_t num_members;
   1706 };
   1707 
   1708 ast_node_t *ast_create_struct_decl_node(char *id, ast_node_t **members, size_t num_members, int line, int col)
   1709 {
   1710   ast_node_t *node = ast_create_node(AST_STRUCT_DECL, line, col, sizeof(struct struct_decl_data));
   1711   struct struct_decl_data *data = ast_get_data(node);   
   1712   data-&gt;id = id;
   1713   data-&gt;members = members;
   1714   data-&gt;num_members = num_members;
   1715   return node;
   1716 }
   1717 
   1718 char *ast_get_struct_decl_id(ast_node_t *node)
   1719 {
   1720   struct struct_decl_data *data = ast_get_data(node);
   1721   return data-&gt;id;
   1722 }
   1723 
   1724 ast_node_t **ast_get_struct_decl_members(ast_node_t *node, size_t *num_members)
   1725 {
   1726   struct struct_decl_data *data = ast_get_data(node);
   1727   *num_members = data-&gt;num_members;
   1728   return data-&gt;members;
   1729 }
   1730 </pre>
   1731 
   1732 
   1733 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1734 </div>
   1735 </div>
   1736 <a name="1:31"><div class="section"><h4 class="noheading">31. </h4></a>
   1737 
   1738 <div class="codeblock">
   1739 <span class="codeblock_name">{Implementation - Nodes (Union Declaration Nodes) <a href="ast.html#1:31">31</a>}</span>
   1740 <pre class="prettyprint lang-c">
   1741 struct union_decl_data {
   1742   char *id;
   1743   ast_node_t **members;
   1744   size_t num_members;
   1745 };
   1746 
   1747 ast_node_t *ast_create_union_decl_node(char *id, ast_node_t **members, size_t num_members, int line, int col)
   1748 {
   1749   ast_node_t *node = ast_create_node(AST_UNION_DECL, line, col, sizeof(struct union_decl_data));
   1750     struct union_decl_data *data = ast_get_data(node);
   1751   data-&gt;id = id;
   1752   data-&gt;members = members;
   1753   data-&gt;num_members = num_members;
   1754   return node;
   1755 }
   1756 
   1757 char *ast_get_union_decl_id(ast_node_t *node)
   1758 {
   1759   struct union_decl_data *data = ast_get_data(node);
   1760   return data-&gt;id;
   1761 }
   1762 
   1763 ast_node_t **ast_get_union_decl_members(ast_node_t *node, size_t *num_members)
   1764 {
   1765   struct union_decl_data *data = ast_get_data(node);
   1766   *num_members = data-&gt;num_members;
   1767   return data-&gt;members;
   1768 }
   1769 
   1770 </pre>
   1771 
   1772 
   1773 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1774 </div>
   1775 </div>
   1776 <a name="1:32"><div class="section"><h4 class="noheading">32. </h4></a>
   1777 
   1778 <div class="codeblock">
   1779 <span class="codeblock_name">{Implementation - Nodes (Enum Declaration Nodes) <a href="ast.html#1:32">32</a>}</span>
   1780 <pre class="prettyprint lang-c">
   1781 struct enum_decl_data {
   1782   char *id;
   1783   ast_node_t **enums;
   1784   size_t num_enums;
   1785 };
   1786 
   1787 ast_node_t *ast_create_enum_decl_node(char *id, ast_node_t **enums, size_t num_enums, int line, int col)
   1788 {
   1789   ast_node_t *node = ast_create_node(AST_ENUM_DECL, line, col, sizeof(struct enum_decl_data));
   1790     struct enum_decl_data *data = ast_get_data(node);
   1791   data-&gt;id = id;
   1792   data-&gt;enums = enums;
   1793   data-&gt;num_enums = num_enums;
   1794   return node;
   1795 }
   1796 
   1797 char *ast_get_enum_decl_id(ast_node_t *node)
   1798 {
   1799   struct enum_decl_data *data = ast_get_data(node);
   1800   return data-&gt;id;
   1801 }
   1802 
   1803 ast_node_t **ast_get_enum_decl_enums(ast_node_t *node, size_t *num_enums)
   1804 {
   1805   struct enum_decl_data *data = ast_get_data(node);
   1806   *num_enums = data-&gt;num_enums;
   1807   return data-&gt;enums;
   1808 }
   1809 
   1810 </pre>
   1811 
   1812 
   1813 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1814 </div>
   1815 </div>
   1816 <a name="1:33"><div class="section"><h4 class="noheading">33. </h4></a>
   1817 
   1818 <div class="codeblock">
   1819 <span class="codeblock_name">{Implementation - Nodes (Typedef Declaration Nodes) <a href="ast.html#1:33">33</a>}</span>
   1820 <pre class="prettyprint lang-c">
   1821 struct typedef_data {
   1822   ast_node_t *type;
   1823   char *id;
   1824 };
   1825 
   1826 ast_node_t *ast_create_typedef_node(ast_node_t *type, char *id, int line, int col)
   1827 {
   1828   ast_node_t *node = ast_create_node(AST_TYPEDEF, line, col, sizeof(struct typedef_data));
   1829     struct typedef_data *data = ast_get_data(node);
   1830   data-&gt;type = type;
   1831   data-&gt;id = id;
   1832   return node;
   1833 }
   1834 
   1835 ast_node_t *ast_get_typedef_type(ast_node_t *node)
   1836 {
   1837   struct typedef_data *data = ast_get_data(node);
   1838   return data-&gt;type;
   1839 }
   1840 
   1841 char *ast_get_typedef_id(ast_node_t *node)
   1842 {
   1843   struct typedef_data *data = ast_get_data(node);
   1844   return data-&gt;id;
   1845 }
   1846 
   1847 </pre>
   1848 
   1849 
   1850 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1851 </div>
   1852 </div>
   1853 <a name="1:34"><div class="section"><h4 class="noheading">34. </h4></a>
   1854 
   1855 <div class="codeblock">
   1856 <span class="codeblock_name">{Implementation - Nodes (Types/Members) <a href="ast.html#1:34">34</a>}</span>
   1857 <pre class="prettyprint lang-c">
   1858 struct type_data {
   1859   token_t **type;
   1860   size_t num_type;
   1861 };
   1862 
   1863 ast_node_t *ast_create_type_node(token_t *type[], size_t num_type, int line, int col)
   1864 {
   1865   ast_node_t *node = ast_create_node(AST_TYPE, line, col, sizeof(struct type_data));
   1866     struct type_data *data = ast_get_data(node);
   1867   data-&gt;type = type;
   1868   data-&gt;num_type = num_type;
   1869   return node;
   1870 }
   1871 
   1872 token_t **ast_get_type(ast_node_t *node, size_t *num_type)
   1873 {
   1874   struct type_data *data = ast_get_data(node);
   1875   *num_type = data-&gt;num_type;
   1876   return data-&gt;type;
   1877 }
   1878 
   1879 struct member_data {
   1880   ast_node_t *type;
   1881   char *id;
   1882 };
   1883 
   1884 ast_node_t *ast_create_member_node(ast_node_t *type, char *id, int line, int col)
   1885 {
   1886   ast_node_t *node = ast_create_node(AST_MEMBER, line, col, sizeof(struct member_data));
   1887     struct member_data *data = ast_get_data(node);
   1888   data-&gt;type = type;
   1889   data-&gt;id = id;
   1890   return node;
   1891 }
   1892 
   1893 ast_node_t *ast_get_member_type(ast_node_t *node)
   1894 {
   1895   struct member_data *data = ast_get_data(node);
   1896   return data-&gt;type;
   1897 }
   1898 
   1899 char *ast_get_member_id(ast_node_t *node)
   1900 {
   1901   struct member_data *data = ast_get_data(node);
   1902   return data-&gt;id;
   1903 }
   1904 
   1905 struct enum_member_data {
   1906   char *id;
   1907   ast_node_t *value;
   1908 };
   1909 
   1910 ast_node_t *ast_create_enum_member_node(char *id, ast_node_t *value, int line, int col)
   1911 {
   1912   ast_node_t *node = ast_create_node(AST_ENUM_MEMBER, line, col, sizeof(struct enum_member_data));
   1913     struct enum_member_data *data = ast_get_data(node);
   1914   data-&gt;id = id;
   1915   data-&gt;value = value;
   1916   return node;
   1917 }
   1918 
   1919 char *ast_get_enum_member_id(ast_node_t *node)
   1920 {
   1921   struct enum_member_data *data = ast_get_data(node);
   1922   return data-&gt;id;
   1923 }
   1924 
   1925 ast_node_t *ast_get_enum_member_expr(ast_node_t *node)
   1926 {
   1927   struct enum_member_data *data = ast_get_data(node);
   1928   return data-&gt;value;
   1929 }
   1930 
   1931 </pre>
   1932 
   1933 
   1934 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1935 </div>
   1936 </div>
   1937 <a name="1:35"><div class="section"><h4 class="noheading">35. </h4></a>
   1938 
   1939 <div class="codeblock">
   1940 <span class="codeblock_name">{Implementation - Nodes (Translation Unit Nodes) <a href="ast.html#1:35">35</a>}</span>
   1941 <pre class="prettyprint lang-c">
   1942 struct translation_unit_data {
   1943   ast_node_t **items;
   1944   size_t num_items;
   1945 };
   1946 
   1947 ast_node_t *ast_create_translation_unit_node(ast_node_t **items, size_t num_items, int line, int col)
   1948 {
   1949   ast_node_t *node = ast_create_node(AST_TRANSLATION_UNIT, line, col, sizeof(struct translation_unit_data));
   1950     struct translation_unit_data *data = ast_get_data(node);
   1951   data-&gt;items = items;
   1952   data-&gt;num_items = num_items;
   1953   return node;
   1954 }
   1955 
   1956 ast_node_t **ast_get_translation_unit_items(ast_node_t *node, size_t *num_items)
   1957 {
   1958   struct translation_unit_data *data = ast_get_data(node);
   1959   *num_items = data-&gt;num_items;
   1960   return data-&gt;items;
   1961 }
   1962 </pre>
   1963 
   1964 
   1965 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   1966 </div>
   1967 </div>
   1968 <a name="1:36"><div class="section"><h4 class="noheading">36. </h4></a>
   1969 <p>Freeing the AST is going to be pretty painful. We need to free all the nodes, and all the data associated with them. We'll start by freeing the data associated with each node, and then free the node itself. We'll do this recursively, so that we can free all the nodes in the tree.
   1970 </p>
   1971 
   1972 <div class="codeblock">
   1973 <span class="codeblock_name">{Implementation - Nodes (Freeing) <a href="ast.html#1:36">36</a>}</span>
   1974 <pre class="prettyprint lang-c">
   1975 void ast_free_node(ast_node_t *node) {
   1976   if (!node) {
   1977     return;
   1978   }
   1979   switch (ast_get_node_type(node)) {
   1980   case AST_INTU32:
   1981   case AST_INTU64:
   1982   case AST_INTS32:
   1983   case AST_INTS64:
   1984   case AST_FLOAT:
   1985   case AST_DOUBLE:
   1986   case AST_STRING:
   1987   case AST_CHAR:
   1988   case AST_VAR:
   1989     break;
   1990   case AST_SUBSCRIPT:
   1991     ast_free_node(ast_get_subscript_expr(node));
   1992     ast_free_node(ast_get_subscript_idx(node));
   1993     free(node);
   1994     break;
   1995   case AST_DIRECT_COMPONENT_SELECTION:
   1996   case AST_INDIRECT_COMPONENT_SELECTION:
   1997     ast_free_node(ast_get_component_expr(node));
   1998     free(node);
   1999     break;
   2000   case AST_FUNCTION_CALL: {
   2001     size_t num_args;
   2002     ast_node_t **args = ast_get_function_call_args(node, &amp;num_args);
   2003     for (size_t i = 0; i &lt; num_args; i++) {
   2004       ast_free_node(args[i]);
   2005     }
   2006     free(args);
   2007     ast_free_node(ast_get_function_call_expr(node));
   2008     free(node);
   2009     break;
   2010   }
   2011   case AST_POSTFIX_INC:
   2012   case AST_POSTFIX_DEC: {
   2013     ast_free_node(ast_get_postfix_expr(node));
   2014     free(node);
   2015     break;
   2016   }
   2017   case AST_UNARY_PLUS:
   2018   case AST_UNARY_MINUS:
   2019   case AST_LOGICAL_NOT:
   2020   case AST_BITWISE_NOT:
   2021   case AST_ADDRESS_OF:
   2022   case AST_INDIRECTION:
   2023   case AST_SIZEOF:
   2024   case AST_PRE_INC:
   2025   case AST_PRE_DEC: {
   2026     ast_free_node(ast_get_unary_expr(node));
   2027     free(node);
   2028     break;
   2029   }
   2030   case AST_CAST: {
   2031     ast_free_node(ast_get_cast_type(node));
   2032     ast_free_node(ast_get_cast_expr(node));
   2033     free(node);
   2034     break;
   2035   }
   2036   case AST_MUL:
   2037   case AST_DIV:
   2038   case AST_MOD:
   2039   case AST_ADD:
   2040   case AST_SUB:
   2041   case AST_LEFT_SHIFT:
   2042   case AST_RIGHT_SHIFT:
   2043   case AST_LESS_THAN:
   2044   case AST_GREATER_THAN:
   2045   case AST_LESS_THAN_OR_EQUAL:
   2046   case AST_GREATER_THAN_OR_EQUAL:
   2047   case AST_EQUAL:
   2048   case AST_NOT_EQUAL:
   2049   case AST_BITWISE_AND:
   2050   case AST_BITWISE_XOR:
   2051   case AST_BITWISE_OR:
   2052   case AST_LOGICAL_AND:
   2053   case AST_LOGICAL_OR:
   2054   case AST_COMMA:
   2055   case AST_ASSIGN:
   2056   case AST_ADD_ASSIGN:
   2057   case AST_SUB_ASSIGN:
   2058   case AST_MUL_ASSIGN:
   2059   case AST_DIV_ASSIGN:
   2060   case AST_MOD_ASSIGN:
   2061   case AST_LEFT_SHIFT_ASSIGN:
   2062   case AST_RIGHT_SHIFT_ASSIGN:
   2063   case AST_AND_ASSIGN:
   2064   case AST_XOR_ASSIGN:
   2065   case AST_OR_ASSIGN:
   2066  {
   2067     ast_free_node(ast_get_left_expr(node));
   2068     ast_free_node(ast_get_right_expr(node));
   2069     free(node);
   2070     break;
   2071   }
   2072   case AST_CONDITIONAL: {
   2073     ast_free_node(ast_get_conditional_condition(node));
   2074     ast_free_node(ast_get_conditional_true_expr(node));
   2075     ast_free_node(ast_get_conditional_false_expr(node));
   2076     free(node);
   2077     break;
   2078   }
   2079   case AST_EXPRESSION_STATEMENT:
   2080     ast_free_node(ast_get_expression_statement_expr(node));
   2081     free(node);
   2082     break;
   2083   case AST_LABEL_STATEMENT:
   2084     free(node);
   2085     break;
   2086   case AST_CASE_STATEMENT:
   2087     ast_free_node(ast_get_case_statement_expr(node));
   2088     free(node);
   2089     break;
   2090   case AST_DEFAULT_STATEMENT:
   2091     free(node);
   2092     break;
   2093   case AST_COMPOUND_STATEMENT:
   2094     {
   2095       size_t size = 0;
   2096       ast_node_t **comp_stmts = ast_get_compound_statement_contents(node, &amp;size);
   2097       for(size_t i = 0; i &lt; size; i++)
   2098       {
   2099         ast_free_node(comp_stmts[i]);
   2100       }
   2101       free(comp_stmts);
   2102       free(node);
   2103       break;
   2104     }
   2105   case AST_IF_STATEMENT:
   2106   {
   2107     ast_free_node(ast_get_if_statement_condition(node));
   2108     ast_free_node(ast_get_if_statement_true_stmt(node));
   2109     ast_free_node(ast_get_if_statement_false_stmt(node));
   2110     free(node);
   2111     break;
   2112   }
   2113   case AST_WHILE_STATEMENT:
   2114   case AST_DO_WHILE_STATEMENT:
   2115   {
   2116     ast_free_node(ast_get_iteration_statement_condition(node));
   2117     ast_free_node(ast_get_iteration_statement_stmt(node));
   2118     free(node);
   2119     break;
   2120   }
   2121   case AST_FOR_STATEMENT:
   2122   {
   2123     ast_free_node(ast_get_for_statement_init(node));
   2124     ast_free_node(ast_get_iteration_statement_condition(node));
   2125     ast_free_node(ast_get_for_statement_update(node));
   2126     ast_free_node(ast_get_iteration_statement_stmt(node));
   2127     free(node);
   2128     break;
   2129   }
   2130   case AST_GOTO_STATEMENT:
   2131     free(node);
   2132     break;
   2133   case AST_CONTINUE_STATEMENT:
   2134   case AST_BREAK_STATEMENT:
   2135     free(node);
   2136     break;
   2137   case AST_RETURN_STATEMENT:
   2138     ast_free_node(ast_get_return_statement_expr(node));
   2139     free(node);
   2140     break;
   2141   case AST_SWITCH_STATEMENT:
   2142   {
   2143     ast_free_node(ast_get_switch_statement_expr(node));
   2144     ast_free_node(ast_get_switch_statement_stmt(node));
   2145     free(node);
   2146     break;
   2147   }
   2148   case AST_NULL_STATEMENT:
   2149     free(node);
   2150     break;
   2151   case AST_VAR_DECL:
   2152   {
   2153     ast_node_t *type = ast_get_var_decl_type(node);
   2154     ast_free_node(type);
   2155     free(node);
   2156     break;
   2157   }
   2158   case AST_FUN_DECL:
   2159   {
   2160     ast_node_t *type = ast_get_fun_decl_type(node);
   2161     ast_free_node(type);
   2162     size_t num_params;
   2163     ast_node_t **params = ast_get_fun_decl_params(node, &amp;num_params);
   2164     for(size_t i = 0; i &lt; num_params; i++)
   2165     {
   2166       ast_free_node(params[i]);
   2167     }
   2168     free(params);
   2169     free(node);
   2170     break;
   2171   }
   2172   case AST_PARAM:
   2173   {
   2174     ast_node_t *type = ast_get_param_type(node);
   2175     ast_free_node(type);
   2176     free(node);
   2177     break;
   2178   }
   2179   case AST_FUN_DEF:
   2180   {
   2181     ast_node_t *type = ast_get_fun_def_type(node);
   2182     ast_free_node(type);
   2183     size_t num_params;
   2184     ast_node_t **params = ast_get_fun_def_params(node, &amp;num_params);
   2185     for(size_t i = 0; i &lt; num_params; i++)
   2186     {
   2187       ast_free_node(params[i]);
   2188     }
   2189     free(params);
   2190     ast_free_node(ast_get_fun_def_stmt(node));
   2191     free(node);
   2192     break;
   2193   }
   2194   case AST_STRUCT_DECL:
   2195   {
   2196     size_t num_members;
   2197     ast_node_t **members = ast_get_struct_decl_members(node, &amp;num_members);
   2198     for(size_t i = 0; i &lt; num_members; i++)
   2199     {
   2200       ast_free_node(members[i]);
   2201     }
   2202     free(members);
   2203     free(node);
   2204     break;
   2205   }
   2206   case AST_UNION_DECL:
   2207   {
   2208     size_t num_members;
   2209     ast_node_t **members = ast_get_union_decl_members(node, &amp;num_members);
   2210     for(size_t i = 0; i &lt; num_members; i++)
   2211     {
   2212       ast_free_node(members[i]);
   2213     }
   2214     free(members);
   2215     free(node);
   2216     break;
   2217   }
   2218   case AST_ENUM_DECL:
   2219   {
   2220     size_t num_enums;
   2221     ast_node_t **enums = ast_get_enum_decl_enums(node, &amp;num_enums);
   2222     for(size_t i = 0; i &lt; num_enums; i++)
   2223     {
   2224       ast_free_node(enums[i]);
   2225     }
   2226     free(enums);
   2227     free(node);
   2228     break;
   2229   }
   2230   case AST_TYPEDEF:
   2231   {
   2232     ast_node_t *type = ast_get_typedef_type(node);
   2233     ast_free_node(type);
   2234     free(node);
   2235     break;
   2236   }
   2237   case AST_TYPE:
   2238   {
   2239     token_t **type;
   2240     size_t num_type;
   2241     type = ast_get_type(node, &amp;num_type);
   2242     for(size_t i = 0; i &lt; num_type; i++)
   2243     {
   2244       free(type[i]);
   2245     }
   2246     free(type);
   2247     free(node);
   2248     break;
   2249   }
   2250   case AST_MEMBER:
   2251   {
   2252     ast_node_t *type = ast_get_member_type(node);
   2253     ast_free_node(type);
   2254     free(node);
   2255     break;
   2256   }
   2257   case AST_ENUM_MEMBER:
   2258   {
   2259     ast_node_t *value = ast_get_enum_member_expr(node);
   2260     ast_free_node(value);
   2261     free(node);
   2262     break;
   2263   }
   2264   case AST_TRANSLATION_UNIT:
   2265   {
   2266     size_t num_items;
   2267     ast_node_t **items = ast_get_translation_unit_items(node, &amp;num_items);
   2268     for(size_t i = 0; i &lt; num_items; i++)
   2269     {
   2270       ast_free_node(items[i]);
   2271     }
   2272     free(items);
   2273     free(node);
   2274     break;
   2275   }
   2276   default:
   2277     assert(0);
   2278   }
   2279 
   2280 }
   2281 </pre>
   2282 
   2283 
   2284 <p class="seealso">Used in section <a href="ast.html#1:37">37</a></p>
   2285 </div>
   2286 </div>
   2287 <a name="1:37"><div class="section"><h4 class="noheading">37. </h4></a>
   2288 
   2289 <div class="codeblock">
   2290 <span class="codeblock_name">{<strong>ast.c</strong> <a href="ast.html#1:37">37</a>}</span>
   2291 <pre class="prettyprint lang-c">
   2292 #include &lt;stdlib.h&gt;
   2293 #include &lt;assert.h&gt;
   2294 #include "ast.h"
   2295 <span class="nocode pln">{Implementation - Common Node Structure, <a href="ast.html#1:15">15</a>}</span>
   2296 <span class="nocode pln">{Implementation - Nodes (Primary), <a href="ast.html#1:16">16</a>}</span>
   2297 <span class="nocode pln">{Implementation - Nodes (Postfix), <a href="ast.html#1:17">17</a>}</span>
   2298 <span class="nocode pln">{Implementation - Nodes (Unary/Cast), <a href="ast.html#1:18">18</a>}</span>
   2299 <span class="nocode pln">{Implementation - Nodes (Binary/Assign/Comma), <a href="ast.html#1:19">19</a>}</span>
   2300 <span class="nocode pln">{Implementation - Nodes (Conditional), <a href="ast.html#1:20">20</a>}</span>
   2301 <span class="nocode pln">{Implementation - Nodes (Expression Statement Nodes), <a href="ast.html#1:21">21</a>}</span>
   2302 <span class="nocode pln">{Implementation - Nodes (Label/Case Statement Nodes), <a href="ast.html#1:22">22</a>}</span>
   2303 <span class="nocode pln">{Implementation - Nodes (Compound Statement Nodes), <a href="ast.html#1:23">23</a>}</span>
   2304 <span class="nocode pln">{Implementation - Nodes (Conditional Statement Nodes), <a href="ast.html#1:24">24</a>}</span>
   2305 <span class="nocode pln">{Implementation - Nodes (Iteration Statement Nodes), <a href="ast.html#1:25">25</a>}</span>
   2306 <span class="nocode pln">{Implementation - Nodes (Jump Statement Nodes), <a href="ast.html#1:26">26</a>}</span>
   2307 <span class="nocode pln">{Implementation - Nodes (Switch Statement Nodes), <a href="ast.html#1:27">27</a>}</span>
   2308 <span class="nocode pln">{Implementation - Nodes (Simple Declaration Nodes), <a href="ast.html#1:27">27</a>}</span>
   2309 <span class="nocode pln">{Implementation - Nodes (Parameter Declaration Nodes), <a href="ast.html#1:28">28</a>}</span>
   2310 <span class="nocode pln">{Implementation - Nodes (Function Definition Nodes), <a href="ast.html#1:29">29</a>}</span>
   2311 <span class="nocode pln">{Implementation - Nodes (Struct Declaration Nodes), <a href="ast.html#1:30">30</a>}</span>
   2312 <span class="nocode pln">{Implementation - Nodes (Union Declaration Nodes), <a href="ast.html#1:31">31</a>}</span>
   2313 <span class="nocode pln">{Implementation - Nodes (Enum Declaration Nodes), <a href="ast.html#1:32">32</a>}</span>
   2314 <span class="nocode pln">{Implementation - Nodes (Typedef Declaration Nodes), <a href="ast.html#1:33">33</a>}</span>
   2315 <span class="nocode pln">{Implementation - Nodes (Types/Members), <a href="ast.html#1:34">34</a>}</span>
   2316 <span class="nocode pln">{Implementation - Nodes (Translation Unit Nodes), <a href="ast.html#1:35">35</a>}</span>
   2317 <span class="nocode pln">{Implementation - Nodes (Freeing), <a href="ast.html#1:36">36</a>}</span>
   2318 </pre>
   2319 
   2320 
   2321 
   2322 </div>
   2323 
   2324 </div>
   2325 </body>