1<!-- 2 Licensed to the Apache Software Foundation (ASF) under one 3 or more contributor license agreements. See the NOTICE file 4 distributed with this work for additional information 5 regarding copyright ownership. The ASF licenses this file 6 to you under the Apache License, Version 2.0 (the 7 "License"); you may not use this file except in compliance 8 with the License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, 13 software distributed under the License is distributed on an 14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 KIND, either express or implied. See the License for the 16 specific language governing permissions and limitations 17 under the License. 18--> 19 20# OpenFormula 1.4 Small Group Audit — Apache OpenOffice Calc 21 22## Methodology and Normative Source 23 24**Normative source:** OASIS Open Document Format for Office Applications (OpenDocument) Version 1.4, Part 4: Recalculated Formula (OpenFormula) Format, OASIS Standard, 6 October 2025. 25 26URL: <https://docs.oasis-open.org/office/OpenDocument/v1.4/os/part4-formula/OpenDocument-v1.4-os-part4-formula.html> 27 28**Primary sections audited:** 29 30- §2.3.1 — OpenDocument Formula Evaluator 31- §2.3.2 — OpenDocument Formula Small Group Evaluator 32- §3.7 — Basic Limits 33- §4 — Types 34- §5 — Expression Syntax 35- §6 — Operators and Functions 36 37**Source-of-truth:** Apache OpenOffice implementation (main/sc, main/formula, main/scaddins). Findings marked **[CONFIRMED]** have source file:line evidence; **[UNVERIFIED]** require runtime testing or full spec text not available locally. 38 39**Milestone context:** Milestones A, B, and C have been completed on branch `openformula`. Milestone B implemented IFNA and SKEWP. Milestone C corrected CONVERT unit constants and completed the Pica unit family. This audit reflects the current branch state after those changes. 40 41--- 42 43## 1. Conformance Group Claim 44 45**[CONFIRMED] AOO claims NO Part 4 conformance group.** 46 47- `odf_docs/ODF14-IMPLEMENTATION-DEFINED-PUBLIC.md:134` (§4): "AOO does not claim the Part 4 evaluator groups (Small, Medium, Large)." 48 49Therefore **no conformance level (Small/Medium/Large) may be claimed for AOO Calc.** This audit reports implementation coverage only; it does not certify conformance. 50 51--- 52 53## 2. Basic Limits (§3.7) 54 55| ReqID | Requirement | Status | Source Evidence | Runtime Verified | 56|-------|-------------|--------|-----------------|-------------------| 57| SG-BL-001 | Formula length >= 1024 characters | **MET** | The compiler limit was 512 tokens, too few for 1024 characters of `1+1+...`; it is now 2048 (`MAXCODE`, compiler.hxx:59). Calcval `SG.BL-001-1024chars` (1026 characters, result 513) matches on a Linux aarch64 build. | Yes | 58| SG-BL-002 | >= 30 parameters per function | **MET** | `SG.BL-002-30params` (MAX with 30 arguments) matches on a Linux aarch64 build; a call with more than 255 arguments is an error. | Yes | 59| SG-BL-003 | Strings up to 32767 ASCII chars | **MET** | Run-time strings reach 32767 characters (`SG.BL-003-32767chars`, `LEN(REPT("a";32767))`) and so do string literals in a formula (`SG.BL-003-literal32767`; the limit is `MAXSTRLITLEN`, compiler.hxx). `SG.BL-003-literal1022` covers the old 1021-character limit. A literal of 32768 gives Err:513. All three match on a Linux aarch64 build. | Yes | 60| SG-BL-004 | >= 7 nesting levels of functions | **MET** | `SG.BL-004-7nesting` (7 nested IF levels) matches on a Linux aarch64 build. The parser has a recursion guard of 42 (`nRecursionMax`, FormulaCompiler.cxx:782 and :1341). | Yes | 61 62**Finding:** the four limits were run on Linux aarch64. Formula length, parameter count and nesting meet the requirement. String length also meets it: run-time strings and string literals both reach 32767 characters (literals stopped at 1021 before). 63 64--- 65 66## 3. Syntax (§2.3.2.B) 67 68| ReqID | Section | Requirement | Status | Source Evidence | Runtime Verified | 69|-------|---------|-------------|--------|-----------------|-------------------| 70| SG-SYN-001 | 4.11.11 | Criteria syntax | **UNVERIFIED** | Database functions (DSUM, DCOUNT, etc.) use criteria; interpr1.cxx implements DBSum/DBCount | No | 71| SG-SYN-002 | 5.2 | Basic Expressions | **UNVERIFIED** | FormulaCompiler.cxx handles parenthesized expressions via RangeLine/IntersectionLine/UnaryLine | No | 72| SG-SYN-003 | 5.3 | Constant Numbers | **UNVERIFIED** | FormulaCompiler.cxx tokenizes numeric literals | No | 73| SG-SYN-004 | 5.4 | Constant Strings | **UNVERIFIED** | FormulaCompiler.cxx tokenizes string literals with quote escaping | No | 74| SG-SYN-005 | 5.5 | Operators precedence (Table 1) | **UNVERIFIED** | FormulaCompiler.cxx:1203-1237 implements UnionLine -> IntersectionLine -> RangeLine -> UnaryLine -> binary ops | No | 75| SG-SYN-006 | 5.6 | Functions and parameters | **UNVERIFIED** | FormulaCompiler.cxx compiles function calls with argument lists | No | 76| SG-SYN-007 | 5.7 | Nonstandard function names as errors | **UNVERIFIED** | ocNoName opcode; xlformula.cxx uses ocNoName stubs | No | 77| SG-SYN-008 | 5.8 | References | **UNVERIFIED** | compiler.cxx PopDoubleRef/PopSingleRef handle cell/range references | No | 78| SG-SYN-009 | 5.11 | Simple Named Expressions | **UNVERIFIED** | compiler.cxx:NameLine handles named expressions; ocName opcode | No | 79| SG-SYN-010 | 5.12 | Errors | **UNVERIFIED** | Error constants (ocErrNull through ocErrNA) in compiler.hrc; interpr1.cxx error handling | No | 80| SG-SYN-011 | 5.14 | Whitespace | **UNVERIFIED** | ocSpaces converted to intersection at FormulaCompiler.cxx:830-831 | No | 81 82**Specific unverified grammar cases:** 83 84- Operator precedence and associativity (e.g., `2+3*4`, `2^3^2`) — parser structure exists but no runtime verification of correct precedence 85- Automatic intersection (whitespace between references) — ocSpaces → ocIntersect conversion at FormulaCompiler.cxx:830-831 exists but runtime behavior unverified 86- Reference union `~` — NOT required for Small Group (§2.3.2.G), so absence is acceptable 87- Quoted labels as implicit intersection (ODF 1.4 §3.9/§5.10) — not confirmed in source 88 89**Finding:** All syntax requirements have parser/compiler infrastructure present, but none have been verified at runtime against ODF 1.4 normative expected results. 90 91--- 92 93## 4. Implicit Conversions (§2.3.2.C) 94 95| ReqID | Section | Requirement | Status | Source Evidence | Runtime Verified | 96|-------|---------|-------------|--------|-----------------|-------------------| 97| SG-CONV-001 | 6.3.14 | Conversion to Text | **IMPLEMENTED_UNVERIFIED** | ScInterpreter::GetString() (interpre.hxx:374), ScText() (interpr1.cxx) | No | 98| SG-CONV-002 | 6.3.5 | Conversion to Number | **IMPLEMENTED_UNVERIFIED** | ScInterpreter::GetDouble() (interpre.hxx:370), ConvertStringToValue() (interpre.hxx:228) | No | 99| SG-CONV-003 | 4.8 | Reference conversion | **IMPLEMENTED_UNVERIFIED** | ScInterpreter::GetCellValueOrZero() (interpre.hxx:231), PopSingleRef/PopDoubleRef | No | 100| SG-CONV-004 | 6.3.12 | Conversion to Logical | **IMPLEMENTED_UNVERIFIED** | ScInterpreter::GetBool() returns GetDouble() != 0.0 (interpre.hxx:373) | No | 101| SG-CONV-005 | 5.12 | Error propagation | **IMPLEMENTED_UNVERIFIED** | nGlobalError (interpre.hxx:196), SetError() (interpre.hxx:854), Push() substitutes FormulaErrorToken (interpre.hxx:263) | No | 102 103**Distinction:** Implementation presence confirmed (conversion functions exist in source), but semantic conformance to ODF 1.4 conversion rules (locale sensitivity, edge cases, error conditions) is **unverified**. 104 105**Finding:** All conversion requirements have implementation entry points, but none have been verified at runtime against ODF 1.4 normative expected results. 106 107--- 108 109## 5. Operators (§2.3.2.D) 110 111All operators required by §2.3.2.D (all operators except reference union `~`) are implemented: 112 113| ReqID | Section | Operator | Status | Source | Runtime Verified | 114|-------|---------|----------|--------|--------|------------------| 115| SG-OP-001 | 6.4.9 | Ordered comparison (<, <=, >, >=) | **IMPLEMENTED_UNVERIFIED** | interpr1.cxx:ScLess/ScLessEqual/ScGreater/ScGreaterEqual | No | 116| SG-OP-002 | 6.4.10 | Concatenation (&) | **IMPLEMENTED_UNVERIFIED** | interpr5.cxx:ScAmpersand | No | 117| SG-OP-003 | 6.4.2 | Addition (+) | **IMPLEMENTED_UNVERIFIED** | interpr5.cxx:ScAdd | No | 118| SG-OP-004 | 6.4.3 | Subtraction (-) | **IMPLEMENTED_UNVERIFIED** | interpr5.cxx:ScSub | No | 119| SG-OP-005 | 6.4.4 | Multiplication (*) | **IMPLEMENTED_UNVERIFIED** | interpr5.cxx:ScMul | No | 120| SG-OP-006 | 6.4.5 | Division (/) | **IMPLEMENTED_UNVERIFIED** | interpr5.cxx:ScDiv; division by zero -> errDivisionByZero (interpre.hxx:955-959) | No | 121| SG-OP-007 | 6.4.6 | Power (^) | **IMPLEMENTED_UNVERIFIED** | interpr5.cxx:ScPow; right-associative | No | 122| SG-OP-008 | 6.4.7 | Equality (=) | **IMPLEMENTED_UNVERIFIED** | interpr1.cxx:ScEqual | No | 123| SG-OP-009 | 6.4.8 | Not equal (<>) | **IMPLEMENTED_UNVERIFIED** | interpr1.cxx:ScNotEqual | No | 124| SG-OP-010 | 6.4.14 | Postfix % | **IMPLEMENTED_UNVERIFIED** | interpr1.cxx:ScPercentSign | No | 125| SG-OP-011 | 6.4.15 | Prefix + | **IMPLEMENTED_UNVERIFIED** | Unary plus handled by compiler; ocAdd with single operand | No | 126| SG-OP-012 | 6.4.16 | Prefix - | **IMPLEMENTED_UNVERIFIED** | interpr1.cxx:ScNeg | No | 127| SG-OP-013 | 6.4.12 | Reference intersection (!) | **IMPLEMENTED_UNVERIFIED** | interpr1.cxx:ScIntersect | No | 128| SG-OP-014 | 6.4.11 | Reference range (:) | **IMPLEMENTED_UNVERIFIED** | interpr1.cxx:ScRangeFunc | No | 129 130**Finding:** All 14 operator requirements are implemented. Reference union (`~`) is explicitly NOT required for Small Group (§2.3.2.G). 131 132--- 133 134## 6. Required Functions (§2.3.2.E) 135 136The Small Group requires 110 functions (§2.3.2.E). All 110 have opcodes and implementations in the current source. IFNA and SKEWP were implemented in Milestone B (IFNA = Large Group only; SKEWP = Medium Group only — neither is Small Group). 137 138### Function status summary 139 140| Status | Count | Description | 141|--------|-------|-------------| 142| IMPLEMENTED_UNVERIFIED | 110 | All 110 Small Group functions have opcodes, implementations, dispatch entries, and metadata, but runtime semantics have NOT been verified against ODF 1.4. Implementation presence confirmed; semantic equivalence not established. | 143| IMPLEMENTED_MATCH | 0 | No function has been verified as semantically matching ODF 1.4 at runtime. | 144| PARTIAL | 0 | None identified in this audit. | 145| MISSING | 0 | All 110 required functions are present in source. | 146| MAPPING_ONLY | 0 | None identified in this audit. | 147| NOT_APPLICABLE | 4 | The four explicit allowances (§2.3.2.F/G) - inline arrays, complex numbers, multi-area references, reference union (~). | 148 149**Key conceptual distinction:** An opcode, evaluator implementation, dispatch entry, and function metadata establish **implementation presence**, not **semantic equivalence**. All 110 functions are marked IMPLEMENTED_UNVERIFIED because no runtime tests have been executed against the ODF 1.4 normative expected results. 150 151--- 152 153## 7. Explicit Small Group Allowances (§2.3.2.F and G) 154 155| Allowance | Section | Description | Status | 156|-----------|---------|-------------|--------| 157| SG-ALW-001 | 2.3.2.F | References containing more than one area need not be evaluated | Documented — AOO returns as-is for ref lists | 158| SG-ALW-002 | 2.3.2.G | Inline arrays need not be implemented | Documented — inline arrays not required for Small Group | 159| SG-ALW-003 | 2.3.2.G | Complex numbers need not be implemented | Documented — complex functions not required | 160| SG-ALW-004 | 2.3.2.G | Reference union operator (~) need not be implemented | Documented — union not required for Small Group | 161 162**Finding:** These are explicit permissions to omit, not conformance failures. 163 164--- 165 166## 8. Summary Counts 167 168| Category | Total | Status | Count | 169|----------|-------|--------|-------| 170| Basic Limits | 4 | Awaiting runtime | 0 verified, 4 awaiting | 171| Syntax | 11 | Awaiting runtime | 0 verified, 11 awaiting (SG-SYN-001 criteria §4.11.11 now included in E.1 test inventory) | 172| Conversions | 5 | IMPLEMENTED_UNVERIFIED | 0 verified, 5 UNVERIFIED | 173| Operators | 14 | IMPLEMENTED_UNVERIFIED | 0 verified, 14 UNVERIFIED | 174| Functions | 110 | IMPLEMENTED_UNVERIFIED | 0 verified, 110 UNVERIFIED | 175| Allowances | 4 | NOT_APPLICABLE | 4 documented (§2.3.2.F/G explicit permissions to omit) | 176 177**Grand total: 148 inventory entries — 144 applicable requirements awaiting runtime verification (Basic Limits 4 + Syntax 11 + Conversions 5 + Operators 14 + Functions 110), 4 explicit allowances marked NOT_APPLICABLE (§2.3.2.F/G: inline arrays, complex numbers, multi-area references, reference union), 0 runtime-verified.** 178 179--- 180 181## 9. Known Semantic Differences (ODF 1.4 vs AOO) 182 183| Function/Area | Section | AOO Behavior | ODF 1.4 Normative | Severity | Source | 184|---------------|---------|-------------|-------------------|----------|--------| 185| INDEX row-vector single-arg | 6.14.6 | Returns error (Milestone A fix: removed ODF 1.3 row-vector shortcut) | Error (ODF 1.4 removed rule) | Fixed in Milestone A; regression risk | interpr1.cxx; KNOWN-LIMITATIONS:71 | 186| CONVERT atm | 6.16.18 | 101325.1 Pa (Milestone C fix: corrected from 101324.996583 Pa) | 101325.1 Pa | Fixed in Milestone C | interpr2.cxx; KNOWN-LIMITATIONS:72 | 187| DATE pre-1583 (FN-016-DATE-pre1583) | 6.10.2 | AOO observed #VALUE! for `DATE(1500;1;1)` (outside 1904 ≤ Year ≤ 9956) | §6.10.2 constrains Year/Month/Day; evaluators may evaluate out-of-constraint but `DATE(1500;1;1)` is implementation-defined/diagnostic, not a mandatory `#ERR`. Normative expected value is `-` (not an ODF conformance error assertion); calcval `DATE.pre1583` retains `#ERR` only as explicitly identified AOO-specific diagnostic. | Impl-defined/diagnostic (E.1 reclassified) | interpr2.cxx; IMPLEMENTATION-DEFINED:155 | 188| COUNTA empty cells / empty string | 6.13.7 | ODF 1.3 semantics | ODF 1.4 §6.13.7: counts non-blank cells; empty string `""` is not blank. E.1 adds fixtures for empty cells and `""` (where harness-expressible). | UNVERIFIED | interpr1.cxx:ScCount2 | 189| COUNTBLANK "" in cell | 6.13.8 | Unverified | §6.13.8: implementation-defined whether a cell returning `""` is blank. `FN-014-COUNTBLANK-empty-cells` covers truly empty cells; `FN-014-COUNTBLANK-empty-string` retained as diagnostic only with expected `-` (NOT testing `""`-in-cell). `""`-in-cell blankness is impl-defined; calcval harness cannot place `""` into a data cell. | Impl-defined/UNVERIFIED | interpr1.cxx:ScCountEmptyCells | 190 191--- 192 193## E.1 Corrections (this milestone) 194 195- **SG-BL-001**: corrected to formula expression length 1026 chars (`=1` + `+1`*512), expected 513 (replaces `REPT("a";1024)` which measured string length, not formula length). 196- **SG-BL-004**: corrected to 7 genuinely nested function levels (`IF(TRUE;IF(...IF(TRUE;1;2)...))`, 7 nested IF calls), balanced parens, deterministic result 1. 197- **All 4 Basic Limits (§3.7)**: run on a Linux aarch64 build; results are in the status table above. 198- **SG-SYN-001**: added Criteria syntax §4.11.11 test `SYN-001-criteria` (`=DCOUNT(R1:T6;;V1:V2)`, expected 4) using existing calcval database/criteria fixtures. 199- **SG-SYN-009**: marked not directly executable in calcval harness (requires pre-defined named expression `MYNAME`); test remains UNVERIFIED with explicit note. 200- **SG-FN-013/COUNTA**: fixtures added for truly empty cells and empty string "" per §6.13.7 (empty string non-blank). Harness-expressible via inline args; empty-cell cases use unset D6:D7. 201- **SG-FN-014/COUNTBLANK**: FN-014-COUNTBLANK-empty-cells (=COUNTBLANK(D6:D7), expected 2) covers truly empty cells. FN-014-COUNTBLANK-empty-string is retained as diagnostic only with expected - — it uses =COUNTBLANK(D6:D7) (genuinely empty cells, not ""), clearly labeled as NOT testing a cell containing ""; the required ""-in-cell fixture cannot be established by calcval harness (scratch cleared each case; no pre-populated "" data cells). ""-in-cell blankness is impl-defined per §6.13.8. 202- **SG-FN-016/FN-016-DATE-pre1583**: reclassified as implementation-defined/diagnostic (out-of-constraint Year < 1904), not mandatory #ERR. Normative expected value is - (not an ODF conformance error assertion). The calcval DATE.pre1583 row retains #ERR only as an explicitly identified AOO-specific diagnostic assertion (AOO observed #VALUE!), clearly labeled as not an ODF conformance assertion. 203- **BITAND arity**: confirmed `BITAND.3params` (`=BITAND(6;3;1)` expected `#ERR`) remains valid per §6.6.2 (`BITAND(Integer X; Integer Y)`); no classification change. 204- **Runtime verification**: the Basic Limits results are in the status table above (Linux aarch64). 205 206## 10. Runtime-Verification Limitations 207 208The following could not be verified at runtime because no configured AOO build tree exists in this environment: 209 210- All 4 Basic Limits (§3.7) — source evidence supports compliance but runtime execution not performed 211- Runtime behavior of all 110 Small Group functions 212- Error propagation edge cases 213- Locale-sensitive conversions 214- ODF save/reload round-trip 215 216Static source tracing confirms all opcodes, implementations, dispatch, and metadata are present, and no blocking limits found for Basic Limits requirements. 217 218--- 219 220## 11. Prioritized Candidate Gaps for Next Implementation Milestone 221 222| Priority | Gap | Category | Rationale | Effort | 223|----------|-----|----------|-----------|--------| 224| 1 | COUNTA ODF 1.4 empty-cell semantics | Semantic difference | ODF 1.4 changed COUNTA/COUNTBLANK empty-cell handling; AOO uses ODF 1.3 semantics | Medium | 225| 2 | COUNTBLANK "" impl-defined | Semantic difference | ODF 1.4 marks "" case as impl-defined; AOO behavior unverified | Low | 226| 3 | DATE out-of-constraint/pre-1583 behavior | Semantic difference (impl-defined) | `DATE(1500;1;1)` outside §6.10.2 constraints; result is impl-defined/diagnostic (AOO observed #VALUE!), not mandatory error. | Low | 227| 4 | INDEX row-vector compatibility | Semantic difference | Milestone A fixed ODF 1.4 behavior; legacy ODF 1.3 documents may break | High (regression risk) | 228 229**Recommended next milestone:** Small Group semantic conformance — verify and correct COUNTA/COUNTBLANK empty-cell semantics per ODF 1.4, verify DATE pre-1583 behavior, and assess INDEX row-vector regression risk. 230 231--- 232 233## 12. What Was NOT Checked 234 235- Runtime execution of any function (no build available) 236- ODF save/reload round-trip 237- Excel import/export of function names 238- Function wizard integration 239- Numerical precision beyond 48-bit integer handling 240