Class CppTarget


  • public class CppTarget
    extends Target
    • Field Detail

      • cppKeywords

        protected static final String[] cppKeywords
      • badWords

        protected final Set<String> badWords
        Avoid grammar symbols in this set to prevent conflicts in gen'd code.
    • Method Detail

      • getVersion

        public String getVersion()
        Description copied from class: Target
        ANTLR tool should check output templates / target are compatible with tool code generation. For now, a simple string match used on x.y of x.y.z scheme. We use a method to avoid mismatches between a template called VERSION. This value is checked against Tool.VERSION during load of templates. This additional method forces all targets 4.3 and beyond to add this method.
        Specified by:
        getVersion in class Target
      • needsHeader

        public boolean needsHeader()
        Overrides:
        needsHeader in class Target
      • getBadWords

        public Set<String> getBadWords()
      • addBadWords

        protected void addBadWords()
      • getTargetStringLiteralFromANTLRStringLiteral

        public String getTargetStringLiteralFromANTLRStringLiteral​(CodeGenerator generator,
                                                                   String literal,
                                                                   boolean addQuotes)

        Convert from an ANTLR string literal found in a grammar file to an equivalent string literal in the target language.

        For Java, this is the translation 'a\n"'"a\n\"". Expect single quotes around the incoming literal. Just flip the quotes and replace double quotes with \".

        Note that we have decided to allow people to use '\"' without penalty, so we must build the target string in a loop as String.replace(char, char) cannot handle both \" and " without a lot of messing around.

        For C++, this is the translation 'a\n"'"a\n\"". Expect single quotes around the incoming literal. Just flip the quotes and replace double quotes with \".

        Note that we have decided to allow people to use '\"' without penalty, so we must build the target string in a loop as String.replace(char, char) cannot handle both \" and " without a lot of messing around.

        Overrides:
        getTargetStringLiteralFromANTLRStringLiteral in class Target
      • getSerializedATNSegmentLimit

        public int getSerializedATNSegmentLimit()
        Description copied from class: Target
        Gets the maximum number of 16-bit unsigned integers that can be encoded in a single segment of the serialized ATN.
        Overrides:
        getSerializedATNSegmentLimit in class Target
        Returns:
        the serialized ATN segment limit
        See Also:
        SerializedATN.getSegments()
      • getRecognizerFileName

        public String getRecognizerFileName​(boolean header)
        Description copied from class: Target
        Generate TParser.java and TLexer.java from T.g4 if combined, else just use T.java as output regardless of type.
        Overrides:
        getRecognizerFileName in class Target
      • getListenerFileName

        public String getListenerFileName​(boolean header)
        Description copied from class: Target
        A given grammar T, return the listener name such as TListener.java, if we're using the Java target.
        Overrides:
        getListenerFileName in class Target
      • getVisitorFileName

        public String getVisitorFileName​(boolean header)
        Description copied from class: Target
        A given grammar T, return the visitor name such as TVisitor.java, if we're using the Java target.
        Overrides:
        getVisitorFileName in class Target
      • getBaseListenerFileName

        public String getBaseListenerFileName​(boolean header)
        Description copied from class: Target
        A given grammar T, return a blank listener implementation such as TBaseListener.java, if we're using the Java target.
        Overrides:
        getBaseListenerFileName in class Target
      • getBaseVisitorFileName

        public String getBaseVisitorFileName​(boolean header)
        Description copied from class: Target
        A given grammar T, return a blank listener implementation such as TBaseListener.java, if we're using the Java target.
        Overrides:
        getBaseVisitorFileName in class Target
      • loadTemplates

        protected org.stringtemplate.v4.STGroup loadTemplates()
        Overrides:
        loadTemplates in class Target