Example #1
0
std::size_t size_of(const Type& type,
                    const std::unique_ptr<TypeParser>& parser) {
  return type.match<std::size_t>(
    [&](const VoidType*) -> std::size_t { always_assert(false); },
    [&](const FuncType*) -> std::size_t { always_assert(false); },
    [&](const MemberType*) -> std::size_t { always_assert(false); },

    [&](const PtrType*) { return sizeof(void*); },
    [&](const RefType*) { return sizeof(void*); },
    [&](const RValueRefType*) { return sizeof(void*); },

    [&](const ConstType* t) { return size_of(t->modified, parser); },
    [&](const VolatileType* t) { return size_of(t->modified, parser); },
    [&](const RestrictType* t) { return size_of(t->modified, parser); },

    [&](const ArrType* t) {
      return t->count ? *t->count * size_of(t->element, parser) : 0;
    },
    [&](const ObjectType* t) {
      always_assert(!t->incomplete);
      auto const obj = parser->getObject(t->key);
      return obj.size;
    }
  );
}
Example #2
0
 inline bool check_consistent_sizes(const char* function,
                                    const T1& x1, 
                                    const T2& x2, 
                                    const char* name1,
                                    const char* name2,
                                    T_result* result,
                                    const Policy&) {
   size_t max_size = std::max(size_of(x1),
                              size_of(x2));
   return check_consistent_size(max_size,function,x1,name1,result,Policy())
     && check_consistent_size(max_size,function,x2,name2,result,Policy());
 }
Example #3
0
File: rnalib.c Project: u-u-h/adpc
int il_energy(int i, int j, int k, int l)
{
  int sl, sr;
  sl = size_of(i,j);
  sr = size_of(k,l);
  if ((sl > 2) || (sr > 2)) 
    return((il_ent (sl + sr))
         + (il_stack (i,j,k,l))
         + (il_asym(sl,sr))); else
  if ((sl == 1) && (sr == 1)) return(il11_energy(i,l+1)); else  
  if ((sl == 1) && (sr == 2)) return(il12_energy(i,l+1)); else  
  if ((sl == 2) && (sr == 1)) return(il21_energy(i,l+1)); else  
  if ((sl == 2) && (sr == 2)) return(il22_energy(i,l+1)); else
  return 65000;
}
Example #4
0
int pop(Queue *queue, int *val) {
    if (NULL == queue) {
        fprintf(stderr,
                "Failed to free the Queue, illegal access to a NULL pointer\n");
        return -1;
    }

    if (is_empty(queue)) {
        printf("Failed to pop value from the Queue, the Queue is empty now\n");
        return -1;
    }

    // write the next element to val
    *val = queue->front->val;

    // remove the front element from the Queue
    Queue_Node *tmp_node = queue->front;

    if (1 == size_of(queue)) {
        queue->front = NULL;
        queue->back = NULL;
    } else {
        queue->front = queue->front->prev;
        queue->front->next = NULL;
    }

    (queue->size)--;

    free(tmp_node);

    return 0;
}
Example #5
0
	void insert(string& str, int i, int vi) {
		if (i == size_of(str)) {
			node[vi].end = true;
			return;
		}
		
		int ci = alph.toInt(str[i]);
		
		if (node[vi].link[ci] != -1) {
			insert(str, i + 1, node[vi].link[ci]);
		} else {
			node.push_back(Node(alph.N));
			node[vi].link[ci] = size_of(node) - 1;
			insert(str, i + 1, node[vi].link[ci]);
		}
	}
Example #6
0
 void *pinned(const size_t elements, const af::dtype type)
 {
     void *ptr;
     AF_THROW(af_alloc_pinned(&ptr, elements * size_of(type)));
     // FIXME: Add to map
     return ptr;
 }
Example #7
0
/* Parse array declarations of the form [s0][s1]..[sn], resulting in type
 * [s0] [s1] .. [sn] (base).
 *
 * Only the first dimension s0 can be unspecified, yielding an incomplete type.
 * Incomplete types are represented by having size of zero.
 */
