Ejemplo n.º 1
0
/*
 * fieldset_copy
 *
 * Copy-constructor for field sets.  In the copy,
 * the nameref's must point to the entries in the
 * newly-constructed scope.
 */
static int
fieldset_copy (void *vctx, name_t *dst, void *dp,
            name_t *src, void *sp)
{
    namereflist_t *drefs = dp;
    namereflist_t *srefs = sp;
    expr_ctx_t ctx = vctx;
    scopectx_t dscope = name_scope(dst);
    namectx_t namectx = expr_namectx(ctx);
    nameref_t *ref;
    name_t *np;

    for (ref = namereflist_head(srefs); ref != 0; ref = ref->tq_next) {
        if (ref->np == 0) {
            // XXX should never happen
            continue;
        }
        strdesc_t *str = name_string(ref->np);
        np = name_search(dscope, str->ptr, str->len, 0);
        namereflist_instail(drefs, nameref_alloc(namectx, np));
    }

    return 1;

} /* fieldset_copy */
Ejemplo n.º 2
0
/*
 * prepare_body
 *
 * Builds a lexeme sequence with the expansion of the body of
 * a macro.
 */
static int
prepare_body (macroctx_t mctx, expansion_t *curexp, lexseq_t *result)
{
    expr_ctx_t ctx = mctx->ectx;
    parse_ctx_t pctx = expr_parse_ctx(ctx);
    lexctx_t lctx = parser_lexmemctx(pctx);
    struct macrodecl_s *macro = name_extraspace(curexp->curmacro);
    lexeme_t *lex;
    name_t *np;
    static strdesc_t mend = STRDEF("<macro-end>");

    // Prepare the grouper and separator lexemes, in case
    // they are needed (only applicable to iterative macros)
    if (curexp->count == 0 && macro->type == MACRO_ITER) {
        curexp->sep = parser_punct_separator(pctx);
        lex = parser_punct_grouper(pctx, 0);
        if (lex != 0) {
            lexseq_instail(result, lex);
        }
        curexp->closer = parser_punct_grouper(pctx, 1);
    }

    // Associate the iterative-formals with any actuals
    if (macro->type == MACRO_ITER) {
        nameref_t *iformal;
        lextype_t lt, terms[1] = { LEXTYPE_DELIM_COMMA };

        for (iformal = namereflist_head(&macro->ilist); iformal != 0;
             iformal = iformal->tq_next) {
            strdesc_t *namestr = name_string(iformal->np);
            np = macparam_special(curexp->expscope, namestr, 0);
            parse_lexeme_seq(pctx, &curexp->remaining, QL_MACRO, terms, 1,
                             macparam_lexseq(np), &lt);
        }
    }

    // Expand the macro parameters here, instead of relying on the parser
    // to do this while processing the expansion.  If we were to wait, we'd
    // have to push a new scope on the parser's stack and remove it when we're
    // done -- but the expansion could declare other names, and those would
    // get declared in the scope we're removing.
    for (lex = lexseq_head(&macro->body); lex != 0; lex = lexeme_next(lex)) {
        if (curexp->expscope != 0 && lexeme_boundtype(lex) == LEXTYPE_NAME) {
            lexseq_t seq;
            lexseq_init(&seq);
            if (macparam_lookup(lctx, curexp->expscope, lexeme_text(lex), &seq) != 0) {
                lexseq_append(result, &seq);
            } else {
                lexseq_instail(result, lexeme_copy(lctx, lex));
            }
        } else {
            lexseq_instail(result, lexeme_copy(lctx, lex));
        }
    }
    lexseq_instail(result, lexeme_create(lctx, LEXTYPE_MACROEND, &mend));
    curexp->count += 1;

    return 1;

} /* prepare_body */
Ejemplo n.º 3
0
/*
 * macro_copydata
 *
 * Copy-constructor for macros.
 */
static int
macro_copydata (void *vctx, name_t *dst, void *dp, name_t *src, void *sp)
{
    struct macrodecl_s *srcm = sp;
    struct macrodecl_s *dstm = dp;
    nameref_t *ref;
    expr_ctx_t ctx = vctx;
    namectx_t namectx = expr_namectx(ctx);
    lexctx_t lctx = expr_lexmemctx(ctx);

    lexseq_init(&dstm->body);
    lexseq_copy(lctx, &dstm->body, &srcm->body);
    dstm->ptable = scope_copy(srcm->ptable, 0);
    namereflist_init(&dstm->plist);
    namereflist_init(&dstm->ilist);
    dstm->type = srcm->type;
    // We can't just copy the namereflists over verbatim; the copied
    // list has to reference the names in the copied name table, not
    // the original.
    for (ref = namereflist_head(&srcm->plist); ref != 0; ref = ref->tq_next) {
        name_t *np;
        if (ref->np == 0) {
            np = 0;
        } else {
            strdesc_t *namestr = name_string(ref->np);
            np = name_search(dstm->ptable, namestr->ptr, namestr->len, 0);
        }
        namereflist_instail(&dstm->plist, nameref_alloc(namectx, np));
    }
    for (ref = namereflist_head(&srcm->ilist); ref != 0; ref = ref->tq_next) {
        name_t *np;
        if (ref->np == 0) {
            np = 0;
        } else {
            strdesc_t *namestr = name_string(ref->np);
            np = name_search(dstm->ptable, namestr->ptr, namestr->len, 0);
        }
        namereflist_instail(&dstm->ilist, nameref_alloc(namectx, np));
    }

    return 1;

} /* macro_copydata */
Ejemplo n.º 4
0
	void const_copy_to(const char *name, void *host, size_t size)
	{
		RPCSend snd(socket, "const_copy_to");

		string name_string(name);

		snd.add(name_string);
		snd.add(size);
		snd.write();
		snd.write_buffer(host, size);
	}
