Esempio n. 1
0
struct node *parse_statements(struct compiler *compiler)
{
    skip_seps(compiler);

    if(is_expression(compiler))
    {
        struct node *result = parse_statement(compiler);

        if (is_sep(compiler))
        {
            skip_seps(compiler);

            if(is_expression(compiler))
            {
                struct node *node = alloc_node(compiler, N_STATEMENTS);

                node->left = result;
                node->right = parse_statements(compiler);

                return node;
            }
        }

        return result;

    }
    else
        return &nil_node;
}
// assert_decl             = "assert" "(" identifier "," expression ")".
bool adam_test_parser::is_assert_decl() {
    if (is_keyword(assert_k)) {
        require_token(open_parenthesis_k);
        name_t name;
        if (!is_identifier(name))
            throw_exception("sheet name expected");
        queryable_sheet_t& qs(sheet_from_name(name));
        require_token(comma_k);
        array_t expression;
        if (!is_expression(expression))
            throw_exception("expression expected");
        require_token(close_parenthesis_k);
        any_regular_t result = qs.inspect(expression);
        bool success = result.cast<bool>();
        out_m << "\n### assert " << (success ? std::string("succeeded: ") : std::string("failed: "))
#if defined(ADOBE_STD_SERIALIZATION)
              << begin_asl_cel << expression << end_asl_cel
#endif
              << " in sheet " << name << std::endl;
        if (!success)
            all_checks_passed_m = false;
        return true;
    }
    return false;
}
Esempio n. 3
0
/*
 * Loop over all principals matching exp.  If any of calls to `func'
 * failes, the first error is returned when all principals are
 * processed.
 */
int
foreach_principal(const char *exp_str,
		  int (*func)(krb5_principal, void*),
		  const char *funcname,
		  void *data)
{
    char **princs = NULL;
    int num_princs = 0;
    int i;
    krb5_error_code saved_ret = 0, ret = 0;
    krb5_principal princ_ent;
    int is_expr;

    /* if this isn't an expression, there is no point in wading
       through the whole database looking for matches */
    is_expr = is_expression(exp_str);
    if(is_expr)
	ret = kadm5_get_principals(kadm_handle, exp_str, &princs, &num_princs);
    if(!is_expr || ret == KADM5_AUTH_LIST) {
	/* we might be able to perform the requested opreration even
           if we're not allowed to list principals */
	num_princs = 1;
	princs = malloc(sizeof(*princs));
	if(princs == NULL)
	    return ENOMEM;
	princs[0] = strdup(exp_str);
	if(princs[0] == NULL){
	    free(princs);
	    return ENOMEM;
	}
    } else if(ret) {
	krb5_warn(context, ret, "kadm5_get_principals");
	return ret;
    }
    for(i = 0; i < num_princs; i++) {
	ret = krb5_parse_name(context, princs[i], &princ_ent);
	if(ret){
	    krb5_warn(context, ret, "krb5_parse_name(%s)", princs[i]);
	    continue;
	}
	ret = (*func)(princ_ent, data);
	if(ret) {
	    krb5_clear_error_message(context);
	    krb5_warn(context, ret, "%s %s", funcname, princs[i]);
	    if (saved_ret == 0)
		saved_ret = ret;
	}
	krb5_free_principal(context, princ_ent);
    }
    if (ret == 0 && saved_ret != 0)
	ret = saved_ret;
    kadm5_free_name_list(kadm_handle, princs, &num_princs);
    return ret;
}
//  argument_list = expression { "," expression }.
bool expression_parser::is_argument_list(array_t& expression_stack) {
    if (!is_expression(expression_stack))
        return false;

    std::size_t count = 1;

    while (is_token(comma_k)) {
        require_expression(expression_stack);
        ++count;
    }

    expression_stack.push_back(any_regular_t(double(count)));
    expression_stack.push_back(any_regular_t(array_k));

    return true;
}
Esempio n. 5
0
	void Parser::parse_return(StatementList *list)
	{
		ReturnNode *node = list->add<ReturnNode>(memory_pool);

		node->range.capture(lexer.lexeme);
		
		step();

		if(is_expression(lexeme()))
		{
			node->has_value = true;
			node->value = parse_expression();
			lexer.lexeme.prev_set(node->range);
		}
		else
			node->has_value = false;
	}