static struct typetree *direct_declarator_array(struct typetree *base)
{
    if (peek().token == '[') {
        long length = 0;

        consume('[');
        if (peek().token != ']') {
            struct var expr = constant_expression();
            assert(expr.kind == IMMEDIATE);
            if (!is_integer(expr.type) || expr.imm.i < 1) {
                error("Array dimension must be a natural number.");
                exit(1);
            }
            length = expr.imm.i;
        }
        consume(']');

        base = direct_declarator_array(base);
        if (!size_of(base)) {
            error("Array has incomplete element type.");
            exit(1);
        }

        base = type_init(T_ARRAY, base, length);
    }

    return base;
}
Example #8
0
int
gx_begin_transparency_mask(gs_imager_state * pis, gx_device * pdev,
				const gs_pdf14trans_params_t * pparams)
{
    gx_transparency_mask_params_t tmp;
    const int l = sizeof(pparams->Background[0]) * pparams->Background_components;

    tmp.subtype = pparams->subtype;
    tmp.Background_components = pparams->Background_components;
    memcpy(tmp.Background, pparams->Background, l);
    tmp.GrayBackground = pparams->GrayBackground;
    tmp.function_is_identity = pparams->function_is_identity;
    tmp.idle = pparams->idle;
    tmp.replacing = pparams->replacing;
    tmp.mask_id = pparams->mask_id;
    memcpy(tmp.transfer_fn, pparams->transfer_fn, size_of(tmp.transfer_fn));
    if_debug8('v', "[v](0x%lx)gx_begin_transparency_mask [%g %g %g %g]\n\
      subtype = %d  Background_components = %d  %s\n",
	      (ulong)pis, pparams->bbox.p.x, pparams->bbox.p.y,
	      pparams->bbox.q.x, pparams->bbox.q.y,
	      (int)tmp.subtype, tmp.Background_components,
	      (tmp.function_is_identity ? "no TR" :
	       "has TR"));
    if (dev_proc(pdev, begin_transparency_mask) != 0)
	return (*dev_proc(pdev, begin_transparency_mask))
	    		(pdev, &tmp, &(pparams->bbox), pis, NULL, NULL);
    else
	return 0;
}
Example #9
0
 void *array::pinned(size_t elements, af_dtype type)
 {
     void *ptr;
     AF_THROW(af_alloc_pinned(&ptr, elements * size_of(type)));
     // FIXME: Add to map
     return ptr;
 }
Example #10
0
/*******************************Get Map Routine*************************************/
char* getMapReduceRoutine(char* pathFile) {
	int mapper;
	char* mapeo;
	int size;

	/* Get size of File */
	int size_of(int fd) {
		struct stat buf;
		fstat(fd, &buf);
		return buf.st_size;
	}

	mapper = open(pathFile, O_RDONLY);
	size = size_of(mapper);
	if ((mapeo = mmap( NULL, size, PROT_READ, MAP_SHARED, mapper, 0))
			== MAP_FAILED) {
		//Si no se pudo ejecutar el MMAP, imprimir el error y abortar;
		fprintf(stderr,
				"Error al ejecutar MMAP del archivo '%s' de tamaƱo: %d: %s\nfile_size",
				pathFile, size, strerror(errno));
		abort();
	}
	//Se unmapea , y se cierrra el archivo
	//munmap( mapeo, size );
	close(mapper);
	return mapeo;
}
Example #11
0
	bool find(string& str, int i, int vi) {
		if (i == size_of(str)) return node[vi].end;
		
		int ci = alph.toInt(str[i]);
		
		if (node[vi].link[ci] != -1) return find(str, i + 1, node[vi].link[ci]);
		return false;
	}
    //////////////////////////////////////////////////////////////////////////////////////////
    //! Path::getModulePath
    //! Get absolute path of the executing module
    //!
    //! \return Path - New instance containing absolute path of the executing module
    //!
    //! \throw wtl::platform_error - Unable to query module path
    //////////////////////////////////////////////////////////////////////////////////////////
    static Path  getModulePath()
    {
      typename base::array_t tmp;     //!< Path storage

      // Get absolute module path
      if (!WinAPI<encoding>::getModuleFileName(nullptr, tmp, size_of(tmp)))
        throw wtl::platform_error(HERE, "Unable to query module path");

      // Return path
      return tmp;
    }