Ejemplo n.º 5
0
/*
 * structure_copy
 *
 * Copy-constructor for a structure cell.  Handles
 * the fact that name references must point to the
 * newly-constructed scope tables, rather than the
 * originals.
 */
static int
structure_copy (void *vctx, name_t *dst, void *dp,
                name_t *src, void *sp)
{
    expr_ctx_t ctx = vctx;
    lexctx_t lctx = expr_lexmemctx(ctx);
    strudef_t *dstru = dp;
    strudef_t *sstru = sp;
    namectx_t namectx = expr_namectx(ctx);
    nameref_t *ref;
    name_t *np;

    dstru->acctbl = scope_copy(sstru->acctbl, 0);
    dstru->allotbl = scope_copy(sstru->allotbl, 0);
    for (ref = namereflist_head(&sstru->accformals); ref != 0;
         ref = ref->tq_next) {
        if (ref->np == 0) {
            np = 0;
        } else {
            strdesc_t *str = name_string(ref->np);
            np = name_search(dstru->acctbl, str->ptr, str->len, 0);
        }
        namereflist_instail(&dstru->accformals, nameref_alloc(namectx, np));
    }
    for (ref = namereflist_head(&sstru->alloformals); ref != 0;
         ref = ref->tq_next) {
        if (ref->np == 0) {
            np = 0;
        } else {
            strdesc_t *str = name_string(ref->np);
            np = name_search(dstru->allotbl, str->ptr, str->len, 0);
        }
        namereflist_instail(&dstru->alloformals, nameref_alloc(namectx, np));
    }
    lexseq_copy(lctx, &dstru->accbody, &sstru->accbody);
    lexseq_copy(lctx, &dstru->allobody, &sstru->allobody);

    return 1;

} /* structure_copy */
Ejemplo n.º 6
0
	void const_copy_to(const char *name, void *host, size_t size)
	{
		thread_scoped_lock lock(rpc_lock);

		RPCSend snd(socket, &error_func, "const_copy_to");

		string name_string(name);

		snd.add(name_string);
		snd.add(size);
		snd.write();
		snd.write_buffer(host, size);
	}
Ejemplo n.º 7
0
/*
 * handle_exits
 */
