using pdf.js in mvc : Bulk pdf to jpg converter SDK software service wpf winforms .net dnn GrGenNET-Manual36-part1937

26.3 SearchPlanninginCodeGeneration
347
26.3 SearchPlanninginCodeGeneration
Intheprevioussectionasearchprogramforthepattern(repeatedingure26.17)wasgiven.
Itfollowstheschedule
lkp(v1:A); out(v1,e1:a); tgt(e1,v2:B); out(v2,e3:b); tgt(e3,v3:C); out(v3,e2:a)
Ascheduleisamoreabstractversionofasearchprogram,withsearchoperationslkpdenot-
ingnode(oredge)lookupinthegraphbyiteratingthetypelist,outiteratingtheoutgoing
edgesofthegivensourcenodeandiniteratingtheincomingedgesofthegiventargetnode,
srcfetchingthesourcefromthegivenedgeandtgtfetchingthetargetfromthegivenedge.
Forsomegraphsitmightworkwell,butforthegraphgiveningure26.18isisabadsearch
plan. Whysocanbeseeninthesearchordersketchedingure26.19. Duetothemultiple
outgoingedgesofv1ofwhichonlyoneleadstoamatchithastobacktrackseveraltimes.A
bettersearchorderwouldbeonematchingthisedgefromv2oninreversedirection;dueto
thegraphmodelcontainingalistofoutgoingandalistofincomingedges,eachedgecanbe
traversedineitherdirection.
Foreverypatterntherearenormallymultiplesearchprogramsavailable,eachabletond
allthematcheswhichexist,butwithvastlydierentperformancecharacteristics.Inorderto
improveperformance,GrGen.NETtriestopreventfollowinggraphstructuressplittinginto
breadthasgiveninthisexampleorlookupsontypeswhichareavailableinhighquantities,
byrstexecutingaplanningphasetochooseagoodschedule. Duetothe e planningphase
thisscheduleischosen:
lkp(v3:C); out(v3,e2:a); tgt(e2,v2:B); out(v2,e3:b); in(v2,e1:a); src(e1,v1:A)
correspondingtothesearchorderdepictedingure26.20andthesearchprogram:
1
foreach(v3:C ingraph) {
2
foreach(e2inoutgoing(v3)) {
3
if(type(e2)!=a)continue;
4
v2 =e2.tgt;
5
if(type(v2)!=B)continue;
6
foreach(e3in outgoing(v2)) {
7
if(type(e3)!=b)continue;
8
if(e3.tgt!=v3) continue;
9
foreach(e1 inincoming(v2)) {
10
if(type(e1)!=a)continue;
11
v1= e1.src;
12
if(type(v1)!=A)continue;
13
buildMatchObjectOfPatternWith(v3,e2,v2,e3,e1,v1);
14
}
15
}
16
}
17
}
Bulk pdf to jpg converter - Convert PDF to JPEG images in C#.net, ASP.NET MVC, WinForms, WPF project
How to convert PDF to JPEG using C#.NET PDF to JPEG conversion / converter library control SDK
convert multi page pdf to jpg; pdf to jpeg converter
Bulk pdf to jpg converter - VB.NET PDF Convert to Jpeg SDK: Convert PDF to JPEG images in vb.net, ASP.NET MVC, WinForms, WPF project
Online Tutorial for PDF to JPEG (JPG) Conversion in VB.NET Image Application
to jpeg; convert pdf file into jpg
348
UnderstandingandExtendingGrGen.NET
Figure26.19:Badsearchorder
Figure26.20:Goodsearchorder
Themechanismofsearchplanningworksbycomputingfromthepatterngraphasearch
plangraph. Asearchplangraphis s anedge-weightedgraph, , withnodes s corresponding to
the patternelements { bothnodes andedges {andedges correspondingto operations to
matchthem,withweightattributesgivinganestimatedcostoftheoperation.Asearchplan
graphcontainsanadditionalrootnode,withanoutgoingedgetoeachothernodedening
alookupoperation. Fromplannodes s createdfornodes thereare outgoingandincoming
operationsleavingtowardsplannodescreatedfromedges,fromplannodescreatedforedges
there are source and target t operations s leaving towards plannodes created d from nodes.
The cost is s determined by analyzing g the e amount t of splitting betweenadjacent nodes for
everytripleof(nodetype;edgetype;nodetype) inthegraph{calledaV-Structure{andby
counting the e number of f elements s of f every y node type e or edge type. . In n the plan grapha
minimumspanningarborescence,i.e. directedtreeiscomputed. Thearborescencedening
C# Imaging - Planet Barcode Generation Guide
Draw, paint PLANET bar codes on images of jpeg/jpg, png, gif, and bmp formats. Creating single or bulk PLANET bar codes on documents such as PDF, Office Word
convert pdf to jpeg on; convert pdf file to jpg on
26.3 SearchPlanninginCodeGeneration
349
thematchingoperationscausingleastcostisthenlinearizedintoaschedule,whichisalist
ofthesearchoperationschosenasalreadyintroducedwiththegoodandthebadschedules.
Thedetailsofsearchplanningandsomeevaluationhowwellitworksaregivenin[Bat06b]
andin[BKG08].
root
v1:A
e1:a
v2 :B
e2:a
e3:b
v3 :C
lkp/2
lkp/7
lkp/4
lkp/7
lkp/2
lkp/1
out/2.83
src/1
tgt/1
in/1
out/1
src/1
out/1
src/1
tgt/1
in/1
tgt/1
in/2
Figure26.21: Thesearchplangraphfor r the patterngraphofFigure26.17withestimated
backtrackingcostsinducedbythehostgraphofFigure26.18.Thefoundminimumdirected
spanningtreeisdenotedbythickedges.
Asearchprogramisalowerabstractionversionofaschedule. Structurallyit t isatree
data structure re ecting the syntax tree of the code togenerate (with list entries maybe
containingfurther lists),assketchedingure26.22;incontrasttotheschedule whichisa
simplelistdatastructure.
SPL = SearchProgramList
SO = SearchOperation
SP = SearchProgram
:SP
:SPL
:SO
Next
Prev
:SO
Next
Prev
:SO
Next
Prev
:SPL
:SO
Next
Prev
:SO
Next
Prev
Prev
Prev
Figure26.22: AsimpleSearchProgram
Itcontainsexplicitinstructionsforisomorphycheckingandconnectednesschecking,which
are inserted d after the schedule was determined along g the e exact t sequence e of instructions.
Connectednesscheckingcanbeseeninthegoodsearchprogramoftheexampleinthecheck
that thetarget of e3is indeedv3; ; atarget t matchingoperationtgt(e3,v3:C)is not used
350
UnderstandingandExtendingGrGen.NET
becausev3wasalready matchedbythe lookupoperation, , andisalready y containedinthe
spanningtree. Furthermoreit t contains exact locations wheretocontinueat,whichmight
bedierentthanthedirectlyprecedingsearchoperation(becausethatonedoesnotdenea
choicepointofin uence).
A remark on isomorphy handling: : As s a a consequence of the simple e loop p based graph
elementbindingtopatternelements,without anexplicit checkallpatternelements could
getmatchedcompletelyhomomorphicallytoeachother(duetotheloopsstartingwiththe
sameelements,the homomorphicmatches are e normally y therst to be found). . Toensure
thattwopatternelementsarenotboundtothesamegraphelement, agscontainedinthe
graphelementsaresetwhenagraphelementisboundtoapatternvariableandresetwhen
thebindingisgivenupagain(one agforeachnegative/independentnestinglevel,untilthe
implementationdenedlimitof agsavailableinthegraphelementsisreached,thenalistof
dictionariesisused);the agsarecheckedtheninthefollowing,nestedmatchingoperations.
Aniso-checkschedulingpass ensures thatchecksareonlyinsertediftheelementsmust be
isomorphicandtheirtypesdonotalreadyensurethat theycan’tgetmatchedtothesame
elements.
26.4 TheCodeGenerator
26.4.1 Frontend
IR
.gm
AST u.     AST r.
.grg
RulePattern
PatternGraph
Parsing actions
getIR
Symbol
Table,
Scope
resolve
check
Lexer
Parser
ActionsGen
ModelGen
NegPatternGraph
Alternative
AltPatternGraph
Subpattern
Graph 
Representation
Replacement
Code
MatchingPattern
PatternGraph
NegPatternGraph
Alternative
AltPatternGraph
IterPatternGraph
Replacement,
Create, Delete
Code
ModifyGen
points to
IdptPatternGraph
IterPatternGraph
IdptPatternGraph
Subpattern
Figure26.23: FrontendCodeGeneration
Thefrontendisspreadoverthedirectoriesparser,ast,ir,beandutil,withtheircode
beingusedfromMain.java.
SyntaxandStaticSemantics
Thedirectoryparsercontains parser helperslikethesymboltableandscopesandwithin
theantlrsubdirectory the ANTLRparsergrammarofGrGen.NETinthele Grgen.g.
Thesemanticactionsoftheparserbuildanabstractsyntaxtreeconsistingofinstancesofthe
classesgiveninthedirectoryast,withthebaseclassBaseNode.TheASTisoperateduponin
threepasses,rstresolvingbyresolveandresolveLocal,mainlyreplacingidentiernodes
bytheirdeclarationnodesduringa(largely)preorderwalk. AfterwardstheASTischecked
by check and d checkLocal during a (largely) ) postorder walk for type and d other r semantic
26.4 TheCodeGenerator
351
constraints.Finallyanintermediaterepresentationisbuiltfromtheabstractsyntaxtreeby
thegetIRandconstructIRmethods.
IntermediateRepresentation
TheIRclassesgivenintheirfoldercanbeseenasmorelightweightASTclasses;theirname
isoftenthesameasfortheircorrespondingASTclasses,butwithouttheNode-suxwhichis
appendedtoallASTclasses.ThemostinterestingclassesareRuleusedforrules,alternative
casesanditerateds,aswellasPatternGraphusedforallpatterngraphsincludingnegatives
andindependents;severaldata owanalysesarecontainedinPatternGraph,somecovering
thenestingofpatterns, somebeingevenglobal. . Aparticularly y interestingone is ensure-
DirectlyNestingPatternContainsAllNonLocalElementsOfNestedPattern which ensures
that,fromapatternwhichcontainsacertainentitythersttime,uptoeverypatternthat
referencesthisentity,allintermediatepatternscontainthatentity,too.
ThisisdoneinarecursivewalkoverthenestedpatternsintheIR-structure.Eachpattern
receives the set t of already y knownelements as s parameter, , before descending the elements
availableinthecurrentpatternareaddedtothesetofalreadyknownelements,thenrecursive
descentintothedirectlynestedpatternsfollowshandingdownthealreadyknownelements.
Onascendingelementsareaddedtothecurrentpatterniftheyarecontainedinadirectly
nested pattern, but t not in n the current t pattern, , although h they are known n in n the e current
pattern.
ThisisdoneintheIRtokeepthebackendssimple. TheIRclassesaretheinputtothe
twobackendsofthefrontend,asgiveninthefoldersbe/Candbe/Csharp.
Backends
Thedirectorybe/CcontainsthecodegeneratorfortheCbasedbackendintegratedintothe
IPDCcompiler.(ThecompilertransformsaCprogramintoagraphandSSAbasedcompiler
intermediaterepresentationnamedFIRMusinglibFirm(seelibfirm.org,[TLB99],[Lin02])
andfurtherontox86machinecode.)
Thedirectorybe/CsharpcontainsthecodegeneratorfortheC#basedbackendofGr-
Gen.NET.ItgeneratesthemodelsourcecodeFooModel.cswiththenodeandedgeclasses
forarulelenamedFoo.grg,andtheintermediaterulessourcecodeFooActions
intermediate
withadescriptionofthepatternstomatch,adescriptionoftheembeddedgraphrewritese-
quences, andtherewriting code. . This s is done inseveralrecursive passes over thenesting
structureofthepatternsintheIR.
Thebackendofthefrontenddoes not t generatethecompleterulessourcecodewiththe
matchercodeorthecodefortheembeddedrewritesequences|thisisdonebygrgen.exe
whichonlycallsthegrgen.jarofthefrontend. YoumaycalltheJavaarchiveonyourown
togetavisualizationofthemodelandrewriterulesfroma.vcg-dumpoftheIR,cf.Note3.
ModelGeneration
ThemodelgenerationcodeinModelGenisratherstraightforward:
1. rstcodefortheuserdenedenumsisgenerated,
2. thenthenodeclassesaregenerated,
3. followedbythenodemodel,
4. thenthetheedgeclassesaregenerated,
5. followedbytheedgemodel,
6. andnallythegraphmodelisgenerated.
352
UnderstandingandExtendingGrGen.NET
Forthenodesaswellasfortheedgesthreeclassesaregenerated:
1. therstbeingtheinterfacevisibletotheuser,givingaccesstotheattributes,
2. the e secondbeingtheimplementationimplementing the interface andinheritingfrom
LGSPNodeorLGSPEdge,
3. andthethirdbeingatyperepresentationclassinheritingfromNodeTypeorEdgeType
givinginformationsaboutthetypeanditsattributes,usedinthenode/edgemodeland
thusgraphmodel.
RuleRepresentationPass
Theactioncode,betterrepresentationgenerationisimplementedinActionsGen,inthecode
calledfromgenSubpatternforthesubpatternsandgenActionfortherulesandtestson.
InaprerunfromgenRuleOrSubpatternClassEntitiesonsomeneededentitiesaregen-
erated,e.g. typearraysfor r the allowedtypes ofthepatternelements(the arraysare only
lledifthebasetypewasconstrained),orindexingenums,whichmapthepatternelement
namestotheirindexinthearraysofthematchedhostgraphelementsinthematchobjects
ofthegenericmatchinterface.
IntherulerepresentationpassfromgenRuleOrSubpatternInitonthesubpattern-and
rule representations s of f type MatchingPattern and RulePattern are generated, including
thecontainedPatternGraph-objectsforthe(nested)patterngraph(s),inamutualrecursion
gameofgenPatternGraphandgenElementsRequiredByPatternGraph.
The method genElementsRequiredByPatternGraph h generates for r a a pattern n graph its
containedelements,thepatternnodes,thepatternedges,theusedsubpatternsasPattern-
GraphEmbeddingmembers,thecontainedalternatives,andtheiterateds;therepresentations
ofcontainednegativesubpatternsandalternativecasesgetgeneratedviagenPatternGraph
beforethecontainingpattern.
Agraphelementcontainedinpattern,butdenedinanestingpattern,issavedinthe
patternas areferencetotheelement inthenestingpattern. . The e PatternGraphinwhich
it wasusedrstis rememberedina PointOfDefinition-membervariable. . Thesourceand
targetnodes ofedgesaresavedinthe PatternGraphinhashtables (sothat anedgewith
anundenedtarget canreceiveatarget inanestedpattern),sourceandtargetnodesare
determinedbyascendingalongthepatternnestinguntiladenitionisfound.
As all l graph elements, including the ones s of the nested d patterns, are created atly in
theinitialize-methodoftheMatchingPattern,nameprexesareneededtopreventname
clashes;thisisensuredbytheparameter pathPrefix. . Correctnamingofalreadydeclared
elements is ensuredwitha alreadyDefinedEntityToName-hash-table. . The e split intocon-
structor and d initialize-Methode ist t neededbecause arecursive MatchingPattern must
referenceitselfatconstruction.
Furthermore expressions s trees for r the attribute e checks are e generated, , as s well as s local
andglobalhomomorphytablesforthenodesandtheedges,deningwhichpatternelements
maymatchthesamehostgraphelement(theglobaltablesspecifythehomomorphyinbe-
tweenelementsfromthePatternGraphofanalternativecaseoraniteratedandanenclosing
PatternGraph).
RewriteCodePass
Intherewritepasstherewritecodegetsgenerated,viagenModifyofModifyGen;thenesting
ofnegative or independent patterns does not needtobe takencare ofhereas they don’t
possessrewriteparts.
Foreverypatternpieceanditsrewriterole(dependentrewriting,creation,deletion)are
local rewrite methods generated, , bringing at t runtime the overall l rewriting into eect t by
26.4 TheCodeGenerator
353
calling eachother. . ModifyGenerationState e holds the state during generation, , while the
ModifyGenerationTasks allowtogivea leftand d right t graphindependent oftherewriting
speciedwith the rule. . The e codefor subpattern creation isgeneratedbyusing anempty
graphasleftgraphandthepatterngraphasrightgraph,thecodeforsubpatterndeletionis
generatedbyusingthepatterngraphasleftgraphandanemptygraphasrightgraph,for
adependentrewritethegraphsfromIR::Rulearesimplyreferenced,foratestthepattern
graphis usedasleft and d right t graph. . For r alternatives anditeratedsdispatching methods
getgeneratedcallingtherewritemethodsoftheinstancesofthepatternsmatched.Rewrite
parametersaremappedtolocalparametersoftherewritemethods.
Thecore methodofrewrite codegenerationgenModifyRuleOr-Subrule generates the
rewritingofthe givenpatternandthecalls totherewritemethods ofthenestedpatterns.
Becausetherewritemethodsofthenestedpatternsareplaced atlyintheirMatchingPattern
orRulePattern,they receive theirnestingpathasnameprex,their roleisdistinguished
by one ofthe name postxs Modify, , CreateorDelete; forkeepingapatternunmodied
obviouslynomethodsareneeded.
For embedded d sequences s LGSPEmbeddedSequenceInfo objects are generated, , which do
contain the e sequence e as s string g plus additional parameter r informations, , the real l sequence
code is s generated in the e backend. . For r sequences embedded d in alternatives, iterateds, , or
subpatternsadditionallyclosureclassesinheritingfromLGSPEmbeddedSequenceClosureare
generated.Theystorethegraphelementsthepatternelementswereboundtoofthepattern
containingtheexec;thesequenceexecutionfunctionisthencalledfromthisclosure,which
isstoredinaqueueandexecutedfromthetoplevelrule.
Finallymatchclassesaregenerated,foreverypatternbesidesnegativepatternsaninter-
faceandaclassimplementingthisinterface.Thematchclassesareinstantiatedafteramatch
ofthecorrespondingpatternwasfound,givingahighlyconvenientandtypesafeinterfaceto
thematchedentitiestotheuseratAPIlevel.
26.4.2 Backend
Therealmatchercodeisgeneratedbythebackendgiveninengine-net-2,inthesrc/lgspBackend
subdirectory. Theprocessing g is done inseveralpasses inlgspMatcherGenerator.cs; the
base data structureis s the e PatternGraph,resp. . the e nestingof the PatternGraph-objects,
containedintheRulePattern-objectsoftherules/testsortheMatchingPattern-objectsof
thesubpatterns.
354
UnderstandingandExtendingGrGen.NET
1.Step
SearchPlanGraph
Graph-
analysis
data
GeneratePlanGraph
MarkMinimumSpanningArborescence
GenerateSearchPlanGraph
ScheduleSearchPlan
AppendHomomorphyInformation
PatternGraph
. . .
PatternGraph
. . .
Schedule
PlanGraph
Scheduled
SearchPlan
InlineSubpatternUsages
Figure26.24:BackendCodeGeneration,step1
First the subpatternusages are inlined d wheninlining is s assumed d to be benecial; this
allowstheprogrammertoextractcommonpatternsintosubpatternsincreasingreadability
and modularity y without t loosing performance e (but as s of now w only y one level of f inlining is
supported, so beware of toomuch subpattern extraction, especially y ifthe containing pat-
ternwouldget disconnectedby this). . After(andpartly y before)thispatternrewritingthe
patterns andtheir relations areanalyzedby the PatternGraphAnalyzer {theanalyzere-
sults are usedfor emitting better code later on(choosingmore ecient but morelimited
implementations for language featureswhichare not sucientin n the generalcasebut t are
soforthespecicationathand). ThenaPlanGraphiscreatedfromthePatternGraphand
data from analyzingthe host graph (for generating the initial matcher some default data
givenfromthefrontendis used). . Aminimumspanningarborescenceis s computeddening
ahopefullyoptimalsetofoperations for matchingthepattern(thehopes arefounded,see
[BKG08]). ASearchPlanGraph h is s built fromthe arborescence marked d inthe PlanGraph
andusedthereafterforschedulingtheoperationsintoaScheduledSearchPlan,whichgets
completedby AppendHomomorphyInformation withisomorphy checkinginformation. . The
ScheduledSearchPlanisthenstoredinthePatternGraphitwascomputedfrom.
2.Step
PatternGraph
. . .
Schedule
NegPatternGraph
Schedule
PatternGraph
. . .
Schedule
InclNegIdpt
MergeNegativeAndIndependentSchedules
IntoEnclosingSchedules
IdptPatternGraph
Schedule
Figure26.25:BackendCodeGeneration,step2
InasecondsteptheSchedulesofthenegativeorindependentPatternGraphsareinte-
gratedintotheScheduleoftheenclosingPatternGraph,byMergeNegativeAndIndependent-
SchedulesIntoEnclosingSchedules in a recursive run over the e nesting structure e of the
PatternGraphs inthe MatchingPatterns orRulePatterns. . Duetonestednegativeorin-
dependent graphs this may happenspanningseveral l nesting levels; the result t is s saved in
theScheduleIncludingNegativesAndIndependentseldofthenon-negative/independent
PatternGraphs.
26.4 TheCodeGenerator
355
3.Step
C#-Code
Action
Matcher
Assembly
SearchProgramBuilder
(Rule)
Emit
Rule Pattern
PatternGraph
Alternative
AltPatternGraph
Subpattern
. . .
SPr u.     SPr c.
MatchingPattern
PatternGraph
. . .
. . .
points to
SearchProgramCompleter
SPr u.     SPr c.
SearchProgramCompleter
(Alternative)
SearchProgramBuilder
SearchProgramBuilder
(Subpattern)
SPr u.     SPr c.
SearchProgramCompleter
C#-Code
AlternativeAction
C#-Code
PatternAction
Emit
Emit
C#-Compiler
C#-Compiler
C#-Compiler
Schedule
InclNegIdpt
Schedule
InclNegIdpt
Schedule
InclNegIdpt
IterPatternGraph
Schedule
InclNegIdpt
Emit
SPr u.     SPr c.
SearchProgramCompleter
(Iterated)
SearchProgramBuilder
C#-Code
IteratedAction
C#-Compiler
Figure26.26:BackendCodeGeneration,step3
Finally,inathirdstepcodeisgeneratedbyGenerateMatcherSourceCode,againinare-
cursiverunoverthenestingstructureofthePatternGraphs,usingtheScheduleIncluding-
NegativesAndIndependentsstoredinthem.
Foreach RulePattern n anAction-class is generated, , andfor r eachMatchingPattern a
SubpatternAction-classisgenerated. Additionallyforeachalternativeoriteratedwhichis
nestedinarule,test,orsubpattern,anAlternativeAction-classoranIteratedAction-
classaregenerated;thealternativematcherwillcontaincodeforallalternativecases. The
realmatchingcodeisthengeneratedintotheseclasses.
TheSearchProgramBuilderbuildsaSearchProgramtreedatastructureresemblingthe
syntaxtreeofthecodetogenerateoutoftheScheduleIncludingNegativesAndIndependents
inthePatternGraphs. Inafurtherpass s theSearchProgramiscompletedby the Search-
ProgramCompleter,determiningthelocationstocontinueatwhenacheckfails,writingundo
codefortheeectswhichwereappliedfromthatpointontothecurrentone.FinallytheC#
codegetsgeneratedbycallingtheEmitmethodsoftheSearchProgram. Ifyouwanttoex-
tendsthiscodeyoumaybeinterestedintheDumpmethodswhichdumptheSearchProgram
inaneasierreadableformintotextles.
The SubpatternAction-classes s do o not t only y contain n the matcher code, but t are at t the
sametimethetasks ofthe 2+n pushdownmachine,whicharepushedonthe opentasks
stack; they contain the subpattern parameters as s member r variables. . The e same holds for
the AlternativeAction-and IteratedAction-classes, which donot holdparameters but
entitiesfromthenestingpatterntheyreference.
356
UnderstandingandExtendingGrGen.NET
NestedandSubpatternMatching
Thehigherlevelsofcodegenerationareinlargepartsindependentfromnestedandsubpattern
matchingandcontrolofthe2+npushdownmachine.Onlyonthelevelofsearchprogramsit
becomesvisible,withanInitializeSubpatternMatching-searchprogramoperationatthe
beginofasearchprogramandaFinalizeSubpatternMatching-searchprogramoperationat
theendofasearchprogram;butmainlywithacalltobuildMatchCompletewhentheendof
thescheduleisreachedduringsearchprogrambuilding. Thiscorrespondstotheinnermost
location inthe search program, the location at which during execution the e local l pattern
wasjustfound;nowthecontrolcodeisinsertedbyinsertPushSubpatternTasks,pushing
the tasks forthe subpatterns usedfromthis pattern,aswellasalternatives and iterateds
nestedinthispattern. ToexecutetheopentasksaMatchSubpatternsoperationisinserted
intothesearchprogram.AfterwardsinsertPopSubpatternTasksinsertstheoperationsfor
cleaningthetaskstack,insertCheckForSubpatternsFoundtheoperationstohandlesuccess
andfailure,andinsertMatchObjectBuildingthecodeformaintainingtheresultstack.
FurtherFunctionality
ThecompiledgraphrewritesequencesarehandledbythelgspSequenceCheckerandlgsp-
SequenceGenerator (together with h the sequence parser r fromthe libGr). . The e src/GrGen
subdirectorycontainsthegrgen.execompilerdriverprocedure.Thesrc/libGrsubdirectory
contains the libGr, , oering g the e base interfaces s a a user of GrGen.NET sees on n the e API
levelforthemodel,theactions,thepatterngraphsandthehostgraph. Theinterfacesget
implementedbycodefromthelibGrsearchplan(lgsp)backendandbythegeneratedcode.
ThelibGrfurtheroersageneric,namestringandobjectbasedinterfacetoaccessthenamed
entities ofthegeneratedcode. . Inadditionit t oerstherewritesequenceparserwhichgets
generatedoutof SequenceParser.csc,buildingtherewritesequenceASTfromtheclasses
inSequence.csfurtherutilizingSymbolTable.cs. Therewritesequenceclassescontaina
method ApplyImpl(IGraph h graph) ) which h executes s them. . Finally y thelibGr oers several
importersandexportersinthesrc/libGr/IOsubfolder.
WhenGrGenrulesarematched,aswellaswhenthegraphischanged,eventsarered.
They allowtoto display the matches andchanges tothe user inthe debugger, , torecord
changestoaleforlaterplayback,orrecordchangestoatransactionundologforlaterroll-
back,ortoexecuteusercodeifeventhandlersareregisteredtothem,allowinguserstobuild
aneventbasedgraphrewritingmechanismonAPIlevel.Thegraphdelegatesredaregivenin
IGraph.cs.GrapheventsrecordingisimplementedinRecorder.cs(replayingisnormal.grs
execution);graphtransactionhandlingisimplementedinlgspTransactionManager.cs,with
alist ofundoitems whichknowhowtoundotheeectonthegraphwhichcreatedthem,
which are purged oncommit or r executed d on rollback. . Backtracking g is implementedwith
nestedtransactions.IfyouarechangingthegraphprogrammaticallynotusingGrGenrules
youhavetoretheeventsonyourownincaseyouwanttouseanyofthemechanisms(graph-
icaldebugging,recordandreplay,transactionsandbacktracking,eventbasedprogramming)
above.
Thesrc/GrShellsubdirectorycontainstheGrShellapplication,whichbuildsuponthe
generic interface(as it must be capable of coping witharbitraryuseddenedmodels and
actions at runtime) and d the sequence interpretation facilities s oered d by y the libGr. . The
commandlineparserofGrShellgetsgeneratedoutofGrShell.csc,theshellimplementation
is giveninGrShellImpl.cs. . Graphicaldebuggingis s oeredbythe Debugger.cs together
withtheYCompClient.cs,whichimplements theprotocolavailableforcontrollingyComp,
communicatingwithyCompoveratcpconnectiontolocalhost.
Theexamplessubdirectoryofengine-net-2containsabunchofexamplesforusingGr-
Gen.NETwithGrShell. Theexamples-apisubdirectorycontainsseveralexamplesofhow
touseGrGen.NETfromtheAPI.Incaseyouwanttocontributeandgotfurtherquestions
Documents you may be interested
Documents you may be interested