std::vector<VariableDeclaration> Declaration::GetVariableDeclarations() const { Assert(declSpecs->storageClass != SC_TYPEDEF); std::vector<VariableDeclaration> vars; for (unsigned int i = 0; i < declarators.size(); ++i) { if (declarators[i] == NULL) continue; Declarator *decl = declarators[i]; if (decl == NULL) // Ignore earlier errors continue; Symbol *sym = decl->GetSymbol(); if (dynamic_cast<const FunctionType *>(sym->type) != NULL) { // function declaration m->symbolTable->AddFunction(sym); } else { m->symbolTable->AddVariable(sym); vars.push_back(VariableDeclaration(sym, decl->initExpr)); } } return vars; }
void Declaration::DeclareFunctions() { Assert(declSpecs->storageClass != SC_TYPEDEF); for (unsigned int i = 0; i < declarators.size(); ++i) { Declarator *decl = declarators[i]; if (decl == NULL) { // Ignore earlier errors Assert(m->errorCount > 0); continue; } Symbol *sym = decl->GetSymbol(); if (sym == NULL || sym->type == NULL) { // Ignore errors Assert(m->errorCount > 0); continue; } sym->type = sym->type->ResolveUnboundVariability(Type::Varying); if (dynamic_cast<const FunctionType *>(sym->type) == NULL) continue; bool isInline = (declSpecs->typeQualifiers & TYPEQUAL_INLINE); m->AddFunctionDeclaration(sym, isInline); } }
std::vector<VariableDeclaration> Declaration::GetVariableDeclarations() const { Assert(declSpecs->storageClass != SC_TYPEDEF); std::vector<VariableDeclaration> vars; for (unsigned int i = 0; i < declarators.size(); ++i) { Declarator *decl = declarators[i]; if (decl == NULL) { // Ignore earlier errors Assert(m->errorCount > 0); continue; } Symbol *sym = decl->GetSymbol(); if (sym == NULL || sym->type == NULL) { // Ignore errors Assert(m->errorCount > 0); continue; } sym->type = sym->type->ResolveUnboundVariability(Type::Varying); if (sym->type == AtomicType::Void) Error(sym->pos, "\"void\" type variable illegal in declaration."); else if (dynamic_cast<const FunctionType *>(sym->type) == NULL) { m->symbolTable->AddVariable(sym); vars.push_back(VariableDeclaration(sym, decl->initExpr)); } } return vars; }
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); } } }