int
handle_exits (parse_ctx_t pctx, void *vctx, quotelevel_t ql, lextype_t curlt)
{
    macroctx_t ctx = vctx;
    expansion_t *cur = ctx->curexp;
    struct macrodecl_s *macro;
    lexeme_t *lex;

    if (ctx->curexp == 0) {
        expr_signal(ctx->ectx, STC__INTCMPERR, "handle_exits[1]");
        return 1;
    }

    if (ctx->state != EXP_NORMAL) {
        return 1;
    }

    macro = name_extraspace(cur->curmacro);

    switch (curlt) {
        case LEXTYPE_LXF_EXITITER:
            if (macro->type != MACRO_ITER) {
                expr_signal(ctx->ectx, STC__INVEXITER, name_string(cur->curmacro));
                ctx->state = EXP_EXITMACRO;
            }
            parser_skipmode_set(pctx, 1);
            ctx->state = EXP_EXITITER;
            break;
        case LEXTYPE_LXF_EXITMACRO:
            parser_skipmode_set(pctx, 1);
            ctx->state = EXP_EXITMACRO;
            break;
        case LEXTYPE_LXF_ERRORMACRO:
            lex = parse_string_params(pctx, 0);
            if (lex == 0) {
                expr_signal(ctx->ectx, STC__SYNTAXERR);
            } else {
                expr_signal(ctx->ectx, STC__USRERR, lexeme_text(lex));
                lexeme_free(expr_lexmemctx(ctx->ectx), lex);
            }
            parser_skipmode_set(pctx, 1);
            ctx->state = EXP_ERRORMACRO;
            break;
        default:
            expr_signal(ctx->ectx, STC__INTCMPERR, "handle_exits[2]");
            break;
    }

    return 1;

} /* handle_exits */
Ejemplo n.º 8
0
void AbstractHdf5Access::SetUnlimitedDatasetId()
{
    // Now deal with the unlimited dimension

    // In terms of an Unlimited dimension dataset:
    // * Files pre - r16738 (inc. Release 3.1 and earlier) use simply "Time" for "Data"'s unlimited variable.
    // * Files generated by r16738 - r18257 used "<DatasetName>_Time" for "<DatasetName>"'s unlimited variable,
    //   - These are not to be used and there is no backwards compatibility for them, since they weren't in a release.
    // * Files post r18257 (inc. Release 3.2 onwards) use "<DatasetName>_Unlimited" for "<DatasetName>"'s
    //   unlimited variable,
    //   - a new attribute "Name" has been added to the Unlimited Dataset to allow it to assign
    //     any name to the unlimited variable. Which can then be easily read by Hdf5DataReader.
    //   - if this dataset is missing we look for simply "Time" to remain backwards compatible with Releases <= 3.1

    if (DoesDatasetExist(mDatasetName + "_Unlimited"))
    {
        mUnlimitedDatasetId = H5Dopen(mFileId, (mDatasetName + "_Unlimited").c_str());
        hid_t name_attribute_id = H5Aopen_name(mUnlimitedDatasetId, "Name");
        hid_t unit_attribute_id = H5Aopen_name(mUnlimitedDatasetId, "Unit");

        hid_t attribute_type  = H5Aget_type(name_attribute_id);

        // Read into it.
        char* string_array = (char *)malloc(sizeof(char)*MAX_STRING_SIZE);
        H5Aread( name_attribute_id, attribute_type, string_array);
        std::string name_string(&string_array[0]);
        mUnlimitedDimensionName = name_string;

        H5Aread( unit_attribute_id, attribute_type, string_array);
        std::string unit_string(&string_array[0]);
        mUnlimitedDimensionUnit = unit_string;

        free(string_array);
        H5Tclose(attribute_type);
        H5Aclose(name_attribute_id);
        H5Aclose(unit_attribute_id);
    }
    else if (DoesDatasetExist("Time"))
    {
        mUnlimitedDimensionName = "Time";
        mUnlimitedDimensionUnit = "msec";
        mUnlimitedDatasetId = H5Dopen(mFileId, mUnlimitedDimensionName.c_str());
    }
    else
    {
        NEVER_REACHED;
    }
    mIsUnlimitedDimensionSet = true;
}
Ejemplo n.º 9
0
	void tex_alloc(const char *name, device_memory& mem, bool interpolation, bool periodic)
	{
		mem.device_pointer = ++mem_counter;

		RPCSend snd(socket, "tex_alloc");

		string name_string(name);

		snd.add(name_string);
		snd.add(mem);
		snd.add(interpolation);
		snd.add(periodic);
		snd.write();
		snd.write_buffer((void*)mem.data_pointer, mem.memory_size());
	}
Ejemplo n.º 10
0
void debug_view_memory::enumerate_sources()
{
	// start with an empty list
	m_source_list.reset();
	std::string name;

	// first add all the devices' address spaces
	for (device_memory_interface &memintf : memory_interface_iterator(machine().root_device()))
		for (int spacenum = 0; spacenum < memintf.max_space_count(); ++spacenum)
			if (memintf.has_space(spacenum))
			{
				address_space &space = memintf.space(spacenum);
				name = string_format("%s '%s' %s space memory", memintf.device().name(), memintf.device().tag(), space.name());
				m_source_list.append(*global_alloc(debug_view_memory_source(name.c_str(), space)));
			}

	// then add all the memory regions
	for (auto &region : machine().memory().regions())
	{
		name = string_format("Region '%s'", region.second->name());
		m_source_list.append(*global_alloc(debug_view_memory_source(name.c_str(), *region.second.get())));
	}

	// finally add all global array symbols in alphabetical order
	std::vector<std::tuple<std::string, void *, u32, u32> > itemnames;
	itemnames.reserve(machine().save().registration_count());

	for (int itemnum = 0; itemnum < machine().save().registration_count(); itemnum++)
	{
		u32 valsize, valcount;
		void *base;
		std::string name_string(machine().save().indexed_item(itemnum, base, valsize, valcount));

		// add pretty much anything that's not a timer (we may wish to cull other items later)
		// also, don't trim the front of the name, it's important to know which VIA6522 we're looking at, e.g.
		if (strncmp(name_string.c_str(), "timer/", 6))
			itemnames.emplace_back(std::move(name_string), base, valsize, valcount);
	}

	std::sort(itemnames.begin(), itemnames.end(), [] (auto const &x, auto const &y) { return std::get<0>(x) < std::get<0>(y); });

	for (auto const &item : itemnames)
		m_source_list.append(*global_alloc(debug_view_memory_source(std::get<0>(item).c_str(), std::get<1>(item), std::get<2>(item), std::get<3>(item))));

	// reset the source to a known good entry
	set_source(*m_source_list.first());
}
Ejemplo n.º 11
0
	void tex_alloc(const char *name, device_memory& mem, InterpolationType interpolation, bool periodic)
	{
		thread_scoped_lock lock(rpc_lock);

		mem.device_pointer = ++mem_counter;

		RPCSend snd(socket, &error_func, "tex_alloc");

		string name_string(name);

		snd.add(name_string);
		snd.add(mem);
		snd.add(interpolation);
		snd.add(periodic);
		snd.write();
		snd.write_buffer((void*)mem.data_pointer, mem.memory_size());
	}
