aboutsummaryrefslogblamecommitdiff
path: root/semantics.h
blob: 65d1b7e98524fe3b48e68a2ea3748394a9eeeb69 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                   
                  
 
                           
                                



                           

                               

                         
 
                                
                                
             
               

                                                 
              
               
                     


                                                    
  
 
                                                         
                           
 
              
          





                

             
           
               
           



                                                        
                                           
                
                         

                                                
                


                          
                        
                                                  
          
                                      
               
  
 
                                                       
                                   
 
                                                  
                                            
 

                             
                    
              
                 
            
  

                       
                                 
                     
                      


         
                                                            
                                 
                                                  

                                                                    
                                     
 



                             



                             
                    





                             
            

                    
                 


                                                  
  
 
                        
                 


             


                

             



                     
                   


                                      

                                         






                                                               
                             
                                                                   
                                                         
                                                         
                                                            

                               
                                     
 
                                        
                                         
 
                                     






               
                                    
                      
                      



                                   
                            
      
#ifndef SEMANTICS_H
#define SEMANTICS_H
#include "const.h"

typedef struct CNode CNode;
typedef struct CTable *CTable_t;
typedef struct CType CType;
typedef CType *CType_t;
typedef struct CVar CVar;
typedef CVar *CVar_t;
typedef struct CSymbol CSymbol;
typedef CSymbol *CSymbol_t;
typedef struct CDef CDef;
typedef CDef *CDef_t;

typedef struct CBList *CBList_t;
typedef struct COList *COList_t;
struct CVar {
    char *name;
    CVar_t next;    /* next in the linked list */
    CType_t type;
    int start;
    CNode *ast;
    CBList_t defsite;
    /* the following fields are used for renaming */
    int cnt;
    COList_t stack;
};

CVar_t cvar_create(char *name, CType_t type, CNode *ast);
void cvar_print(CVar_t cv);

struct CType {
    enum {
        CINT,
        CCHAR,
        CVOID,
        CSTRUCT,
        CUNION,
        CARR,
        CPTR,
        CFUNC
    } type;
    char *name;
    union {
        struct {
            CTable_t fields; /* for a struct or union */
            CVar_t flist;
        } st;
        CType_t ref;    /* for a pointer */
        struct {
            CType_t elem;
            int len;
        } arr;                /* for an array */
        struct {
            CVar_t params;
            CVar_t local;
            CType_t ret;
            CNode *body;
        } func;               /* for a function */
    } rec;
    int size;   /* memory footprint */
    CNode *ast;
};

CType_t ctype_create(