void doLocalAnsiArgument(int type) { char symbol_name[NAMESIZE]; int identity, address, argptr, ptr; if (match("*")) { identity = POINTER; } else { if (type == STRUCT) { error("cannot pass struct"); return; } identity = VARIABLE; if (type == VOID) return; } if (symname(symbol_name)) { if (find_locale(symbol_name) > -1) { multidef(symbol_name); } else { argptr = add_local (symbol_name, identity, type, 0, AUTO); argstk = argstk + INTSIZE; ptr = local_table_index; while (ptr != NUMBER_OF_GLOBALS) { // modify stack offset as we push more params ptr = ptr - 1; address = symbol_table[ptr].offset; symbol_table[ptr].offset = address + INTSIZE; /* Struct etc FIXME */ } } } else { error("illegal argument name"); junk(); } if (match("[")) { while (inbyte() != ']') { if (endst()) { break; } } identity = POINTER; symbol_table[argptr].identity = identity; } }
void putatom (LISP p, FILE *fd) { if (p == NIL) { fputs ("()", fd); return; } switch (mem[p].type) { case TSYMBOL: fputs (symname (p), fd); break; case TBOOL: fputs ("#t", fd); break; case TINTEGER: fprintf (fd, "%ld", numval (p)); break; case TREAL: fprintf (fd, "%#g", realval (p)); break; case TSTRING: putstring (p, fd); break; case TVECTOR: putvector (p, fd); break; case TCHAR: putchr (charval (p), fd); break; case THARDW: fprintf (fd, "<builtin-%lx>", (long) hardwval (p)); break; case TCLOSURE: fprintf (fd, "<closure-%lx>", p); break; default: fputs ("<?>", fd); break; } }
void PragmaBytes(int flag) { FILE *fp; char sname[NAMESIZE]; int32_t value; int count; if ( symname(sname) ) { if ( (fp=fopen("zcc_opt.def","a")) == NULL ) { error(E_ZCCOPT); } fprintf(fp,"\nIF NEED_%s\n",sname); if ( flag ) fprintf(fp,"\tdefc DEFINED_NEED_%s = 1\n",sname); /* Now, do the numbers */ count=0; while ( !cmatch(';') ) { if ( count == 0 ) fprintf(fp,"\n\tdefb\t"); else fprintf(fp,","); if ( number(&value) ) { fprintf(fp,"%d",value); } else { warning(W_EXPARG); } if ( rcmatch(';') ) { break; } needchar(','); count++; if ( count == 9 ) count=0; } fprintf(fp,"\nENDIF\n"); fclose(fp); needchar(';'); } }
void putexpr (LISP p, FILE *fd) { LISP h, a; if (! istype (p, TPAIR)) { putatom (p, fd); return; } if (istype (h = car (p), TSYMBOL) && istype (a = cdr (p), TPAIR) && cdr (a) == NIL) { char *funcname = symname (h); if (!strcmp (funcname, "quote")) { putc ('\'', fd); putexpr (car (a), fd); return; } if (!strcmp (funcname, "quasiquote")) { putc ('`', fd); putexpr (car (a), fd); return; } if (!strcmp (funcname, "unquote")) { putc (',', fd); putexpr (car (a), fd); return; } if (!strcmp (funcname, "unquote-splicing")) { putc (',', fd); putc ('@', fd); putexpr (car (a), fd); return; } } putc ('(', fd); putlist (p, fd); putc (')', fd); }
void defenum(char *sname, char storage) { SYMBOL *ptr; char name[NAMEMAX]; long value; /* Add it into the symbol table, we do not need to keep track of the * tag because we treat enums as constants */ addglb(sname, ENUM, CINT, 0, storage, 0, 0); value=0; /* initial constant */ needchar('{'); do { if (symname(name)==0) illname(name); if ( cmatch('=') ) constexpr(&value,1); ptr=addglb(name,VARIABLE,ENUM,0,STATIK,0,0); ptr->size=value; value++; } while (cmatch(',')); needchar('}'); }
/** * declare argument types * called from "newfunc", this routine adds an entry in the local * symbol table for each named argument * completely rewritten version. p.l. woods * @param t argument type (char, int) * @return */ void getarg(int t) { int j, legalname, address, argptr; char n[NAMESIZE]; FOREVER { if (argstk == 0) return; if (match("*")) j = POINTER; else j = VARIABLE; if (!(legalname = symname(n))) illname(); if (match("[")) { while (inbyte() != ']') if (endst()) break; j = POINTER; } if (legalname) { if ((argptr = find_locale(n)) > -1) { symbol_table[argptr].identity = j; symbol_table[argptr].type = t; address = argtop - symbol_table[argptr].offset; symbol_table[argptr].offset = address; } else error("expecting argument name"); } argstk = argstk - INTSIZE; if (endst()) return; if (!match(",")) error("expected comma"); } }
/** * local declarations * @param stclass * @return */ int do_local_declares(int stclass) { int type = 0; int otag; // tag of struct object being declared int sflag; // TRUE for struct definition, zero for union char sname[NAMESIZE]; blanks(); if ((sflag=amatch("struct", 6)) || amatch("union", 5)) { if (symname(sname) == 0) { // legal name ? illname(); } if ((otag=find_tag(sname)) == -1) { // structure not previously defined otag = define_struct(sname, stclass, sflag); } declare_local(STRUCT, stclass, otag); } else if ((type = get_type()) != 0) { declare_local(type, stclass, -1); } else if (stclass == LSTATIC || stclass == DEFAUTO) { declare_local(CINT, stclass, -1); } else { return(0); } need_semicolon(); return(1); }
LISP eval (LISP expr, LISP *ctxp) { LISP ctx = ctxp ? *ctxp : NIL; LISP func; again: if (expr == NIL) return (NIL); /* Если это символ, берем его значение */ if (istype (expr, TSYMBOL)) { /* Поиск значения по контексту */ LISP pair = findatom (expr, ctx); if (pair == NIL) { fprintf (stderr, "unbound symbol: `%s'\n", symname (expr)); return (NIL); } return (cdr (pair)); } /* Все, что не атом и не список, не вычисляется */ if (! istype (expr, TPAIR)) return (expr); /* Перебираем специальные формы. * quote define set! begin lambda let let* letrec if * and or cond else => quasiquote unquote unquote-splicing */ /* Зарезервированные имена: * delay do case */ func = car (expr); if (istype (func, TSYMBOL)) { char *funcname = symname (func); if (!strcmp (funcname, "quote")) { if (! istype (expr = cdr (expr), TPAIR)) return (NIL); return (car (expr)); } if (!strcmp (funcname, "define")) { LISP value, atom, pair, arg; int lambda; if (! istype (expr = cdr (expr), TPAIR)) return (NIL); lambda = istype (atom = car (expr), TPAIR); if (lambda) { /* define, совмещенный с lambda */ arg = cdr (atom); atom = car (atom); } if (! istype (atom, TSYMBOL) || ! istype (expr = cdr (expr), TPAIR)) return (NIL); pair = findatom (atom, ctx); if (pair == NIL) { /* Расширяем контекст */ pair = cons (atom, NIL); if (ctxp) /* локальный контекст */ *ctxp = ctx = cons (pair, ctx); else /* контекст верхнего уровня */ ENV = cons (pair, ENV); } if (lambda) value = closure (cons (arg, expr), ctx); else value = evalblock (expr, ctx); setcdr (pair, value); return (value); } if (!strcmp (funcname, "set!")) { LISP value = NIL; if (! istype (expr = cdr (expr), TPAIR)) return (NIL); if (istype (cdr (expr), TPAIR)) value = evalblock (cdr (expr), ctx); setatom (car (expr), value, ctx); return (value); } if (!strcmp (funcname, "begin")) return (evalblock (cdr (expr), ctx)); if (!strcmp (funcname, "lambda")) { LISP arg = NIL; if (istype (expr = cdr (expr), TPAIR)) { arg = car (expr); if (! istype (expr = cdr (expr), TPAIR)) expr = NIL; } return (closure (cons (arg, expr), ctx)); } if (!strcmp (funcname, "let")) { LISP arg = NIL, oldctx = ctx; if (istype (expr = cdr (expr), TPAIR)) { arg = car (expr); if (! istype (expr = cdr (expr), TPAIR)) expr = NIL; } /* Расширяем контекст новыми переменными */ while (istype (arg, TPAIR)) { LISP var = car (arg); arg = cdr (arg); /* Значения вычисляем в старом контексте */ if (istype (var, TPAIR)) ctx = cons (cons (car (var), evalblock (cdr (var), oldctx)), ctx); else if (istype (var, TSYMBOL)) ctx = cons (cons (var, NIL), ctx); } return (evalblock (expr, ctx)); } if (!strcmp (funcname, "let*")) { LISP arg = NIL; if (istype (expr = cdr (expr), TPAIR)) { arg = car (expr); if (! istype (expr = cdr (expr), TPAIR)) expr = NIL; } /* Расширяем контекст новыми переменными */ while (istype (arg, TPAIR)) { LISP var = car (arg); arg = cdr (arg); /* Значения вычисляем в текущем контексте */ if (istype (var, TPAIR)) ctx = cons (cons (car (var), evalblock (cdr (var), ctx)), ctx); else if (istype (var, TSYMBOL)) ctx = cons (cons (var, NIL), ctx); } return (evalblock (expr, ctx)); } if (!strcmp (funcname, "letrec")) { LISP arg = NIL, a; if (istype (expr = cdr (expr), TPAIR)) { arg = car (expr); if (! istype (expr = cdr (expr), TPAIR)) expr = NIL; } /* Расширяем контекст новыми переменными с пустыми значениями */ for (a=arg; istype (a, TPAIR); a=cdr(a)) { LISP var = car (a); if (istype (var, TPAIR)) ctx = cons (cons (car (var), NIL), ctx); else if (istype (var, TSYMBOL)) ctx = cons (cons (var, NIL), ctx); } /* Вычисляем значения в новом контексте */ for (a=arg; istype (a, TPAIR); a=cdr(a)) { LISP var = car (a); if (istype (var, TPAIR)) setatom (car (var), evalblock (cdr (var), ctx), ctx); } return (evalblock (expr, ctx)); } if (!strcmp (funcname, "if")) { LISP iftrue = NIL, iffalse = NIL, test; if (! istype (expr = cdr (expr), TPAIR)) return (NIL); test = car (expr); if (istype (expr = cdr (expr), TPAIR)) { iftrue = car (expr); iffalse = cdr (expr); } if (eval (test, &ctx) != NIL) return (eval (iftrue, &ctx)); return (evalblock (iffalse, ctx)); } if (!strcmp (funcname, "and")) { while (istype (expr = cdr (expr), TPAIR)) if (eval (car (expr), &ctx) == NIL) return (NIL); return (T); } if (!strcmp (funcname, "or")) { while (istype (expr = cdr (expr), TPAIR)) if (eval (car (expr), &ctx) == NIL) return (T); return (NIL); } if (!strcmp (funcname, "cond")) { LISP oldctx = ctx, test, clause; while (istype (expr = cdr (expr), TPAIR)) { if (! istype (clause = car (expr), TPAIR)) continue; ctx = oldctx; if (istype (car (clause), TSYMBOL) && ! strcmp (symname (car (clause)), "else")) return (evalblock (cdr (clause), ctx)); test = eval (car (clause), &ctx); if (test == NIL || ! istype (clause = cdr (clause), TPAIR)) continue; if (istype (car (clause), TSYMBOL) && ! strcmp (symname (car (clause)), "=>")) { clause = evalblock (cdr (clause), ctx); if (istype (clause, THARDW)) return ((*hardwval (clause)) (cons (test, NIL), ctx)); if (istype (clause, TCLOSURE)) return (evalclosure (clause, cons (test, NIL))); return (NIL); } return (evalblock (clause, ctx)); } return (NIL); } if (!strcmp (funcname, "quasiquote")) { if (! istype (expr = cdr (expr), TPAIR)) return (NIL); return (quasiquote (car (expr), ctx, 0)); } if (!strcmp (funcname, "unquote") || !strcmp (funcname, "unquote-splicing")) { if (! istype (expr = cdr (expr), TPAIR)) return (NIL); expr = car (expr); goto again; } } /* Вычисляем все аргументы */ expr = evallist (expr, ctx); return (evalfunc (car (expr), cdr (expr), ctxp ? *ctxp : TOPLEVEL)); }
void DoFnKR( SYMBOL *currfn, char simple) { char n[NAMESIZE]; SYMBOL *prevarg; /* ptr to symbol table entry of most recent argument */ SYMBOL *cptr; TAG_SYMBOL *otag ; /* structure tag for structure argument */ struct varid var; prevarg=0; Zsp=0; /* Reset stack pointer */ undeclared=0; infunc=1; while ( !simple && cmatch(')') == 0 ) { /* then count args */ /* any legal name bumps arg count */ if ( symname(n) ) { /* add link to argument chain */ if ( (cptr=addloc(n,0,CINT,0,0)) ) cptr->offset.p = prevarg ; prevarg = cptr ; ++undeclared ; } else { error(E_ARGNAME); junk(); } blanks(); /* if not closing paren, should be comma */ if ( ch() != ')' && cmatch(',') == 0 ) { warning(W_EXPCOM); } if ( endst() ) break ; } Zsp = 0 ; /* preset stack ptr */ while ( undeclared ) { char regit=NO; if (amatch("register") ) regit=YES; /* Auto is be default in function defns, but someone might * try it on... */ if (amatch("auto") ) warning(W_AUTO); otag=GetVarID(&var,STATIK); if (var.type==STRUCT) { getarg(STRUCT, otag,NO,0,0, var.zfar,NO) ; } else if (var.type || regit) { if (regit && var.type == NO ) var.type=CINT; getarg(var.type,NULL_TAG,NO,0,var.sign,var.zfar,NO); } else { error(E_BADARG) ; break ; } } /* Have finished K&R parsing */ setlocvar(prevarg,currfn); }
/** * declare a static variable * @param type * @param storage * @param mtag tag of struct whose members are being declared, or zero * @param otag tag of struct object being declared. only matters if mtag is non-zero * @param is_struct struct or union or no meaning * @return 1 if a function was parsed */ int declare_global(int type, int storage, TAG_SYMBOL *mtag, int otag, int is_struct) { int dim, identity; char sname[NAMESIZE]; FOREVER { FOREVER { if (endst ()) return 0; dim = 1; if (match ("*")) { identity = POINTER; } else { identity = VARIABLE; } if (!symname (sname)) illname (); if (match ("(")) { /* FIXME: We need to deal with pointer types properly here */ if (identity == POINTER) type = CINT; newfunc_typed(storage, sname, type); /* Can't int foo(x){blah),a=4; */ return 1; } /* FIXME: we need to deal with extern properly here */ if (find_global (sname) > -1) multidef (sname); if (identity == VARIABLE) notvoid(type); if (match ("[")) { dim = needsub (); //if (dim || storage == EXTERN) { identity = ARRAY; //} else { // identity = POINTER; //} } // add symbol if (mtag == 0) { // real variable, not a struct/union member identity = initials(sname, type, identity, dim, otag); add_global (sname, identity, type, (dim == 0 ? -1 : dim), storage); if (type == STRUCT) { symbol_table[current_symbol_table_idx].tagidx = otag; } break; } else if (is_struct) { // structure member, mtag->size is offset add_member(sname, identity, type, mtag->size, storage); // store (correctly scaled) size of member in tag table entry if (identity == POINTER) type = CINT; scale_const(type, otag, &dim); mtag->size += dim; } else { // union member, offset is always zero add_member(sname, identity, type, 0, storage); // store maximum member size in tag table entry if (identity == POINTER) type = CINT; scale_const(type, otag, &dim); if (mtag->size < dim) mtag->size = dim; } } if (!match (",")) return 0; } }
/** * declare local variables * works just like "declglb", but modifies machine stack and adds * symbol table entry with appropriate stack offset to find it again * @param typ * @param stclass * @param otag index of tag in tag_table */ void declare_local(int typ, int stclass, int otag) { int k, j; char sname[NAMESIZE]; FOREVER { FOREVER { if (endst()) return; if (match("*")) j = POINTER; else j = VARIABLE; if (!symname(sname)) illname(); if (-1 != find_locale(sname)) multidef (sname); if (match("[")) { k = needsub(); if (k) { j = ARRAY; if (typ & CINT) { k = k * INTSIZE; } else if (typ == STRUCT) { k = k * tag_table[otag].size; } } else { j = POINTER; k = INTSIZE; } } else { if (j == POINTER) { k = INTSIZE; } else { switch (typ) { case CCHAR: case UCHAR: k = 1; break; case STRUCT: k = tag_table[otag].size; break; default: k = INTSIZE; } } } if (stclass == LSTATIC) { add_local(sname, j, typ, k, LSTATIC); break; } if (stclass == REGISTER) { int r = gen_register(j, k, typ); if (r != -1) { add_local(sname, j, typ, r, REGISTER); break; } } if (match("=")) { gen_modify_stack(stkp); expression(0); gen_push(0); } else stkp = gen_defer_modify_stack(stkp - k); add_local(sname, j, typ, stkp, AUTO); break; } if (!match(",")) return; } }
primary (lvalue_t *lval) { char sname[NAMESIZE]; int num[1], k, symbol_table_idx, offset, reg; symbol_t *symbol; lval->ptr_type = 0; /* clear pointer/array type */ if (match ("(")) { k = hier1 (lval); needbrack (")"); return (k); } if (amatch("sizeof", 6)) { needbrack("("); gen_immediate_c(); if (amatch("int", 3)) output_number(INTSIZE); else if (amatch("char", 4)) output_number(1); else if (symname(sname)) { if ((symbol_table_idx = findloc(sname)) || (symbol_table_idx = findglb(sname))) { symbol = &symbol_table[symbol_table_idx]; if (symbol->storage == LSTATIC) error("sizeof local static"); offset = symbol->count; if ((symbol->type & CINT) || (symbol->identity == POINTER)) offset *= INTSIZE; output_number(offset); } else { error("sizeof undeclared variable"); output_number(0); } } else { error("sizeof only on simple type or variable"); } needbrack(")"); newline(); lval->symbol = 0; lval->indirect = 0; return(0); } if (symname (sname)) { if (symbol_table_idx = findloc (sname)) { symbol = &symbol_table[symbol_table_idx]; reg = gen_get_location (symbol); lval->symbol = symbol; lval->indirect = symbol->type; if (symbol->identity == ARRAY) { //lval->ptr_type = symbol->type; lval->ptr_type = 0; return 0; } if (symbol->identity == POINTER) { lval->indirect = UINT; lval->ptr_type = symbol->type; } return reg; } if (symbol_table_idx = findglb (sname)) { symbol = &symbol_table[symbol_table_idx]; lval->symbol = symbol; switch (symbol->identity) { case ARRAY: gen_immediate_a (); output_string (symbol->name); newline (); /* Fall through */ case FUNCTION: lval->indirect = lval->ptr_type = symbol_table[symbol_table_idx].type; lval->ptr_type = 0; return 0; default: lval->indirect = 0; if (symbol->identity == POINTER) { lval->ptr_type = symbol->type; } return 1; } } blanks (); if (ch() != '(') error("undeclared variable"); symbol_table_idx = add_global (sname, FUNCTION, CINT, 0, PUBLIC, 1); symbol = &symbol_table[symbol_table_idx]; lval->symbol = symbol; lval->indirect = 0; return 0; } if (constant (num)) { lval->symbol = 0; lval->indirect = 0; return 0; } error ("invalid expression"); gen_immediate_c (); output_number(0); newline (); junk (); return 0; }
newfunc () { char n[NAMESIZE], *ptr; fexitlab = getlabel(); if (!symname (n) ) { error ("illegal function or declaration"); kill (); return; } if (ptr = findglb (n)) { if (ptr[IDENT] != FUNCTION) multidef (n); else if (ptr[OFFSET] == FUNCTION) multidef (n); else ptr[OFFSET] = FUNCTION; } else addglb (n, FUNCTION, CINT, FUNCTION, PUBLIC); prologue (); if (!match ("(")) error ("missing open paren"); prefix (); outstr (n); col (); nl (); locptr = STARTLOC; argstk = 0; while (!match (")")) { if (symname (n)) { if (findloc (n)) multidef (n); else { addloc (n, 0, 0, argstk, AUTO); argstk = argstk + intsize(); } } else { error ("illegal argument name"); junk (); } blanks (); if (!streq (line + lptr, ")")) { if (!match (",")) error ("expected comma"); } if (endst ()) break; } stkp = 0; argtop = argstk; while (argstk) { if (amatch ("register", 8)) { if (amatch("char", 4)) getarg(CCHAR); else if (amatch ("int", 3)) getarg(CINT); else getarg(CINT); ns(); } else if (amatch ("char", 4)) { getarg (CCHAR); ns (); } else if (amatch ("int", 3)) { getarg (CINT); ns (); } else { error ("wrong number args"); break; } } statement(YES); printlabel(fexitlab); col(); nl(); modstk (0); gret (); stkp = 0; locptr = STARTLOC; }
void MakeTOFResMisAlignment() { // // Create TClonesArray of residual misalignment objects for TOF // const char* macroname = "MakeTOFResMisAlignment.C"; TClonesArray *array = new TClonesArray("AliAlignObjParams",2000); TClonesArray &alobj = *array; // Activate CDB storage and load geometry from CDB AliCDBManager* cdb = AliCDBManager::Instance(); if (!cdb->IsDefaultStorageSet()) cdb->SetDefaultStorage("local://$ALICE_ROOT/OCDB"); cdb->SetRun(0); AliCDBStorage* storage; TString Storage; if( TString(gSystem->Getenv("TOCDB")) == TString("kTRUE") ){ Storage = gSystem->Getenv("STORAGE"); if (!Storage.BeginsWith("local://") && !Storage.BeginsWith("alien://")) { Error(macroname,"STORAGE variable set to %s is not valid. Exiting\n",Storage.Data()); return; } storage = cdb->GetStorage(Storage.Data()); if (!storage) { Error(macroname,"Unable to open storage %s\n",Storage.Data()); return; } AliCDBPath path("GRP","Geometry","Data"); AliCDBEntry *entry = storage->Get(path.GetPath(),cdb->GetRun()); if (!entry) Fatal(macroname,"Could not get the specified CDB entry!"); entry->SetOwner(0); TGeoManager* geom = (TGeoManager*) entry->GetObject(); AliGeomManager::SetGeometry(geom); } else AliGeomManager::LoadGeometry(); //load geom from default CDB storage AliGeomManager::ELayerID idTOF = AliGeomManager::kTOF; Int_t j=0; Int_t nSectors=18; //Produce objects for TOF supermodules Int_t iIndex=0; //let all modules have index=0 in a layer with no LUT AliGeomManager::ELayerID iLayer = AliGeomManager::kInvalidLayer; UShort_t dvoluid = AliGeomManager::LayerToVolUID(iLayer,iIndex); //dummy vol id Double_t smdx, smdy, smdz=0., dpsi=0., dtheta, dphi=0.; for(Int_t isect=0; isect<nSectors; isect++) { TString symname(Form("TOF/sm%02d",isect)); new(alobj[j++]) AliAlignObjParams(symname.Data(), dvoluid, smdx, smdy, smdz, dpsi, dtheta, dphi, kFALSE); } Int_t strId=-1; Double_t dx=0., dy=0., dz=0., dpsi=0., dtheta=0., dphi=0.; //TRandom *rnd = new TRandom(4357); Double_t sigmatr = 0.1; // sigma (in cm) for shift w.r.t. local ideal RS Int_t nstrA=15; Int_t nstrB=19; Int_t nstrC=19; Int_t nStrips=nstrA+2*nstrB+2*nstrC; Double_t cuty=0., cutz=0., cut=3*sigmatr; for (Int_t isect = 0; isect < nSectors; isect++) { for (Int_t istr = 1; istr <= nStrips; istr++) { //dy = rnd->Gaus(0.,sigmatr); //dz = rnd->Gaus(0.,sigmatr); //strId++; switch (istr) { case 25: case 29: case 63: case 67: cuty = sigmatr*0.6; dy = AliMathBase::TruncatedGaus(0., sigmatr, cut, cuty); dz = AliMathBase::TruncatedGaus(0., sigmatr, cut); strId++; break; /* case 38: cuty = sigmatr*2.5; cutz = sigmatr*2.5; dy = AliMathBase::TruncatedGaus(0., sigmatr, cut, cuty); dz = AliMathBase::TruncatedGaus(0., sigmatr, cut, cutz); strId++; break; case 54: cuty = sigmatr*2.5; cutz = sigmatr*2.5; dy = AliMathBase::TruncatedGaus(0., sigmatr, cut, cuty); dz = AliMathBase::TruncatedGaus(0., sigmatr, cutz, cut); strId++; break; */ default: dy = AliMathBase::TruncatedGaus(0., sigmatr, cut); dz = AliMathBase::TruncatedGaus(0., sigmatr, cut); strId++; break; } if ((isect==13 || isect==14 || isect==15) && (istr >= 39 && istr <= 53)) continue; new(alobj[j++]) AliAlignObjParams(AliGeomManager::SymName(idTOF,strId), AliGeomManager::LayerToVolUID(idTOF,strId), dx, dy, dz, dpsi, dtheta, dphi, kFALSE); } } if( TString(gSystem->Getenv("TOCDB")) != TString("kTRUE") ) { // save on file const char* filename = "TOFresidualMisalignment.root"; TFile f(filename,"RECREATE"); if(!f){ Error(macroname,"cannot open file for output\n"); return; } Info(macroname,"Saving alignment objects to the file %s", filename); f.cd(); f.WriteObject(array,"TOFAlignObjs","kSingleKey"); f.Close(); } else { // save in CDB storage AliCDBMetaData* md = new AliCDBMetaData(); md->SetResponsible("Silvia Arcelli"); md->SetComment("Residual misalignment for TOF, sigmatr=1mm in the local RS"); md->SetAliRootVersion(gSystem->Getenv("ARVERSION")); AliCDBId id("TOF/Align/Data",0,AliCDBRunRange::Infinity()); storage->Put(array,id,md); } array->Delete(); }
bool KICADMODULE::Read( SEXPR::SEXPR* aEntry ) { if( NULL == aEntry ) return false; if( aEntry->IsList() ) { size_t nc = aEntry->GetNumberOfChildren(); SEXPR::SEXPR* child = aEntry->GetChild( 0 ); std::string name = child->GetSymbol(); if( name != "module" ) { std::ostringstream ostr; ostr << "* BUG: module parser invoked for type '" << name << "'\n"; wxLogMessage( "%s\n", ostr.str().c_str() ); return false; } bool result = true; for( size_t i = 1; i < nc && result; ++i ) { child = aEntry->GetChild( i ); // skip the module name and the optional 'locked' attribute; // due to the vagaries of the kicad version of sexpr, the // name may be a Symbol or a String if( i <= 2 && ( child->IsSymbol() || child->IsString() ) ) continue; if( !child->IsList() ) { std::ostringstream ostr; ostr << "* corrupt module in PCB file\n"; wxLogMessage( "%s\n", ostr.str().c_str() ); return false; } std::string symname( child->GetChild( 0 )->GetSymbol() ); if( symname == "layer" ) result = result && parseLayer( child ); else if( symname == "at" ) result = result && parsePosition( child ); else if( symname == "fp_text" ) result = result && parseText( child ); else if( symname == "fp_arc" ) result = result && parseCurve( child, CURVE_ARC ); else if( symname == "fp_line" ) result = result && parseCurve( child, CURVE_LINE ); else if( symname == "fp_circle" ) result = result && parseCurve( child, CURVE_CIRCLE ); else if( symname == "pad" ) result = result && parsePad( child ); else if( symname == "model" ) result = result && parseModel( child ); } return result; } std::ostringstream ostr; ostr << "* data is not a valid PCB module\n"; wxLogMessage( "%s\n", ostr.str().c_str() ); return false; }
void newfunc_typed(int storage, char *n, int type) { int idx; SYMBOL *symbol; char an[NAMESIZE]; fexitlab = getlabel(); if ((idx = find_global(n)) > -1) { symbol = &symbol_table[idx]; if (symbol->identity != FUNCTION) multidef(n); } else { /* extern implies global scope */ idx = add_global(n, FUNCTION, CINT, 0, storage == EXTERN ? PUBLIC : storage); symbol = &symbol_table[idx]; } local_table_index = NUMBER_OF_GLOBALS; //locptr = STARTLOC; argstk = 0; // ANSI style argument declaration if (doAnsiArguments()) { if (storage == EXTERN) { need_semicolon(); return; } /* No body .. just a definition */ if (match(";")) return; } else { // K&R style argument declaration while (!match(")")) { if (symname(an)) { if (find_locale(an) > -1) multidef(an); else { /* FIXME: struct */ add_local(an, 0, 0, argstk, AUTO); argstk = argstk + INTSIZE; } } else { error("illegal argument name"); junk(); } blanks(); if (!streq(line + lptr, ")")) { if (!match(",")) error("expected comma"); } if (endst()) break; } if (storage == EXTERN) { need_semicolon(); return; } /* No body .. just a definition */ if (match(";")) return; stkp = 0; argtop = argstk; while (argstk) { if ((type = get_type()) != -1) { notvoid(type); getarg(type); need_semicolon(); } else { error("wrong number args"); break; } } } if (symbol->offset == FUNCTION) multidef(n); symbol->offset = FUNCTION; output_string(n); output_label_terminator(); newline(); gen_prologue(); statement(YES); print_label(fexitlab); output_label_terminator(); newline(); gen_epilogue(); gen_modify_stack(0); gen_ret(); stkp = 0; local_table_index = NUMBER_OF_GLOBALS; //locptr = STARTLOC; }
/** * begin a function * called from "parse", this routine tries to make a function out * of what follows * modified version. p.l. woods */ newfunc() { char n[NAMESIZE]; int idx, type; fexitlab = getlabel(); if (!symname(n)) { error("illegal function or declaration"); kill(); return; } if (idx = findglb(n)) { if (symbol_table[idx].identity != FUNCTION) multidef(n); else if (symbol_table[idx].offset == FUNCTION) multidef(n); else symbol_table[idx].offset = FUNCTION; } else add_global(n, FUNCTION, CINT, FUNCTION, PUBLIC); if (!match("(")) error("missing open paren"); output_string(n); output_label_terminator(); newline(); local_table_index = NUMBER_OF_GLOBALS; //locptr = STARTLOC; argstk = 0; // ANSI style argument declaration if (doAnsiArguments() == 0) { // K&R style argument declaration while (!match(")")) { if (symname(n)) { if (findloc(n)) multidef(n); else { add_local(n, 0, 0, argstk, AUTO); argstk = argstk + INTSIZE; } } else { error("illegal argument name"); junk(); } blanks(); if (!streq(line + lptr, ")")) { if (!match(",")) error("expected comma"); } if (endst()) break; } stkp = 0; argtop = argstk; while (argstk) { if (type = get_type()) { getarg(type); need_semicolon(); } else { error("wrong number args"); break; } } } statement(YES); print_label(fexitlab); output_label_terminator(); newline(); gen_modify_stack(0); gen_ret(); stkp = 0; local_table_index = NUMBER_OF_GLOBALS; //locptr = STARTLOC; }
int primary(LVALUE *lval) { char sname[NAMESIZE]; int num[1], k, symbol_table_idx, offset, reg; SYMBOL *symbol; lval->ptr_type = 0; // clear pointer/array type lval->tagsym = 0; if (match ("(")) { k = hier1 (lval); needbrack (")"); return (k); } if (amatch("sizeof", 6)) { needbrack("("); gen_immediate(); if (amatch("int", 3)) output_number(INTSIZE); else if (amatch("char", 4)) output_number(1); else if (symname(sname)) { if (((symbol_table_idx = find_locale(sname)) > -1) || ((symbol_table_idx = find_global(sname)) > -1)) { symbol = &symbol_table[symbol_table_idx]; if (symbol->storage == LSTATIC) error("sizeof local static"); offset = symbol->offset; if ((symbol->type & CINT) || (symbol->identity == POINTER)) offset *= INTSIZE; else if (symbol->type == STRUCT) offset *= tag_table[symbol->tagidx].size; output_number(offset); } else { error("sizeof undeclared variable"); output_number(0); } } else { error("sizeof only on type or variable"); } needbrack(")"); newline(); lval->symbol = 0; lval->indirect = 0; return(0); } if (symname (sname)) { if ((symbol_table_idx = find_locale(sname)) > -1) { symbol = &symbol_table[symbol_table_idx]; reg = gen_get_locale(symbol); lval->symbol = symbol; lval->indirect = symbol->type; if (symbol->type == STRUCT) { lval->tagsym = &tag_table[symbol->tagidx]; } if (symbol->identity == ARRAY || (symbol->identity == VARIABLE && symbol->type == STRUCT)) { lval->ptr_type = symbol->type; return reg; } if (symbol->identity == POINTER) { lval->indirect = CINT; lval->ptr_type = symbol->type; } return FETCH | reg; } if ((symbol_table_idx = find_global(sname)) > -1) { symbol = &symbol_table[symbol_table_idx]; if (symbol->identity != FUNCTION) { lval->symbol = symbol; lval->indirect = 0; if (symbol->type == STRUCT) { lval->tagsym = &tag_table[symbol->tagidx]; } if (symbol->identity != ARRAY && (symbol->identity != VARIABLE || symbol->type != STRUCT)) { if (symbol->identity == POINTER) { lval->ptr_type = symbol->type; } return FETCH | HL_REG; } gen_immediate(); output_string(symbol->name); newline(); lval->indirect = symbol->type; lval->ptr_type = symbol->type; return 0; } } blanks(); if (ch() != '(') error("undeclared variable"); symbol_table_idx = add_global(sname, FUNCTION, CINT, 0, PUBLIC); symbol = &symbol_table[symbol_table_idx]; lval->symbol = symbol; lval->indirect = 0; return 0; } lval->symbol = 0; lval->indirect = 0; if (constant(num)) return 0; else { error("invalid expression"); gen_immediate(); output_number(0); newline(); junk(); return 0; } }
SYMBOL * #endif getarg( int typ , /* typ = CCHAR, CINT, DOUBLE or STRUCT */ TAG_SYMBOL *otag , /* structure tag for STRUCT type objects */ int deftype, /* YES=ANSI -> addloc NO=K&R -> findloc */ SYMBOL *prevarg, /* ptr to previous argument, only of use to ANSI */ char issigned, /* YES=unsigned NO=signed */ char zfar, /* FARPTR=far NO=near */ char proto) /* YES=prototyping -> names not needed */ { char n[NAMESIZE] ; SYMBOL *argptr ; int legalname, ident, more ; int brkflag; /* Needed to correctly break out for K&R*/ /* * This is of dubious need since prototyping came about, we could * inadvertently include fp packages if the user includes <math.h> but * didn't actually use them, we'll save the incfloat business for * static doubles and definitions of local doubles * * if (typ == DOUBLE) * incfloat=1; */ argptr = NULL; /* Only need while loop if K&R defs */ while ( undeclared) { ident = get_ident() ; more =0; if ( (legalname=symname(n)) == 0 ) { if (!proto) { illname(n); } else { /* * Obligatory silly fake name */ sprintf(n,"sg6p_%d",proto); legalname=1; } } if ( ident == FUNCTIONP ) { needtoken(")()"); /* function returning pointer needs dummy symbol */ more = dummy_idx(typ, otag) ; typ = (zfar ? CPTR : CINT ); } else if ( ident == PTR_TO_FN ) { needtoken(")()") ; ident = POINTER ; } if ( cmatch('[') ) { /* pointer ? */ ptrerror(ident) ; /* it is a pointer, so skip all */ /* stuff between "[]" */ while ( inbyte() != ']' ) if ( endst() ) break; /* add entry as pointer */ ident = (ident == POINTER) ? PTR_TO_PTR : POINTER ; } if ( legalname ) { /* * For ANSI we need to add symbol name to local table - this CINT is * temporary */ if (deftype) { argptr=addloc(n,0,CINT,0,0); argptr->offset.p = prevarg; } /* * If prototyping, then we can't find the name, but if we're prototyping * we have been defined as ANSI, therefore argptr already holds * the correct pointer - kinda neat! */ if ( proto || (argptr=findloc(n)) ) { argptr->flags=(zfar&FARPTR)|(issigned&UNSIGNED); /* add in details of the type of the name */ if ( ident == PTR_TO_PTR ) { /* djm mods will be here for long pointer */ // argptr->flags = UNSIGNED |FARPTR ; /*unsigned*/ argptr->ident = POINTER ; argptr->type = typ; // argptr->type = ( (zfar&FARPTR) ? CPTR : CINT ); argptr->more = dummy_idx(typ, otag) ; } else { argptr->more = more; argptr->ident = ident ; argptr->type = typ ; } } else warning(W_EXPARG); if ( otag ) { argptr->tag_idx = otag - tagtab ; argptr->ident = POINTER ; argptr->type = STRUCT ; } } brkflag=0; if (!deftype) { --undeclared; /* cnt down */ if ( endst() ) { brkflag=1; break; } if ( cmatch(',') == 0 ) warning(W_EXPCOM) ; } if (brkflag || deftype) break; } if (deftype) return(argptr); ns(); return(0); }
cell_t *read_list(secd_t *secd, secd_parser_t *p) { const char *parse_err = NULL; cell_t *head = SECD_NIL; cell_t *tail = SECD_NIL; cell_t *newtail, *val; while (true) { int tok = lexnext(p); switch (tok) { case TOK_EOF: case ')': -- p->nested; return head; case '(': ++ p->nested; val = read_list(secd, p); if (p->token == TOK_ERR) { parse_err = "read_list: error reading subexpression"; goto error_exit; } if (p->token != ')') { parse_err = "read_list: TOK_EOF, ')' expected"; goto error_exit; } break; default: val = read_token(secd, p); if (is_error(val)) { parse_err = "read_list: read_token failed"; goto error_exit; } /* reading dot-lists */ if (is_symbol(val) && (str_eq(symname(val), "."))) { free_cell(secd, val); switch (lexnext(p)) { case TOK_ERR: case ')': parse_err = "read_list: failed to read a token after dot"; goto error_exit; case '(': /* there may be a list after dot */ val = read_list(secd, p); if (p->token != ')') { parse_err = "read_list: expected a ')' reading sublist after dot"; goto error_exit; } lexnext(p); // consume ')' break; default: val = read_token(secd, p); lexnext(p); } if (is_nil(head)) /* Guile-like: (. val) returns val */ return val; tail->as.cons.cdr = share_cell(secd, val); return head; } } newtail = new_cons(secd, val, SECD_NIL); if (not_nil(head)) { tail->as.cons.cdr = share_cell(secd, newtail); tail = newtail; } else { head = tail = newtail; } } error_exit: free_cell(secd, head); errorf("read_list: TOK_ERR, %s\n", parse_err); return new_error(secd, SECD_NIL, parse_err); }
/* * Declare a static variable (i.e. define for use) * * makes an entry in the symbol table so subsequent * references can call symbol by name */ void declglb( int typ , /* typ is CCHAR, CINT, DOUBLE, STRUCT, LONG, */ int storage, TAG_SYMBOL *mtag , /* tag of struct whose members are being declared, or zero */ TAG_SYMBOL *otag , /* tag of struct for object being declared */ int is_struct , /* TRUE if struct member being declared, zero if union */ char sign , /* TRUE if need signed */ char zfar ) /* TRUE if far */ { char sname[NAMESIZE]; int size, ident, more, itag, type, size_st; long addr = -1; char flagdef,match,ptrtofn; char libdef,fastcall,callee; SYMBOL *myptr ; do { if ( endst() ) break; /* do line */ type = typ ; size = 1 ; /* assume 1 element */ more = /* assume dummy symbol not required */ itag = 0 ; /* just for tidiness */ flagdef=libdef=fastcall=callee=NO; match=ptrtofn=NO; while (blanks(),rcmatch('_') ) { match=NO; if (amatch("__APPFUNC__") ) { match=YES; flagdef=1; } if (amatch("__LIB__") /* && libdef==0 */) {match=YES; libdef|=LIBRARY; } if (amatch("__FASTCALL__") ) {match=YES; fastcall=REGCALL; } if (amatch("__SHARED__") ) {match=YES; libdef|=SHARED; } if (amatch("__SHAREDC__") ) {match=YES; libdef|=SHAREDC; } if (amatch("__CALLEE__") ) {match=YES; callee=CALLEE; } if (match ==NO )break; } ident = get_ident() ; if (storage==TYPDEF && ident !=VARIABLE && mtag ==0 ) warning(W_TYPEDEF); if ( symname(sname) == 0 ) /* name ok? */ illname(sname) ; /* no... */ if ( ident == PTR_TO_FNP ) { /* function returning pointer needs dummy symbol */ more = dummy_idx(typ, otag) ; type = (zfar ? CPTR : CINT ); size=0; ptrtofn=YES; } else if ( ident == PTR_TO_FN ) { ident = POINTER ; ptrtofn=YES; #if 0 } else if ( cmatch('@') ) { storage = EXTERNP; constexpr(&addr,1); #endif } else if ( cmatch('(') ) { /* * Here we check for functions, but we can never have a pointer to * function because thats considered above. Which means as a very * nice side effect that we don't have to consider structs/unions * since they can't contain functions, only pointers to functions * this, understandably(!) makes the work here a lot, lot easier! */ storage=AddNewFunc(sname,type,storage,zfar,sign,otag,ident,&addr); /* * On return from AddNewFunc, storage will be: * EXTERNP = external pointer, in which case addr will be set * !! FUNCTION = have prototyped a function (NOT USED!) * 0 = have declared a function/!! prototyped ANSI * * If 0, then we have to get the hell out of here, FUNCTION * then gracefully loop round again, if EXTERNP, carry on with * this function, anything else means that we've come up * against a K&R style function definition () so carry on * as normal! * * If we had our function prefixed with __APPFUNC__ then we want * to write it out to the zcc_opt.def file (this bloody thing * is becoming invaluable for messaging! * * __SHARED__ indicates in a library so preserve carry flag * (so we can test with iferror) * * __CALLEE__ indicates that the function called cleans up * the stack * * __SHAREDC__ is indicates call by rst 8 but is unused.. * (old idea unused, but may yet be useful) */ if (flagdef) WriteDefined(sname,0); if (currfn) { /* djm 1/2/03 - since we can override lib functions don't reset the library flag currfn->flags&=(~LIBRARY); */ if (libdef) { // currfn->flags|=LIBRARY; currfn->flags|=libdef; } if (callee && (libdef&SHARED) != SHARED && \ (libdef&SHAREDC) != SHAREDC ) currfn->flags|=callee; if (fastcall) currfn->flags|=fastcall; } if (storage==0) { if ( addr != -1 ) { currfn->size = addr; } return; } /* * External pointer..check for the closing ')' */ if (storage==EXTERNP) { needchar(')'); } else { /* * Must be a devilishly simple prototype! ();/, type... */ ptrerror(ident) ; if ( ident == POINTER ) { /* function returning pointer needs dummy symbol */ more = dummy_idx(typ, otag) ; type = (zfar ? CPTR : CINT ); ident=FUNCTIONP; } else { ident=FUNCTION; } size = 0 ; } } if (cmatch('[')) { /* array? */ ptrerror(ident) ; if ( ident == POINTER) { /* array of pointers needs dummy symbol */ more = dummy_idx(typ, otag) ; type = (zfar ? CPTR : CINT ); } size = needsub() ; /* get size */ if (size == 0 && ident == POINTER ) size=0; ident = ARRAY; if ( ptrtofn ) needtoken(")()"); } else if ( ptrtofn ) { needtoken(")()") ; } else if ( ident == PTR_TO_PTR ) { ident = POINTER ; more = dummy_idx(typ, otag) ; type = (zfar ? CPTR : CINT ); } if ( cmatch('@') ) { storage = EXTERNP; constexpr(&addr,1); }
/* * evaluate one initialiser * * if dump is TRUE, dump literal immediately * save character string in litq to dump later * this is used for structures and arrays of pointers to char, so that the * struct or array is built immediately and the char strings are dumped later */ void init(int size, int ident, int *dim, int more, int dump, int is_struct) { int32_t value; int sz; /* number of chars in queue */ /* * djm 14/3/99 We have to rewrite this bit (ugh!) so that we store * our literal in a temporary queue, then if needed, we then dump * it out.. */ if ((sz = qstr(&value)) != -1 ) { sz++; #if 0 if (ident == VARIABLE || (size != 1 && more != CCHAR)) error(E_ASSIGN); #endif #ifdef INIT_TEST outstr("ident="); outdec(ident); outstr("size="); outdec(size); outstr("more="); outdec(more); outstr("dim="); outdec(*dim); outstr("sz="); outdec(sz); nl(); #endif if (ident == ARRAY && more == 0) { /* * Dump the literals where they are, padding out as appropriate */ if (*dim != -1 && sz > *dim) { /* * Ooops, initialised to long a string! */ warning(W_INIT2LONG); sz = *dim; gltptr = sz; *(glbq + sz - 1) = '\0'; /* Terminate string */ } dumplits(((size == 1) ? 0 : size), NO, gltptr, glblab, glbq); *dim -= sz; gltptr = 0; dumpzero(size, *dim); return; } else { /* * Store the literals in the queue! */ storeq(sz, glbq, &value); gltptr = 0; defword(); printlabel(litlab); outbyte('+'); outdec(value); nl(); --*dim; return; } } /* * djm, catch label names in structures (for (*name)() initialisation */ else { char sname[NAMEMAX + 1]; SYMBOL *ptr; if (symname(sname) && strcmp(sname,"sizeof") ) { /* We have got something.. */ if ((ptr = findglb(sname))) { /* Actually found sommat..very good! */ if (ident == POINTER || (ident == ARRAY && more)) { defword(); outname(ptr->name, dopref(ptr)); nl(); --*dim; } else if (ptr->type == ENUM) { value = ptr->size; goto constdecl; } else { error(E_DDECL); } } else error(E_UNSYMB, sname); } else if (rcmatch('}')) { #if 0 dumpzero(size,*dim); #endif } else if (constexpr(&value, 1)) { constdecl: if (ident == POINTER) { /* 24/1/03 dom - We want to be able to assign values to pointers or they're a bit useless.. */ #if 0 /* the only constant which can be assigned to a pointer is 0 */ if (value != 0) warning(W_ASSPTR); #endif size = 2; dump = YES; } if (dump) { /* struct member or array of pointer to char */ if (size == 4) { /* there appears to be a bug in z80asm regarding defl */ defbyte(); outdec((value % 65536UL) % 256); outbyte(','); outdec((value % 65536UL) / 256); outbyte(','); outdec((value / 65536UL) % 256); outbyte(','); outdec((value / 65536UL) / 256); } else { if (size == 1) defbyte(); else defword(); outdec(value); } nl(); /* Dump out a train of zeros as appropriate */ if (ident == ARRAY && more == 0) { dumpzero(size,(*dim)-1); } } else stowlit(value, size); --*dim; } } }