Top Fields Constructors Methods
org.antlr.codegen

public Class CTarget

extends Target
Class Inheritance
Imports
org.antlr.Tool, org.stringtemplate.v4.ST, org.antlr.tool.Grammar, java.io.IOException, java.util.ArrayList, .List

Field Summary

Modifier and TypeField and Description
pack-priv List<String>
Inherited from org.antlr.codegen.Target:
targetCharValueEscape

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected ST
chooseWhereCyclicDFAsGo(Tool tool, CodeGenerator generator, Grammar grammar, ST recognizerST, ST cyclicDFAST)

protected void
protected void
public String
getTargetCharLiteralFromANTLRCharLiteral(CodeGenerator generator, String literal)

Overrides org.antlr.codegen.Target.getTargetCharLiteralFromANTLRCharLiteral.

Convert from an ANTLR char literal found in a grammar file to an equivalent char literal in the target language.
public String
getTargetStringLiteralFromANTLRStringLiteral(CodeGenerator generator, String literal)

Overrides org.antlr.codegen.Target.getTargetStringLiteralFromANTLRStringLiteral.

Convert from an ANTLR string literal found in a grammar file to an equivalent string literal in the C target.
public boolean
isValidActionScope(int grammarType, String scope)

Overrides org.antlr.codegen.Target.isValidActionScope.

Is scope in @scope::name {action} valid for this kind of grammar?
protected void
performGrammarAnalysis(CodeGenerator
An instance of the generic code generator class.
generator
,
Grammar
The grammar that we are currently analyzing
grammar
)

Overrides org.antlr.codegen.Target.performGrammarAnalysis.

Overrides the standard grammar analysis so we can prepare the analyser a little differently from the other targets.
Inherited from org.antlr.codegen.Target:
encodeIntAsCharEscapegetMaxCharValuegetTarget64BitStringFromValuegetTargetStringLiteralFromStringgetTargetStringLiteralFromStringgetTokenTypeAsTargetLabelpostProcessActionuseBaseTemplatesForSynPredFragments

Field Detail

stringsback to summary
pack-priv List<String> strings

Constructor Detail

CTargetback to summary
public CTarget()

Method Detail

chooseWhereCyclicDFAsGoback to summary
protected ST chooseWhereCyclicDFAsGo(Tool tool, CodeGenerator generator, Grammar grammar, ST recognizerST, ST cyclicDFAST)
genRecognizerFileback to summary
protected void genRecognizerFile(Tool tool, CodeGenerator generator, Grammar grammar, ST outputFileST) throws IOException

Overrides org.antlr.codegen.Target.genRecognizerFile.

Annotations
@Override
genRecognizerHeaderFileback to summary
protected void genRecognizerHeaderFile(Tool tool, CodeGenerator generator, Grammar grammar, ST headerFileST, String extName) throws IOException

Overrides org.antlr.codegen.Target.genRecognizerHeaderFile.

Annotations
@Override
getTargetCharLiteralFromANTLRCharLiteralback to summary
public String getTargetCharLiteralFromANTLRCharLiteral(CodeGenerator generator, String literal)

Overrides org.antlr.codegen.Target.getTargetCharLiteralFromANTLRCharLiteral.

Doc from org.antlr.codegen.Target.getTargetCharLiteralFromANTLRCharLiteral.

Convert from an ANTLR char literal found in a grammar file to an equivalent char literal in the target language. For most languages, this means leaving 'x' as 'x'. Actually, we need to escape ' ' so that it doesn't get converted to \n by the compiler. Convert the literal to the char value and then to an appropriate target char literal. Expect single quotes around the incoming literal.

Annotations
@Override
getTargetStringLiteralFromANTLRStringLiteralback to summary
public String getTargetStringLiteralFromANTLRStringLiteral(CodeGenerator generator, String literal)

Overrides org.antlr.codegen.Target.getTargetStringLiteralFromANTLRStringLiteral.

Convert from an ANTLR string literal found in a grammar file to an equivalent string literal in the C target. Because we must support Unicode character sets and have chosen to have the lexer match UTF32 characters, then we must encode string matches to use 32 bit character arrays. Here then we must produce the C array and cater for the case where the lexer has been encoded with a string such as 'xyz\n',

Annotations
@Override
isValidActionScopeback to summary
public boolean isValidActionScope(int grammarType, String scope)

Overrides org.antlr.codegen.Target.isValidActionScope.

Is scope in @scope::name {action} valid for this kind of grammar? Targets like C++ may want to allow new scopes like headerfile or some such. The action names themselves are not policed at the moment so targets can add template actions w/o having to recompile ANTLR.

Annotations
@Override
performGrammarAnalysisback to summary
protected void performGrammarAnalysis(CodeGenerator generator, Grammar grammar)

Overrides org.antlr.codegen.Target.performGrammarAnalysis.

Overrides the standard grammar analysis so we can prepare the analyser a little differently from the other targets. In particular we want to influence the way the code generator makes assumptions about switchs vs ifs, vs table driven DFAs. In general, C code should be generated that has the minimum use of tables, and tha meximum use of large switch statements. This allows the optimizers to generate very efficient code, it can reduce object code size by about 30% and give about a 20% performance improvement over not doing this. Hence, for the C target only, we change the defaults here, but only if they are still set to the defaults.

Parameters
generator:CodeGenerator

An instance of the generic code generator class.

grammar:Grammar

The grammar that we are currently analyzing

Annotations
@Override