On the cooccurrence of demixing and thermoreversible gelation of polymer solutions. 2. Thermodynamic background