Example #13
0
int in_M(double complex z){
	double complex c = z;
	int count = 0;
	while(size_of(z) <= 2){
		if(count > 200){
			return 1;
		}
		z = map(z, c);
		++count;
	}
	return 0;
}
Example #14
0
File: rnalib.c Project: u-u-h/adpc
int br_energy(int bl, int i, int j, int br){
  int stacking, size, entropy;

  if (bl < 1)
    return UNDEF;

  stacking    = stack_dg[inp(bl)][inp(bl+1)][inp(i)][inp(br)];
  size        = size_of(i,j);
  entropy     = bl_ent(size);

  if (size==1) return(stacking + entropy - termaupenalty_ar[inp(bl+1)][inp(br-2)]);
  if (size>1)  return(entropy + termaupenalty_ar[inp(bl)][inp(br)]);
}
Example #15
0
bool ascp_path(const char **cmd, const char **key) {
    static int idx = 0;

    static const char *c[] = {
        "C:\\Program Files (x86)\\Aspera\\Aspera Connect\\bin\\ascp.exe",
        "C:\\Program Files (x86)\\Aspera\\Aspera Connect\\bin\\ascp.exe",

              "C:\\Program Files\\Aspera\\Aspera Connect\\bin\\ascp.exe",
              "C:\\Program Files\\Aspera\\Aspera Connect\\bin\\ascp.exe",
    };

    static const char *k[] = {
"C:\\Program Files (x86)\\Aspera\\Aspera Connect\\etc\\asperaweb_id_dsa.openssh"
                                                                               ,
"C:\\Program Files (x86)\\Aspera\\Aspera Connect\\etc\\asperaweb_id_dsa.putty",

      "C:\\Program Files\\Aspera\\Aspera Connect\\etc\\asperaweb_id_dsa.openssh"
                                                                               ,
      "C:\\Program Files\\Aspera\\Aspera Connect\\etc\\asperaweb_id_dsa.putty",
    };

    int size = size_of(c);

    assert(cmd != NULL && key != NULL);
    assert(size_of(c) == size_of(k));

    if (idx < size) {
        *cmd = c[idx];
        *key = k[idx];
        ++idx;
        return true;
    }
    else {
        *cmd =  *key = NULL;
        idx = 0;
        return false;
    }
}
Example #16
0
File: rnalib.c Project: u-u-h/adpc
int bl_energy(int bl, int i, int j, int br){
  int stacking, size, entropy;

  if (br < 2 || bl < 1)
    return UNDEF;

  stacking    = stack_dg[inp(bl)][inp(j+1)][inp(br-1)][inp(br)];
  size        = size_of(i,j);
  entropy     = bl_ent(size);

  if     (size==1)  return(stacking + entropy - termaupenalty_ar[inp(bl+2)][inp(br-1)]);
  else if (size>1)  return(entropy + termaupenalty_ar[inp(bl)][inp(br)]);
  else {printf("bl_energy size < 1\n"); exit(-1);}
}
Example #17
0
PCB_p search(Priority_queue_p pq) {
	if(pq != NULL && size_of(pq) != 0) {
		int i = pq->topPriority;
	        if(i > 15 || i < 0) return NULL;
		FIFO_queue_p tempList = pq->Queue_List[i];

		struct node* temp = dequeue(tempList);
		if(temp == NULL) return NULL;
		pq->topPriority = checkTopPriority(pq);
		return temp->data;
	} else {
            return NULL;
	}
}
Example #18
0
void symbol_table::new_func_params(const vector<func_arg>& args)
{
    // add parameter as variable
    int offset = 0;
    for (auto arg : args)
    {
        symbol_entry arg_ent;
        new_variable(arg.name, arg.type, arg_ent);
        arg_ent->second.place("ebp");
        arg_ent->second.offset(offset);
        arg_ent->second.is_parameter(true);
        offset += size_of(arg.type);
    }
}
Example #19
0
void consumer(struct buffer *b)
  /*@ requires [_]b->m |-> ?m &*&
               [_]b->v |-> ?v &*& 
               [_]mutex(m) &*& 
               inv(m) == buffer(b) &*& 
               [_]b->gid |-> ?gid &*&
               obs(?O) &*&
               tic(gid) &*&
               no_cycle(v,O) == true &*&
               no_cycle(m,O) == true; @*/
  /*@ ensures  [_]b->m |-> m &*&
               [_]b->v |-> v &*& 
               [_]mutex(m) &*& 
               obs(O); @*/
{
  //@ close mutex_inv(m,buffer(b));
  mutex_acquire(b->m);
  //@ open buffer(b)(?Wt1,?Ot1);
  //@ leak [_]b->v |-> v;
  
  while (size_of(b->q)==0)
  /*@ invariant [_]b->m |-> m &*& 
                [_]b->v |-> v &*& 
                b->q |-> ?q &*& 
                [_]b->gid |-> gid &*& 
                queue(q,?s) &*& 
                s>=0 &*& 
                mutex_held(m, _, ?Wt, ?Ot) &*& 
                ctr(gid,?Ct) &*&
                Wt(v) + Ct <= Ot(v) + s &*&
                Wt(v) <= Ot(v) &*&
                obs(cons(m,O)) &*&
                tic(gid); @*/
  {
    //@ dec_ctr(gid);
    //@ close buffer(b)(finc(Wt,v),Ot);
    //@ close mutex_inv(m,buffer(b));
    //@ close condvar_trn(v,vtrn(gid));
    condvar_wait(b->v, b->m);
    //@ open buffer(b)(_,_);
    //@ open vtrn(gid)();
  }
  dequeue(b->q);
  //@ dec_ctr(gid);
  //@ close buffer(b)(Wt, Ot);
  //@ close mutex_inv(m,buffer(b));
  mutex_release(b->m);
  //@ leak [_]mutex(m);
}
Example #20
0
String get_line(){
    char c;
    int saida;
    String string = new_string();
    string = copy_string("");
    saida = scanf(" %c", &c);
    while (c != '\n') {
        if ((saida == EOF) && (size_of(string) > 0))
            return copy_string("exit"); 
        if (saida != 0)
            append(&string, c);
        saida = scanf("%c", &c); 
    }
    append(&string, '\0');
    return string; 
}
Example #21
0
void generate_entry(const Object& object, std::ostream& o,
                    const std::unique_ptr<TypeParser>& parser) {
  o << folly::format(
    "  {{\n"
    "    \"{}\",\n"
    "    [](const void* base, const void* internal) -> const char* {{\n"
    "      auto const diff = reinterpret_cast<const char*>(internal) -\n"
    "                        reinterpret_cast<const char*>(base);\n"
    "      (void)diff;\n",
    object.name.name
  );

  auto const gen_range_check = [&] (const Object::Member& member,
                                    std::size_t base_off) {
    if (!member.offset) return; // static

    auto const off = base_off + *member.offset;
    auto const size = size_of(member.type, parser);

    auto const name = member.name.empty()
      ? folly::format("union@{}", off).str()
      : member.name;

    o << "      " << folly::format(
      "if ({} <= diff && diff < {}) return \"{}\";\n",
      off, off + size, name
    );
  };

  for (auto const& base : object.bases) {
    if (!base.offset) continue;
    auto const base_object = parser->getObject(base.type.key);

    for (auto const& member : base_object.members) {
      gen_range_check(member, *base.offset);
    }
  }

  for (auto const& member : object.members) {
    gen_range_check(member, 0);
  }

  o << "      return nullptr;\n"
    << "    }\n"
    << "  }";
}
Example #22
0
String parse_proc_name(String name){
    int i;
    int size = size_of(name);
    int found = -1;
    String buffer = new_string();
    for(i = 0; i < size; i++){
        append(&buffer, name[i]);
        if(name[i] == '/'){
            found = i;
            dispose_string(&buffer);
            buffer = new_string();
        }
    }
    if(found == -1)
        return name;
    return buffer;
}
Example #23
0
//Quebra uma String e cria um StringList, separando os comandos, do parser
StringList explode(String string, char separator){
    StringList list = new_string_list();
    int i;
    int size = size_of(string);
    String buffer = new_string();
    // loop in string
    for(i = 0; i <= size; i++){
        if(string[i] != separator && i < size)
            append(&buffer, string[i]);
        else{
            list_append(&list, buffer);
            dispose_string(&buffer);
            buffer = new_string();
        }
    }
    dispose_string(&buffer);
    return list;
}
	FLOW dfs(int v, int t, FLOW f) {
		if (v == t) return f;
		
		int edge_nums = size_of(edges[v]);
		for (int& i = iter[v]; i < edge_nums; ++i) {
			Edge& e = edges[v][i];
			
			if (e.cost > 0 && level[v] < level[e.to]) {
				FLOW d = dfs(e.to, t, min(f, e.cost));
				if (d > 0) {
					e.cost -= d;
					edges[e.to][e.rev].cost += d;
					return d;
				}
			}
		}
		
		return FLOW(-1);
	}
