Ejemplo n.º 1
0
void
GetStructTypesNamesPositions(const std::vector<StructDeclaration *> &sd,
                             llvm::SmallVector<const Type *, 8> *elementTypes,
                             llvm::SmallVector<std::string, 8> *elementNames,
                             llvm::SmallVector<SourcePos, 8> *elementPositions) {
    std::set<std::string> seenNames;
    for (unsigned int i = 0; i < sd.size(); ++i) {
        const Type *type = sd[i]->type;
        if (type == NULL)
            continue;

        // FIXME: making this fake little DeclSpecs here is really
        // disgusting
        DeclSpecs ds(type);
        if (Type::Equal(type, AtomicType::Void) == false) {
            if (type->IsUniformType()) 
                ds.typeQualifiers |= TYPEQUAL_UNIFORM;
            else if (type->IsVaryingType())
                ds.typeQualifiers |= TYPEQUAL_VARYING;
            else if (type->GetSOAWidth() != 0)
                ds.soaWidth = type->GetSOAWidth();
            // FIXME: ds.vectorSize?
        }

        for (unsigned int j = 0; j < sd[i]->declarators->size(); ++j) {
            Declarator *d = (*sd[i]->declarators)[j];
            d->InitFromDeclSpecs(&ds);

            if (Type::Equal(d->type, AtomicType::Void))
                Error(d->pos, "\"void\" type illegal for struct member.");

            elementTypes->push_back(d->type);

            if (seenNames.find(d->name) != seenNames.end())
                Error(d->pos, "Struct member \"%s\" has same name as a "
                      "previously-declared member.", d->name.c_str());
            else
                seenNames.insert(d->name);

            elementNames->push_back(d->name);
            elementPositions->push_back(d->pos);
        }
    }

    for (int i = 0; i < (int)elementTypes->size() - 1; ++i) {
        const ArrayType *arrayType = CastType<ArrayType>((*elementTypes)[i]);

        if (arrayType != NULL && arrayType->GetElementCount() == 0)
            Error((*elementPositions)[i], "Unsized arrays aren't allowed except "
                  "for the last member in a struct definition.");
    }
}
Ejemplo n.º 2
0
Archivo: decl.cpp Proyecto: mwiebe/ispc
void
GetStructTypesNamesPositions(const std::vector<StructDeclaration *> &sd,
                             std::vector<const Type *> *elementTypes,
                             std::vector<std::string> *elementNames,
                             std::vector<SourcePos> *elementPositions) {
    std::set<std::string> seenNames;
    for (unsigned int i = 0; i < sd.size(); ++i) {
        const Type *type = sd[i]->type;
        if (type == NULL)
            continue;

        // FIXME: making this fake little DeclSpecs here is really
        // disgusting
        DeclSpecs ds(type);
        if (type->IsUniformType()) 
            ds.typeQualifiers |= TYPEQUAL_UNIFORM;
        else if (type->IsVaryingType())
            ds.typeQualifiers |= TYPEQUAL_VARYING;

        for (unsigned int j = 0; j < sd[i]->declarators->size(); ++j) {
            Declarator *d = (*sd[i]->declarators)[j];
            d->InitFromDeclSpecs(&ds);

            Symbol *sym = d->GetSymbol();

            if (sym->type == AtomicType::Void)
                Error(d->pos, "\"void\" type illegal for struct member.");

            const ArrayType *arrayType = 
                dynamic_cast<const ArrayType *>(sym->type);
            if (arrayType != NULL && arrayType->GetElementCount() == 0) {
                Error(d->pos, "Unsized arrays aren't allowed in struct "
                      "definitions.");
                elementTypes->push_back(NULL);
            }
            else
                elementTypes->push_back(sym->type);

            if (seenNames.find(sym->name) != seenNames.end())
                Error(d->pos, "Struct member \"%s\" has same name as a "
                      "previously-declared member.", sym->name.c_str());
            else
                seenNames.insert(sym->name);

            elementNames->push_back(sym->name);
            elementPositions->push_back(sym->pos);
        }
    }
}