public static void writeUnionFacet(Function function, DataType dt, int fieldNum, Address addr,
			long hash, SourceType source) throws InvalidInputException, DuplicateNameException {
		if (dt instanceof PartialUnion) {
			dt = ((PartialUnion) dt).getParent();
		}
		int firstUseOffset = (int) addr.subtract(function.getEntryPoint());
		String symbolName = UnionFacetSymbol.buildSymbolName(fieldNum, addr);
		boolean nameCollision = false;
		Variable[] localVariables =
			function.getLocalVariables(VariableFilter.UNIQUE_VARIABLE_FILTER);
		// Clean out any facet symbols with bad data-types
		for (int i = 0; i < localVariables.length; ++i) {
			Variable var = localVariables[i];
			if (var.getName().startsWith(UnionFacetSymbol.BASENAME)) {
				if (!UnionFacetSymbol.isUnionType(var.getDataType())) {
					function.removeVariable(var);
					localVariables[i] = null;
				}
			}
		}
		Variable preexistingVar = null;
		for (Variable var : localVariables) {
			if (var == null) {
				continue;
			}
			if (var.getFirstUseOffset() == firstUseOffset &&
				var.getFirstStorageVarnode().getOffset() == hash) {
				preexistingVar = var;
			}
			else if (var.getName().startsWith(symbolName)) {
				nameCollision = true;
			}
		}
		if (nameCollision) {	// Uniquify the name if necessary
			symbolName = symbolName + '_' + Integer.toHexString(DynamicHash.getComparable(hash));
		}
		if (preexistingVar != null) {
			if (!preexistingVar.getName().equals(symbolName)) {
				preexistingVar.setName(symbolName, source);		// Change the name
			}
			if (!preexistingVar.getDataType().equals(dt)) {
				preexistingVar.setDataType(dt, source);
			}
			return;
		}
		Program program = function.getProgram();
		VariableStorage storage =
			new VariableStorage(program, AddressSpace.HASH_SPACE.getAddress(hash), dt.getLength());
		Variable var = new LocalVariableImpl(symbolName, firstUseOffset, dt, storage, program);
		function.addLocalVariable(var, SourceType.USER_DEFINED);
	}
Write a union facet to the database (UnionFacetSymbol).  Parameters provide the
pieces for building the dynamic LocalVariable.  This method clears out any preexisting
union facet with the same dynamic hash and firstUseOffset.
@param function is the function affected by the union facet
@param dt is the parent data-type; a union, a pointer to a union, or a partial union
@param fieldNum is the ordinal of the desired union field
@param addr is the first use address of the facet
@param hash is the dynamic hash
@param source is the SourceType for the LocalVariable
@throws InvalidInputException if the LocalVariable cannot be created
@throws DuplicateNameException if the (auto-generated) name is used elsewhere
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/HighFunctionDBUtil.java