예제 #1
0
파일: structs.cpp 프로젝트: rainers/ldc
void DtoResolveStruct(StructDeclaration* sd, Loc& callerLoc)
{
    // Make sure to resolve each struct type exactly once.
    if (sd->ir.isResolved()) return;
    sd->ir.setResolved();

    IF_LOG Logger::println("Resolving struct type: %s (%s)", sd->toChars(), sd->loc.toChars());
    LOG_SCOPE;

    // make sure type exists
    DtoType(sd->type);

    // if it's a forward declaration, all bets are off. The type should be enough
    if (sd->sizeok != SIZEOKdone)
    {
        error(callerLoc, "struct %s.%s unknown size", sd->getModule()->toChars(), sd->toChars());
        fatal();
    }

    // create the IrAggr
    getIrAggr(sd, true);

    // Set up our field metadata.
    for (VarDeclarations::iterator I = sd->fields.begin(),
            E = sd->fields.end();
            I != E; ++I)
    {
        VarDeclaration *vd = *I;
        IF_LOG {
            if (isIrFieldCreated(vd))
                Logger::println("struct field already exists");
        }
        getIrField(vd, true);
    }
}
예제 #2
0
파일: classes.cpp 프로젝트: Philpax/ldc
void DtoResolveClass(ClassDeclaration* cd)
{
    if (cd->ir.isResolved()) return;
    cd->ir.setResolved();

    IF_LOG Logger::println("DtoResolveClass(%s): %s", cd->toPrettyChars(), cd->loc.toChars());
    LOG_SCOPE;

    // make sure the base classes are processed first
    for (BaseClasses::iterator I = cd->baseclasses->begin(),
                               E = cd->baseclasses->end();
                               I != E; ++I)
    {
        DtoResolveClass((*I)->base);
    }

    // make sure type exists
    DtoType(cd->type);

    // create IrAggr
    IrAggr* irAggr = getIrAggr(cd, true);

    // make sure all fields really get their ir field
    for (VarDeclarations::iterator I = cd->fields.begin(),
                                   E = cd->fields.end();
                                   I != E; ++I)
    {
        VarDeclaration* vd = *I;
        IF_LOG {
            if (isIrFieldCreated(vd))
                Logger::println("class field already exists");
        }
        getIrField(vd, true);
    }

    // emit the interfaceInfosZ symbol if necessary
    if (cd->vtblInterfaces && cd->vtblInterfaces->dim > 0)
        irAggr->getInterfaceArraySymbol(); // initializer is applied when it's built

    // interface only emit typeinfo and classinfo
    if (cd->isInterfaceDeclaration())
    {
        irAggr->initializeInterface();
    }
}
예제 #3
0
파일: classes.cpp 프로젝트: John-Colvin/ldc
void DtoResolveClass(ClassDeclaration *cd) {
  if (cd->ir->isResolved()) {
    return;
  }
  cd->ir->setResolved();

  IF_LOG Logger::println("DtoResolveClass(%s): %s", cd->toPrettyChars(),
                         cd->loc.toChars());
  LOG_SCOPE;

  // make sure the base classes are processed first
  for (auto bc : *cd->baseclasses) {
    DtoResolveClass(bc->sym);
  }

  // make sure type exists
  DtoType(cd->type);

  // create IrAggr
  IrAggr *irAggr = getIrAggr(cd, true);

  // make sure all fields really get their ir field
  for (auto vd : cd->fields) {
    IF_LOG {
      if (isIrFieldCreated(vd)) {
        Logger::println("class field already exists");
      }
    }
    getIrField(vd, true);
  }

  // emit the interfaceInfosZ symbol if necessary
  if (cd->vtblInterfaces && cd->vtblInterfaces->dim > 0) {
    irAggr->getInterfaceArraySymbol(); // initializer is applied when it's built
  }

  // interface only emit typeinfo and classinfo
  if (cd->isInterfaceDeclaration()) {
    irAggr->initializeInterface();
  }
}