compiler/PPCCompilationOptions.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 04 Sep 2015 14:06:56 +0100
changeset 535 a8feb0f47574
parent 534 a949c4fe44df
child 538 16e8536f5cfb
permissions -rw-r--r--
PPCConfiguration refactoring: [7/10]: allow to configure passes ...run during compilation by setting a collection of passes to run. Got rid of PPCPluggableConfiguration and PPCConfiguration subclasses. Removed a bunch of options used to suppress certain passes.

"{ Package: 'stx:goodies/petitparser/compiler' }"

"{ NameSpace: Smalltalk }"

Object subclass:#PPCCompilationOptions
	instanceVariableNames:'options'
	classVariableNames:''
	poolDictionaries:''
	category:'PetitCompiler-Core'
!

!PPCCompilationOptions class methodsFor:'as yet unclassified'!

default
    ^ self new
!

new
    ^ self basicNew 
        initialize;
        yourself
! !

!PPCCompilationOptions methodsFor:'initialization'!

initialize
    super initialize.
    options := IdentityDictionary new
! !

!PPCCompilationOptions methodsFor:'options'!

mode
    ^ self at: #mode ifAbsent: #JIT

    "Created: / 26-08-2015 / 23:18:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

mode: mode
    "Set the compilation mode - valid values are #JIT or #AOT.

     #JIT mode put less constraints on the original pure PetitParser
       parser (such as action blocks are not required to be purely functional,
       support mixing of compiled parsing code with custom PPParsers and so on).
       However, JIT-compiled parser class SHOULD NOT be commited into the
       repository - it won't work when loaded back. 

     #AOT mode allows for parser to be pre-compiled and generated code
       to be commited to repository. Thus, the deployed application don't need
       to contain full PetitCompiler. However, this is at cost of more contraints
       being put on the original Petit Parser. In other words, not all PetitParser
       parser may be compiled in AOT mode.
       WARNING: #AOT mode is not yet fully supported, do not use!!
    "

    (#(JIT AOT) includes: mode) ifFalse:[ 
        PPCCompilationError new signal: 'Invalid mode: option value - must be either #JIT or #AOT'.
    ].
    mode == #AOT ifTrue:[ 
        PPCCompilationWarning new signal: '#AOT mode not yet supported'.
    ].
    self at: #mode put: mode

    "Created: / 26-08-2015 / 23:07:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

parserName
    ^ self at: #parserName ifAbsent: #PPGeneratedParser

    "Modified (format): / 26-08-2015 / 23:04:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

parserName: aSymbol
    "Sets the name of the generated parser class.
     Defaults to #PPGeneratedParser."

    self set: #parserName to: aSymbol.

    "Modified (comment): / 26-08-2015 / 23:05:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

scannerName
    ^ self at: #scannerName ifAbsent: #PPGeneratedScanner
!

scannerName: value
    "Sets the name of the generated parser class.
     Defaults to #PPGeneratedScanner."    

    self set: #scannerName to: value.

    "Modified (comment): / 26-08-2015 / 23:06:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

tokenize
    ^ self at: #tokenize ifAbsent: false

    "Modified: / 04-09-2015 / 15:53:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

tokenize: aBoolean
    "Build tokenizing parser, i.e., build scanner that tokenizes the input and then
     parser consuming tokens produced by scanner.

     Tokenizing parser more resemble hand-written top-down parser and
     makes hand-tuning of the parser / scanner easier. However, not all
     PetitParsers may be tokenized.

     Default value is true. If the compilation fails, try to set it to
     false
    "    
    self set: #tokenize to: aBoolean.

    "Modified (comment): / 26-08-2015 / 23:24:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!PPCCompilationOptions methodsFor:'options - undocumented (do not use)'!

debug
    ^ self at: #debug ifAbsent: true
!

debug: value
    self set: #debug to: value.
!

generate
    ^ self at: #generate ifAbsent: true
!

generate: value
    ^ self set: #generate to: value
!

guards
    ^ self at: #guards ifAbsent: true
!

guards: value
    self set: #guards to: value.
!

parserSuperclass
    ^ self at: #parserSuperclass ifAbsent: nil

    "Modified: / 04-09-2015 / 16:06:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

parserSuperclass: value
    self set: #parserSuperclass to: value.
!

profile
    ^ self at: #profile ifAbsent: false
!

profile: value
    self set: #profile to: value.
!

scannerSuperclass
    ^ self at: #scannerSuperclass ifAbsent: PPCDistinctScanner
!

scannerSuperclass: value
    self set: #scannerSuperclass to: value.
! !

!PPCCompilationOptions methodsFor:'private'!

at: symbol ifAbsent: defaultValue
    ^ options at: symbol ifAbsent: [ ^ defaultValue  ]
!

set: symbol to: defaultValue
    ^ options at: symbol put: defaultValue 
! !