Attempt to classify what comes next in the input as a parameter type list or a (possibly abstract) declarator.
(classify-partys/declor/ambig pstate) → (mv erp classification num-tokens new-pstate)
See the discussion in type-spec for background,
specifically the part regarding the
_Atomic ( I ) ( I (
where
If there are no errors, besides returning the (possibly ambiguous) classification, this function also returns the number of tokens it has read so that the caller can put them back into the parsing state. The reason why this function does not put back the tokens itself is that, after it is recursively called, we may need to read more tokens (see code and comments).
Function:
(defun classify-partys/declor/ambig (pstate) (declare (xargs :guard (parstatep pstate))) (let ((__function__ 'classify-partys/declor/ambig)) (declare (ignorable __function__)) (b* (((reterr) (irr-partys/declor/ambig) 0 (irr-parstate)) ((erp token span pstate) (read-token pstate))) (cond ((and token (token-case token :ident)) (b* (((erp token2 span2 pstate) (read-token pstate))) (cond ((equal token2 (token-punctuator "(")) (b* (((erp classification num-tokens pstate) (classify-partys/declor/ambig pstate))) (partys/declor/ambig-case classification :partys (retok (partys/declor/ambig-declor) (+ num-tokens 2) pstate) :declor (retok (partys/declor/ambig-partys) (+ num-tokens 2) pstate) :ambig (b* (((erp token3 span3 pstate) (read-token pstate))) (cond ((equal token3 (token-punctuator ")")) (retok (partys/declor/ambig-ambig) (+ num-tokens 3) pstate)) ((equal token3 (token-punctuator ",")) (retok (partys/declor/ambig-partys) (+ num-tokens 3) pstate)) ((or (equal token3 (token-punctuator "(")) (equal token3 (token-punctuator "["))) (retok (partys/declor/ambig-partys) (+ num-tokens 3) pstate)) (t (reterr-msg :where (position-to-msg (span->start span3)) :expected "an open parenthesis ~ or a closed parenthesis ~ or an open square bracket ~ or a comma" :found (token-to-msg token3)))))))) ((equal token2 (token-punctuator ")")) (retok (partys/declor/ambig-ambig) 2 pstate)) ((token-declaration-specifier-start-p token2) (retok (partys/declor/ambig-partys) 2 pstate)) ((equal token2 (token-punctuator "[")) (retok (partys/declor/ambig-declor) 2 pstate)) ((equal token2 (token-punctuator "*")) (retok (partys/declor/ambig-partys) 2 pstate)) (t (reterr-msg :where (position-to-msg (span->start span2)) :expected "an identifier ~ or an open parenthesis ~ or a closed parenthesis ~ or an open square bracket ~ or a keyword in {~ _Alignas, ~ _Atomic, ~ _Bool, ~ _Complex, ~ char, ~ const, ~ double, ~ enum, ~ float, ~ int, ~ long, ~ restrict, ~ short, ~ signed, ~ struct, ~ union, ~ unsigned, ~ void, ~ volatile~ }" :found (token-to-msg token2)))))) ((token-declaration-specifier-start-p token) (retok (partys/declor/ambig-partys) 1 pstate)) ((or (token-declarator-start-p token) (token-abstract-declarator-start-p token)) (retok (partys/declor/ambig-declor) 1 pstate)) ((equal token (token-punctuator ")")) (retok (partys/declor/ambig-partys) 1 pstate)) (t (reterr-msg :where (position-to-msg (span->start span)) :expected "an identifier ~ or an open parenthesis ~ or a closed parenthesis ~ or an open square bracket ~ or a star" :found (token-to-msg token)))))))
Theorem:
(defthm partys/declor/ambig-p-of-classify-partys/declor/ambig.classification (b* (((mv acl2::?erp ?classification ?num-tokens ?new-pstate) (classify-partys/declor/ambig pstate))) (partys/declor/ambig-p classification)) :rule-classes :rewrite)
Theorem:
(defthm natp-of-classify-partys/declor/ambig.num-tokens (b* (((mv acl2::?erp ?classification ?num-tokens ?new-pstate) (classify-partys/declor/ambig pstate))) (natp num-tokens)) :rule-classes (:rewrite :type-prescription))
Theorem:
(defthm parstatep-of-classify-partys/declor/ambig.new-pstate (b* (((mv acl2::?erp ?classification ?num-tokens ?new-pstate) (classify-partys/declor/ambig pstate))) (parstatep new-pstate)) :rule-classes :rewrite)
Theorem:
(defthm parsize-of-classify-partys/declor/ambig-uncond (b* (((mv acl2::?erp ?classification ?num-tokens ?new-pstate) (classify-partys/declor/ambig pstate))) (<= (parsize new-pstate) (parsize pstate))) :rule-classes :linear)
Theorem:
(defthm parsize-of-classify-partys/declor/ambig-cond (b* (((mv acl2::?erp ?classification ?num-tokens ?new-pstate) (classify-partys/declor/ambig pstate))) (implies (not erp) (<= (parsize new-pstate) (- (parsize pstate) num-tokens)))) :rule-classes :linear)