• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • 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
          • Syntax-for-tools
            • Disambiguator
            • Abstract-syntax
            • Parser
            • Validator
              • Valid-exprs/decls/stmts
              • Valid-stmt
              • Valid-expr
              • Valid-dirdeclor
              • Valid-type-spec
              • Valid-transunit
              • Valid-stor-spec-list
              • Valid-binary
              • Valid-unary
              • Valid-initdeclor
              • Valid-fundef
              • Valid-type-spec-list-residual
              • Valid-cond
              • Valid-lookup-ord
              • Valid-transunit-ensemble
              • Valid-declor
              • Valid-iconst
              • Valid-initer
              • Valid-c-char
              • Valid-stringlit-list
              • Valid-funcall
              • Valid-add-ord
              • Valid-arrsub
              • Valid-univ-char-name
              • Valid-extdecl
              • Valid-extdecl-list
              • Valid-cast
              • Valid-add-ord-file-scope
              • Valid-spec/qual
              • Valid-sizeof/alignof
              • Valid-memberp
              • Valid-decl-spec
              • Valid-var
              • Valid-param-declon
              • Valid-oct-escape
              • Valid-structdeclor
              • Valid-structdecl
              • Valid-designor
              • Valid-escape
              • Valid-enum-const
              • Valid-cconst
                • Valid-s-char
                • Valid-dec/oct/hex-const
                • Valid-const
                • Valid-gensel
                • Valid-decl-spec-list
                • Valid-lookup-ord-file-scope
                • Valid-member
                • Valid-param-declor
                • Valid-spec/qual-list
                • Valid-fconst
                • Valid-stringlit
                • Valid-s-char-list
                • Valid-c-char-list
                • Valid-block-item
                • Valid-structdeclor-list
                • Valid-simple-escape
                • Valid-align-spec
                • Valid-enumer
                • Valid-dirabsdeclor
                • Valid-decl
                • Valid-pop-scope
                • Valid-enumspec
                • Valid-declor-option
                • Valid-push-scope
                • Valid-initer-option
                • Valid-block-item-list
                • Valid-absdeclor
                • Valid-label
                • Valid-genassoc
                • Valid-tyname
                • Valid-strunispec
                • Valid-structdecl-list
                • Valid-genassoc-list
                • Valid-dirabsdeclor-option
                • Valid-designor-list
                • Valid-const-expr
                • Valid-initdeclor-list
                • Valid-desiniter-list
                • Valid-absdeclor-option
                • Valid-table-num-scopes
                • Valid-expr-list
                • Valid-param-declon-list
                • Valid-desiniter
                • Valid-const-expr-option
                • Valid-expr-option
                • Valid-statassert
                • Valid-enumer-list
                • Valid-init-table
                • Valid-empty-scope
                • Valid-member-designor
                • Valid-decl-list
              • Printer
              • Formalized-subset
              • Mapping-to-language-definition
              • Input-files
              • Defpred
              • Output-files
              • Abstract-syntax-operations
              • Validation-information
              • Implementation-environments
              • Concrete-syntax
              • Unambiguity
              • Ascii-identifiers
              • Preprocessing
              • Abstraction-mapping
            • Atc
            • Language
            • Representation
            • Transformation-tools
            • Insertion-sort
            • Pack
          • Bv
          • Imp-language
          • Event-macros
          • Java
          • 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
    • Validator

    Valid-cconst

    Validate a character constant.

    Signature
    (valid-cconst cconst) → (mv erp type)
    Arguments
    cconst — Guard (cconstp cconst).
    Returns
    type — Type (typep type).

    We check the characters that form the constant, with respect to the prefix (if any). If validation is successful, we return the type of the constant. According to [C17:6.4.4.4/10], a character constant without prefix has type int. According to [C17:6.4.4.4/11], a character constant with a prefix has type wchar_t, char16_t, or char32_t; since for now we do not model these, we return an unknown type in this case.

    The types wchar_t, char16_t, and char32_t may vary across implementations. In order to handle these in a general way, we should probably extend our implementation environments with information about which built-in types those types expand to. Once we do that, we will be able to perform a full validation of character constants here.

    Definitions and Theorems

    Function: valid-cconst

    (defun valid-cconst (cconst)
      (declare (xargs :guard (cconstp cconst)))
      (let ((__function__ 'valid-cconst))
        (declare (ignorable __function__))
        (b* (((reterr) (irr-type))
             ((cconst cconst) cconst)
             ((erp &)
              (valid-c-char-list cconst.cchars cconst.prefix?)))
          (if cconst.prefix? (retok (type-unknown))
            (retok (type-sint))))))

    Theorem: typep-of-valid-cconst.type

    (defthm typep-of-valid-cconst.type
      (b* (((mv acl2::?erp ?type)
            (valid-cconst cconst)))
        (typep type))
      :rule-classes :rewrite)

    Theorem: valid-cconst-of-cconst-fix-cconst

    (defthm valid-cconst-of-cconst-fix-cconst
      (equal (valid-cconst (cconst-fix cconst))
             (valid-cconst cconst)))

    Theorem: valid-cconst-cconst-equiv-congruence-on-cconst

    (defthm valid-cconst-cconst-equiv-congruence-on-cconst
      (implies (cconst-equiv cconst cconst-equiv)
               (equal (valid-cconst cconst)
                      (valid-cconst cconst-equiv)))
      :rule-classes :congruence)