bool Lex::AddDynamic(Param *p, const char *name, const char *func) { Dynamic *d; d = f_dynamics; while(d != f_start_dynamics && d != 0) { if(strcmp(name, d->GetName()) == 0) { fprintf(stderr, "%s:%ld: error: the dynamic function named \"%s\" is defined twice (first defined at line %ld)\n", f_filename, f_line, name, d->Line()); g_errcnt++; return false; } d = d->Next(); } d = f_dynamics; while(d != 0) { if(strcmp(name, d->GetName()) == 0) { if(!d->CheckParams(p)) { fprintf(stderr, "%s:%ld: error: the parameters of the dynamic functions defined on line %ld and the one on line %ld are not compatible\n", f_filename, f_line, f_line, d->Line()); g_errcnt++; } else { d->AddFunc(func); } return false; } d = d->Next(); } f_dynamics = new Dynamic(f_dynamics, f_line, p, name); f_dynamics->AddFunc(func); return true; }
void Lex::TimedDynamic(void) { Dynamic *d; d = f_dynamics; while(d != f_start_dynamics) { d->SetTimed(); d = d->Next(); } }
void parse_class(Lex& lex, FILE *h, FILE *cpp) { int t, l, brackets; const char *s, *e; do { t = lex.GetToken(); lex.Write(h); } while(isspace(t) || t == '\n'); if(t != Lex::IDENTIFIER) { // is it possible that we don't have an identifier after the keyword class?! fprintf(stderr, "%s:%ld: error: expected an identifier after the 'class' keyword\n", lex.Filename(), lex.Line()); g_errcnt++; return; } // we got the class name! s = lex.GetStart(); e = lex.GetEnd(); l = static_cast<int>(e - s); char* class_name = new char[l + 1]; str_keeper sk(class_name); memcpy(class_name, s, l); class_name[l] = '\0'; brackets = 0; for(;;) { t = lex.GetToken(); if(t == '\0') { // that's a big problem in the source file! return; } if(t == ';') { if(brackets == 0) { // in this special case, we don't have a full declaration // i.e.: class Stuff; lex.Write(h); return; } } else if(t == '{') { brackets++; } else if(t == '}') { if(brackets == 0) { fprintf(stderr, "%s:%ld: error: could not find { in a class definition\n", lex.Filename(), lex.Line()); g_errcnt++; } else { brackets--; } if(brackets == 0) { break; } } else if(t == Lex::IDENTIFIER) { s = lex.GetStart(); e = lex.GetEnd(); if(e - s == 5 && memcmp(s, "class", 5) == 0) { // warning: this is a recursive call... lex.Write(h); parse_class(lex, h, cpp); } else if(e - s == 5 && memcmp(s, "async", 5) == 0) { // we found an asynchroneous function convert_async(lex, class_name, h, cpp); continue; } } lex.Write(h); } // once a class is being closed, we need to put the dynamic // functions if any were defined Dynamic *d = lex.GetDynamic(); if(d != 0) { fprintf(h, "public:\n"); while(d != 0) { d->Output(lex, h, cpp, class_name); d = d->Next(); } } lex.ClearDynamic(); // we don't expect the lexical input to be messed up by // the Dynamic::Output() calls... lex.Write(h); }