I have never used the AutoStretchHorizontal/Vertical, so I can't say if they take precident over AutoStretch, but approaching it logically, your order seems the most correct.
I don't know if your psuedo-code is comprehensive, but don't forget to factor in the property RelativePositioning. True behaves just as we have been talking about. False, however, ignores the parent container. I have never observed the behavior of an element within another container and having RelativePositioning set to false, but I have accidently done it for top level elements. I have on many occassions placed buttons at 0,0, only to find them at the top-left corner of EQ. Honestly, I can't even imagine why anyone would not use relative postioning for elements.
As a note, I am a coder for a living, so unless you're writing this in Delphi or Fortran, I can most likely read any code you paste