Ejemplo n.º 12
0
static void ReportException(Environment* env, v8::Handle<v8::Value> er, v8::Handle<v8::Message> message)
{
    v8::HandleScope scope(env->isolate());

    AppendExceptionLine(env, er, message);

    v8::Local<v8::Value> trace_value;

    if (er->IsUndefined() || er->IsNull())
        trace_value = Undefined(env->isolate());
    else
        trace_value = er->ToObject()->Get(env->stack_string());

    v8::String::Utf8Value trace(trace_value);

    // range errors have a trace member set to undefined
    if (trace.length() > 0 && !trace_value->IsUndefined()) {
        fprintf(stderr, "%s\n", *trace);
    } else {
        // this really only happens for RangeErrors, since they're the only
        // kind that won't have all this info in the trace, or when non-Error
        // objects are thrown manually.
        v8::Local<v8::Value> message;
        v8::Local<v8::Value> name;

        if (er->IsObject()) {
            v8::Local<v8::Object> err_obj = er.As<v8::Object>();
            message = err_obj->Get(env->message_string());
            name = err_obj->Get(FIXED_UTF8_STRING(env->isolate(), "name"));
        }

        if (message.IsEmpty() || message->IsUndefined() || name.IsEmpty() || name->IsUndefined()) {
            // Not an error object. Just print as-is.
            v8::String::Utf8Value message(er);
            fprintf(stderr, "%s\n", *message);
        } else {
            v8::String::Utf8Value name_string(name);
            v8::String::Utf8Value message_string(message);
            fprintf(stderr, "%s: %s\n", *name_string, *message_string);
        }
    }

    fflush(stderr);
}
Ejemplo n.º 13
0
int wpl_text::output_as_json_var(wpl_state *state, wpl_value *final_result) {
	wpl_value_string name_string(get_name());

	wpl_io &io = state->get_io();

	io << "\"";
	name_string.output_json(io);
	io << "\": \"";

	wpl_io_buffer buf;
	wpl_output_json json_io;

	run(state, final_result, buf);

	json_io.output_json(io, buf.c_str(), buf.size());

	io << "\",\n";
	return WPL_OP_OK;
}
Ejemplo n.º 14
0
	void tex_alloc(const char *name,
	               device_memory& mem,
	               InterpolationType interpolation,
	               ExtensionType extension)
	{
		VLOG(1) << "Texture allocate: " << name << ", " << mem.memory_size() << " bytes.";

		thread_scoped_lock lock(rpc_lock);

		mem.device_pointer = ++mem_counter;

		RPCSend snd(socket, &error_func, "tex_alloc");

		string name_string(name);

		snd.add(name_string);
		snd.add(mem);
		snd.add(interpolation);
		snd.add(extension);
		snd.write();
		snd.write_buffer((void*)mem.data_pointer, mem.memory_size());
	}
Ejemplo n.º 15
0
/*
 * structure_reference
 *
 * Expands a structure reference, for both the general case
 * and the ordinary case.
 *
 * General structure reference
 * structure-name [ expression {,access-actual...} {; alloc-actual...} ]
 *
 * Ordinary structure reference
 * segment-name [ access-actual... ]
 *
 */
