An extension of the Dirac theory of constraints