00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __loaded__aoc_cpp__
00021 #define __loaded__aoc_cpp__
00022 using namespace std;
00023 #line 1 "aoc.c++"
00024 #include <map>
00025 #include <iostream>
00026 #include <fstream>
00027 #include <stdlib.h>
00028 #include <assert.h>
00029 #include <stdio.h>
00030 #include <vector>
00031 #include "ao-lexer.h"
00032 #include "ao-grammar.h"
00033 #include "ao-syntax.h"
00034 #include "sao-printer.h"
00035 outputbuf object;
00036 outputbuf object2;
00037 outputbuf meta;
00038 outputbuf msgs;
00039 outputbuf msgs1;
00040 outputbuf globhead;
00041 outputbuf useslist;
00042 outputbuf impl;
00043 map<string,string> field2init;
00044 char* current_ao;
00045 void aoset_in(FILE * i);
00046 int aoparse();
00047
00048 bool pascal=false;
00049
00050 void dopascal(int argc, char* argv[])
00051 {
00052 pascal=true;
00053 print(useslist,"Active_Objects");
00054
00055 FILE* f=fopen(argv[1],"rb");
00056 assert(f);
00057 aoset_in(f);
00058 aoparse();
00059 fclose(f);
00060
00061
00062 char* s = strdup(argv[2]);
00063 char* s2=strdup(s);
00064 s2[strlen(s2)-4]=0;
00065
00066 char pascal_fwd[100];
00067 char pascal_ifc[100];
00068 char pascal_imp[100];
00069 strcpy(pascal_fwd,s2);
00070 strcpy(pascal_ifc,s2);
00071 strcpy(pascal_imp,s2);
00072 strcat(pascal_fwd,"_fwd.inc");
00073 strcat(pascal_ifc,"_ifc.inc");
00074 strcat(pascal_imp,"_imp.inc");
00075
00076 ofstream fwd(pascal_fwd);
00077 ofstream ifc(pascal_ifc);
00078 ofstream imp(pascal_imp);
00079
00080 fwd << "{Active Object compiled file\n"
00081 "Do not modify. Changes might be lost\n"
00082 " --------------------------------------------}\n";
00083 ifc << "{Active Object compiled file\n"
00084 "Do not modify. Changes might be lost\n"
00085 " --------------------------------------------}\n";
00086 imp << "{Active Object compiled file\n"
00087 "Do not modify. Changes might be lost\n"
00088 " --------------------------------------------}\n";
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 for(unsigned i = 0 ; i < globhead.size(); i++)
00099 fwd << globhead[i];
00100
00101
00102 ifc << "\n//-------------------------------------"
00103 "\n// Active Object base messaging classes"
00104 "\n//-------------------------------------\n";
00105 for(unsigned i = 0 ; i < msgs1.size(); i++)
00106 ifc << msgs1[i];
00107
00108 ifc << "\n//-------------------------------------"
00109 "\n// Main object definition"
00110 "\n//-------------------------------------\n";
00111 for(unsigned i = 0 ; i < object.size(); i++)
00112 ifc << object[i];
00113 ifc << "\n//-------------------------------------"
00114 "\n// Specific messaging classes "
00115 "\n//-------------------------------------\n";
00116 for(unsigned i = 0 ; i < msgs.size(); i++)
00117 ifc << msgs[i];
00118 ifc << "\n//-------------------------------------"
00119 "\n// Active Object wrapper "
00120 "\n//-------------------------------------\n";
00121 for(unsigned i = 0 ; i < meta.size(); i++)
00122 ifc << meta[i];
00123
00124 imp << "\n//-------------------------------------"
00125 "\n// Active Object Methods "
00126 "\n//-------------------------------------\n";
00127 for(unsigned i = 0 ; i < object2.size(); i++)
00128 imp << object2[i];
00129
00130
00131 for(unsigned i = 0 ; i < impl.size(); i++)
00132 imp << impl[i];
00133
00134 ifc.close();
00135 imp.close();
00136 fwd.close();
00137 }
00138
00139 void cpp(int argc, char* argv[])
00140 {
00141 FILE* f=fopen(argv[1],"rb");
00142 assert(f);
00143 aoset_in(f);
00144 aoparse();
00145 fclose(f);
00146
00147 ofstream out(argv[2]);
00148 if (!pascal)
00149 out << "/****\n"
00150 " Active Object compiled file\n"
00151 " Copyright (C) 2006-2010 Werner Van Belle\n"
00152 " Do not modify. Changes might be lost\n"
00153 " --------------------------------------------\n"
00154 " This program is free software; you can redistribute it and/or modify\n"
00155 " it under the terms of the GNU General Public License as published by\n"
00156 " the Free Software Foundation; either version 2 of the License, or\n"
00157 " (at your option) any later version.\n"
00158 "\n"
00159 " This program is distributed in the hope that it will be useful,\n"
00160 " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
00161 " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
00162 " GNU General Public License for more details.\n"
00163 "****/\n\n";
00164 else
00165 out << "{Active Object compiled file\n"
00166 "Do not modify. Changes might be lost\n"
00167 " --------------------------------------------}\n";
00168
00169 char* s = strdup(argv[2]);
00170
00171 char* s2=strdup(s);
00172 s2[strlen(s2)-4]=0;
00173
00174 char pascal_fwd[100];
00175 char pascal_ifc[100];
00176 char pascal_imp[100];
00177 strcpy(pascal_fwd,s2);
00178 strcpy(pascal_ifc,s2);
00179 strcpy(pascal_imp,s2);
00180 strcat(pascal_fwd,"_fwd.inc");
00181 strcat(pascal_ifc,"_ifc.inc");
00182 strcat(pascal_imp,"_imp.inc");
00183
00184 for(unsigned int j = 0 ; j < strlen(s) ; j++)
00185 {
00186 s[j]=toupper(s[j]);
00187 if (!isalnum(s[j]))
00188 s[j]='_';
00189 }
00190
00191 if (!pascal)
00192 {
00193 out << "#ifndef __" << s <<"\n";
00194 out << "#define __" << s <<"\n";
00195 out << "#include \"active-objects.h\"\n";
00196 out << "using namespace std;\n";
00197 }
00198 else
00199 {
00200 out << "Unit " << s2 << ";\n";
00201 out << "{$mode objfpc}{$H+}\n";
00202 out << "\nINTERFACE\nUses ";
00203 for(unsigned i = 0 ; i < useslist.size(); i++)
00204 out << useslist[i];
00205 out << ";\n";
00206 }
00207
00208 for(unsigned i = 0 ; i < globhead.size(); i++)
00209 out << globhead[i];
00210
00211 if (!pascal)
00212 {
00213 out << "\n//-------------------------------------"
00214 "\n// Active Object base messaging classes"
00215 "\n//-------------------------------------\n";
00216
00217 for(unsigned i = 0 ; i < msgs1.size(); i++)
00218 out << msgs1[i];
00219
00220 out << "\n//-------------------------------------"
00221 "\n// Main object definition"
00222 "\n//-------------------------------------\n";
00223 for(unsigned i = 0 ; i < object.size(); i++)
00224 out << object[i];
00225 out << "\n//-------------------------------------"
00226 "\n// Specific messaging classes "
00227 "\n//-------------------------------------\n";
00228 for(unsigned i = 0 ; i < msgs.size(); i++)
00229 out << msgs[i];
00230 out << "\n//-------------------------------------"
00231 "\n// Active Object wrapper "
00232 "\n//-------------------------------------\n";
00233 for(unsigned i = 0 ; i < meta.size(); i++)
00234 out << meta[i];
00235 out << "\n//-------------------------------------"
00236 "\n// Active Object Methods"
00237 "\n//-------------------------------------\n";
00238 for(unsigned i = 0 ; i < object2.size(); i++)
00239 out << object2[i];
00240 out << "#endif // __" << s <<"\n";
00241 }
00242 else
00243 {
00244
00245 out << "\n//-------------------------------------"
00246 "\n// Active Object base messaging classes"
00247 "\n//-------------------------------------\n";
00248 for(unsigned i = 0 ; i < msgs1.size(); i++)
00249 out << msgs1[i];
00250
00251 out << "\n//-------------------------------------"
00252 "\n// Main object definition"
00253 "\n//-------------------------------------\n";
00254 for(unsigned i = 0 ; i < object.size(); i++)
00255 out << object[i];
00256 out << "\n//-------------------------------------"
00257 "\n// Specific messaging classes "
00258 "\n//-------------------------------------\n";
00259 for(unsigned i = 0 ; i < msgs.size(); i++)
00260 out << msgs[i];
00261 out << "\n//-------------------------------------"
00262 "\n// Active Object wrapper "
00263 "\n//-------------------------------------\n";
00264 for(unsigned i = 0 ; i < meta.size(); i++)
00265 out << meta[i];
00266 out << "\n//-------------------------------------"
00267 "\n// Active Object Methods "
00268 "\n//-------------------------------------\n";
00269 for(unsigned i = 0 ; i < object2.size(); i++)
00270 out << object2[i];
00271
00272 out << "\n\nIMPLEMENTATION\n\n";
00273 for(unsigned i = 0 ; i < impl.size(); i++)
00274 out << impl[i];
00275 out << "end.\n";
00276 }
00277 out.close();
00278 exit(0);
00279 }
00280
00281 int main(int argc,char* argv[])
00282 {
00283 assert(argc==3 || argc==4);
00284 if (argc==4)
00285 {
00286 assert(strcmp(argv[3],"--pascal")==0);
00287 dopascal(argc,argv);
00288 }
00289 else
00290 {
00291 cpp(argc,argv);
00292 }
00293 }
00294 #endif // __loaded__aoc_cpp__