expr_node_t *
structure_reference (expr_ctx_t ctx, name_t *struname, int ctce_accessors,
                     name_t *symname, lexeme_t *curlex)
{
    parse_ctx_t pctx = expr_parse_ctx(ctx);
    lexctx_t lctx = expr_lexmemctx(ctx);
    lextype_t delim;
    lexseq_t seq;
    scopectx_t myscope, fldscope;
    nameref_t *ref;
    expr_node_t *exp, *resexp;
    textpos_t pos = parser_curpos(pctx);
    strudef_t *stru = name_extraspace(struname);
    static lextype_t delims[3] = { LEXTYPE_DELIM_RBRACK, LEXTYPE_DELIM_COMMA,
        LEXTYPE_DELIM_SEMI };
    int ndelims;

    fldscope = 0;
    lexseq_init(&seq);
    // If this is a general structure reference, get the
    // address expression
    if (symname == 0) {

        // It might be more correct to use expr_parse_expr() here to get
        // the address expression, rather than deferring that to the
        // expansion step later, but just handling it lexically was
        // simpler to implement. XXX
        ndelims = 3;
        if (!parse_lexeme_seq(pctx, 0, QL_NORMAL, delims, 3, &seq, &delim)) {
            return 0;
        }
        myscope = scope_copy(stru->acctbl, 0);
    } else {
        // Here we have an ordinary structure reference, and can use
        // the symbol name for the base address.
        data_attr_t *attr = datasym_attr(symname);
        if (attr == 0) {
            expr_signal(ctx, STC__INTCMPERR, "structure_reference[1]");
            return 0;
        }
        lexseq_instail(&seq,lexeme_copy(lctx, curlex));
        // Semicolons (and allocation-formals) not allowed in this case
        ndelims = 2;
        delim = LEXTYPE_DELIM_COMMA;
        myscope = ((attr->struscope == 0)
                   ? scope_begin(expr_namectx(ctx), 0)
                   : scope_copy(attr->struscope, 0));
        // Bring in the field names, so they can be used in the
        // the structure expression
        if (namereflist_length(&attr->fields) > 0) {
            fldscope = scope_begin(scope_namectx(myscope), 0);
            for (ref = namereflist_head(&attr->fields); ref != 0;
                 ref = ref->tq_next) {
                if (ref->np != 0) {
                    strdesc_t *fname = name_string(ref->np);
                    macparam_special(fldscope, fname, field_lexseq(ref->np));
                }
            }
        }
    }
    // In the expansion, the name of the structure represents the
    // base address, so define that as a macro parameter.
    macparam_special(myscope, name_string(struname), &seq);
    lexseq_free(lctx, &seq);

    // Now parse the access-actuals, bringing the field names into scope.
    if (fldscope != 0) {
        parser_scope_push(pctx, fldscope);
    }
    for (ref = namereflist_head(&stru->accformals); ref != 0; ref = ref->tq_next) {
        if (ref->np != 0) {
            strdesc_t *pname = name_string(ref->np);
            lexseq_init(&seq);
            if (delim == LEXTYPE_DELIM_COMMA) {
                if (!parse_lexeme_seq(pctx, 0, QL_NORMAL, delims, ndelims,
                                      &seq, &delim)) {
                    expr_signal(ctx, STC__SYNTAXERR);
                    break;
                }
                if (ctce_accessors) {
                    lexseq_t testseq;
                    lexseq_init(&testseq);
                    lexseq_copy(lctx, &testseq, &seq);
                    if (!expr_parse_seq(ctx, &testseq, &exp) ||
                        expr_type(exp) != EXPTYPE_PRIM_LIT) {
                        expr_signal(ctx, STC__EXPCTCE);
                    } else {
                        expr_node_free(ctx, exp);
                    }
                    lexseq_free(lctx, &testseq);
                }
            }
            if (lexseq_length(&seq) == 0) {
                macparam_lookup(lctx, stru->acctbl, pname, &seq);
            }
            // Parenthesize the parameter value if it's non-null, because we're
            // doing lexical substitution and this could be used in an expression
            // that is expecting it to be a single operand.
            if (lexseq_length(&seq) > 0) {
                lexseq_inshead(&seq, lexeme_create(lctx, LEXTYPE_DELIM_LPAR, &leftparen));
                lexseq_instail(&seq, lexeme_create(lctx, LEXTYPE_DELIM_RPAR, &rightparen));
            }
            macparam_special(myscope, pname, &seq);
            lexseq_free(lctx, &seq);
        }
    }
    if (fldscope != 0) {
        parser_scope_end(pctx);
    }

    // Allocation-actuals are only used in the general-reference case
    if (symname == 0) {
        for (ref = namereflist_head(&stru->alloformals); ref != 0;
             ref = ref->tq_next) {
            if (ref->np != 0) {
                strdesc_t *pname = name_string(ref->np);
                lexseq_init(&seq);
                if (delim != LEXTYPE_DELIM_RBRACK) {
                    if (!parse_lexeme_seq(pctx, 0, QL_NORMAL, delims, 3,
                                          &seq, &delim)) {
                        break;
                    }
                }
                if (lexseq_length(&seq) == 0) {
                    macparam_lookup(lctx, stru->allotbl, pname, &seq);
                }
                // Parenthesize the parameter value if it's non-null, because we're
                // doing lexical substitution and this could be used in an expression
                // that is expecting it to be a single operand.
                if (lexseq_length(&seq) > 0) {
                    lexseq_inshead(&seq, lexeme_create(lctx, LEXTYPE_DELIM_LPAR, &leftparen));
                    lexseq_instail(&seq, lexeme_create(lctx, LEXTYPE_DELIM_RPAR, &rightparen));
                }
                macparam_special(myscope, pname, &seq);
            }
        }
    }
    if (delim != LEXTYPE_DELIM_RBRACK) {
        expr_signal(ctx, STC__DELIMEXP, "]");
        parser_skip_to_delim(pctx, LEXTYPE_DELIM_RBRACK);
    }

    // At this point, we have built the complete sequence
    // of lexemes to convert into the structure reference
    // expression.
    lexseq_init(&seq);
    lexseq_copy(lctx, &seq, &stru->accbody);
    parser_scope_push(pctx, myscope);
    if (!expr_parse_seq(ctx, &seq, &exp) || exp == 0) {
        expr_signal(ctx, STC__SYNTAXERR);
        lexseq_free(lctx, &seq);
        parser_scope_end(pctx);
        return 0;
    }

    parser_scope_end(pctx);

    // Since STRUREF auto-parenthesizes the expression, we can
    // simplify a resultant block expression if it only contains
    // one expression and has no declarations, labels, or codecomments.
    exp = expr_block_simplify(ctx, exp);
    if (exp == 0) {
        expr_signal(ctx, STC__INTCMPERR, "structure_reference[2]");
        return 0;
    }
    resexp = expr_node_alloc(ctx, EXPTYPE_PRIM_STRUREF, pos);
    expr_struref_accexpr_set(resexp, exp);
    expr_struref_referer_set(resexp, symname);
    expr_is_ctce_set(resexp, expr_is_ctce(exp));
    expr_is_ltce_set(resexp, expr_is_ltce_only(exp));
    expr_has_value_set(resexp, 1); // XXX *must* have value, right?
    return resexp;

} /* structure_reference */
Ejemplo n.º 16
0
/*
 * structure_allocate
 *
 * Expands a structure allocation.
 */
