Esempio n. 1
0
bool exprNodeArrayResolve(Node *n, Function *f, CompileUnit *u)
{
  if(n->expression->resolve(n->expression, f, u)) {
    TypeEnum tt = n->expression->type->type;
    if(tt != TYPE_array &&
       tt != TYPE_pointer) {
      printf("Object not of array or pointer type\n");
      return false;
    }

    if(tt == TYPE_array) {
      Array *a = n->expression->type->array;
      
      u32 loc = n->expression->location;
      Type *t = a->type;
      if(a->maxBounds > 1) {
        int index = n->expression->index;

        if(index == a->maxBounds) {
          printf("Too many indices for array\n");
          return false;
        }

        if((index+1) < a->maxBounds) {
          n->type = n->expression->type;
          n->index = index+1;
          n->locType = LOCATION_memory;
          n->location = n->expression->location +
            n->value * exprNodeGetSize(a, index);
          return true;
        }
      }
      n->type = t;
      n->location = loc + n->value * t->size;
      n->locType = LOCATION_memory;
    } else {
      Type *t = n->expression->type->pointer;
      u32 loc = n->expression->location;
      if(n->expression->locType == LOCATION_register)
        loc = reg[loc].I;
      else
        loc = debuggerReadMemory(loc);
      n->type = t;
      n->location = loc + n->value * t->size;
      n->locType = LOCATION_memory;
    }
    return true;
  }
  return false;
}
Esempio n. 2
0
bool exprNodeArrowResolve(Node *n, Function *f, CompileUnit *u)
{
  if(n->expression->resolve(n->expression, f, u)) {
    TypeEnum tt = n->expression->type->type;
    if(tt != TYPE_pointer) {
      printf("Object not of pointer type\n");
      return false;
    }
    tt = n->expression->type->pointer->type;
    
    if(tt == TYPE_struct ||
       tt == TYPE_union) {
      u32 loc = debuggerReadMemory(n->expression->location);
      Type *t = n->expression->type->pointer;
      int count = t->structure->memberCount;
      int i = 0;
      while(i < count) {
        Member *m = &t->structure->members[i];
        if(strcmp(m->name, n->name) == 0) {
          // found member
          n->type = m->type;
          if(tt == TYPE_struct) {
            n->location = elfDecodeLocation(f, m->location, &n->locType,
                                            loc);
            n->objLocation = loc;
          } else {
            n->location = loc;
            n->objLocation = loc;
          }
          n->locType = LOCATION_memory;
          n->member = m;
          return true;
        }
        i++;
      }
      printf("Member %s not found\n", n->name);
    } else {
      printf("Object is not of structure type\n");
    }
  }
  return false;
}
Esempio n. 3
0
bool exprNodeStarResolve(Node* n, Function* f, CompileUnit* u)
{
    if (n->expression->resolve(n->expression, f, u)) {
        if (n->expression->type->type == TYPE_pointer) {
            n->location = n->expression->location;
            if (n->expression->locType == LOCATION_memory) {
                n->location = debuggerReadMemory(n->location);
            } else if (n->expression->locType == LOCATION_register) {
                n->location = reg[n->expression->location].I;
            } else {
                n->location = n->expression->location;
            }
            n->type = n->expression->type->pointer;
            n->locType = LOCATION_memory;
            return true;
        } else {
            printf("Object is not of pointer type\n");
        }
    }
    return false;
}