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# Milestone G — OpenFormula Small Group Semantic Conformance: Implementation Sequence 21 22**Branch:** `openformula` 23**Baseline:** `9c42008d93` (post-E.1.1) 24**Source:** `openformula-small-group-semantic-audit.md`, `openformula-small-group-semantic-gaps.tsv` 25**Scope:** Implementation planning only. No code changes in this document. 26 27## Current Status 28 29| Phase | Status | Commit | Notes | 30|---|---|---|---| 31| G.1 | Complete | `41da3628f9` + Help topics commit | STRING_MAXLEN documented; ScDBCount empty-cell fix applied via `CountRecords()`; Help topics added for IFNA, SKEWP, BITAND, BITOR, BITXOR, BITLSHIFT, BITRSHIFT | 32| G.2 | Fixed | `b5a1b43b5b`, `30877e2746` (fix); `ad46309f51` (docs, 3 test rows) | `ScDBCount()` missing-field path uses `CountRecords()` (dociter.cxx:685-716) which iterates row-by-row via `IsQueryValid()`; `ScDBCount2()` same pattern; calcval `DB.*` regression cases added. `DB.DCOUNT.nf.nocrit` gives 3 (was 0) | 33| G.3 | Complete (decision documented) | `7e6ad45c82` | COUNTBLANK formula-cell `""` behavior decision: `lcl_IsCountBlankEmpty()` (interpr1.cxx:4745-4758) inspects formula results and treats formula-cell-returning-`""` as blank — implementation-defined per §6.13.8; no code change needed | 34| G.4 | Compatibility audit complete (decision documented) | `ac2d06a54a` | `bRowArray` shortcut present in `ScIndex()` (interpr1.cxx:7588-7612); `INDEX(H1:L1;3)` returns column value instead of ODF 1.4 Error; kept as legacy-compatible deviation | 35| G.5 | Run on Linux aarch64 | `1ac0d2f4ee`, `fb522d42ea` (source audit); results in `openformula-small-group-audit.md` | Formula length, parameter count and nesting: MET. String length: MET, string literals and run-time strings both reach 32767 (literals stopped at 1021 before). Formula limit raised from 512 to 2048 tokens | 36| G.6 | Complete (source-level audit) | `551759aef8` | All 11 ODF 1.4 §2.3.2.B syntax requirements source-audited; implementation present for all; no blocking limits; all classified RUNTIME_PENDING. Includes Basic Expressions, Constant Numbers, Constant Strings, Operators, Functions, Nonstandard Function Names, References, Simple Named Expressions, Errors, Whitespace. Runtime verification blocked (no build tree) | 37 38**Runtime results:** the Basic Limits (G.5) rows were run on a Linux aarch64 build. Items marked RUNTIME_PENDING have no recorded run. 39 40## Principles 41 421. **Audit-first:** Implementation follows the F-audit findings; no speculative fixes. 432. **Dependency-ordered:** Changes with no dependencies first; dependent changes after. 443. **Risk-ordered:** Lower-risk, self-contained changes before higher-risk behavior changes. 454. **No LibreOffice code:** All fixes derived from AOO source inspection only. 465. **No production changes without runtime validation.** 47 48## Phase G.1 — Zero-Risk Documentation & Test Harness (No Code Changes) 49 50**STATUS: COMPLETE** (committed at `41da3628f9`) 51 52These items require no production source modification and can be completed immediately. 53 54| Order | Gap ID | Area | Action | Rationale | Status | 55|---|---|---|---|---|---| 56| G.1.1 | F-GAP-008 | Basic Limits — strings | Locate `STRING_MAXLEN` definition; confirm value >= 32767 or document actual limit | Static lookup; no code change | Complete — `main/tools/inc/tools/string.hxx:110-120`; default `STRING_MAXLEN = 65,535` (0xFFFF without STRING32), exceeds ODF 1.4 32,767 minimum | 57| G.1.2 | F-GAP-012 | Syntax — named expressions | Document named expression test requirement (pre-defined `MYNAME` not available in calcval harness) | Test infrastructure note | Complete — documented in F-GAP-012; SYN-009-named marked not directly executable | 58| G.1.3 | F-GAP-015 | COUNTA/COUNTBLANK | Document scalar `""` vs formula-cell `""` distinction as implementation-defined | Audit documentation | Complete — documented in F-GAP-001, F-GAP-002, F-GAP-015 | 59| G.1.4 | — | Help documentation | Add Help topics for IFNA, SKEWP, BITAND, BITOR, BITXOR, BITLSHIFT, BITRSHIFT; verify HID_FUNC_* → topic mapping | `main/helpcontent2/source/text/scalc/01/func_*.xhp` (7 files) + `scfuncs.src` metadata | Complete — Help topics created, Function Wizard HIDs resolve, scfuncs.src descriptions corrected | 60 61## Phase G.2 — Investigation Complete: Criteria Syntax Empty-Cell Fix (ScDBCount) 62 63**STATUS: FIXED** (`b5a1b43b5b`, `30877e2746`) — DCOUNT and DCOUNTA without a field count every matching record via `CountRecords()`; calcval `DB.*` regression cases added. `DB.DCOUNT.nf.nocrit` gives 3 (was 0). 64 65The root cause is confirmed: `ScQueryCellIterator` ("run through all not empty cells") skips empty cells, and `ScDBQueryDataIterator::getCurrent()` skips `CELLTYPE_NONE` via `default` case at `dociter.cxx:655-657`. Per ODF 1.4 §6.9.3, DCOUNT without a field should count ALL matching rows including those with empty result cells. 66 67**Fix applied** (trunk commits rebased onto `openformula`): 68 69- `main/sc/source/core/data/dociter.cxx:685-716` — `ScDBQueryDataIterator::DataAccessInternal::countRecords()` iterates row-by-row from `nRow1` to `nRow2`, checking `aHasContent` (row has any non-NOTE cell in any database column) and `IsQueryValid()` per row. Counts all matching records regardless of cell emptiness in the field column. 70- `main/sc/source/core/tool/interpr1.cxx:6871-6902` — `ScDBCount()` missing-field path calls `aRecIter.CountRecords()` instead of `ScQueryCellIterator` iteration. 71- `main/sc/source/core/tool/interpr1.cxx:6905-6935` — `ScDBCount2()` (DCOUNTA) missing-field path calls `aRecIter.CountRecords()`. 72 73**Regression tests added** to `test/odf-validate/calcval-cases14.tsv`: 74 75- `DB.DCOUNT.f.zero` — DCOUNT with field, numeric zero vs empty: A=0 counts via COUNT, B empty does not 76- `DB.DCOUNT.nf.zero` — DCOUNT without field: all matching records count regardless of cell content 77- `DB.DCOUNTA.f.zero` — DCOUNTA with field, numeric zero vs empty: A=0 counts as non-empty via COUNTA, B empty does not 78 79| Order | Gap ID | Area | File | Finding | Fix | Risk | 80|---|---|---|---|---|---|---| 81| G.2.1 | F-GAP-004 | Criteria — DCOUNT empty-cell matching | `interpr1.cxx:6838-6845` (was) → `interpr1.cxx:6879-6882` + `dociter.cxx:685-716` | ScDBCount missing-field path previously used `ScQueryCellIterator` which skips empty cells; DCOUNT undercounted when matching rows had empty result cells | Replaced with row-by-row `CountRecords()` using `IsQueryValid()` per row; counts all matching rows regardless of cell emptiness | Low — isolated to DCOUNT/DCOUNTA without field; documented TODO already resolved | 82 83**Dependencies:** None. 84**Runtime validation needed:** the three `DB.*.zero` rows (numeric zero vs empty result cell). 85 86## Phase G.3 — Medium-Risk: COUNTA/COUNTBLANK Behavior Review 87 88**STATUS: COMPLETE** (decision documented; no code change needed) 89 90ODF 1.4 §6.13.8 makes formula-cell-returning-`""` blank-counting implementation-defined. AOO already exercises this choice via `lcl_IsCountBlankEmpty()` (interpr1.cxx:4745-4758) which inspects formula results and treats formula-cell-returning-`""` as blank for COUNTBLANK. ISBLANK (§6.13.14) returns FALSE for empty string — no conflict since COUNTBLANK's behavior is explicitly implementation-defined. 91 92| Order | Gap ID | Area | Decision Point | Decision | Risk | 93|---|---|---|---|---|---| 94| G.3.1 | F-GAP-001 | COUNTA matrix | Confirm matrix empty-string handling is acceptable | ODF 1.4 silent; AOO counts all matrix elements including strings — acceptable | Low | 95| G.3.2 | F-GAP-002 | COUNTBLANK formula-cell `""` | Decide whether to inspect formula result for `""` | Decision: inspect formula result; treat formula-cell-returning-`""` as blank. Already implemented via `lcl_IsCountBlankEmpty()`; no code change needed | Low — no behavior change; decision documents existing implementation | 96 97**Dependencies:** None (implementation already in place). 98**Runtime validation needed:** Yes — COUNTBLANK with formula cells returning `""`. **Blocked:** No AOO build tree available; calcval cannot run. Existing test case `COUNTBLANK.emptystr` (calcval-cases14.tsv:164) covers this. 99 100## Phase G.4 — Medium-Risk: INDEX Row-Vector Compatibility 101 102**STATUS: COMPATIBILITY AUDIT COMPLETE** (no code change) 103 104ODF 1.4 §6.14.6 removed the ODF 1.2/1.3 row-vector shortcut where `INDEX(rowvector; n)` treated Row as a column offset. Milestone A (bb58e28fc2) removed the `bRowArray` shortcut, but it was restored by commit 8f3b3b25a2 ("INDEX on a row vector keeps the Excel rule, a documented deviation"). Current `ScIndex()` (interpr1.cxx:7588-7612) still has `bRowArray`, so `INDEX(H1:L1;3)` returns column 3 (value 30) — ODF 1.3/Excel compatible, NOT ODF 1.4 compliant. 105 106| Order | Gap ID | Area | Decision Point | Decision | Risk | 107|---|---|---|---|---|---| 108| G.4.1 | F-GAP-003 | INDEX row-vector | Keep bRowArray (legacy compatible) or remove (ODF 1.4 compliant) | Keep bRowArray for now; document as known ODF 1.4 deviation. Consider compatibility option if corpus testing shows legacy document impact. | Medium — affects existing documents; ODF 1.4 non-conformance | 109 110**Dependencies:** None. 111**Runtime validation needed:** Yes — corpus regression test against existing documents to assess legacy document impact. **Blocked:** No AOO build tree available; calcval cannot run. Existing test case `INDEX.row.rowonly` (calcval-cases14.tsv:39) expects `#ERR` (ODF 1.4) but current implementation returns `30` — test/implementation mismatch noted. 112 113## Phase G.5 — Low-Risk: Basic Limits Source Audit 114 115**STATUS: RUN on Linux aarch64** (results in `openformula-small-group-audit.md`) 116 117ODF 1.4 §3.7 requires: (1) formulas up to at least 1024 characters, (2) at least 30 parameters per function, (3) strings up to 32,767 ASCII characters, (4) at least 7 nesting levels of functions. Three are MET and one is PARTIAL. 118 119| Order | Gap ID | Area | Source Finding | Classification | 120|---|---|---|---|---| 121| G.5.1 | F-GAP-006 | Formula length | The compiler limit was 512 tokens; it is now 2048 (MAXCODE, compiler.hxx:59). MAXSTRLEN=1024 per symbol (compiler.hxx:60). `SG.BL-001-1024chars` matches. | MET | 122| G.5.2 | F-GAP-007 | Parameter count | No global 30-param cap; MAX uses MustHaveParamCountMin(1) (interpr1.cxx:3396-3400). `SG.BL-002-30params` matches; more than 255 arguments is an error. | MET | 123| G.5.3 | F-GAP-008 | String length | STRING_MAXLEN=65,535 (string.hxx:119, STRING32 not defined) > 32,767; `SG.BL-003-32767chars` matches. A string literal of up to 32767 characters is accepted (`MAXSTRLITLEN`; `SG.BL-003-literal32767` matches), 32768 gives Err:513. | MET | 124| G.5.4 | F-GAP-009 | Nesting depth | The parser stops at a recursion count of 42 (nRecursionMax, FormulaCompiler.cxx:782 and :1341). `SG.BL-004-7nesting` matches. | MET | 125 126**Dependencies:** None. 127String literals used to stop at about 1021 characters (Err:513); `MAXSTRLITLEN` now allows 32767. 128 129## Phase G.6 — Low-Risk: Syntax Verification 130 131**STATUS: COMPLETE** (source-level audit; runtime verification pending) 132 133ODF 1.4 §2.3.2.B requires Small Group Evaluators to implement syntax from 11 sections: Criteria §4.11.11 (covered under F-GAP-004/G.4); Basic Expressions §5.2; Constant Numbers §5.3; Constant Strings §5.4; Operators §5.5; Functions and Function Parameters §5.6; Nonstandard Function Names §5.7; References §5.8; Simple Named Expressions §5.11; Errors §5.12; Whitespace §5.14. Source audit found implementation presence for all 11 requirements with no blocking limitations. All classified as RUNTIME_PENDING. 134 135| Order | Gap ID | Area | Source Finding | Classification | 136|---|---|---|---|---| 137| G.6.1 | F-GAP-016 | Basic Expressions §5.2 | `Formula ::= Intro? Expression`; Expression supports Number, String, Array, PrefixOp, InfixOp, parenthesized, function call, Reference, QuotedLabel, AutomaticIntersection, NamedExpression, Error (`compiler.cxx:3570`, :3780) | RUNTIME_PENDING | 138| G.6.2 | F-GAP-017 | Constant Numbers §5.3 | `Number ::= StandardNumber \| '.' [0-9]+ ([eE] [-+]? [0-9]+)?`; decimal '.', scientific E/e (`compiler.cxx:2650+`) | RUNTIME_PENDING | 139| G.6.3 | F-GAP-018 | Constant Strings §5.4 | `String ::= '"' ([^"#x00] \| '""')* '"'`; double-quote escaped by duplication (`compiler.cxx:2682`) | RUNTIME_PENDING | 140| G.6.4 | F-GAP-010 | Operators §5.5 | PrefixOp '+', '-'; PostfixOp '%'; InfixOp: Arithmetic, Comparison, String, Reference. Precedence: ! > : > prefix +,- > ^ > *,/ > +,- > & > comparison (`compiler.cxx` RangeLine→binary ops; `compiler.hxx:61` MAXJUMPCOUNT=32, the jump targets of CHOOSE, IF and IFNA) | RUNTIME_PENDING | 141| G.6.5 | F-GAP-019 | Functions §5.6 | `FunctionName ::= LetterXML (LetterXML \| DigitXML \| '_' \| '.' \| CombiningCharXML)*`; case-insensitive; ';' separator; empty params allowed (`compiler.cxx:3648`, `interpre.hxx:897-927`) | RUNTIME_PENDING | 142| G.6.6 | F-GAP-020 | Nonstandard Function Names §5.7 | Unknown functions → Error other than #N/A; names need prefix (`compiler.cxx` errNoName; `FormulaCompiler.cxx:891-895`) | RUNTIME_PENDING | 143| G.6.7 | F-GAP-011 | References §5.8 | `Reference ::= '[' (Source? RangeAddress) \| ReferenceError ']'`; supports cell, row, column, whole-row, whole-column (`compiler.cxx` IsReference, PopDoubleRef/PopSingleRef) | RUNTIME_PENDING | 144| G.6.8 | F-GAP-012 | Simple Named Expressions §5.11 | `SimpleNamedExpression ::= Identifier \| '$$' (Identifier \| SingleQuoted)`; global scope, case-consistent (`compiler.cxx` NameLine/ocName) | RUNTIME_PENDING | 145| G.6.9 | F-GAP-013 | Constant Errors §5.12 | `#N/A` required; others optional; Error syntax `'#' [A-Z0-9]+ ...` (`compiler.hrc:58-64`; `interpr4.cxx` PushError) | RUNTIME_PENDING | 146| G.6.10 | F-GAP-014 | Whitespace §5.14 | Whitespace ::= #x20 \| #x09 \| #x0a \| #x0d; ignored outside strings, around operators, before/after =, before function names (`compiler.cxx:3583-3593`, :3655-3667); only #x20 is set as whitespace in the compiler character table (`compiler.cxx:448`), so #x09, #x0a and #x0d are unverified | RUNTIME_PENDING | 147 148**Dependencies:** None. 149**Runtime validation needed:** Yes — all syntax tests (SYN-001 through SYN-011). **Blocked:** No AOO build tree available; calcval cannot run. Source audit complete; no production code changes needed. 150 151## Dependency Summary 152 153``` 154G.1 (docs, COMPLETE) ──┐ 155 ├── G.2 (ScDBCount empty-cell, FIXED) ──┐ 156G.5 (limits audit, RUN on Linux aarch64) ──┤ ├── G.3 (COUNTBLANK decision, COMPLETE) 157G.6 (syntax audit, COMPLETE source-level) ──┤ │ 158G.4 (INDEX compatibility) ──┘ └── (runtime-validated) 159``` 160 161G.4 compatibility audit: `bRowArray` shortcut present (interpr1.cxx:7588-7612); `INDEX(H1:L1;3)` returns column value instead of ODF 1.4 Error. Kept as documented deviation; removal would break legacy ODF 1.3 documents. 162 163## Estimated Implementation Complexity 164 165| Phase | Complexity | Rationale | Status | 166|---|---|---|---| 167| G.1 (docs) | Trivial | No code changes | Complete | 168| G.2 (ScDBCount) | Low | Fix applied via `CountRecords()`; regression tests added | Fixed | 169| G.3 (COUNTBLANK) | Low | Decision documented; implementation already in place via `lcl_IsCountBlankEmpty()` | Complete (decision documented) | 170| G.4 (INDEX compat) | Medium | Compatibility audit complete; `bRowArray` shortcut present; ODF 1.4 deviation documented | Compatibility audit complete (decision documented) | 171| G.5 (limits audit) | Low | Run on Linux aarch64: 4 MET (string literals raised from 1021 to 32767 characters) | Run | 172| G.6 (syntax audit) | Low | Source audit complete; implementation present for all 11 syntax requirements; no blocking limits; all classified RUNTIME_PENDING | Complete (source-level) | 173 174## Definition of Done for Milestone G 175 176- All G.1 documentation items complete (committed at `41da3628f9`; Help topics for 7 functions committed separately) 177- G.1 Help topics: IFNA, SKEWP, BITAND, BITOR, BITXOR, BITLSHIFT, BITRSHIFT — all HID_FUNC_* IDs resolve to topics, discoverable via Help index/search 178- G.2 ScDBCount/DCOUNTA empty-cell fix (`b5a1b43b5b`, `30877e2746`): `CountRecords()` in `dociter.cxx:685-716`, used by `ScDBCount()` at `interpr1.cxx:6879-6882` and `ScDBCount2()` at `interpr1.cxx:6913-6917`; calcval `DB.*` regression cases added to `calcval-cases14.tsv` (DB.DCOUNT.f.zero, DB.DCOUNT.nf.zero, DB.DCOUNTA.f.zero) 179- G.2 result: `DB.DCOUNT.nf.nocrit` gives 3 (was 0); the three `DB.*.zero` rows are not yet recorded as run 180- G.3 COUNTBLANK behavior: decision documented — `lcl_IsCountBlankEmpty()` (interpr1.cxx:4745-4758) inspects formula results and treats formula-cell-returning-`""` as blank for COUNTBLANK (implementation-defined per §6.13.8); ISBLANK (§6.13.14) returns FALSE for empty string — the two differ, which §6.13.8 allows. No code change needed. 181- G.4 INDEX compatibility: compatibility audit complete — `bRowArray` shortcut present in `ScIndex()` (interpr1.cxx:7588-7612); `INDEX(H1:L1;3)` returns column value instead of ODF 1.4 Error; kept as documented legacy-compatible deviation | 182- G.5 Basic Limits: run on Linux aarch64 — formula length, parameter count and nesting MET; string length MET (string literals and run-time strings both reach 32767). Formula limit raised from 512 to 2048 tokens (MAXCODE). 183- G.6 Syntax Verification: source audit complete — implementation present for all 11 ODF 1.4 §2.3.2.B syntax requirements (Basic Expressions, Constant Numbers, Constant Strings, Operators, Functions, Nonstandard Function Names, References, Simple Named Expressions, Errors, Whitespace) plus Criteria §4.11.11 (covered under F-GAP-004). All classified RUNTIME_PENDING. Runtime verification blocked (no build tree). 184- G.6 runtime tests: prepared, not yet run 185- No production changes without corresponding calcval test coverage 186- All G.1-G.3 requirements verified at source level against ODF 1.4 normative text; G.4 INDEX documented as known deviation (bRowArray shortcut, not ODF 1.4 compliant); G.6 runtime verification pending 187 188## Deferred Items (Post-G) 189 190- Full function-by-function semantic verification of all 110 Small Group functions (requires runtime) 191- ODF save/reload round-trip testing 192- Excel import/export function name alignment 193