int
structure_allocate (expr_ctx_t ctx, name_t *struname,
                    strudef_t **strup, unsigned int *nunits,
                    scopectx_t *scopep, int is_ref)
{
    parse_ctx_t pctx = expr_parse_ctx(ctx);
    strudef_t *stru = name_extraspace(struname);
    machinedef_t *mach = expr_machinedef(ctx);
    lexctx_t lctx = expr_lexmemctx(ctx);
    lexseq_t tmpseq;
    scopectx_t myscope, retscope;
    nameref_t *ref;
    int nomoreactuals;
    int nobrackets = 0;
    int allowed_aus = 0;
    static lextype_t aus[4] = { LEXTYPE_AU_BYTE, LEXTYPE_AU_WORD,
        LEXTYPE_AU_LONG, LEXTYPE_AU_QUAD };
    static lextype_t su[2] = { LEXTYPE_ATTR_UNSIGNED, LEXTYPE_ATTR_SIGNED };

    if (!parser_expect(pctx, QL_NORMAL, LEXTYPE_DELIM_LBRACK, 0, 1)) {
        nobrackets = 1;
    }

    // Set up for matching the allocation-unit names to byte counts,
    // but only on byte-addressable machines
    if (machine_unit_bits(mach) == 8) {
        for (allowed_aus = 0; allowed_aus < 4 &&
             machine_scalar_units(mach) >= (1<<allowed_aus); allowed_aus++);
    }

    myscope = parser_scope_begin(pctx);
    if (scopep != 0) {
        retscope = scope_begin(scope_namectx(myscope), 0);
    }

    // Now fill in the default values for the allocation formals, if they
    // have defaults set.
    for (ref = namereflist_head(&stru->alloformals); ref != 0; ref = ref->tq_next) {
        if (ref->np != 0) {
            strdesc_t *alloname = name_string(ref->np);
            lexseq_t seq;
            expr_node_t *exp;
            lexseq_init(&seq);
            lexseq_copy(lctx, &seq, macparam_lexseq(ref->np));
            if (lexseq_length(&seq) > 0 && expr_parse_seq(ctx, &seq, &exp)) {
                if (expr_type(exp) == EXPTYPE_PRIM_LIT)
                    litsym_special(myscope, alloname,
                                   (unsigned int) expr_litval(exp));
                expr_node_free(ctx, exp);
            }
        }
    }
    // Now parse the allocation actuals, if any have been specified.
    // For an omitted actuals, fill in the default values, or zeros
    // where there are no explicit defaults.
    nomoreactuals = nobrackets;
    for (ref = namereflist_head(&stru->alloformals); ref != 0; ref = ref->tq_next) {
        if (ref->np != 0) {
            name_t *np, *rnp;
            strdesc_t *alloname = name_string(ref->np);
            unsigned long val;
            int i = -1;
            np = 0;
            // An actual could be one of the allocation-unit keywords
            // or SIGNED/UNSIGNED, on certain machines, so check for
            // those as well as for a normal compile-time constant
            // expresion.
            if (!nomoreactuals) {
                if (allowed_aus > 0) {
                    i = parser_expect_oneof(pctx, QL_NORMAL, aus,
                                            allowed_aus, 0, 1);
                    if (i >= 0) {
                        val = 1L << i;
                    }
                }
                if ((i < 0) && machine_signext_supported(mach)) {
                    i = parser_expect_oneof(pctx, QL_NORMAL, su, 2, 0, 1);
                    if (i >= 0) {
                        val = i;
                    }
                }
                if ((i < 0) && expr_parse_ctce(ctx, 0, (long *)&val)) {
                    np = litsym_special(myscope, alloname, val);
                    i = 0;
                }
            }
            if (i < 0) {
                np = litsym_search(myscope, alloname, &val);
                if (np == 0) {
                    val = 0;
                }
            }
            if (np == 0) {
                np = litsym_special(myscope, alloname, val);
                if (np == 0) {
                    expr_signal(ctx, STC__INTCMPERR, "structure_allocate[4]");
                }
            }
            // Now copy the declaration into the scope we'll pass back
            // to the caller for later use
            if (scopep != 0) {
                rnp = litsym_special(retscope, alloname, val);
                if (rnp == 0) {
                    expr_signal(ctx, STC__INTCMPERR, "structure_allocate[5]");
                }
            }
        }
        if (!nomoreactuals &&
            !parser_expect(pctx, QL_NORMAL, LEXTYPE_DELIM_COMMA, 0, 1)) {
            nomoreactuals = 1;
        }
    } /* loop through all of the allocation parameters */

    if (!nobrackets &&
        !parser_expect(pctx, QL_NORMAL, LEXTYPE_DELIM_RBRACK, 0, 1)) {
        expr_signal(ctx, STC__DELIMEXP, "]");
    }

    // A structure definition may not actually have an
    // allocation part, but may only be used for accessing
    // storage allocated in some other way.
    if (lexseq_length(&stru->allobody) == 0) {
        *nunits = 0;
    } else {
        long val;
        lexseq_init(&tmpseq);
        lexseq_copy(lctx, &tmpseq, &stru->allobody);
        parser_insert_seq(pctx, &tmpseq);
        if (!expr_parse_ctce(ctx, 0, &val)) {
            expr_signal(ctx, STC__EXPCTCE);
            return 0;
        }
        *nunits = (unsigned int) val;
    }
    if (scopep != 0) *scopep = retscope;
    parser_scope_end(pctx);
    if (strup != 0) *strup = stru;

    return 1;

} /* structure_allocate */
Ejemplo n.º 17
0
void ModelObject::read_obj(const char * filename)
{
    int vert_id = 1;
    std::string temp;
    std::string obj_line;
    std::ifstream obj_file (filename);

    if (obj_file.is_open()) {
        while (getline(obj_file, obj_line)) {
            if (obj_line[0] == 'v') {
                std::istringstream vert_string (obj_line);
                coord * new_coord = new coord;

                new_coord->id = vert_id;

                for (int i = 0; i < 4; i++) {
                    if (getline(vert_string, temp, ' ')) {
                        if (i == 1) {
                            new_coord->x = (float)atof(temp.c_str());
                        }
                        else if (i == 2) {
                            new_coord->y = (float)atof(temp.c_str());
                        }
                        else if (i == 3) {
                            new_coord->z = (float)atof(temp.c_str());
                        }
                    }
                }

                object->vertices.push_back(new_coord);
                object->vert_count++;
                vert_id++;
            }
            else if (obj_line[0] == 'f') {
                object->face_count++;

                std::istringstream face_string (obj_line);
                face * new_face = new face;
                int coord_id;

                getline(face_string, temp, ' ');

                while (getline(face_string, temp, ' '))
                {
                    coord_id = (int)atoi(temp.c_str());

                    new_face->coords.push_back(object->vertices[coord_id - 1]);
                }

                object->faces.push_back(new_face);

            }
            else if (obj_line[0] == 'o' && object->obj_name == 0) {
                std::string name_string (obj_line);

                if (name_string.length() > 2) {
                    object->obj_name = new char[name_string.length() - 1];
                    
                    for (int i = 2; i < name_string.length(); i++)
                        object->obj_name[i - 2] = name_string[i];
                }
            }
        }
        obj_file.close();

        process_object();
    }
}
Ejemplo n.º 18
0
/*
 * macro_expand
 *
 * Expands a macro.
 */