Example #25
0
int
gx_begin_transparency_mask(gs_imager_state * pis, gx_device * pdev,
                                const gs_pdf14trans_params_t * pparams)
{
    gx_transparency_mask_params_t tmp;
    const int l = sizeof(pparams->Background[0]) * pparams->Background_components;

    tmp.group_color = pparams->group_color;
    tmp.subtype = pparams->subtype;
    tmp.group_color_numcomps = pparams->group_color_numcomps;
    tmp.Background_components = pparams->Background_components;
    memcpy(tmp.Background, pparams->Background, l);
    tmp.GrayBackground = pparams->GrayBackground;
    tmp.function_is_identity = pparams->function_is_identity;
    tmp.idle = pparams->idle;
    tmp.replacing = pparams->replacing;
    tmp.mask_id = pparams->mask_id;

    if (tmp.group_color == ICC ) {
        /* Do I need to ref count here? */
        tmp.iccprofile = pparams->iccprofile;
        tmp.icc_hashcode = pparams->icc_hash;
    } else {
        tmp.iccprofile = NULL;
        tmp.icc_hashcode = 0;
    }
    memcpy(tmp.transfer_fn, pparams->transfer_fn, size_of(tmp.transfer_fn));
    if_debug9('v', "[v](0x%lx)gx_begin_transparency_mask [%g %g %g %g]\n\
      subtype = %d  Background_components = %d  Num_grp_clr_comp = %d %s\n",
              (ulong)pis, pparams->bbox.p.x, pparams->bbox.p.y,
              pparams->bbox.q.x, pparams->bbox.q.y,
              (int)tmp.subtype, tmp.Background_components,
              tmp.group_color_numcomps,
              (tmp.function_is_identity ? "no TR" :
               "has TR"));
    if (dev_proc(pdev, begin_transparency_mask) != 0)
        return (*dev_proc(pdev, begin_transparency_mask))
                        (pdev, &tmp, &(pparams->bbox), pis, NULL, NULL);
    else
        return 0;
}
Example #26
0
	// pos is assumed to be a global coordinate.
	void set_patch( vec3i pos, volT vol )
	{
		STRONG_ASSERT((this->rng_).contains(pos));

		// [08/15/2014]
		// This condition can be relaxed.
		STRONG_ASSERT(size_of(vol) == this->FoV_);

		pos 	-= this->off_;			// local coordinate
		vec3i uc = pos - this->rad_;	// upper corner

		std::size_t ox = uc[0];
	    std::size_t oy = uc[1];
	    std::size_t oz = uc[2];
	    std::size_t sx = this->FoV_[0];
	    std::size_t sy = this->FoV_[1];
	    std::size_t sz = this->FoV_[2];

		(*(this->vol_))[boost::indices[range(ox,ox+sx)][range(oy,oy+sy)][range(oz,oz+sz)]] =
                    (*vol)[boost::indices[range(0,sx)][range(0,sy)][range(0,sz)]];
	}
