• 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-iconst

    Validate an integer constant.

    Signature
    (valid-iconst iconst ienv) → (mv erp new-iconst type)
    Arguments
    iconst — Guard (iconstp iconst).
    ienv — Guard (ienvp ienv).
    Returns
    new-iconst — Type (iconstp new-iconst).
    type — Type (typep type).

    An integer constant is valid iff it has a type according to the table in [C17:6.4.4.1/5]. We formalize that table here, and we return the type of the constant. If the constant is too large, it does not have a type, and it is invalid.

    Definitions and Theorems

    Function: valid-iconst

    (defun valid-iconst (iconst ienv)
     (declare (xargs :guard (and (iconstp iconst) (ienvp ienv))))
     (let ((__function__ 'valid-iconst))
      (declare (ignorable __function__))
      (b*
       (((reterr) (irr-iconst) (irr-type))
        ((iconst iconst) iconst)
        (value (valid-dec/oct/hex-const iconst.core))
        ((erp type)
         (b* (((reterr) (irr-type)))
          (cond
           ((not iconst.suffix?)
            (if (dec/oct/hex-const-case iconst.core :dec)
                (cond ((sint-rangep value ienv)
                       (retok (type-sint)))
                      ((slong-rangep value ienv)
                       (retok (type-slong)))
                      ((sllong-rangep value ienv)
                       (retok (type-sllong)))
                      (t (reterr (msg "The constant ~x0 is too large."
                                      (iconst-fix iconst)))))
              (cond ((sint-rangep value ienv)
                     (retok (type-sint)))
                    ((uint-rangep value ienv)
                     (retok (type-uint)))
                    ((slong-rangep value ienv)
                     (retok (type-slong)))
                    ((ulong-rangep value ienv)
                     (retok (type-ulong)))
                    ((sllong-rangep value ienv)
                     (retok (type-sllong)))
                    ((ullong-rangep value ienv)
                     (retok (type-ullong)))
                    (t (reterr (msg "The constant ~x0 is too large."
                                    (iconst-fix iconst)))))))
           ((isuffix-case iconst.suffix? :u)
            (cond ((uint-rangep value ienv)
                   (retok (type-uint)))
                  ((ulong-rangep value ienv)
                   (retok (type-ulong)))
                  ((ullong-rangep value ienv)
                   (retok (type-ullong)))
                  (t (reterr (msg "The constant ~x0 is too large."
                                  (iconst-fix iconst))))))
           ((isuffix-case iconst.suffix? :l)
            (cond
             ((member-eq
                   (lsuffix-kind (isuffix-l->length iconst.suffix?))
                   '(:locase-l :upcase-l))
              (if (dec/oct/hex-const-case iconst.core :dec)
                  (cond ((slong-rangep value ienv)
                         (retok (type-slong)))
                        ((sllong-rangep value ienv)
                         (retok (type-sllong)))
                        (t (reterr (msg "The constant ~x0 is too large."
                                        (iconst-fix iconst)))))
                (cond ((slong-rangep value ienv)
                       (retok (type-slong)))
                      ((ulong-rangep value ienv)
                       (retok (type-ulong)))
                      ((sllong-rangep value ienv)
                       (retok (type-sllong)))
                      ((ullong-rangep value ienv)
                       (retok (type-ullong)))
                      (t (reterr (msg "The constant ~x0 is too large."
                                      (iconst-fix iconst)))))))
             ((member-eq
                   (lsuffix-kind (isuffix-l->length iconst.suffix?))
                   '(:locase-ll :upcase-ll))
              (if (dec/oct/hex-const-case iconst.core :dec)
                  (cond ((sllong-rangep value ienv)
                         (retok (type-sllong)))
                        (t (reterr (msg "The constant ~x0 is too large."
                                        (iconst-fix iconst)))))
                (cond ((sllong-rangep value ienv)
                       (retok (type-sllong)))
                      ((ullong-rangep value ienv)
                       (retok (type-ullong)))
                      (t (reterr (msg "The constant ~x0 is too large."
                                      (iconst-fix iconst)))))))
             (t (prog2$ (impossible) (reterr t)))))
           ((or
             (and
                 (isuffix-case iconst.suffix? :ul)
                 (member-eq
                      (lsuffix-kind (isuffix-ul->length iconst.suffix?))
                      '(:locase-l :upcase-l)))
             (and
                 (isuffix-case iconst.suffix? :lu)
                 (member-eq
                      (lsuffix-kind (isuffix-lu->length iconst.suffix?))
                      '(:locase-l :upcase-l))))
            (cond ((ulong-rangep value ienv)
                   (retok (type-ulong)))
                  ((ullong-rangep value ienv)
                   (retok (type-ullong)))
                  (t (reterr (msg "The constant ~x0 is too large."
                                  (iconst-fix iconst))))))
           ((or
             (and
                 (isuffix-case iconst.suffix? :ul)
                 (member-eq
                      (lsuffix-kind (isuffix-ul->length iconst.suffix?))
                      '(:locase-ll :upcase-ll)))
             (and
                 (isuffix-case iconst.suffix? :lu)
                 (member-eq
                      (lsuffix-kind (isuffix-lu->length iconst.suffix?))
                      '(:locase-ll :upcase-ll))))
            (cond ((ullong-rangep value ienv)
                   (retok (type-ullong)))
                  (t (reterr (msg "The constant ~x0 is too large."
                                  (iconst-fix iconst))))))
           (t (prog2$ (impossible) (reterr t))))))
        (info (make-iconst-info :type type
                                :value value))
        (new-iconst (change-iconst iconst :info info)))
       (retok new-iconst type))))

    Theorem: iconstp-of-valid-iconst.new-iconst

    (defthm iconstp-of-valid-iconst.new-iconst
      (b* (((mv acl2::?erp ?new-iconst ?type)
            (valid-iconst iconst ienv)))
        (iconstp new-iconst))
      :rule-classes :rewrite)

    Theorem: typep-of-valid-iconst.type

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

    Theorem: valid-iconst-of-iconst-fix-iconst

    (defthm valid-iconst-of-iconst-fix-iconst
      (equal (valid-iconst (iconst-fix iconst) ienv)
             (valid-iconst iconst ienv)))

    Theorem: valid-iconst-iconst-equiv-congruence-on-iconst

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

    Theorem: valid-iconst-of-ienv-fix-ienv

    (defthm valid-iconst-of-ienv-fix-ienv
      (equal (valid-iconst iconst (ienv-fix ienv))
             (valid-iconst iconst ienv)))

    Theorem: valid-iconst-ienv-equiv-congruence-on-ienv

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