| 154 | } |
| 155 | |
| 156 | void Statements::AddStruct(std::shared_ptr<StructType>& s) |
| 157 | { |
| 158 | if (s == nullptr) |
| 159 | yyerror("Struct is null!"); |
| 160 | if (s->name->empty()) |
| 161 | yyerror("Struct name is invalid!"); |
| 162 | if (!s->body) |
| 163 | yyerror("Struct is empty - " + *s->name.get()); |
| 164 | |
| 165 | // Check for duplicates |
| 166 | auto it = std::find_if(structs.begin(), structs.end(), [&s](auto item)->bool { return *item->name.get() == *s->name.get(); }); |
| 167 | if (it != structs.end()) |
| 168 | yyerror("Duplicate struct name " + *s->name.get()); |
| 169 | it = std::find_if(structs.begin(), structs.end(), [&s](auto item)->bool { return (item->type == s->type) && item->fixed && s->fixed; }); |
| 170 | if (it != structs.end()) |
| 171 | yyerror("Duplicate struct type " + std::to_string(s->type)); |
| 172 | |
| 173 | structs.push_back(s); |
| 174 | } |
| 175 | |
| 176 | void Import::AddImport(std::string* i) |
| 177 | { |