Example #27
0
static int
ref_param_begin_read_collection(gs_param_list * plist, gs_param_name pkey,
				gs_param_dict * pvalue,
				gs_param_collection_type_t coll_type)
{
    iparam_list *const iplist = (iparam_list *) plist;
    iparam_loc loc;
    bool int_keys = coll_type != 0;
    int code = ref_param_read(iplist, pkey, &loc, -1);
    dict_param_list *dlist;

    if (code != 0)
	return code;
    dlist = (dict_param_list *)
	gs_alloc_bytes(plist->memory, size_of(dict_param_list),
		       "ref_param_begin_read_collection");
    if (dlist == 0)
	return_error(e_VMerror);
    if (r_has_type(loc.pvalue, t_dictionary)) {
	code = dict_param_list_read(dlist, loc.pvalue, NULL, false,
				    iplist->ref_memory);
	dlist->int_keys = int_keys;
	if (code >= 0)
	    pvalue->size = dict_length(loc.pvalue);
    } else if (int_keys && r_is_array(loc.pvalue)) {
	code = array_indexed_param_list_read(dlist, loc.pvalue, NULL, false,
					     iplist->ref_memory);
	if (code >= 0)
	    pvalue->size = r_size(loc.pvalue);
    } else
	code = gs_note_error(e_typecheck);
    if (code < 0) {
	gs_free_object(plist->memory, dlist, "ref_param_begin_write_collection");
	return iparam_note_error(loc, code);
    }
    pvalue->list = (gs_param_list *) dlist;
    return 0;
}
Example #28
0
static int
ref_param_begin_write_collection(gs_param_list * plist, gs_param_name pkey,
				 gs_param_dict * pvalue,
				 gs_param_collection_type_t coll_type)
{
    iparam_list *const iplist = (iparam_list *) plist;
    gs_ref_memory_t *imem = iplist->ref_memory;
    dict_param_list *dlist = (dict_param_list *)
	gs_alloc_bytes(plist->memory, size_of(dict_param_list),
		       "ref_param_begin_write_collection");
    int code;

    if (dlist == 0)
	return_error(e_VMerror);
    if (coll_type != gs_param_collection_array) {
	ref dref;

	code = dict_alloc(imem, pvalue->size, &dref);
	if (code >= 0) {
	    code = dict_param_list_write(dlist, &dref, NULL, imem);
	    dlist->int_keys = coll_type == gs_param_collection_dict_int_keys;
	}
    } else {
	ref aref;

	code = gs_alloc_ref_array(imem, &aref, a_all, pvalue->size,
				  "ref_param_begin_write_collection");
	if (code >= 0)
	    code = array_new_indexed_plist_write(dlist, &aref, NULL, imem);
    }
    if (code < 0)
	gs_free_object(plist->memory, dlist, "ref_param_begin_write_collection");
    else
	pvalue->list = (gs_param_list *) dlist;
    return code;
}
Example #29
0
File: qcc.c Project: HackLinux/qcc
// take a tokenized expression (expr) with precalculated internal values (llp and ldp) and evaluate it
// HIHI maybe put the return value in an arg, and pass back an error flag? -- otherwise need *inf, so I can show_errors?
// -- move this back into cpp?? It's not generic enough.
int32_t calculate_expr(uint8_t *expr, uint64_t *llp, int32_t llcnt, double *ldp, int32_t ldblcnt)
{
	uint8_t *s, *e, *p, *c, restart, tok, type[200];
	int i;
	restart = 0;

	i = 200;
	while (--i >= 0) type[i] = 0;			// init the unused part of the array to 0
	i = llcnt;
	while (--i >= 0) type[i] = 1;			// init all the ints to uint64_t
	i = ldblcnt;
	while (--i >= 0) type[199 - i] = 42;	// init all the floats to long double
// HIHI! enforce that llcnt + ldblcnt < 256 - TOK_SIZEOF

	s = expr;
	// scan to the first ')' token, scan backwards to the first '(' token -- then evaluate that subexpression
	// -- each pair of parens get deleted after their whole subexpression is done parsing
	while (*s != TOK_C_PAREN && *s != TOK_ILLEGAL) ++s;
	while (*s != TOK_ILLEGAL)
	{
		e = s;
		while (*--s != TOK_O_PAREN);
		// find the highest precedence operator in the expression
		// no "primary" operators are allowed in the preprocessor -- scan right to left for the first active unary operator
		p = e;
		// + - ! ~ sizeof(cast) (casts)=masking
		while (*--p != TOK_O_PAREN && restart == 0)
		{
			if (*p == TOK_B_NOT || *p == TOK_NOT)		// in this compiler, bitwise not and boolean not are the same operator
			{
				tok = next_tok(p);			// the next token *must* be an rvalue for the operator
//				if (tok <= TOK_SIZEOF, or if the variable is a float?) show_error;
				// modify the rvalue at the right end of the expression
				llp[tok - TOK_SIZEOF - 1] = ~llp[tok - TOK_SIZEOF - 1];
				*p = TOK_NO_OP;							// now that the operator has been processed, delete it
				p = e;
			}
			// a minus sign is a NEG unary operator if there is another operator (and not a "variable") to the left
	// HIHI!! gotta handle the float case, too!
			else if (*p == TOK_SUB && prev_tok(p) <= TOK_SIZEOF)
			{
				tok = next_tok(p);			// the next token *must* be an rvalue for the operator
//				if (tok <= TOK_SIZEOF) show_error;
				// modify the rvalue at the right end of the expression
	// check "type" to see if this tok is a float
				llp[tok - TOK_SIZEOF - 1] = - (int64_t) llp[tok - TOK_SIZEOF - 1];
				*p = TOK_NO_OP;							// now that the operator has been processed, delete it
				p = e;
			}
			// a plus sign is a unary operator (and a no-op) if there is another operator (and not a "variable") to the left
			else if (*p == TOK_ADD && prev_tok(p) <= TOK_SIZEOF)
			{
				*p = TOK_NO_OP;							// delete the + operator and restart the scan
				p = e;
			}
			else if (*p >= TOK_BOOL_T && *p <= TOK_UNSGN_T)
			{
				// either this is an input into sizeof (as a cast), or it's a cast of the following value
				// -- so (multiple) type keywords should be the only thing inside the parens
				// -- because the preprocessor doesn't know about function or variable declarations
				c = p - 1;
				while (*c == TOK_NO_OP || (*c >= TOK_BOOL_T && *c <= TOK_UNSGN_T)) --c;
				// verify the open and close parens around this (cast)
				// obviously, s also points at the '(' and e points at the ')'
	// HIHI!!! woops! the next tok may be a *, and not a paren! Need to scan that direction, too!
				if (next_tok(p) != TOK_C_PAREN || c != s)
				{
					i = 0;
//					show_error(0,"typecast(?) not in parens",NULL,1);
				}
				p = s;
				while (*--p == TOK_NO_OP);
				if (*p == TOK_SIZEOF)		// immediately convert a sizeof(cast) into a variable (with the correct value)
				{
					// get the next open int variable number
					type[llcnt] = 0;
					i = -1;
					while (type[++i] != 0);
					if (i == llcnt) ++llcnt;				// HIHI!! need to put a 199 limit on llcnt!
					// replace the sizeof() token with the actual size, and no-op the cast
					*p = i + TOK_SIZEOF + 1;
					llp[i] = size_of(s + 1);
					type[i] = 1;
					while (*++p != TOK_C_PAREN) *p = TOK_NO_OP;
					*p = TOK_NO_OP;
					restart = 1;
				}
				else
				{
					// do an immediate mask and type modification of the rvalue variable
					tok = next_tok(p);				// get the variable index
					i = size_of(s + 1) - 1;			// get the byte count - 1
					if (i == 3) i = 2;				// convert to a mask index
					if (i < 3)
						llp[tok - TOK_SIZEOF - 1] &= size_mask[i];
					else i = 3;
					type[tok - TOK_SIZEOF - 1] = 4 - i;		// convert to a type (maybe I should reverse the order of the types?? HIHI)
				}
			}
		}
		// then the multiplicative operators -- p already points to the start
		while (restart == 0 && *++p != TOK_C_PAREN)
		{
			if (*p == TOK_MULT || *p == TOK_DIV || *p == TOK_MOD)
			{
				restart = 1;
				binary_op(p, llp, type);
			}
		}

		// then additiive
		p = s;
		while (restart == 0 && *++p != TOK_C_PAREN)
		{
			if (*p == TOK_ADD || *p == TOK_SUB)
			{
				restart = 1;
				binary_op(p, llp, type);
			}
		}

		// then shifts
		p = s;
		while (restart == 0 && *++p != TOK_C_PAREN)
		{
			if (*p == TOK_SHR || *p == TOK_SHL)
			{
				restart = 1;
				binary_op(p, llp, type);
			}
		}

		// then relational conditionals
		p = s;
		while (restart == 0 && *++p != TOK_C_PAREN)
		{
			if (*p == TOK_B_LT || *p == TOK_B_GT || *p == TOK_B_LE || *p == TOK_B_GE)
			{
				restart = 1;
				binary_op(p, llp, type);
			}
		}

		// then equality conditionals
		p = s;
		while (restart == 0 && *++p != TOK_C_PAREN)
		{
			if (*p == TOK_B_EQ || *p == TOK_B_NE)
			{
				restart = 1;
				binary_op(p, llp, type);
			}
		}

		// then bitwise operators -- AND &
		p = s;
		while (restart == 0 && *++p != TOK_C_PAREN)
		{
			if (*p == TOK_AND)
			{
				restart = 1;
				binary_op(p, llp, type);
			}
		}

		// XOR ^
		p = s;
		while (restart == 0 && *++p != TOK_C_PAREN)
		{
			if (*p == TOK_XOR)
			{
				restart = 1;
				binary_op(p, llp, type);
			}
		}

		// OR |
		p = s;
		while (restart == 0 && *++p != TOK_C_PAREN)
		{
			if (*p == TOK_OR)
			{
				restart = 1;
				binary_op(p, llp, type);
			}
		}

		// then booleans &&
		p = s;
		while (restart == 0 && *++p != TOK_C_PAREN)
		{
			if (*p == TOK_B_AND)
			{
				restart = 1;
				binary_op(p, llp, type);
			}
		}

		// ||
		p = s;
		while (restart == 0 && *++p != TOK_C_PAREN)
		{
			if (*p == TOK_B_OR)
			{
				restart = 1;
				binary_op(p, llp, type);
			}
		}

		// and last, the stupid "ternary condtional" ?	evaluate right to left, p is already set properly
		while (restart == 0 && *--p != TOK_O_PAREN)
		{
			if (*p == TOK_QMARK)
				i = 8;			// HIHI!!! gotta parse it and eliminate it from the expr
		}

		// are there any operators left between s and e? If not, destroy the parens of this fully evaluated subexpression.
		p = s + 1;
		while (*p > TOK_SIZEOF || *p == TOK_NO_OP) ++p;
		if (*p == TOK_C_PAREN)
		{
			*s = TOK_NO_OP;
			*p = TOK_NO_OP;
		}
		restart = 0;
		s = expr;
		while (*s != TOK_C_PAREN && *s != TOK_ILLEGAL) ++s;
	}
	// there must be one variable left in the expression now -- that's the return value
	p = expr + 1;
	while (*p < TOK_SIZEOF) ++p;

	if (llp[*p - TOK_SIZEOF - 1] == 0) return 0;
	return -1;
}
Example #30
0
 size_t array::bytes() const
 {
     dim_type nElements;
     AF_THROW(af_get_elements(&nElements, arr));
     return nElements * size_of(type());
 }