28.01.2015 Views

Hermes: A Tutorial and Reference Manual - Researcher - IBM

Hermes: A Tutorial and Reference Manual - Researcher - IBM

Hermes: A Tutorial and Reference Manual - Researcher - IBM

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

563.Type<strong>and</strong>TypestateChecking<br />

anerroneousexecution. thereforemaynotbeinstantiated).A<strong>Hermes</strong>compilerwillrejectaprogram whosePascalorAdacounterpartwouldcompilesuccessfullybutproduce therbereadnorwritten),<strong>and</strong>whereaprogramvalueisunchecked(<strong>and</strong> everyexpression<strong>and</strong>(2)beconsistentwiththetyperules. notberead),whereavariantisinthewrongcase(<strong>and</strong>thereforemayneiing|ageneralizationofdataowanalysis..<strong>Hermes</strong>compilersusetypestatecheckingtotrackwhereavariableisuninitialized(<strong>and</strong>thereforemay<br />

Here'sanexampleoftypestatecheckingappliedtoasimple(<strong>and</strong>rather Theproblemofundenedvaluesissolvedin<strong>Hermes</strong>bytypestatecheck-<br />

meaningless)programfragment: begin block callParms.GetLine(L); declare L:Charstring; A:Char; B:Charstring; C:Charstring; ifsizeofL=0 then else callParms.PutLine(B); B:="EmptyLine"; A:='NUL';<br />

on(GetLineInterface.EndStream) insertAintoL;<br />

callParms.GetLine(L); endif; callParms.GetLine(C); A:=L[0];<br />

endblock; Fornow,letuslookonlyatthesimplestapplicationoftypestate| callParms.PutLine(L); callParms.PutLine(C);<br />

tributeinit(A)ispresentinthetypestate;otherwisetheattributeisab-<br />

sent.Typestateanalysiscomputesatypestateforeachprogrampoint.This initializedoruninitialized.WedonotallowAtobeinitializedalongsome meansthatatagivenprogrampointvariableAmustbeknowntobeeither avariableisinitializedoruninitialized.IfvariableAisinitialized,theat-<br />

asasetofattributesdescribingpropertiesofvariables,suchaswhether paths<strong>and</strong>notothers. keepingtrackofwhichvariablesareinitialized:Atypestateisrepresented

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!