| 111 | } |
| 112 | |
| 113 | void AstSerializer::patch () { |
| 114 | patchRefs(functionRefs, smartFunctionMap); |
| 115 | patchRefs(variableRefs, smartVariableMap); |
| 116 | patchRefs(structureRefs, smartStructureMap); |
| 117 | patchRefs(enumerationRefs, smartEnumerationMap); |
| 118 | // finally, patch block refs (differenct container) |
| 119 | for ( auto & p : blockRefs ) { |
| 120 | auto it = exprBlockMap.find(p.second); |
| 121 | if ( it == exprBlockMap.end() ) { |
| 122 | throw_formatted_error("ast serializer block ref not found"); |
| 123 | } else { |
| 124 | *p.first = it->second; |
| 125 | } |
| 126 | } |
| 127 | blockRefs.clear(); |
| 128 | |
| 129 | for ( auto & [field, mod, name, fieldname] : fieldRefs ) { |
| 130 | auto struct_ = moduleLibrary->findStructure(name, mod); |
| 131 | if ( struct_.size() == 0 ) { |
| 132 | throw_formatted_error("expected to find structure '%s'", name.c_str()); |
| 133 | } else if ( struct_.size() > 1 ) { |
| 134 | throw_formatted_error("too many candidates for structure '%s'", name.c_str()); |
| 135 | } |
| 136 | // set the missing field field |
| 137 | *field = struct_.front()->findFieldRef(fieldname); |
| 138 | } |
| 139 | fieldRefs.clear(); |
| 140 | } |
| 141 | |
| 142 | void AstSerializer::write ( const void * data, size_t size ) { |
| 143 | buffer->write(data, size); |
no test coverage detected