The conversion to atoms types uses a lot of copy and pasted code that
can be put into a generic function. This PR does that.
Testing: This should not change behavior so is covered by existing
tests.
Signed-off-by: Martin Robinson <mrobinson@igalia.com>