// print_decl              = "print" "(" identifier "," expression ")".
bool adam_test_parser::is_print_decl() {
    if (is_keyword(print_k)) {
        require_token(open_parenthesis_k);
        name_t name;
        if (!is_identifier(name))
            throw_exception("sheet name expected");
        queryable_sheet_t& qs(sheet_from_name(name));
        require_token(comma_k);
        array_t expression;
        if (!is_expression(expression))
            throw_exception("expression expected");
        require_token(close_parenthesis_k);
        any_regular_t result = qs.inspect(expression);
#if defined(ADOBE_STD_SERIALIZATION)
        out_m << begin_asl_cel << expression << end_asl_cel << std::endl;
#endif
        return true;
    }
    return false;
}
Esempio n. 7
0
bool binspector_parser_t::is_enum_list_item()
{
    adobe::array_t expression;

    if (!is_expression(expression))
        return false;

    static std::size_t          uid_s(0);
    static const adobe::array_t empty_array_k;

    std::string lambda_identifier;

    // REVISIT (fbrereto) : String concatenation here.
    lambda_identifier += std::string("<")
                      + current_struct_m.c_str()
                      + ":enumerate_list_option_"
                      + boost::lexical_cast<std::string>(++uid_s)
                      + ">";

    adobe::name_t       identifier(lambda_identifier.c_str());
    adobe::dictionary_t parameters;

    parameters[key_enumerated_option_expression].assign(expression);
    parameters[key_field_name].assign(identifier);
    parameters[key_field_size_expression].assign(empty_array_k);
    parameters[key_field_offset_expression].assign(empty_array_k);
    parameters[key_field_type].assign(value_field_type_enumerated_option);
    parameters[key_named_type_name].assign(identifier);

    insert_parser_metadata(parameters);
    add_field_proc_m(identifier, parameters);

    // This call adds an empty structure to the structure map. Remember the list
    // is intended to be syntactic sugar, so this kind of "hack" is OK.
    temp_assign_and_call<adobe::name_t> tmp(current_struct_m,
                                            identifier,
                                            set_structure_proc_m);

    return true;
}
Esempio n. 8
0
bool binspector_parser_t::is_enum_map_item()
{
    adobe::array_t expression;

    if (!is_expression(expression))
        return false;

    require_token(adobe::colon_k);

    static std::size_t          uid_s(0);
    static const adobe::array_t empty_array_k;

    std::string lambda_identifier;

    // REVISIT (fbrereto) : String concatenation here.
    lambda_identifier += std::string("<")
                      + current_struct_m.c_str()
                      + ":enumerate_map_option_"
                      + boost::lexical_cast<std::string>(++uid_s)
                      + ">";

    adobe::name_t       identifier(lambda_identifier.c_str());
    adobe::dictionary_t parameters;

    parameters[key_enumerated_option_expression].assign(expression);
    parameters[key_field_name].assign(identifier);
    parameters[key_field_size_expression].assign(empty_array_k);
    parameters[key_field_offset_expression].assign(empty_array_k);
    parameters[key_field_type].assign(value_field_type_enumerated_option);
    parameters[key_named_type_name].assign(identifier);

    insert_parser_metadata(parameters);
    add_field_proc_m(identifier, parameters);

    require_scope_content(identifier);

    return true;
}
Esempio n. 9
0
bool
fs_visitor::opt_cse_local(bblock_t *block, exec_list *aeb)
{
   bool progress = false;

   void *mem_ctx = ralloc_context(this->mem_ctx);

   for (fs_inst *inst = (fs_inst *)block->start;
	inst != block->end->next;
	inst = (fs_inst *) inst->next) {

      /* Skip some cases. */
      if (is_expression(inst) && !inst->predicate && inst->mlen == 0 &&
          !inst->force_uncompressed && !inst->force_sechalf &&
          !inst->conditional_mod)
      {
	 bool found = false;

	 aeb_entry *entry;
	 foreach_list(entry_node, aeb) {
	    entry = (aeb_entry *) entry_node;

	    /* Match current instruction's expression against those in AEB. */
	    if (inst->opcode == entry->generator->opcode &&
		inst->saturate == entry->generator->saturate &&
		operands_match(entry->generator->src, inst->src)) {

	       found = true;
	       progress = true;
	       break;
	    }
	 }

	 if (!found) {
	    /* Our first sighting of this expression.  Create an entry. */
	    aeb_entry *entry = ralloc(mem_ctx, aeb_entry);
	    entry->tmp = reg_undef;
	    entry->generator = inst;
	    aeb->push_tail(entry);
	 } else {
	    /* This is at least our second sighting of this expression.
	     * If we don't have a temporary already, make one.
	     */
	    bool no_existing_temp = entry->tmp.file == BAD_FILE;
	    if (no_existing_temp) {
	       entry->tmp = fs_reg(this, glsl_type::float_type);
	       entry->tmp.type = inst->dst.type;

	       fs_inst *copy = new(ralloc_parent(inst))
		  fs_inst(BRW_OPCODE_MOV, entry->generator->dst, entry->tmp);
	       entry->generator->insert_after(copy);
	       entry->generator->dst = entry->tmp;
	    }

	    /* dest <- temp */
	    fs_inst *copy = new(ralloc_parent(inst))
	       fs_inst(BRW_OPCODE_MOV, inst->dst, entry->tmp);
	    inst->replace_with(copy);

	    /* Appending an instruction may have changed our bblock end. */
	    if (inst == block->end) {
	       block->end = copy;
	    }

	    /* Continue iteration with copy->next */
	    inst = copy;
	 }
      }
Esempio n. 10
0
bool
fs_visitor::opt_cse_local(bblock_t *block, exec_list *aeb)
{
   bool progress = false;

   void *cse_ctx = ralloc_context(NULL);

   int ip = block->start_ip;
   for (fs_inst *inst = (fs_inst *)block->start;
        inst != block->end->next;
        inst = (fs_inst *) inst->next) {

      /* Skip some cases. */
      if (is_expression(inst) && !inst->is_partial_write() &&
          (inst->dst.file != HW_REG || inst->dst.is_null()))
      {
         bool found = false;

         aeb_entry *entry;
         foreach_list(entry_node, aeb) {
            entry = (aeb_entry *) entry_node;

            /* Match current instruction's expression against those in AEB. */
            if (instructions_match(inst, entry->generator)) {
               found = true;
               progress = true;
               break;
            }
         }

         if (!found) {
            /* Our first sighting of this expression.  Create an entry. */
            aeb_entry *entry = ralloc(cse_ctx, aeb_entry);
            entry->tmp = reg_undef;
            entry->generator = inst;
            aeb->push_tail(entry);
         } else {
            /* This is at least our second sighting of this expression.
             * If we don't have a temporary already, make one.
             */
            bool no_existing_temp = entry->tmp.file == BAD_FILE;
            if (no_existing_temp && !entry->generator->dst.is_null()) {
               int written = entry->generator->regs_written;

               fs_reg orig_dst = entry->generator->dst;
               fs_reg tmp = fs_reg(GRF, virtual_grf_alloc(written),
                                   orig_dst.type);
               entry->tmp = tmp;
               entry->generator->dst = tmp;

               fs_inst *copy;
               if (written > 1) {
                  fs_reg *sources = ralloc_array(mem_ctx, fs_reg, written);
                  for (int i = 0; i < written; i++) {
                     sources[i] = tmp;
                     sources[i].reg_offset = i;
                  }
                  copy = LOAD_PAYLOAD(orig_dst, sources, written);
               } else {
                  copy = MOV(orig_dst, tmp);
                  copy->force_writemask_all =
                     entry->generator->force_writemask_all;
               }
               entry->generator->insert_after(copy);
            }

            /* dest <- temp */
            if (!inst->dst.is_null()) {
               int written = inst->regs_written;
               assert(written == entry->generator->regs_written);
               assert(inst->dst.type == entry->tmp.type);
               fs_reg dst = inst->dst;
               fs_reg tmp = entry->tmp;
               fs_inst *copy;
               if (written > 1) {
                  fs_reg *sources = ralloc_array(mem_ctx, fs_reg, written);
                  for (int i = 0; i < written; i++) {
                     sources[i] = tmp;
                     sources[i].reg_offset = i;
                  }
                  copy = LOAD_PAYLOAD(dst, sources, written);
               } else {
                  copy = MOV(dst, tmp);
                  copy->force_writemask_all = inst->force_writemask_all;
               }
               inst->insert_before(copy);
            }

            /* Set our iterator so that next time through the loop inst->next
             * will get the instruction in the basic block after the one we've
             * removed.
             */
            fs_inst *prev = (fs_inst *)inst->prev;

            inst->remove();

            /* Appending an instruction may have changed our bblock end. */
            if (inst == block->end) {
               block->end = prev;
            }

            inst = prev;
         }
      }
void expression_parser::require_expression(array_t& expression_stack) {
    if (!is_expression(expression_stack)) {
        throw_exception("Expression required.");
    }
}
Esempio n. 12
0
bool
fs_visitor::opt_cse_local(bblock_t *block, exec_list *aeb)
{
   bool progress = false;

   void *mem_ctx = ralloc_context(this->mem_ctx);

   int ip = block->start_ip;
   for (fs_inst *inst = (fs_inst *)block->start;
	inst != block->end->next;
	inst = (fs_inst *) inst->next) {

      /* Skip some cases. */
      if (is_expression(inst) &&
          !inst->predicate &&
          !inst->is_partial_write() &&
          !inst->conditional_mod)
      {
	 bool found = false;

	 aeb_entry *entry;
	 foreach_list(entry_node, aeb) {
	    entry = (aeb_entry *) entry_node;

	    /* Match current instruction's expression against those in AEB. */
	    if (inst->opcode == entry->generator->opcode &&
		inst->saturate == entry->generator->saturate &&
                inst->dst.type == entry->generator->dst.type &&
                operands_match(entry->generator->src, inst->src)) {

	       found = true;
	       progress = true;
	       break;
	    }
	 }

	 if (!found) {
	    /* Our first sighting of this expression.  Create an entry. */
	    aeb_entry *entry = ralloc(mem_ctx, aeb_entry);
	    entry->tmp = reg_undef;
	    entry->generator = inst;
	    aeb->push_tail(entry);
	 } else {
	    /* This is at least our second sighting of this expression.
	     * If we don't have a temporary already, make one.
	     */
	    bool no_existing_temp = entry->tmp.file == BAD_FILE;
	    if (no_existing_temp) {
               int written = entry->generator->regs_written;

               fs_reg orig_dst = entry->generator->dst;
               fs_reg tmp = fs_reg(GRF, virtual_grf_alloc(written),
                                   orig_dst.type);
               entry->tmp = tmp;
               entry->generator->dst = tmp;

               for (int i = 0; i < written; i++) {
                  fs_inst *copy = MOV(orig_dst, tmp);
                  copy->force_writemask_all =
                     entry->generator->force_writemask_all;
                  entry->generator->insert_after(copy);

                  orig_dst.reg_offset++;
                  tmp.reg_offset++;
               }
	    }

	    /* dest <- temp */
            int written = inst->regs_written;
            assert(written == entry->generator->regs_written);
            assert(inst->dst.type == entry->tmp.type);
            fs_reg dst = inst->dst;
            fs_reg tmp = entry->tmp;
            fs_inst *copy = NULL;
            for (int i = 0; i < written; i++) {
               copy = MOV(dst, tmp);
               copy->force_writemask_all = inst->force_writemask_all;
               inst->insert_before(copy);

               dst.reg_offset++;
               tmp.reg_offset++;
            }
            inst->remove();

	    /* Appending an instruction may have changed our bblock end. */
	    if (inst == block->end) {
	       block->end = copy;
	    }

	    /* Continue iteration with copy->next */
	    inst = copy;
	 }
      }
Esempio n. 13
0
	bool Parser::parse_statement(StatementList *list)	
	{
		lexer.identify_keywords();
		
		switch(lexeme())
		{
			case Lexeme::KW_IF:
				parse_if(list);
				break;
				
			case Lexeme::KW_WHILE:
				parse_while(list);
				break;
				
			case Lexeme::KW_DO:
				parse_do(list);
				parse_terminator();
				break;

			case Lexeme::KW_RETURN:
				parse_return(list);
				parse_terminator();
				break;
			
			case Lexeme::KW_BREAK:
				parse_break(list);
				parse_terminator();
				break;
			
			case Lexeme::KW_CONTINUE:
				parse_continue(list);
				parse_terminator();
				break;
			
			case Lexeme::KW_CONST:
				step();
				parse_local(true, parse_expression(), list);
				parse_terminator();
				break;
			
			case Lexeme::BRACET_OPEN:
				list->append(parse_block<true, false>(Scope::EMPTY));
				break;
			
			case Lexeme::SEMICOLON:
				step();
				break;
			
			case Lexeme::END:
			case Lexeme::BRACET_CLOSE:
				return false;
	
			default:
				if(is_expression(lexeme()))
				{
					ExpressionNode *node = parse_expression();

					if(lexeme() == Lexeme::IDENT && node->is_type_name(document, false))
						parse_local(false, node, list);
					else
						list->append(node);

					parse_terminator();
				}
				else
					return false;
		}
		
		return true;
	}