exprt c_typecheck_baset::zero_initializer( const typet &type, const locationt &location) { const irep_idt &type_id=type.id(); if(type_id==ID_bool) { exprt result=false_exprt(); result.location()=location; return result; } else if(type_id==ID_unsignedbv || type_id==ID_signedbv || type_id==ID_floatbv || type_id==ID_fixedbv || type_id==ID_pointer) { exprt result=gen_zero(type); result.location()=location; return result; } else if(type_id==ID_code) { err_location(location); throw "cannot zero-initialize code-type"; } else if(type_id==ID_c_enum || type_id==ID_incomplete_c_enum) { constant_exprt value(type); value.set_value(ID_0); value.location()=location; return value; } else if(type_id==ID_array) { const array_typet &array_type=to_array_type(type); exprt tmpval=zero_initializer(array_type.subtype(), location); mp_integer array_size; if(array_type.size().id()==ID_infinity) { exprt value(ID_array_of, type); value.copy_to_operands(tmpval); value.location()=location; return value; } else if(to_integer(array_type.size(), array_size)) { err_location(location); str << "failed to zero-initialize array of non-fixed size `" << to_string(array_type.size()) << "'"; throw 0; } if(array_size<0) { err_location(location); throw "failed to zero-initialize array of with negative size"; } exprt value(ID_array, type); value.operands().resize(integer2long(array_size), tmpval); value.location()=location; return value; } else if(type_id==ID_incomplete_array) { // we initialize this with an empty array exprt value(ID_array, type); value.type().id(ID_array); value.type().set(ID_size, gen_zero(size_type())); value.location()=location; return value; } else if(type_id==ID_struct) { const struct_typet::componentst &components= to_struct_type(type).components(); exprt value(ID_struct, type); value.operands().reserve(components.size()); for(struct_typet::componentst::const_iterator it=components.begin(); it!=components.end(); it++) value.copy_to_operands(zero_initializer(it->type(), location)); value.location()=location; return value; } else if(type_id==ID_union) { const union_typet::componentst &components= to_union_type(type).components(); exprt value(ID_union, type); if(components.empty()) return value; // stupid empty union value.set(ID_component_name, components.front().get(ID_name)); value.copy_to_operands( zero_initializer(components.front().type(), location)); value.location()=location; return value; } else if(type_id==ID_symbol) return zero_initializer(follow(type), location); else { err_location(location); str << "Failed to zero-initialize `" << to_string(type) << "'"; throw 0; } }
void c_typecheck_baset::typecheck_c_bit_field_type(c_bit_field_typet &type) { typecheck_type(type.subtype()); mp_integer i; { exprt &width_expr=static_cast<exprt &>(type.add(ID_size)); typecheck_expr(width_expr); make_constant_index(width_expr); if(to_integer(width_expr, i)) { error().source_location=type.source_location(); error() << "failed to convert bit field width" << eom; throw 0; } if(i<0) { error().source_location=type.source_location(); error() << "bit field width is negative" << eom; throw 0; } type.set_width(integer2size_t(i)); type.remove(ID_size); } const typet &subtype=follow(type.subtype()); std::size_t sub_width=0; if(subtype.id()==ID_bool) { // This is the 'proper' bool. sub_width=1; } else if(subtype.id()==ID_signedbv || subtype.id()==ID_unsignedbv || subtype.id()==ID_c_bool) { sub_width=to_bitvector_type(subtype).get_width(); } else if(subtype.id()==ID_c_enum_tag) { // These point to an enum, which has a sub-subtype, // which may be smaller or larger than int, and we thus have // to check. const typet &c_enum_type= follow_tag(to_c_enum_tag_type(subtype)); if(c_enum_type.id()==ID_incomplete_c_enum) { error().source_location=type.source_location(); error() << "bit field has incomplete enum type" << eom; throw 0; } sub_width=c_enum_type.subtype().get_int(ID_width); } else { error().source_location=type.source_location(); error() << "bit field with non-integer type: " << to_string(subtype) << eom; throw 0; } if(i>sub_width) { error().source_location=type.source_location(); error() << "bit field (" << i << " bits) larger than type (" << sub_width << " bits)" << eom; throw 0; } }
void main(int argc, char *argv[]) { char *p; Sym *s; Binit(&bso, 1, OWRITE); listinit(); nerrors = 0; outfile = "5.out"; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; LIBINITENTRY = 0; linkmode = LinkInternal; // TODO: LinkAuto once everything works. nuxiinit(); p = getgoarm(); if(p != nil) goarm = atoi(p); else goarm = 6; if(goarm == 5) debug['F'] = 1; flagcount("1", "use alternate profiling code", &debug['1']); flagfn1("B", "info: define ELF NT_GNU_BUILD_ID note", addbuildinfo); flagstr("E", "sym: entry symbol", &INITENTRY); flagint32("D", "addr: data address", &INITDAT); flagcount("G", "debug pseudo-ops", &debug['G']); flagfn1("I", "interp: set ELF interp", setinterp); flagfn1("L", "dir: add dir to library path", Lflag); flagfn1("H", "head: header type", setheadtype); flagcount("K", "add stack underflow checks", &debug['K']); flagcount("M", "disable software div/mod", &debug['M']); flagcount("O", "print pc-line tables", &debug['O']); flagcount("P", "debug code generation", &debug['P']); flagint32("R", "rnd: address rounding", &INITRND); flagint32("T", "addr: text address", &INITTEXT); flagfn0("V", "print version and exit", doversion); flagcount("W", "disassemble input", &debug['W']); flagfn2("X", "name value: define string data", addstrdata); flagcount("Z", "clear stack frame on entry", &debug['Z']); flagcount("a", "disassemble output", &debug['a']); flagcount("c", "dump call graph", &debug['c']); flagcount("d", "disable dynamic executable", &debug['d']); flagstr("extld", "linker to run in external mode", &extld); flagstr("extldflags", "flags for external linker", &extldflags); flagcount("f", "ignore version mismatch", &debug['f']); flagcount("g", "disable go package data checks", &debug['g']); flagstr("k", "sym: set field tracking symbol", &tracksym); flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode); flagcount("n", "dump symbol table", &debug['n']); flagstr("o", "outfile: set output file", &outfile); flagcount("p", "insert profiling code", &debug['p']); flagstr("r", "dir1:dir2:...: set ELF dynamic linker search path", &rpath); flagcount("race", "enable race detector", &flag_race); flagcount("s", "disable symbol table", &debug['s']); flagstr("tmpdir", "leave temporary files in this directory", &tmpdir); flagcount("u", "reject unsafe packages", &debug['u']); flagcount("v", "print link trace", &debug['v']); flagcount("w", "disable DWARF generation", &debug['w']); flagcount("shared", "generate shared object", &flag_shared); // TODO: link mode flag flagparse(&argc, &argv, usage); if(argc != 1) usage(); // getgoextlinkenabled is based on GO_EXTLINK_ENABLED when // Go was built; see ../../make.bash. if(linkmode == LinkAuto && strcmp(getgoextlinkenabled(), "0") == 0) linkmode = LinkInternal; if(linkmode == LinkExternal) { diag("only -linkmode=internal is supported"); errorexit(); } else if(linkmode == LinkAuto) { linkmode = LinkInternal; } libinit(); if(HEADTYPE == -1) HEADTYPE = headtype(goos); switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case Hnoheader: /* no header */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hrisc: /* aif for risc os */ HEADR = 128L; if(INITTEXT == -1) INITTEXT = 0x10005000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hplan9x32: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4128; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hixp1200: /* boot for IXP1200 */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0x0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hipaq: /* boot for ipaq */ HEADR = 16L; if(INITTEXT == -1) INITTEXT = 0xC0008010; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 1024; break; case Hlinux: /* arm elf */ case Hfreebsd: case Hnetbsd: debug['d'] = 0; // with dynamic linking tlsoffset = -8; // hardcoded number, first 4-byte word for g, and then 4-byte word for m // this number is known to ../../pkg/runtime/cgo/gcc_linux_arm.c elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = 0x10000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%ux is ignored because of -R0x%ux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%d -T0x%ux -D0x%ux -R0x%ux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); zprg.as = AGOK; zprg.scond = 14; zprg.reg = NREG; zprg.from.name = D_NONE; zprg.from.type = D_NONE; zprg.from.reg = NREG; zprg.to = zprg.from; buildop(); histgen = 0; pc = 0; dtype = 4; version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); // embed goarm to runtime.goarm s = lookup("runtime.goarm", 0); s->dupok = 1; adduint8(s, goarm); addlibpath("command line", "command line", argv[0], "main"); loadlib(); // mark some functions that are only referenced after linker code editing if(debug['F']) mark(rlookup("_sfloat", 0)); deadcode(); if(textp == nil) { diag("no code"); errorexit(); } patch(); if(debug['p']) if(debug['1']) doprof1(); else doprof2(); doelf(); follow(); softfloat(); // 5l -Z means zero the stack frame on entry. // This slows down function calls but can help avoid // false positives in garbage collection. if(debug['Z']) dozerostk(); noops(); // generate stack split prolog, handle div/mod, etc. dostkcheck(); span(); addexport(); // textaddress() functionality is handled in span() pclntab(); symtab(); dodata(); address(); doweak(); reloc(); asmb(); undef(); hostlink(); if(debug['c']) print("ARM size = %d\n", armsize); if(debug['v']) { Bprint(&bso, "%5.2f cpu time\n", cputime()); Bprint(&bso, "%d sizeof adr\n", sizeof(Adr)); Bprint(&bso, "%d sizeof prog\n", sizeof(Prog)); } Bflush(&bso); errorexit(); }
void cpp_typecheckt::convert_anonymous_union( cpp_declarationt &declaration, codet &code) { codet new_code(ID_decl_block); new_code.reserve_operands(declaration.declarators().size()); // unnamed object std::string identifier="#anon_union"+i2string(anon_counter++); irept name(ID_name); name.set(ID_identifier, identifier); name.set(ID_C_location, declaration.location()); cpp_namet cpp_name; cpp_name.move_to_sub(name); cpp_declaratort declarator; declarator.name()=cpp_name; cpp_declarator_convertert cpp_declarator_converter(*this); const symbolt &symbol= cpp_declarator_converter.convert(declaration, declarator); if(!cpp_is_pod(declaration.type())) { err_location(follow(declaration.type()).location()); str << "anonymous union is not POD"; throw 0; } codet decl_statement(ID_decl); decl_statement.reserve_operands(2); decl_statement.copy_to_operands(cpp_symbol_expr(symbol)); new_code.move_to_operands(decl_statement); // do scoping symbolt union_symbol=context.symbols[follow(symbol.type).get(ID_name)]; const irept::subt &components=union_symbol.type.add(ID_components).get_sub(); forall_irep(it, components) { if(it->find(ID_type).id()==ID_code) { err_location(union_symbol.type.location()); str << "anonymous union `" << union_symbol.base_name << "' shall not have function members\n"; throw 0; } const irep_idt &base_name=it->get(ID_base_name); if(cpp_scopes.current_scope().contains(base_name)) { err_location(union_symbol.type.location()); str << "identifier `" << base_name << "' already in scope"; throw 0; } cpp_idt &id=cpp_scopes.current_scope().insert(base_name); id.id_class = cpp_idt::SYMBOL; id.identifier=it->get(ID_name); id.class_identifier=union_symbol.name; id.is_member=true; } context.symbols[union_symbol.name].type.set( "#unnamed_object", symbol.base_name); code.swap(new_code); }
exprt c_typecheck_baset::do_initializer_list( const exprt &value, const typet &type, bool force_constant) { assert(value.id()==ID_initializer_list); const typet &full_type=follow(type); exprt result; if(full_type.id()==ID_struct || full_type.id()==ID_union || full_type.id()==ID_vector) { // start with zero everywhere result=zero_initializer(type, value.source_location(), *this, get_message_handler()); } else if(full_type.id()==ID_array) { if(to_array_type(full_type).size().is_nil()) { // start with empty array result=exprt(ID_array, full_type); result.add_source_location()=value.source_location(); } else { // start with zero everywhere result=zero_initializer(type, value.source_location(), *this, get_message_handler()); } // 6.7.9, 14: An array of character type may be initialized by a character // string literal or UTF-8 string literal, optionally enclosed in braces. if(value.operands().size()>=1 && value.op0().id()==ID_string_constant && (full_type.subtype().id()==ID_signedbv || full_type.subtype().id()==ID_unsignedbv) && full_type.subtype().get(ID_width)==char_type().get(ID_width)) { if(value.operands().size()>1) { warning().source_location=value.find_source_location(); warning() << "ignoring excess initializers" << eom; } return do_initializer_rec(value.op0(), type, force_constant); } } else { // The initializer for a scalar shall be a single expression, // * optionally enclosed in braces. * if(value.operands().size()==1) return do_initializer_rec(value.op0(), type, force_constant); err_location(value); error() << "cannot initialize `" << to_string(full_type) << "' with an initializer list" << eom; throw 0; } designatort current_designator; designator_enter(type, current_designator); forall_operands(it, value) { do_designated_initializer( result, current_designator, *it, force_constant); // increase designator -- might go up increment_designator(current_designator); }
lex() { int c, d; char *s; if (regexflg) return sym = scanreg(); next: while ((c = Getc()) == ' ' || c == '\t') ; while (c == '#') for (c = Getc(); c != '\n'; c = Getc()) ; switch (c) { case '\\': if ((c = Getc()) == '\n') { lineno++; goto next; } break; case '\n': lineno++; break; } switch (c) { case EOF: return sym = 0; case '+': return sym = follow2('=', '+', ADDEQ, INC, ADD); case '-': return sym = follow2('=', '-', SUBEQ, DEC, SUB); case '*': return sym = follow('=', MULTEQ, MULT); case '/': return sym = follow('=', DIVEQ, DIV); case '%': return sym = follow('=', MODEQ, MOD); case '^': return sym = follow('=', POWEQ, POWER); case '=': return sym = follow('=', EQ, ASSIGN); case '!': return sym = follow2('=', '~', NE, NOMATCH, NOT); case '&': return sym = follow('&', AND, BINAND); case '|': sym = follow('|', OR, BINOR); if (printflg && sym == BINOR) sym = R_POUT; return sym; case '<': sym = follow2('=', '<', LE, SHIFTL, LT); if (getlineflg && sym == LT) sym = R_IN; return sym; case '>': sym = follow2('=', '>', GE, SHIFTR, GT); if (printflg) { switch (sym) { case GT: sym = R_OUT; break; case SHIFTR: sym = R_APD; break; } } return sym; case '~': return sym = MATCH; break; case ';': case '\n': return sym = EOL; } if (isalpha(c) || c == '_') { for (s = text; isalnum(c) || c == '_'; ) { *s++ = c; c = Getc(); } Ungetc(c); *s = '\0'; if ((d = iskeywd(text)) == 0 && (d = isbuiltin(text, &sym1)) == 0) { if (c == '(') return sym = CALL; else if (funflg) { if ((sym1 = isarg(text)) != -1) return sym = ARG; } } return sym = d ? d : IDENT; } else if (c == '.' || (isdigit(c))) { Ungetc(c); return sym = scannum(text); /* NUMBER */ } else if (c == '"') return sym = scanstr(text); /* STRING */ return sym = c; }
void c_typecheck_baset::typecheck_redefinition_type( symbolt &old_symbol, symbolt &new_symbol) { const typet &final_old=follow(old_symbol.type); const typet &final_new=follow(new_symbol.type); // see if we had something incomplete before if(final_old.id()==ID_incomplete_struct || final_old.id()==ID_incomplete_union || final_old.id()==ID_incomplete_c_enum) { // new one complete? if("incomplete_"+final_new.id_string()==final_old.id_string()) { // overwrite location old_symbol.location=new_symbol.location; // move body old_symbol.type.swap(new_symbol.type); } else if(new_symbol.type.id()==old_symbol.type.id()) return; else { error().source_location=new_symbol.location; error() << "conflicting definition of type symbol `" << new_symbol.display_name() << '\'' << eom; throw 0; } } else { // see if new one is just a tag if(final_new.id()==ID_incomplete_struct || final_new.id()==ID_incomplete_union || final_new.id()==ID_incomplete_c_enum) { if("incomplete_"+final_old.id_string()==final_new.id_string()) { // just ignore silently } else { // arg! new tag type error().source_location=new_symbol.location; error() << "conflicting definition of tag symbol `" << new_symbol.display_name() << '\'' << eom; throw 0; } } else if(config.ansi_c.os==configt::ansi_ct::ost::OS_WIN && final_new.id()==ID_c_enum && final_old.id()==ID_c_enum) { // under Windows, ignore this silently; // MSC doesn't think this is a problem, but GCC complains. } else if(config.ansi_c.os==configt::ansi_ct::ost::OS_WIN && final_new.id()==ID_pointer && final_old.id()==ID_pointer && follow(final_new.subtype()).id()==ID_c_enum && follow(final_old.subtype()).id()==ID_c_enum) { // under Windows, ignore this silently; // MSC doesn't think this is a problem, but GCC complains. } else { // see if it changed if(follow(new_symbol.type)!=follow(old_symbol.type)) { error().source_location=new_symbol.location; error() << "type symbol `" << new_symbol.display_name() << "' defined twice:\n" << "Original: " << to_string(old_symbol.type) << "\n" << " New: " << to_string(new_symbol.type) << eom; throw 0; } } } }
void c_typecheck_baset::do_designated_initializer( exprt &result, designatort &designator, const exprt &value, bool force_constant) { assert(!designator.empty()); if(value.id()==ID_designated_initializer) { assert(value.operands().size()==1); designator= make_designator( designator.front().type, static_cast<const exprt &>(value.find(ID_designator))); assert(!designator.empty()); return do_designated_initializer( result, designator, value.op0(), force_constant); } exprt *dest=&result; // first phase: follow given designator for(size_t i=0; i<designator.size(); i++) { size_t index=designator[i].index; const typet &type=designator[i].type; const typet &full_type=follow(type); if(full_type.id()==ID_array || full_type.id()==ID_vector) { if(index>=dest->operands().size()) { if(full_type.id()==ID_array && (to_array_type(full_type).size().is_zero() || to_array_type(full_type).size().is_nil())) { // we are willing to grow an incomplete or zero-sized array exprt zero=zero_initializer(full_type.subtype(), value.source_location(), *this, get_message_handler()); dest->operands().resize(integer2size_t(index)+1, zero); // todo: adjust type! } else { err_location(value); error() << "array index designator " << index << " out of bounds (" << dest->operands().size() << ")" << eom; throw 0; } } dest=&(dest->operands()[integer2size_t(index)]); } else if(full_type.id()==ID_struct) { const struct_typet::componentst &components= to_struct_type(full_type).components(); if(index>=dest->operands().size()) { err_location(value); error() << "structure member designator " << index << " out of bounds (" << dest->operands().size() << ")" << eom; throw 0; } assert(index<components.size()); assert(components[index].type().id()!=ID_code && !components[index].get_is_padding()); dest=&(dest->operands()[index]); } else if(full_type.id()==ID_union) { const union_typet &union_type=to_union_type(full_type); const union_typet::componentst &components= union_type.components(); assert(index<components.size()); const union_typet::componentt &component=union_type.components()[index]; if(dest->id()==ID_union && dest->get(ID_component_name)==component.get_name()) { // Already right union component. We can initialize multiple submembers, // so do not overwrite this. } else { // Note that gcc issues a warning if the union component is switched. // Build a union expression from given component. union_exprt union_expr(type); union_expr.op()=zero_initializer(component.type(), value.source_location(), *this, get_message_handler()); union_expr.add_source_location()=value.source_location(); union_expr.set_component_name(component.get_name()); *dest=union_expr; } dest=&(dest->op0()); } else assert(false); } // second phase: assign value // for this, we may need to go down, adding to the designator while(true) { // see what type we have to initialize const typet &type=designator.back().subtype; const typet &full_type=follow(type); assert(full_type.id()!=ID_symbol); // do we initialize a scalar? if(full_type.id()!=ID_struct && full_type.id()!=ID_union && full_type.id()!=ID_array && full_type.id()!=ID_vector) { // The initializer for a scalar shall be a single expression, // * optionally enclosed in braces. * if(value.id()==ID_initializer_list && value.operands().size()==1) *dest=do_initializer_rec(value.op0(), type, force_constant); else *dest=do_initializer_rec(value, type, force_constant); assert(full_type==follow(dest->type())); return; // done } // union? The component in the zero initializer might // not be the first one. if(full_type.id()==ID_union) { const union_typet &union_type=to_union_type(full_type); const union_typet::componentst &components= union_type.components(); if(!components.empty()) { const union_typet::componentt &component=union_type.components().front(); union_exprt union_expr(type); union_expr.op()=zero_initializer(component.type(), value.source_location(), *this, get_message_handler()); union_expr.add_source_location()=value.source_location(); union_expr.set_component_name(component.get_name()); *dest=union_expr; } } // see what initializer we are given if(value.id()==ID_initializer_list) { *dest=do_initializer_rec(value, type, force_constant); return; // done } else if(value.id()==ID_string_constant) { // We stop for initializers that are string-constants, // which are like arrays. We only do so if we are to // initialize an array of scalars. if(full_type.id()==ID_array && (follow(full_type.subtype()).id()==ID_signedbv || follow(full_type.subtype()).id()==ID_unsignedbv)) { *dest=do_initializer_rec(value, type, force_constant); return; // done } } else if(follow(value.type())==full_type) { // a struct/union/vector can be initialized directly with // an expression of the right type. This doesn't // work with arrays, unfortunately. if(full_type.id()==ID_struct || full_type.id()==ID_union || full_type.id()==ID_vector) { *dest=value; return; // done } } assert(full_type.id()==ID_struct || full_type.id()==ID_union || full_type.id()==ID_array || full_type.id()==ID_vector); // we are initializing a compound type, and enter it! // this may change the type, full_type might not be valid anymore const typet dest_type=full_type; designator_enter(type, designator); if(dest->operands().empty()) { err_location(value); error() << "cannot initialize type `" << to_string(dest_type) << "' using value `" << to_string(value) << "'" << eom; throw 0; } dest=&(dest->op0()); // we run into another loop iteration } }
/* returns 0 if error or no more commands to do, * 1 if there are more commands remaining on the current input line */ int cypher(void) { int n; int junk; int lflag = -1; char *filename, *rfilename; size_t filename_len; while (wordnumber <= wordcount) { if (wordtype[wordnumber] != VERB && !(wordtype[wordnumber] == OBJECT && wordvalue[wordnumber] == KNIFE)) { printf("%s: How's that?\n", (wordnumber == wordcount) ? words[wordnumber - 1] : words[wordnumber]); return (0); } switch (wordvalue[wordnumber]) { case AUXVERB: /* Take the following word as the verb */ wordnumber++; return(cypher()); break; case UP: if (location[position].access || wiz || tempwiz) { if (!location[position].access) puts("Zap! A gust of wind lifts you up."); if (!moveplayer(location[position].up, AHEAD)) return (0); } else { puts("There is no way up."); return (0); } lflag = 0; break; case DOWN: if (!moveplayer(location[position].down, AHEAD)) return (0); lflag = 0; break; case LEFT: if (!moveplayer(left, LEFT)) return (0); lflag = 0; break; case RIGHT: if (!moveplayer(right, RIGHT)) return (0); lflag = 0; break; case AHEAD: if (!moveplayer(ahead, AHEAD)) return (0); lflag = 0; break; case BACK: if (!moveplayer(back, BACK)) return (0); lflag = 0; break; case SHOOT: verb_with_all(location[position].objects, OBJ_PERSON, shoot, "shoot at"); break; case TAKE: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { int things; things = 0; for (n = 0; n < NUMOFOBJECTS; n++) if (TestBit(location[position].objects, n) && objsht[n]) { things++; wordvalue[wordnumber + 1] = n; /* Some objects (type NOUNS) have special treatment in take(). For these * we must set the type to NOUNS. However for SWORD and BODY all it does * is find which of many objects is meant, so we need do nothing here. * BATHGOD must become NORMGOD as well. NOUNS with no special case must be * included here to get the right error. DOOR cannot occur as an object so * need not be included. */ switch (n) { case BATHGOD: wordvalue[wordnumber + 1] = NORMGOD; /* FALLTHROUGH */ case NORMGOD: case AMULET: case MEDALION: case TALISMAN: case MAN: case TIMER: case NATIVE: wordtype[wordnumber + 1] = NOUNS; break; default: wordtype[wordnumber + 1] = OBJECT; } wordnumber = take(location[position].objects); wordnumber += 2; } if (!things) puts("Nothing to take!"); } else take(location[position].objects); break; case DROP: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { int things; things = 0; for (n = 0; n < NUMOFOBJECTS; n++) if (TestBit(inven, n)) { things++; wordvalue[wordnumber + 1] = n; wordnumber = drop("Dropped"); } wordnumber++; wordnumber++; if (!things) puts("Nothing to drop!"); } else drop("Dropped"); break; case KICK: case THROW: if (wordnumber < wordcount && wordvalue[wordnumber + 1] == EVERYTHING) { int things, wv; things = 0; wv = wordvalue[wordnumber]; for (n = 0; n < NUMOFOBJECTS; n++) if (TestBit(inven, n) || (TestBit(location[position].objects, n) && objsht[n])) { things++; wordvalue[wordnumber + 1] = n; wordnumber = throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown"); } wordnumber += 2; if (!things) printf("Nothing to %s!\n", wv == KICK ? "kick" : "throw"); } else throw(wordvalue[wordnumber] == KICK ? "Kicked" : "Thrown"); break; case TAKEOFF: verb_with_all(wear, 0, takeoff, "take off"); break; case DRAW: verb_with_all(wear, 0, draw, "draw"); break; case PUTON: verb_with_all(location[position].objects, 0, puton, "put on"); break; case WEARIT: verb_with_all(inven, 0, wearit, "wear"); break; case EAT: verb_with_all(inven, 0, eat, "eat"); break; case PUT: put(); break; case INVEN: if (ucard(inven)) { puts("You are holding:\n"); for (n = 0; n < NUMOFOBJECTS; n++) if (TestBit(inven, n)) printf("\t%s\n", objsht[n]); printf("\n= %d kilogram%s ", carrying, (carrying == 1 ? "." : "s.")); if (WEIGHT) printf("(%d%%)\n", carrying * 100 / WEIGHT); else printf("(can't lift any weight%s)\n", (carrying ? " or move with what you have" : "")); if (CUMBER) printf("Your arms are %d%% full.\n", encumber * 100 / CUMBER); else printf("You can't pick anything up.\n"); } else puts("You aren't carrying anything."); if (ucard(wear)) { puts("\nYou are wearing:\n"); for (n = 0; n < NUMOFOBJECTS; n++) if (TestBit(wear, n)) printf("\t%s\n", objsht[n]); } else puts("\nYou are stark naked."); if (card(injuries, NUMOFINJURIES)) { puts("\nYou have suffered:\n"); for (n = 0; n < NUMOFINJURIES; n++) if (injuries[n]) printf("\t%s\n", ouch[n]); printf("\nYou can still carry up to %d kilogram%s\n", WEIGHT, (WEIGHT == 1 ? "." : "s.")); } else puts("\nYou are in perfect health."); break; case USE: lflag = use(); break; case OPEN: dooropen(); break; case LOOK: if (!notes[CANTSEE] || TestBit(inven, LAMPON) || TestBit(location[position].objects, LAMPON) || matchlight) { beenthere[position] = 2; writedes(); printobjs(); if (matchlight) { puts("\nYour match splutters out."); matchlight = 0; } } else puts("I can't see anything."); return (0); /* No commands after a look */ break; case SU: if (wiz || tempwiz) { getnum(&position, "\nRoom (was %d) = ", position); getnum(&ourtime, "Time (was %d) = ", ourtime); getnum(&fuel, "Fuel (was %d) = ", fuel); getnum(&torps, "Torps (was %d) = ", torps); getnum(&CUMBER, "CUMBER (was %d) = ", CUMBER); getnum(&WEIGHT, "WEIGHT (was %d) = ", WEIGHT); getnum(&ourclock, "Clock (was %d) = ", ourclock); if (getnum(&junk, "Wizard (was %d, %d) = ", wiz, tempwiz) != -1 && !junk) tempwiz = wiz = 0; printf("\nDONE.\n"); return (0); /* No commands after a SU */ } else puts("You aren't a wizard."); break; case SCORE: printf("\tPLEASURE\tPOWER\t\tEGO\n"); printf("\t%3d\t\t%3d\t\t%3d\n\n", pleasure, power, ego); printf("This gives you the rating of %s in %d turns.\n", rate(), ourtime); printf("You have visited %d out of %d rooms this run (%d%%).\n", card(beenthere, NUMOFROOMS), NUMOFROOMS, card(beenthere, NUMOFROOMS) * 100 / NUMOFROOMS); break; /* case KNIFE: */ case KILL: murder(); break; case UNDRESS: undress(); break; case RAVAGE: ravage(); break; case SAVE: printf("\nSave file name (default %s): ", DEFAULT_SAVE_FILE); filename = fgetln(stdin, &filename_len); if (filename_len == 0 || (filename_len == 1 && filename[0] == '\n')) rfilename = save_file_name(DEFAULT_SAVE_FILE, strlen(DEFAULT_SAVE_FILE)); else { if (filename[filename_len - 1] == '\n') filename_len--; rfilename = save_file_name(filename, filename_len); } save(rfilename); free(rfilename); break; case VERBOSE: verbose = 1; printf("[Maximum verbosity]\n"); break; case BRIEF: verbose = 0; printf("[Standard verbosity]\n"); break; case FOLLOW: lflag = follow(); break; case GIVE: give(); break; case KISS: kiss(); break; case LOVE: love(); break; case RIDE: lflag = ride(); break; case DRIVE: lflag = drive(); break; case LIGHT: light(); break; case LAUNCH: if (!launch()) return (0); else lflag = 0; break; case LANDIT: if (!land()) return (0); else lflag = 0; break; case TIME: chime(); break; case SLEEP: zzz(); break; case DIG: dig(); break; case JUMP: lflag = jump(); break; case BURY: bury(); break; case SWIM: puts("Surf's up!"); break; case DRINK: drink(); break; case QUIT: die(0); default: puts("How's that?"); return (0); break; } if (!lflag) newlocation(); if (wordnumber < wordcount && !stop_cypher && (*words[wordnumber] == ',' || *words[wordnumber] == '.')) { wordnumber++; return (1); } else return (0); } return (0); }
int main(int argc, char **argv) { struct stat sb; FILE *fp; off_t off = 0; enum STYLE style; int style_set; int i, ch; file_info_t *file; obsolete(argv); style_set = 0; while ((ch = getopt(argc, argv, "Fb:c:fn:r")) != -1) switch(ch) { case 'F': /* -F is superset of (and implies) -f */ Fflag = fflag = 1; break; case 'b': getarg(512, FBYTES, RBYTES, &style, &style_set, &off); break; case 'c': getarg(1, FBYTES, RBYTES, &style, &style_set, &off); break; case 'f': fflag = 1; break; case 'n': getarg(1, FLINES, RLINES, &style, &style_set, &off); break; case 'r': rflag = 1; break; case '?': default: usage(); } argc -= optind; argv += optind; no_files = argc ? argc : 1; /* * If displaying in reverse, don't permit follow option, and convert * style values. */ if (rflag) { if (fflag) usage(); if (style == FBYTES) style = RBYTES; else if (style == FLINES) style = RLINES; } /* * If style not specified, the default is the whole file for -r, and * the last 10 lines if not -r. */ if (!style_set) { if (rflag) { off = 0; style = REVERSE; } else { off = 10; style = RLINES; } } if (*argv && fflag) { files = malloc(no_files * sizeof(struct file_info)); if (files == NULL) err(1, "Couldn't malloc space for files descriptors."); for (file = files; (fname = *argv++) != NULL; file++) { file->file_name = strdup(fname); if (! file->file_name) errx(1, "Couldn't alloc space for file name."); file->fp = fopen(file->file_name, "r"); if (file->fp == NULL || fstat(fileno(file->fp), &file->st) == -1) { file->fp = NULL; ierr(); continue; } } follow(files, style, off); for (i = 0, file = files; i < no_files; i++, file++) free(file->file_name); free(files); } else if (*argv) { for (i = 0; (fname = *argv++) != NULL; ++i) { if ((fp = fopen(fname, "r")) == NULL || fstat(fileno(fp), &sb)) { ierr(); continue; } if (argc > 1) { showfilename(i, fname); (void)fflush(stdout); } if (rflag) reverse(fp, style, off, &sb); else forward(fp, style, off, &sb); (void)fclose(fp); } } else { fname = "stdin"; if (fstat(fileno(stdin), &sb)) { ierr(); exit(1); } /* * Determine if input is a pipe. 4.4BSD will set the SOCKET * bit in the st_mode field for pipes. Fix this then. */ if (lseek(fileno(stdin), (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE) { errno = 0; fflag = 0; /* POSIX.2 requires this. */ } if (rflag) reverse(stdin, style, off, &sb); else forward(stdin, style, off, &sb); } exit(rval); }
void cfoll(int v) { int i,j,k; uchar *p; i = name[v]; if(i < NCH) i = 1; /* character */ switch(i){ case 1: case RSTR: case RCCL: case RNCCL: case RNULLS: for(j=0;j<tptr;j++) tmpstat[j] = FALSE; count = 0; follow(v); # ifdef PP padd(foll,v); /* packing version */ # endif # ifndef PP add(foll,v); /* no packing version */ # endif if(i == RSTR) cfoll(left[v]); else if(i == RCCL || i == RNCCL){ /* compress ccl list */ for(j=1; j<NCH;j++) symbol[j] = (i==RNCCL); p = ptr[v]; while(*p) symbol[*p++] = (i == RCCL); p = pcptr; for(j=1;j<NCH;j++) if(symbol[j]){ for(k=0;p+k < pcptr; k++) if(cindex[j] == *(p+k)) break; if(p+k >= pcptr)*pcptr++ = cindex[j]; } *pcptr++ = 0; if(pcptr > pchar + pchlen) error("Too many packed character classes"); ptr[v] = p; name[v] = RCCL; /* RNCCL eliminated */ # ifdef DEBUG if(debug && *p){ print("ccl %d: %d",v,*p++); while(*p) print(", %d",*p++); print("\n"); } # endif } break; case CARAT: cfoll(left[v]); break; case STAR: case PLUS: case QUEST: case RSCON: cfoll(left[v]); break; case BAR: case RCAT: case DIV: case RNEWE: cfoll(left[v]); cfoll(right[v]); break; # ifdef DEBUG case FINAL: case S1FINAL: case S2FINAL: break; default: warning("bad switch cfoll %d",v); # endif } }
void c_typecheck_baset::typecheck_array_type(array_typet &type) { exprt &size=type.size(); source_locationt source_location=size.find_source_location(); // check subtype typecheck_type(type.subtype()); // we don't allow void as subtype if(follow(type.subtype()).id()==ID_empty) { error().source_location=type.source_location(); error() << "array of voids" << eom; throw 0; } // check size, if any if(size.is_not_nil()) { typecheck_expr(size); make_index_type(size); // The size need not be a constant! // We simplify it, for the benefit of array initialisation. exprt tmp_size=size; add_rounding_mode(tmp_size); simplify(tmp_size, *this); if(tmp_size.is_constant()) { mp_integer s; if(to_integer(tmp_size, s)) { error().source_location=source_location; error() << "failed to convert constant: " << tmp_size.pretty() << eom; throw 0; } if(s<0) { error().source_location=source_location; error() << "array size must not be negative, " "but got " << s << eom; throw 0; } size=tmp_size; } else if(tmp_size.id()==ID_infinity) { size=tmp_size; } else if(tmp_size.id()==ID_symbol && tmp_size.type().get_bool(ID_C_constant)) { // We allow a constant variable as array size, assuming // it won't change. // This criterion can be tricked: // Of course we can modify a 'const' symbol, e.g., // using a pointer type cast. Interestingly, // at least gcc 4.2.1 makes the very same mistake! size=tmp_size; } else { // not a constant and not infinity assert(current_symbol_id!=irep_idt()); const symbolt &base_symbol=lookup(current_symbol_id); // Need to pull out! We insert new symbol. source_locationt source_location=size.find_source_location(); unsigned count=0; irep_idt temp_identifier; std::string suffix; do { suffix="$array_size"+std::to_string(count); temp_identifier=id2string(base_symbol.name)+suffix; count++; } while(symbol_table.symbols.find(temp_identifier)!= symbol_table.symbols.end()); // add the symbol to symbol table auxiliary_symbolt new_symbol; new_symbol.name=temp_identifier; new_symbol.pretty_name=id2string(base_symbol.pretty_name)+suffix; new_symbol.base_name=id2string(base_symbol.base_name)+suffix; new_symbol.type=size.type(); new_symbol.type.set(ID_C_constant, true); new_symbol.is_type=false; new_symbol.is_static_lifetime=false; new_symbol.value.make_nil(); new_symbol.location=source_location; symbol_table.add(new_symbol); // produce the code that declares and initializes the symbol symbol_exprt symbol_expr; symbol_expr.set_identifier(temp_identifier); symbol_expr.type()=new_symbol.type; code_declt declaration(symbol_expr); declaration.add_source_location()=source_location; code_assignt assignment; assignment.lhs()=symbol_expr; assignment.rhs()=size; assignment.add_source_location()=source_location; // store the code clean_code.push_back(declaration); clean_code.push_back(assignment); // fix type size=symbol_expr; } } }
void c_typecheck_baset::typecheck_code_type(code_typet &type) { // the return type is still 'subtype()' type.return_type()=type.subtype(); type.remove_subtype(); code_typet::parameterst ¶meters=type.parameters(); // if we don't have any parameters, we assume it's (...) if(parameters.empty()) { type.make_ellipsis(); } else // we do have parameters { // is the last one ellipsis? if(type.parameters().back().id()==ID_ellipsis) { type.make_ellipsis(); type.parameters().pop_back(); } parameter_map.clear(); for(auto ¶m : type.parameters()) { // turn the declarations into parameters if(param.id()==ID_declaration) { ansi_c_declarationt &declaration= to_ansi_c_declaration(param); code_typet::parametert parameter; // first fix type typet &type=parameter.type(); type=declaration.full_type(declaration.declarator()); std::list<codet> tmp_clean_code; tmp_clean_code.swap(clean_code); // ignore side-effects typecheck_type(type); tmp_clean_code.swap(clean_code); adjust_function_parameter(type); // adjust the identifier irep_idt identifier=declaration.declarator().get_name(); // abstract or not? if(identifier==irep_idt()) { // abstract parameter.add_source_location()=declaration.type().source_location(); } else { // make visible now, later parameters might use it parameter_map[identifier]=type; parameter.set_base_name(declaration.declarator().get_base_name()); parameter.add_source_location()= declaration.declarator().source_location(); } // put the parameter in place of the declaration param.swap(parameter); } } parameter_map.clear(); if(parameters.size()==1 && follow(parameters[0].type()).id()==ID_empty) { // if we just have one parameter of type void, remove it parameters.clear(); } } typecheck_type(type.return_type()); // 6.7.6.3: // "A function declarator shall not specify a return type that // is a function type or an array type." const typet &return_type=follow(type.return_type()); if(return_type.id()==ID_array) { error().source_location=type.source_location(); error() << "function must not return array" << eom; throw 0; } if(return_type.id()==ID_code) { error().source_location=type.source_location(); error() << "function must not return function type" << eom; throw 0; } }
int ipc_bench(char * flag_str) { double time_elapced; struct shmid_ds ds; int semid, shmid; short sarray[NUMSEMS] = { 1, 1 }; // if (argc < 2) { // printf( // "Please specifivy the IPC method.\nAvailable methotds:\nPIP\nFILE\nSHM\n"); // exit(0); // } int flag; if (strcmp(flag_str, (char *) SHM_IPC) == 0) { key_t semkey = ftok(SLEADKEY, 'S'); key_t shmkey = ftok(BUFKEY, 'B'); semid = semget(semkey, NUMSEM, IPC_CREAT | IPC_EXCL); if (semid == -1) { // printf ("SEMMSL is %d \n",SEMMNI); perror("semget: semget failed"); exit(1); } shmid = shmget(shmkey, MAX_BUF_SIZE * sizeof(int), IPC_CREAT | S_IRUSR | S_IWUSR); flag = SHM_IPC_ID; } else if (strcmp(flag_str, (char *) FILE_IPC) == 0) { flag = FILE_IPC_ID; } else if (strcmp(flag_str, (char *) PIP_IPC) == 0) { flag = PIP_IPC_ID; } else { printf( "BAD INPUT\nPlease specifivy the IPC method.\nAvailable methotds:\nPIP\nFILE\nSHM\n"); exit(1); } // if (file_exist(LEAD_FILE_BUF)){ // printf("exist\n"); // } // exit(0); int itr; for (itr = 0; itr < NUM_ITRS; itr++) { // printf("Iteration %d\n", itr); switch (flag) { case PIP_IPC_ID: unlink(lead_pipfile(itr)); unlink(follow_pipfile(itr)); break; case FILE_IPC_ID: unlink(LOCK_FILE_LEAD); unlink(LOCK_FILE_FOLO); unlink(LEAD_FILE_BUF); unlink(FOLO_FILE_BUF); break; case SHM_IPC_ID: shmctl(shmid, IPC_STAT, &ds); semctl(semid, 0, SETVAL, sarray); break; default: exit(1); } pid_t pid = fork(); if (pid == 0) { follow(itr, flag); exit(0); } else { double lead_time = 0; lead_time = lead(itr, flag); lead_time /= (double) NUM_ITRS; time_elapced += lead_time; wait(NULL); } } if (flag == SHM_IPC_ID) { semctl(semid, 1, IPC_RMID); } printf("> %s IPC: %f seconds\n", flag_str, time_elapced); return 0; }
void c_typecheck_baset::typecheck_redefinition_non_type( symbolt &old_symbol, symbolt &new_symbol) { const typet &final_old=follow(old_symbol.type); const typet &initial_new=follow(new_symbol.type); if(final_old.id()==ID_array && to_array_type(final_old).size().is_not_nil() && initial_new.id()==ID_array && to_array_type(initial_new).size().is_nil() && final_old.subtype()==initial_new.subtype()) { // this is ok, just use old type new_symbol.type=old_symbol.type; } else if(final_old.id()==ID_array && to_array_type(final_old).size().is_nil() && initial_new.id()==ID_array && to_array_type(initial_new).size().is_not_nil() && final_old.subtype()==initial_new.subtype()) { // update the type to enable the use of sizeof(x) on the // right-hand side of a definition of x old_symbol.type=new_symbol.type; } // do initializer, this may change the type if(follow(new_symbol.type).id()!=ID_code && !new_symbol.is_macro) do_initializer(new_symbol); const typet &final_new=follow(new_symbol.type); // K&R stuff? if(old_symbol.type.id()==ID_KnR) { // check the type if(final_new.id()==ID_code) { error().source_location=new_symbol.location; error() << "function type not allowed for K&R function parameter" << eom; throw 0; } // fix up old symbol -- we now got the type old_symbol.type=new_symbol.type; return; } if(final_new.id()==ID_code) { bool inlined= (new_symbol.type.get_bool(ID_C_inlined) || old_symbol.type.get_bool(ID_C_inlined)); if(final_old.id()!=ID_code) { error().source_location=new_symbol.location; error() << "error: function symbol `" << new_symbol.display_name() << "' redefined with a different type:\n" << "Original: " << to_string(old_symbol.type) << "\n" << " New: " << to_string(new_symbol.type) << eom; throw 0; } code_typet &old_ct=to_code_type(old_symbol.type); code_typet &new_ct=to_code_type(new_symbol.type); if(old_ct.has_ellipsis() && !new_ct.has_ellipsis()) old_ct=new_ct; else if(!old_ct.has_ellipsis() && new_ct.has_ellipsis()) new_ct=old_ct; if(inlined) { old_symbol.type.set(ID_C_inlined, true); new_symbol.type.set(ID_C_inlined, true); } // do body if(new_symbol.value.is_not_nil()) { if(old_symbol.value.is_not_nil()) { // gcc allows re-definition if the first // definition is marked as "extern inline" if(old_symbol.type.get_bool(ID_C_inlined) && (config.ansi_c.mode==configt::ansi_ct::flavourt::GCC || config.ansi_c.mode==configt::ansi_ct::flavourt::APPLE || config.ansi_c.mode==configt::ansi_ct::flavourt::ARM)) { // overwrite "extern inline" properties old_symbol.is_extern=new_symbol.is_extern; old_symbol.is_file_local=new_symbol.is_file_local; // remove parameter declarations to avoid conflicts const code_typet::parameterst &old_p=old_ct.parameters(); for(code_typet::parameterst::const_iterator p_it=old_p.begin(); p_it!=old_p.end(); p_it++) { const irep_idt &identifier=p_it->get_identifier(); symbol_tablet::symbolst::iterator p_s_it= symbol_table.symbols.find(identifier); if(p_s_it!=symbol_table.symbols.end()) symbol_table.symbols.erase(p_s_it); } } else { error().source_location=new_symbol.location; error() << "function body `" << new_symbol.display_name() << "' defined twice" << eom; throw 0; } } else if(inlined) { // preserve "extern inline" properties old_symbol.is_extern=new_symbol.is_extern; old_symbol.is_file_local=new_symbol.is_file_local; } else if(new_symbol.is_weak) { // weak symbols old_symbol.is_weak=true; } if(new_symbol.is_macro) old_symbol.is_macro=true; else typecheck_function_body(new_symbol); // overwrite location old_symbol.location=new_symbol.location; // move body old_symbol.value.swap(new_symbol.value); // overwrite type (because of parameter names) old_symbol.type=new_symbol.type; } return; } if(final_old!=final_new) { if(final_old.id()==ID_array && to_array_type(final_old).size().is_nil() && final_new.id()==ID_array && to_array_type(final_new).size().is_not_nil() && final_old.subtype()==final_new.subtype()) { // we don't do symbol types for arrays anymore PRECONDITION(old_symbol.type.id()!=ID_symbol); old_symbol.type=new_symbol.type; } else if((final_old.id()==ID_incomplete_c_enum || final_old.id()==ID_c_enum) && (final_new.id()==ID_incomplete_c_enum || final_new.id()==ID_c_enum)) { // this is ok for now } else if(final_old.id()==ID_pointer && follow(final_old).subtype().id()==ID_code && to_code_type(follow(final_old).subtype()).has_ellipsis() && final_new.id()==ID_pointer && follow(final_new).subtype().id()==ID_code) { // to allow // int (*f) (); // int (*f) (int)=0; old_symbol.type=new_symbol.type; } else if(final_old.id()==ID_pointer && follow(final_old).subtype().id()==ID_code && final_new.id()==ID_pointer && follow(final_new).subtype().id()==ID_code && to_code_type(follow(final_new).subtype()).has_ellipsis()) { // to allow // int (*f) (int)=0; // int (*f) (); } else { error().source_location=new_symbol.location; error() << "symbol `" << new_symbol.display_name() << "' redefined with a different type:\n" << "Original: " << to_string(old_symbol.type) << "\n" << " New: " << to_string(new_symbol.type) << eom; throw 0; } } else // finals are equal { } // do value if(new_symbol.value.is_not_nil()) { // see if we already have one if(old_symbol.value.is_not_nil()) { if(new_symbol.value.get_bool(ID_C_zero_initializer)) { // do nothing } else if(old_symbol.value.get_bool(ID_C_zero_initializer)) { old_symbol.value=new_symbol.value; old_symbol.type=new_symbol.type; } else { if(new_symbol.is_macro && (final_new.id()==ID_incomplete_c_enum || final_new.id()==ID_c_enum) && old_symbol.value.is_constant() && new_symbol.value.is_constant() && old_symbol.value.get(ID_value)==new_symbol.value.get(ID_value)) { // ignore } else { warning().source_location=new_symbol.value.find_source_location(); warning() << "symbol `" << new_symbol.display_name() << "' already has an initial value" << eom; } } } else { old_symbol.value=new_symbol.value; old_symbol.type=new_symbol.type; old_symbol.is_macro=new_symbol.is_macro; } } // take care of some flags if(old_symbol.is_extern && !new_symbol.is_extern) old_symbol.location=new_symbol.location; old_symbol.is_extern=old_symbol.is_extern && new_symbol.is_extern; // We should likely check is_volatile and // is_thread_local for consistency. GCC complains if these // mismatch. }
void c_typecheck_baset::designator_enter( const typet &type, designatort &designator) { designatort::entryt entry; entry.type=type; entry.index=0; const typet &full_type=follow(type); if(full_type.id()==ID_struct) { const struct_typet &struct_type=to_struct_type(full_type); entry.size=struct_type.components().size(); entry.subtype.make_nil(); for(struct_typet::componentst::const_iterator it=struct_type.components().begin(); it!=struct_type.components().end(); ++it) { if(it->type().id()!=ID_code && !it->get_is_padding()) { entry.subtype=it->type(); break; } ++entry.index; } } else if(full_type.id()==ID_union) { const union_typet &union_type=to_union_type(full_type); if(union_type.components().empty()) { entry.size=0; entry.subtype.make_nil(); } else { // The default is to unitialize using the first member of the // union. entry.size=1; entry.subtype=union_type.components().front().type(); } } else if(full_type.id()==ID_array) { const array_typet &array_type=to_array_type(full_type); if(array_type.size().is_nil()) { entry.size=0; entry.subtype=array_type.subtype(); } else { mp_integer array_size; if(to_integer(array_type.size(), array_size)) { err_location(array_type.size()); error() << "array has non-constant size `" << to_string(array_type.size()) << "'" << eom; throw 0; } entry.size=integer2size_t(array_size); entry.subtype=array_type.subtype(); } } else if(full_type.id()==ID_vector) { const vector_typet &vector_type=to_vector_type(full_type); mp_integer vector_size; if(to_integer(vector_type.size(), vector_size)) { err_location(vector_type.size()); error() << "vector has non-constant size `" << to_string(vector_type.size()) << "'" << eom; throw 0; } entry.size=integer2size_t(vector_size); entry.subtype=vector_type.subtype(); } else assert(false); designator.push_entry(entry); }
void c_typecheck_baset::typecheck_symbol(symbolt &symbol) { bool is_function=symbol.type.id()==ID_code; const typet &final_type=follow(symbol.type); // set a few flags symbol.is_lvalue=!symbol.is_type && !symbol.is_macro; irep_idt root_name=symbol.base_name; irep_idt new_name=symbol.name; if(symbol.is_file_local) { // file-local stuff -- stays as is // collisions are resolved during linking } else if(symbol.is_extern && !is_function) { // variables marked as "extern" go into the global namespace // and have static lifetime new_name=root_name; symbol.is_static_lifetime=true; } else if(!is_function && symbol.value.id()==ID_code) { error().source_location=symbol.value.find_source_location(); error() << "only functions can have a function body" << eom; throw 0; } // set the pretty name if(symbol.is_type && (final_type.id()==ID_struct || final_type.id()==ID_incomplete_struct)) { symbol.pretty_name="struct "+id2string(symbol.base_name); } else if(symbol.is_type && (final_type.id()==ID_union || final_type.id()==ID_incomplete_union)) { symbol.pretty_name="union "+id2string(symbol.base_name); } else if(symbol.is_type && (final_type.id()==ID_c_enum || final_type.id()==ID_incomplete_c_enum)) { symbol.pretty_name="enum "+id2string(symbol.base_name); } else { symbol.pretty_name=new_name; } // see if we have it already symbol_tablet::symbolst::iterator old_it= symbol_table.symbols.find(symbol.name); if(old_it==symbol_table.symbols.end()) { // just put into symbol_table symbolt *new_symbol; move_symbol(symbol, new_symbol); typecheck_new_symbol(*new_symbol); } else { if(old_it->second.is_type!=symbol.is_type) { error().source_location=symbol.location; error() << "redeclaration of `" << symbol.display_name() << "' as a different kind of symbol" << eom; throw 0; } if(symbol.is_type) typecheck_redefinition_type(old_it->second, symbol); else typecheck_redefinition_non_type(old_it->second, symbol); } }
designatort c_typecheck_baset::make_designator( const typet &src_type, const exprt &src) { assert(!src.operands().empty()); typet type=src_type; designatort designator; forall_operands(it, src) { const exprt &d_op=*it; designatort::entryt entry; entry.type=type; const typet &full_type=follow(entry.type); if(full_type.id()==ID_array) { if(d_op.id()!=ID_index) { err_location(d_op); error() << "expected array index designator" << eom; throw 0; } assert(d_op.operands().size()==1); exprt tmp_index=d_op.op0(); make_constant_index(tmp_index); mp_integer index, size; if(to_integer(tmp_index, index)) { err_location(d_op.op0()); error() << "expected constant array index designator" << eom; throw 0; } if(to_array_type(full_type).size().is_nil()) size=0; else if(to_integer(to_array_type(full_type).size(), size)) { err_location(d_op.op0()); error() << "expected constant array size" << eom; throw 0; } entry.index=integer2size_t(index); entry.size=integer2size_t(size); entry.subtype=full_type.subtype(); } else if(full_type.id()==ID_struct || full_type.id()==ID_union) { const struct_union_typet &struct_union_type=to_struct_union_type(full_type); if(d_op.id()!=ID_member) { err_location(d_op); error() << "expected member designator" << eom; throw 0; } const irep_idt &component_name=d_op.get(ID_component_name); if(struct_union_type.has_component(component_name)) { // a direct member entry.index=struct_union_type.component_number(component_name); entry.size=struct_union_type.components().size(); entry.subtype=struct_union_type.components()[entry.index].type(); } else { // We will search for anonymous members, // in a loop. This isn't supported by gcc, but icc does allow it. bool found=false, repeat; typet tmp_type=entry.type; do { repeat=false; unsigned number=0; const struct_union_typet::componentst &components= to_struct_union_type(follow(tmp_type)).components(); for(struct_union_typet::componentst::const_iterator c_it=components.begin(); c_it!=components.end(); c_it++, number++) { if(c_it->get_name()==component_name) { // done! entry.index=number; entry.size=components.size(); entry.subtype=components[entry.index].type(); entry.type=tmp_type; } else if(c_it->get_anonymous() && (follow(c_it->type()).id()==ID_struct || follow(c_it->type()).id()==ID_union) && has_component_rec( c_it->type(), component_name, *this)) { entry.index=number; entry.size=components.size(); entry.subtype=c_it->type(); entry.type=tmp_type; tmp_type=entry.subtype; designator.push_entry(entry); found=repeat=true; break; } } } while(repeat); if(!found) { err_location(d_op); error() << "failed to find struct component `" << component_name << "' in initialization of `" << to_string(struct_union_type) << "'" << eom; throw 0; } } } else { err_location(d_op); error() << "designated initializers cannot initialize `" << to_string(full_type) << "'" << eom; throw 0; } type=entry.subtype; designator.push_entry(entry); } assert(!designator.empty()); return designator; }
int main(int argc, char *argv[]) { struct stat sb; const char *fn; FILE *fp; off_t off; enum STYLE style; int i, ch, first; file_info_t *file; char *p; /* * Tail's options are weird. First, -n10 is the same as -n-10, not * -n+10. Second, the number options are 1 based and not offsets, * so -n+1 is the first line, and -c-1 is the last byte. Third, the * number options for the -r option specify the number of things that * get displayed, not the starting point in the file. The one major * incompatibility in this version as compared to historical versions * is that the 'r' option couldn't be modified by the -lbc options, * i.e. it was always done in lines. This version treats -rc as a * number of characters in reverse order. Finally, the default for * -r is the entire file, not 10 lines. */ #define ARG(units, forward, backward) { \ if (style) \ usage(); \ off = strtoll(optarg, &p, 10) * (units); \ if (*p) \ errx(1, "illegal offset -- %s", optarg); \ switch(optarg[0]) { \ case '+': \ if (off) \ off -= (units); \ style = (forward); \ break; \ case '-': \ off = -off; \ /* FALLTHROUGH */ \ default: \ style = (backward); \ break; \ } \ } obsolete(argv); style = NOTSET; off = 0; while ((ch = getopt(argc, argv, "Fb:c:fn:qr")) != -1) switch(ch) { case 'F': /* -F is superset of (and implies) -f */ Fflag = fflag = 1; break; case 'b': ARG(512, FBYTES, RBYTES); break; case 'c': ARG(1, FBYTES, RBYTES); break; case 'f': fflag = 1; break; case 'n': ARG(1, FLINES, RLINES); break; case 'q': qflag = 1; break; case 'r': rflag = 1; break; case '?': default: usage(); } argc -= optind; argv += optind; no_files = argc ? argc : 1; /* * If displaying in reverse, don't permit follow option, and convert * style values. */ if (rflag) { if (fflag) usage(); if (style == FBYTES) style = RBYTES; else if (style == FLINES) style = RLINES; } /* * If style not specified, the default is the whole file for -r, and * the last 10 lines if not -r. */ if (style == NOTSET) { if (rflag) { off = 0; style = REVERSE; } else { off = 10; style = RLINES; } } if (*argv && fflag) { files = (struct file_info *) malloc(no_files * sizeof(struct file_info)); if (!files) err(1, "Couldn't malloc space for file descriptors."); for (file = files; (fn = *argv++); file++) { file->file_name = strdup(fn); if (! file->file_name) errx(1, "Couldn't malloc space for file name."); if ((file->fp = fopen(file->file_name, "r")) == NULL || fstat(fileno(file->fp), &file->st)) { if (file->fp != NULL) { fclose(file->fp); file->fp = NULL; } if (!Fflag || errno != ENOENT) ierr(file->file_name); } } follow(files, style, off); for (i = 0, file = files; i < no_files; i++, file++) { free(file->file_name); } free(files); } else if (*argv) { for (first = 1; (fn = *argv++);) { if ((fp = fopen(fn, "r")) == NULL || fstat(fileno(fp), &sb)) { ierr(fn); continue; } if (argc > 1 && !qflag) { printfn(fn, !first); first = 0; } if (rflag) reverse(fp, fn, style, off, &sb); else forward(fp, fn, style, off, &sb); } } else { fn = "stdin"; if (fstat(fileno(stdin), &sb)) { ierr(fn); exit(1); } /* * Determine if input is a pipe. 4.4BSD will set the SOCKET * bit in the st_mode field for pipes. Fix this then. */ if (lseek(fileno(stdin), (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE) { errno = 0; fflag = 0; /* POSIX.2 requires this. */ } if (rflag) reverse(stdin, fn, style, off, &sb); else forward(stdin, fn, style, off, &sb); } exit(rval); }
void c_typecheck_baset::typecheck_code_type(code_typet &type) { code_typet::parameterst ¶meters=type.parameters(); // if we don't have any parameters, we assume it's (...) if(parameters.empty()) { type.make_ellipsis(); } else { // we do have parameters parameter_map.clear(); for(unsigned i=0; i<type.parameters().size(); i++) { code_typet::parametert ¶meter=type.parameters()[i]; // first fix type typet &type=parameter.type(); typecheck_type(type); adjust_function_parameter(type); // adjust the identifier irep_idt identifier=parameter.get_identifier(); if(identifier!=irep_idt()) { identifier=add_language_prefix(identifier); id_replace_mapt::const_iterator m_it=id_replace_map.find(identifier); if(m_it!=id_replace_map.end()) identifier=m_it->second; parameter.set_identifier(identifier); // make visible now, later parameters might use it parameter_map[identifier]=type; } } parameter_map.clear(); if(parameters.size()==1 && follow(parameters[0].type()).id()==ID_empty) { // if we just have one parameter of type void, remove it parameters.clear(); } } typecheck_type(type.return_type()); // 6.7.6.3: // "A function declarator shall not specify a return type that // is a function type or an array type." const typet &return_type=follow(type.return_type()); if(return_type.id()==ID_array) { err_location(type); throw "function must not return array"; } if(return_type.id()==ID_code) { err_location(type); throw "function must not return function type"; } }
void start_follow() { start_process(follow()); }
parser::SLR1::SLR1(const CFG& cfg) : Parser(cfg) { auto lr0 = parser::LR0(cfg); auto copy = cfg; copy << "<S'> ::= " + cfg[0].getName() + "'EOS'"; for (std::size_t i = 0; i < lr0.size(); i++) { LR0State& state = lr0[i]; // TRACE(i); // parser::printState(state, copy); for (LR0Item& item : state.items) { auto& symbol = copy[item.productionNumber][item.position]; const Production& prod = copy[item.productionNumber]; switch (item.action) { case Action::ACCEPT: if (table[i].count("EOS") > 0) { ECHO("[CONFLICT] ACCEPT"); conflict = true; } table[i]["EOS"] = AscendingAction{item.action, 0}; break; case Action::GOTO: case Action::SHIFT: if (table[i].count(symbol) > 0 && table[i][symbol].action != item.action) { ECHO("[CONFLICT] S " + std::to_string(i) + " " + symbol); conflict = true; } table[i][symbol] = AscendingAction{item.action, item.targetState}; break; case Action::REDUCE: { auto follow = copy.follow(prod.getName()); for (auto& s : follow) { if (table[i].count(s) > 0) { ECHO("[CONFLICT] R " + std::to_string(i) + " " + s); conflict = true; } table[i][s] = AscendingAction{item.action, item.productionNumber}; } break; } default: ECHO("????"); assert(false); } } } // for (auto& pair : table) { // TRACE(pair.first); // for (auto& p : pair.second) { // std::string content; // switch (p.second.action) { // case Action::ACCEPT: // content = "ACCEPT"; // break; // case Action::GOTO: // content = std::to_string(p.second.target); // break; // case Action::REDUCE: // content = "R" + std::to_string(p.second.target); // break; // case Action::SHIFT: // content = "S" + std::to_string(p.second.target); // break; // default: // ECHO("????"); // assert(false); // } // ECHO(p.first + " -> " + content); // } // } }
void AcceleratedParticle::moveAway(Vector2 point, int dt, float velocityFollow) { follow(point, dt, velocityFollow); velocity->x *= -1; velocity->y *= -1; }
void cpp_typecheckt::convert_non_template_declaration( cpp_declarationt &declaration) { assert(!declaration.is_template()); // we first check if this is a typedef typet &type=declaration.type(); bool is_typedef=convert_typedef(type); typecheck_type(type); // elaborate any class template instance _unless_ we do a typedef if(!is_typedef) elaborate_class_template(type); // special treatment for anonymous unions if(declaration.declarators().empty() && follow(declaration.type()).get_bool("#is_anonymous")) { typet final_type=follow(declaration.type()); if(final_type.id()!=ID_union) { err_location(final_type.location()); throw "top-level declaration does not declare anything"; } codet dummy; convert_anonymous_union(declaration, dummy); } // do the declarators (optional) Forall_cpp_declarators(it, declaration) { // copy the declarator (we destroy the original) cpp_declaratort declarator=*it; cpp_declarator_convertert cpp_declarator_converter(*this); cpp_declarator_converter.is_typedef=is_typedef; symbolt &symbol=cpp_declarator_converter.convert( type, declaration.storage_spec(), declaration.member_spec(), declarator); // any template instance to remember? if(declaration.find(ID_C_template).is_not_nil()) { symbol.type.set(ID_C_template, declaration.find(ID_C_template)); symbol.type.set(ID_C_template_arguments, declaration.find(ID_C_template_arguments)); } // replace declarator by symbol expression exprt tmp=cpp_symbol_expr(symbol); it->swap(tmp); // is there a constructor to be called for the declarator? if(symbol.lvalue && declarator.init_args().has_operands()) { symbol.value= cpp_constructor( symbol.location, cpp_symbol_expr(symbol), declarator.init_args().operands()); } }
void main(int argc, char *argv[]) { int c; char *name, *val; Binit(&bso, 1, OWRITE); listinit(); memset(debug, 0, sizeof(debug)); nerrors = 0; outfile = nil; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; nuxiinit(); ARGBEGIN { default: c = ARGC(); if(c == 'l') usage(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': /* output to (next arg) */ outfile = EARGF(usage()); break; case 'E': INITENTRY = EARGF(usage()); break; case 'H': HEADTYPE = headtype(EARGF(usage())); break; case 'I': debug['I'] = 1; // denote cmdline interpreter override interpreter = EARGF(usage()); break; case 'L': Lflag(EARGF(usage())); break; case 'T': INITTEXT = atolwhex(EARGF(usage())); break; case 'D': INITDAT = atolwhex(EARGF(usage())); break; case 'R': INITRND = atolwhex(EARGF(usage())); break; case 'r': rpath = EARGF(usage()); break; case 'V': print("%cl version %s\n", thechar, getgoversion()); errorexit(); case 'X': name = EARGF(usage()); val = EARGF(usage()); addstrdata(name, val); break; case 'B': val = EARGF(usage()); addbuildinfo(val); break; } ARGEND if(argc != 1) usage(); mywhatsys(); // get goos if(HEADTYPE == -1) HEADTYPE = headtype(goos); if(outfile == nil) { if(HEADTYPE == Hwindows) outfile = "6.out.exe"; else outfile = "6.out"; } libinit(); switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case Hplan9x32: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4096+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hplan9x64: /* plan 9 */ HEADR = 32L + 8L; if(INITTEXT == -1) INITTEXT = 0x200000+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 0x200000; break; case Helf: /* elf32 executable */ HEADR = rnd(52L+3*32L, 16); if(INITTEXT == -1) INITTEXT = 0x80110000L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hdarwin: /* apple MACH */ /* * OS X system constant - offset from 0(GS) to our TLS. * Explained in ../../pkg/runtime/cgo/gcc_darwin_amd64.c. */ tlsoffset = 0x8a0; machoinit(); HEADR = INITIAL_MACHO_HEADR; if(INITRND == -1) INITRND = 4096; if(INITTEXT == -1) INITTEXT = 4096+HEADR; if(INITDAT == -1) INITDAT = 0; break; case Hlinux: /* elf64 executable */ case Hfreebsd: /* freebsd */ case Hnetbsd: /* netbsd */ case Hopenbsd: /* openbsd */ /* * ELF uses TLS offset negative from FS. * Translate 0(FS) and 8(FS) into -16(FS) and -8(FS). * Also known to ../../pkg/runtime/sys_linux_amd64.s * and ../../pkg/runtime/cgo/gcc_linux_amd64.c. */ tlsoffset = -16; elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = (1<<22)+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hwindows: /* PE executable */ peinit(); HEADR = PEFILEHEADR; if(INITTEXT == -1) INITTEXT = PEBASE+PESECTHEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = PESECTALIGN; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%llux is ignored because of -R0x%ux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H%d -T0x%llux -D0x%llux -R0x%ux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); instinit(); zprg.link = P; zprg.pcond = P; zprg.back = 2; zprg.as = AGOK; zprg.from.type = D_NONE; zprg.from.index = D_NONE; zprg.from.scale = 1; zprg.to = zprg.from; zprg.mode = 64; pcstr = "%.6llux "; histgen = 0; pc = 0; dtype = 4; version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); addlibpath("command line", "command line", argv[0], "main"); loadlib(); deadcode(); patch(); follow(); doelf(); if(HEADTYPE == Hdarwin) domacho(); dostkoff(); dostkcheck(); paramspace = "SP"; /* (FP) now (SP) on output */ if(debug['p']) if(debug['1']) doprof1(); else doprof2(); span(); if(HEADTYPE == Hwindows) dope(); addexport(); textaddress(); pclntab(); symtab(); dodata(); address(); doweak(); reloc(); asmb(); undef(); if(debug['v']) { Bprint(&bso, "%5.2f cpu time\n", cputime()); Bprint(&bso, "%d symbols\n", nsymbol); Bprint(&bso, "%d sizeof adr\n", sizeof(Adr)); Bprint(&bso, "%d sizeof prog\n", sizeof(Prog)); } Bflush(&bso); errorexit(); }
exprt c_typecheck_baset::do_initializer_rec( const exprt &value, const typet &type, bool force_constant) { const typet &full_type=follow(type); if(full_type.id()==ID_incomplete_struct) { err_location(value); str << "type `" << to_string(full_type) << "' is still incomplete -- cannot initialize"; throw 0; } if(value.id()==ID_initializer_list) return do_initializer_list(value, full_type, force_constant); if(value.id()==ID_array && value.get_bool(ID_C_string_constant) && (full_type.id()==ID_array || full_type.id()==ID_incomplete_array) && (full_type.subtype().id()==ID_signedbv || full_type.subtype().id()==ID_unsignedbv) && full_type.subtype().get(ID_width)==value.type().subtype().get(ID_width)) { exprt tmp=value; // adjust char type tmp.type().subtype()=full_type.subtype(); Forall_operands(it, tmp) it->type()=full_type.subtype(); if(full_type.id()==ID_array) { // check size mp_integer array_size; if(to_integer(to_array_type(full_type).size(), array_size)) { err_location(value); throw "array size needs to be constant"; } if(array_size<0) { err_location(value); throw "array size must not be negative"; } if(mp_integer(tmp.operands().size())>array_size) { // cut off long strings. gcc does a warning for this tmp.operands().resize(integer2long(array_size)); tmp.type()=full_type; } else if(mp_integer(tmp.operands().size())<array_size) { // fill up tmp.type()=full_type; tmp.operands().resize(integer2long(array_size), gen_zero(full_type.subtype())); } } return tmp; } if(value.id()==ID_string_constant && (full_type.id()==ID_array || full_type.id()==ID_incomplete_array) && (full_type.subtype().id()==ID_signedbv || full_type.subtype().id()==ID_unsignedbv) && full_type.subtype().get(ID_width)==char_type().get(ID_width)) { // will go away, to be replaced by the above block string_constantt tmp1=to_string_constant(value); // adjust char type tmp1.type().subtype()=full_type.subtype(); exprt tmp2=tmp1.to_array_expr(); if(full_type.id()==ID_array) { // check size mp_integer array_size; if(to_integer(to_array_type(full_type).size(), array_size)) { err_location(value); throw "array size needs to be constant"; } if(array_size<0) { err_location(value); throw "array size must not be negative"; } if(mp_integer(tmp2.operands().size())>array_size) { // cut off long strings. gcc does a warning for this tmp2.operands().resize(integer2long(array_size)); tmp2.type()=full_type; } else if(mp_integer(tmp2.operands().size())<array_size) { // fill up tmp2.type()=full_type; tmp2.operands().resize(integer2long(array_size), gen_zero(full_type.subtype())); } } return tmp2; } if(full_type.id()==ID_incomplete_array) { err_location(value); str << "type `" << to_string(full_type) << "' cannot be initialized with `" << to_string(value) << "'"; throw 0; } if(value.id()==ID_designated_initializer) { err_location(value); str << "type `" << to_string(full_type) << "' cannot be initialized with designated initializer"; throw 0; } exprt result=value; implicit_typecast(result, type); return result; }
void main(int argc, char *argv[]) { int c; char *p, *name, *val; Binit(&bso, 1, OWRITE); listinit(); nerrors = 0; outfile = "5.out"; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; nuxiinit(); p = getenv("GOARM"); if(p != nil && strcmp(p, "5") == 0) debug['F'] = 1; ARGBEGIN { default: c = ARGC(); if(c == 'l') usage(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': outfile = EARGF(usage()); break; case 'E': INITENTRY = EARGF(usage()); break; case 'I': interpreter = EARGF(usage()); break; case 'L': Lflag(EARGF(usage())); break; case 'T': INITTEXT = atolwhex(EARGF(usage())); break; case 'D': INITDAT = atolwhex(EARGF(usage())); break; case 'R': INITRND = atolwhex(EARGF(usage())); break; case 'r': rpath = EARGF(usage()); break; case 'H': HEADTYPE = headtype(EARGF(usage())); /* do something about setting INITTEXT */ break; case 'V': print("%cl version %s\n", thechar, getgoversion()); errorexit(); case 'X': name = EARGF(usage()); val = EARGF(usage()); addstrdata(name, val); break; } ARGEND USED(argc); if(argc != 1) usage(); libinit(); if(HEADTYPE == -1) HEADTYPE = Hlinux; switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case Hnoheader: /* no header */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hrisc: /* aif for risc os */ HEADR = 128L; if(INITTEXT == -1) INITTEXT = 0x10005000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hplan9x32: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4128; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hnetbsd: /* boot for NetBSD */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 0xF0000020L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hixp1200: /* boot for IXP1200 */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0x0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hipaq: /* boot for ipaq */ HEADR = 16L; if(INITTEXT == -1) INITTEXT = 0xC0008010; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 1024; break; case Hlinux: /* arm elf */ debug['d'] = 1; // no dynamic linking elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = 0x10000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%ux is ignored because of -R0x%ux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%d -T0x%ux -D0x%ux -R0x%ux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); zprg.as = AGOK; zprg.scond = 14; zprg.reg = NREG; zprg.from.name = D_NONE; zprg.from.type = D_NONE; zprg.from.reg = NREG; zprg.to = zprg.from; buildop(); histgen = 0; pc = 0; dtype = 4; version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); addlibpath("command line", "command line", argv[0], "main"); loadlib(); // mark some functions that are only referenced after linker code editing if(debug['F']) mark(rlookup("_sfloat", 0)); deadcode(); if(textp == nil) { diag("no code"); errorexit(); } patch(); if(debug['p']) if(debug['1']) doprof1(); else doprof2(); doelf(); follow(); softfloat(); noops(); dostkcheck(); span(); pclntab(); symtab(); dodata(); address(); doweak(); reloc(); asmb(); undef(); if(debug['c']) print("ARM size = %d\n", armsize); if(debug['v']) { Bprint(&bso, "%5.2f cpu time\n", cputime()); Bprint(&bso, "%d sizeof adr\n", sizeof(Adr)); Bprint(&bso, "%d sizeof prog\n", sizeof(Prog)); } Bflush(&bso); errorexit(); }
void c_typecheck_baset::do_designated_initializer( exprt &result, designatort &designator, const exprt &value, bool force_constant) { assert(!designator.empty()); if(value.id()==ID_designated_initializer) { assert(value.operands().size()==1); designator= make_designator( designator.front().type, static_cast<const exprt &>(value.find(ID_designator))); assert(!designator.empty()); return do_designated_initializer( result, designator, value.op0(), force_constant); } exprt *dest=&result; // first phase: follow given designator for(unsigned i=0; i<designator.size(); i++) { unsigned index=designator[i].index; const typet &type=designator[i].type; assert(type.id()!=ID_symbol); if(type.id()==ID_array || type.id()==ID_struct || type.id()==ID_incomplete_array) { if(index>=dest->operands().size()) { if(type.id()==ID_incomplete_array) { exprt zero=zero_initializer(type.subtype(), value.location()); dest->operands().resize(integer2long(index)+1, zero); } else { err_location(value); str << "index designator " << index << " out of bounds (" << dest->operands().size() << ")"; throw 0; } } dest=&(dest->operands()[integer2long(index)]); } else if(type.id()==ID_union) { // union initialization is quite special const union_typet &union_type=to_union_type(type); const union_typet::componentt &component=union_type.components()[index]; // build a union expression from the argument exprt union_expr(ID_union, type); union_expr.operands().resize(1); union_expr.op0()=zero_initializer(component.type(), value.location()); union_expr.location()=value.location(); union_expr.set(ID_component_name, component.get_name()); *dest=union_expr; dest=&(dest->op0()); } else assert(false); } // second phase: assign value // for this, we may need to go down, adding to the designator while(true) { // see what type we have to initialize typet type=follow(designator.back().subtype); assert(type.id()!=ID_symbol); // do we initialize a scalar? if(type.id()!=ID_struct && type.id()!=ID_union && type.id()!=ID_array && type.id()!=ID_incomplete_array) { // The initializer for a scalar shall be a single expression, // * optionally enclosed in braces. * if(value.id()==ID_initializer_list && value.operands().size()==1) *dest=do_initializer_rec(value.op0(), type, force_constant); else *dest=do_initializer_rec(value, type, force_constant); assert(type==follow(dest->type())); return; // done } // see what initializer we are given if(value.id()==ID_initializer_list) { *dest=do_initializer_rec(value, type, force_constant); return; // done } else if(value.id()==ID_string_constant) { // We stop for initializers that are string-constants, // which are like arrays. We only do so if we are to // initialize an array of scalars. if((type.id()==ID_array || type.id()==ID_incomplete_array) && (follow(type.subtype()).id()==ID_signedbv || follow(type.subtype()).id()==ID_unsignedbv)) { *dest=do_initializer_rec(value, type, force_constant); return; // done } } else if(follow(value.type())==type) { // a struct/union can be initialized directly with // an expression of the right type. This doesn't // work with arrays, unfortunately. if(type.id()==ID_struct || type.id()==ID_union) { *dest=value; return; // done } } // we are initializing a compound type, and enter it! designator_enter(type, designator); assert(!dest->operands().empty()); dest=&(dest->op0()); // we run into another loop iteration } }
void HWChatWidget::onFollow() { QListWidgetItem * curritem = chatNicks->currentItem(); if (curritem) emit follow(curritem->text()); }