static int
macro_expand (macroctx_t mctx, name_t *macroname, lexseq_t *result)
{
    struct macrodecl_s *macro = name_extraspace(macroname);
    expr_ctx_t ctx = mctx->ectx;
    parse_ctx_t pctx = expr_parse_ctx(ctx);
    lexctx_t lctx = parser_lexmemctx(pctx);
    expansion_t *curexp = expansion_alloc(mctx);
    expansion_t *prev_exp;
    lextype_t lt;
    lexeme_t *lex;
    lexseq_t extras;
    name_t *np;
    scopectx_t expscope;
    int which;
    int nactuals;
    punctclass_t pcl;
    lextype_t psep;
    lextype_t terms[3];
    static strdesc_t comma = STRDEF(",");

    if (macro == 0 || curexp == 0) {
        expr_signal(ctx, STC__INTCMPERR, "macro_expand");
        return 1;
    }
    memset(curexp, 0, sizeof(struct expansion_s));

    // We save the punctuation class here, since it will get
    // munged by the parsing of the macro parameters.
    parser_punctclass_get(pctx, &pcl, &psep);

    prev_exp = 0;
    if (macro->type == MACRO_COND) {
        for (prev_exp = mctx->curexp; prev_exp != 0 && prev_exp->curmacro != macroname;
             prev_exp = prev_exp->next);
    }

    nactuals = 0;
    lexseq_init(&extras);

    // Simple macros with no formal arguments get no processing
    // of parameter lists whatsoever.
    if (macro->type == MACRO_SIMPLE && namereflist_length(&macro->plist) == 0) {
        expscope = 0;
        which = 3;
    } else {
        // For keyword macros, prime the scope with the declared
        // formals, so we can inherit the default values.
        if (macro->type == MACRO_KWD) {
            expscope = scope_copy(macro->ptable, 0);
        } else {
            expscope = scope_begin(scope_namectx(parser_scope_get(pctx)), 0);
        }

        lt = parser_next(pctx, QL_NORMAL, &lex);
        if (macro->type == MACRO_KWD) {
            if (lt != LEXTYPE_DELIM_LPAR) {
                expr_signal(ctx, STC__DELIMEXP, "(");
                parser_insert(pctx, lex);
                return 1;
            }
            which = 0;
            lexeme_free(lctx, lex);
        } else {
            for (which = 0; lt != openers[which] && which < 3; which++);
            if (which >= 3 && namereflist_length(&macro->plist) > 0) {
                expr_signal(ctx, STC__DELIMEXP, "(");
                parser_insert(pctx, lex);
                return 1;
            }
            if (which >= 3) {
                parser_insert(pctx, lex);
            } else {
                lexeme_free(lctx, lex);
            }
        }
    }

    // If we had a match on an opener, process
    // the actual parameters.
    if (which < 3) {

        nameref_t *formal;
        lexseq_t val;

        terms[0] = LEXTYPE_DELIM_COMMA;
        terms[1] = closers[which];

        formal = namereflist_head(&macro->plist);

        while (1) {
            // Keyword macro actuals are of the form name=value
            // For positionals, grab the next formal-parameter name,
            // or set np to NULL to add the actual to %REMAINING.
            if (macro->type == MACRO_KWD) {
                lt = parser_next(pctx, QL_NAME, &lex);
                if (lexeme_boundtype(lex) != LEXTYPE_NAME) {
                    expr_signal(ctx, STC__NAMEEXP);
                    lexeme_free(lctx, lex);
                    break;
                }
                np = name_search(macro->ptable, lex->text.ptr, lex->text.len, 0);
                if (np == 0) {
                    expr_signal(ctx, STC__INTCMPERR, "macro_expand[2]");
                }
                lexeme_free(lctx, lex);
                if (!parser_expect(pctx, QL_NORMAL, LEXTYPE_OP_ASSIGN, 0, 1)) {
                    expr_signal(ctx, STC__OPEREXP, "=");
                    break;
                }
            } else if (nactuals < namereflist_length(&macro->plist)) {
                np = formal->np;
                formal = formal->tq_next;
            } else {
                np = 0;
            }
            lexseq_init(&val);
            // Now parse the actual-parameter, which can be an expression
            if (!parse_lexeme_seq(pctx, 0, QL_NAME, terms, 2, &val, &lt)) {
                lexseq_free(lctx, &val);
                break;
            }

            // If we are recursively expanding a conditional macro and
            // there are no parameters, we're done - no expansion.
            if (prev_exp != 0 && lexseq_length(&val) == 0 && nactuals == 0) {
                scope_end(expscope);
                free(curexp);
                return 1;
            }

            if (np == 0) {
                if (lexseq_length(&extras) > 0) {
                    lexseq_instail(&extras,
                                   lexeme_create(lctx, LEXTYPE_DELIM_COMMA, &comma));
                }
                lexseq_append(&extras, &val);
            } else {
                name_t *actual;
                // Associate the actual with the formal.  For keyword
                // macros, the scope_copy() above sets a special "no check"
                // flag that allows each name to be redeclared once.
                // name_declare() clears this flag, so we can catch genuine
                // redeclarations.
                actual = macparam_special(expscope, name_string(np), &val);
                if (actual == 0) {
                    expr_signal(ctx, STC__INTCMPERR, "macro_expand[3]");
                }
                lexseq_free(lctx, &val);
            }

            nactuals += 1;

            if (lt == closers[which]) {
                break;
            }

            if (lt != LEXTYPE_DELIM_COMMA) {
                expr_signal(ctx, STC__DELIMEXP, ",");
                break;
            }

        } /* while (1) */

        if (lt != closers[which]) {
            expr_signal(ctx, STC__DELIMEXP, "closer");
            lexseq_free(lctx, &extras);
            scope_end(expscope);
            return 1;
        }

        if (nactuals < namereflist_length(&macro->plist)) {
            name_t *anp;
            while (formal != 0) {
                anp = macparam_special(expscope, name_string(formal->np), 0);
                if (anp == 0) {
                    expr_signal(ctx, STC__INTCMPERR, "macro_expand[4]");
                }
                formal = formal->tq_next;
            }
        }

    } /* if which < 3 */

    // The macro actual parameters are now processed; hook
    // the scope into the current hierarchy, restore the punctuation
    // class to what it was before we parsed the actuals, and
    // generate the expansion sequence.

    parser_punctclass_set(pctx, pcl, psep);

    curexp->count = (prev_exp == 0 ? 0 : prev_exp->count);
    curexp->expscope = expscope;
    curexp->curmacro = macroname;
    curexp->next = mctx->curexp;
    curexp->nactuals = nactuals;
    lexseq_append(&curexp->remaining, &extras);
    mctx->curexp = curexp;

    return prepare_body(mctx, curexp, result);

} /* macro_expand */