• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Community
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • Soft
        • C
        • Bv
        • Imp-language
        • Event-macros
        • Java
          • Atj
            • Atj-implementation
              • Atj-types
              • Atj-java-primitive-array-model
              • Atj-java-abstract-syntax
              • Atj-input-processing
              • Atj-java-pretty-printer
              • Atj-code-generation
                • Atj-gen-test-method
                • Atj-shallow-code-generation
                • Atj-common-code-generation
                  • Atj-gen-value
                  • Atj-chars-to-jhexcodes
                  • Atj-gen-test-value
                  • Atj-gen-test-main-method
                  • Atj-gen-value-flat
                  • Atj-gen-test-values
                  • Atj-gen-jlocvar-indexed
                  • Atj-gen-pkg-method
                  • Atj-gen-symbol
                  • Atj-gen-jstring
                    • Atj-gen-init-method
                    • Atj-gen-char
                    • Atj-gen-string
                    • Atj-gen-pkg-name
                    • Atj-gen-integer
                    • Atj-gen-test-method-name
                    • Atj-gen-paramlist
                    • Atj-gen-pkg-method-name
                    • Atj-gen-run-tests
                    • Atj-gen-jshort-array
                    • Atj-gen-jboolean-array
                    • Atj-gen-test-failures-field
                    • Atj-gen-pkgs
                    • Atj-gen-jlong-array
                    • Atj-gen-jint-array
                    • Atj-gen-jchar-array
                    • Atj-gen-jchar
                    • Atj-gen-jbyte-array
                    • Atj-char-to-jhexcode
                    • Atj-gen-pkg-methods
                    • Atj-gen-number
                    • Atj-gen-symbols
                    • Atj-gen-static-initializer
                    • Atj-gen-rational
                    • Atj-gen-jlong
                    • Atj-gen-jboolean
                    • Atj-gen-jbigint
                    • Atj-gen-jshort
                    • Atj-gen-jint
                    • Atj-gen-jbyte
                    • *atj-gen-pkg-name-alist*
                  • Atj-shallow-quoted-constant-generation
                  • Atj-pre-translation
                  • Atj-gen-everything
                  • Atj-name-translation
                  • Atj-gen-test-cunit
                  • Atj-gen-test-class
                  • Atj-gen-main-file
                  • Atj-post-translation
                  • Atj-deep-code-generation
                  • Atj-gen-test-methods
                  • Atj-gen-test-file
                  • Atj-gen-env-file
                  • Atj-gen-output-subdir
                • Atj-java-primitives
                • Atj-java-primitive-arrays
                • Atj-type-macros
                • Atj-java-syntax-operations
                • Atj-fn
                • Atj-library-extensions
                • Atj-java-input-types
                • Atj-test-structures
                • Aij-notions
                • Atj-macro-definition
              • Atj-tutorial
            • Aij
            • Language
          • Bitcoin
          • Ethereum
          • Yul
          • Zcash
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Atj-common-code-generation

    Atj-gen-jstring

    Generate Java code to build a Java string from an ACL2 string.

    Signature
    (atj-gen-jstring string) → expr
    Arguments
    string — Guard (stringp string).
    Returns
    expr — Type (jexprp expr).

    Often, an ACL2 string can be turned into a Java string literal that is valid when pretty-printed. Examples are "abc" or "x-y @ 5.A".

    However, if the ACL2 string includes characters like #Return, attempting to turn that into a Java string literal may result in an invalid one when pretty-printed. In this case, a safe way to build the Java string is via a Java character array with an initializer consisting of the codes of the ACL2 string.

    If the ACL2 string consists of only pritable ASCII characters (i.e. space and visible ASCII characters), we turn it into a Java string literal. Otherwise, we turn it into a Java array creation expression that is passed as argument to a Java class instance creation expression for a String object.

    Definitions and Theorems

    Function: atj-gen-jstring

    (defun atj-gen-jstring (string)
     (declare (xargs :guard (stringp string)))
     (let ((__function__ 'atj-gen-jstring))
      (declare (ignorable __function__))
      (b* ((chars (explode string)))
       (if (str::printable-charlist-p chars)
           (jexpr-literal-string string)
        (jexpr-newclass
         (jtype-class "String")
         (list
              (jexpr-newarray-init (jtype-char)
                                   (atj-chars-to-jhexcodes chars))))))))

    Theorem: jexprp-of-atj-gen-jstring

    (defthm jexprp-of-atj-gen-jstring
      (b* ((expr (atj-gen-jstring string)))
        (jexprp expr))
      :rule-classes :rewrite)