#ifndef _DECLARATION_H
#define _DECLARATION_H
#include " Vector.h "
#include < stdio.h >
#include " Stmt.h "
#include " Port.h "
typedef struct Declaration_t CDeclaration;
typedef struct Declaration_VMT ... {
void (*generate)(CDeclaration*, FILE*);
} CDeclaration_VMT;
struct Declaration_t ... {
const CDeclaration_VMT *vmt;
int srcLineNoBegin;
int srcLineNoEnd;
} ;
extern void CDeclaration_Initialize(CDeclaration * , int , int );
extern void CDeclaration_Generate(CDeclaration * , FILE * );
#define Declaration_Generate(this,arg1)
(((CDeclaration * )( this )) -> vmt -> generate((CDeclaration * )( this ),arg1))
#endif
#define _DECLARATION_H
#include " Vector.h "
#include < stdio.h >
#include " Stmt.h "
#include " Port.h "
typedef struct Declaration_t CDeclaration;
typedef struct Declaration_VMT ... {
void (*generate)(CDeclaration*, FILE*);
} CDeclaration_VMT;
struct Declaration_t ... {
const CDeclaration_VMT *vmt;
int srcLineNoBegin;
int srcLineNoEnd;
} ;
extern void CDeclaration_Initialize(CDeclaration * , int , int );
extern void CDeclaration_Generate(CDeclaration * , FILE * );
#define Declaration_Generate(this,arg1)
(((CDeclaration * )( this )) -> vmt -> generate((CDeclaration * )( this ),arg1))
#endif
#include
"
Declaration.h
"
static const CDeclaration_VMT vmt = ... { CDeclaration_Generate } ;
void CDeclaration_Initialize(CDeclaration * this , int no1, int no2)
... {
((CDeclaration*)this)->vmt = (const CDeclaration_VMT*)&vmt;
this->srcLineNoBegin = no1;
this->srcLineNoEnd = no2;
}
void CDeclaration_Generate(CDeclaration * this , FILE * output)
... {
#ifdef DEBUG
fprintf(output, "CDeclaration_Generate ");
#endif
}
static const CDeclaration_VMT vmt = ... { CDeclaration_Generate } ;
void CDeclaration_Initialize(CDeclaration * this , int no1, int no2)
... {
((CDeclaration*)this)->vmt = (const CDeclaration_VMT*)&vmt;
this->srcLineNoBegin = no1;
this->srcLineNoEnd = no2;
}
void CDeclaration_Generate(CDeclaration * this , FILE * output)
... {
#ifdef DEBUG
fprintf(output, "CDeclaration_Generate ");
#endif
}
#ifndef _VARIABLE_DECL_H
#define _VARIABLE_DECL_H
#include " Expression.h "
#include " Declaration.h "
typedef struct VariableDecl_t CVariableDecl;
typedef struct VariableDecl_VMT ... {
void (*generate)(CVariableDecl*, FILE*);
} CVariableDecl_VMT;
struct VariableDecl_t ... {
CDeclaration super;
char *name;
CExpression *constraint;
char *type;
} ;
extern void CVariableDecl_Initialize(CVariableDecl * , char * , CExpression * , char * , int , int );
extern void CVariableDecl_Generate(CVariableDecl * , FILE * );
#endif
#define _VARIABLE_DECL_H
#include " Expression.h "
#include " Declaration.h "
typedef struct VariableDecl_t CVariableDecl;
typedef struct VariableDecl_VMT ... {
void (*generate)(CVariableDecl*, FILE*);
} CVariableDecl_VMT;
struct VariableDecl_t ... {
CDeclaration super;
char *name;
CExpression *constraint;
char *type;
} ;
extern void CVariableDecl_Initialize(CVariableDecl * , char * , CExpression * , char * , int , int );
extern void CVariableDecl_Generate(CVariableDecl * , FILE * );
#endif
#include
<
string
.h
>
#include " VariableDecl.h "
static const CVariableDecl_VMT vmt = ... { CVariableDecl_Generate } ;
void CVariableDecl_Initialize(CVariableDecl * this , char * name, CExpression * constraint, char * type, int no1, int no2)
... {
CDeclaration_Initialize((CDeclaration*)this, no1, no2);
((CDeclaration*)this)->vmt = (const CDeclaration_VMT*)&vmt;
this->name = name;
this->constraint = constraint;
this->type = type;
}
void CVariableDecl_Generate(CVariableDecl * this , FILE * output)
... {
fprintf(output, "Dim %s", this->name);
if(this->constraint != 0)...{
Expression_Generate(this->constraint, output);
}
if(!strncmp(this->type, "string", 6))...{
fprintf(output, " As String ");
}else if(!strncmp(this->type, "integer", 7))...{
fprintf(output, " As Long ");
}else...{
fprintf(output, " As %s ", this->type);
}
}
#include " VariableDecl.h "
static const CVariableDecl_VMT vmt = ... { CVariableDecl_Generate } ;
void CVariableDecl_Initialize(CVariableDecl * this , char * name, CExpression * constraint, char * type, int no1, int no2)
... {
CDeclaration_Initialize((CDeclaration*)this, no1, no2);
((CDeclaration*)this)->vmt = (const CDeclaration_VMT*)&vmt;
this->name = name;
this->constraint = constraint;
this->type = type;
}
void CVariableDecl_Generate(CVariableDecl * this , FILE * output)
... {
fprintf(output, "Dim %s", this->name);
if(this->constraint != 0)...{
Expression_Generate(this->constraint, output);
}
if(!strncmp(this->type, "string", 6))...{
fprintf(output, " As String ");
}else if(!strncmp(this->type, "integer", 7))...{
fprintf(output, " As Long ");
}else...{
fprintf(output, " As %s ", this->type);
}
}
#ifndef _FUNCTION_DECL_H
#define _FUNCTION_DECL_H
#include " Declaration.h "
typedef struct FunctionDecl_t CFunctionDecl;
typedef struct FunctionDecl_VMT ... {
void (*generate)(CFunctionDecl*, FILE*);
} CFunctionDecl_VMT;
struct FunctionDecl_t ... {
CDeclaration super;
Vector *decls;
char *name;
Vector *args;
char *retType;
Vector *stmts;
} ;
extern void CFunctionDecl_Initialize(CFunctionDecl * , char * , Vector * , Vector * , char * , Vector * , int , int );
extern void CFunctionDecl_Generate(CFunctionDecl * , FILE * );
#endif
#define _FUNCTION_DECL_H
#include " Declaration.h "
typedef struct FunctionDecl_t CFunctionDecl;
typedef struct FunctionDecl_VMT ... {
void (*generate)(CFunctionDecl*, FILE*);
} CFunctionDecl_VMT;
struct FunctionDecl_t ... {
CDeclaration super;
Vector *decls;
char *name;
Vector *args;
char *retType;
Vector *stmts;
} ;
extern void CFunctionDecl_Initialize(CFunctionDecl * , char * , Vector * , Vector * , char * , Vector * , int , int );
extern void CFunctionDecl_Generate(CFunctionDecl * , FILE * );
#endif
#include
"
FunctionDecl.h
"
static const CFunctionDecl_VMT vmt = ... { CFunctionDecl_Generate } ;
void CFunctionDecl_Initialize(CFunctionDecl * this , char * name, Vector * decls, Vector * args, char * retType, Vector * stmts, int no1, int no2) ... {
CDeclaration_Initialize((CDeclaration*)this, no1, no2);
((CDeclaration*)this)->vmt = (const CDeclaration_VMT*)&vmt;
this->decls = decls;
this->name = name;
this->args = args;
this->retType = retType;
this->stmts = stmts;
}
void CFunctionDecl_Generate(CFunctionDecl * this , FILE * output) ... {
int i, j;
CDeclaration *decl = (CDeclaration*)this;
fprintf(output, "Function %s(", this->name);
if(this->args != 0)...{
for(i = 0; i < size(this->args); i++)...{
CPort *port = elementAt(this->args, i);
Port_Generate(port, output);
if(i < size(this->args) - 1)...{
fprintf(output, ",");
}
}
}
fprintf(output, ") As %s ", this->retType);
fprintf(output, "Dim s_(%d) as String ", decl->srcLineNoEnd - decl->srcLineNoBegin + 1);
for(i = decl->srcLineNoBegin - 1, j = 0; i < decl->srcLineNoEnd; i++, j++)...{
fprintf(output, "s_(%3d) = "%3d:%s" ", j, i + 1, getLineAt(i));
}
fprintf(output, "LoadSrc2 s_ ", this->name);
if(this->decls != 0)...{
for(i = 0; i < size(this->decls); i++)...{
Declaration_Generate(elementAt(this->decls, i), output);
}
}
fprintf(output, "Dim loop_count As Integer ");
if(this->stmts != 0)...{
for(i = 0; i < size(this->stmts); i++)...{
Stmt_Generate(elementAt(this->stmts, i), output);
}
}
fprintf(output, "End Function ");
}
static const CFunctionDecl_VMT vmt = ... { CFunctionDecl_Generate } ;
void CFunctionDecl_Initialize(CFunctionDecl * this , char * name, Vector * decls, Vector * args, char * retType, Vector * stmts, int no1, int no2) ... {
CDeclaration_Initialize((CDeclaration*)this, no1, no2);
((CDeclaration*)this)->vmt = (const CDeclaration_VMT*)&vmt;
this->decls = decls;
this->name = name;
this->args = args;
this->retType = retType;
this->stmts = stmts;
}
void CFunctionDecl_Generate(CFunctionDecl * this , FILE * output) ... {
int i, j;
CDeclaration *decl = (CDeclaration*)this;
fprintf(output, "Function %s(", this->name);
if(this->args != 0)...{
for(i = 0; i < size(this->args); i++)...{
CPort *port = elementAt(this->args, i);
Port_Generate(port, output);
if(i < size(this->args) - 1)...{
fprintf(output, ",");
}
}
}
fprintf(output, ") As %s ", this->retType);
fprintf(output, "Dim s_(%d) as String ", decl->srcLineNoEnd - decl->srcLineNoBegin + 1);
for(i = decl->srcLineNoBegin - 1, j = 0; i < decl->srcLineNoEnd; i++, j++)...{
fprintf(output, "s_(%3d) = "%3d:%s" ", j, i + 1, getLineAt(i));
}
fprintf(output, "LoadSrc2 s_ ", this->name);
if(this->decls != 0)...{
for(i = 0; i < size(this->decls); i++)...{
Declaration_Generate(elementAt(this->decls, i), output);
}
}
fprintf(output, "Dim loop_count As Integer ");
if(this->stmts != 0)...{
for(i = 0; i < size(this->stmts); i++)...{
Stmt_Generate(elementAt(this->stmts, i), output);
}
}
fprintf(output, "End Function ");
}