Replace Type
- You are using integer variable to carry other kind of information.
Replace the integer type with the appropriate type, and propagate it across the expressions the variable is used.
void function() { int tmp; tmp = ... puts((char *)tmp); }
⇓
void function() { char *tmp; tmp = ... puts(tmp); }
Motivation
Integer types and floating point types (on processors with a Floating Point Unit) are about the only types natively supported by a common processor. Operations with all other high-level types (enums, typedefs, structs, and unions) are translated into operations with these native types. Pointers are translated to memory addresses, which are also indistinguishable from regular integers in most architectures. This refactoring allows to recover the original high level types by propagating the type information across the code.
Mechanism
- Define the new type, if not defined yet.
- Replace the variable type.
- Propagate type in the expressions it is used, adding or removing type casts as needed.