xref: /trunk/odf_docs/openformula-small-group-semantic-audit.md (revision 1354dfcdad4129e7cc561fdcfbb4f6c8958f0428)
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 Semantic Conformance Audit
21
22**Branch:** `openformula`
23**Baseline:** `9c42008d93`
24**Scope:** Audit and report only. No production code modifications.
25**Method:** Source-level static inspection. Items marked RUNTIME_PENDING have not been run; the Basic Limits results from the Linux aarch64 build are in `openformula-small-group-audit.md`.
26
27## Normative Source
28
29OASIS Open Document Format for Office Applications (OpenDocument) Version 1.4, Part 4: Recalculated Formula (OpenFormula) Format, OASIS Standard, 6 October 2025.
30
31---
32
33## F.1 COUNTA / COUNTBLANK (§6.13.7–6.13.8)
34
35### F.1.1 Normative Requirement
36
37**COUNTA (§6.13.7):** Counts non-empty cells. Empty string `""` is not blank and is counted.
38
39**COUNTBLANK (§6.13.8):** Counts empty cells. Whether a cell returning `""` is blank is implementation-defined.
40
41### F.1.2 AOO Implementation Locations
42
43- `ScCount2()` — `main/sc/source/core/tool/interpr1.cxx:3834`
44- `ScCountEmptyCells()` — `main/sc/source/core/tool/interpr1.cxx:4714`
45- `IterateParameters(ifCOUNT2)` — `main/sc/source/core/tool/interpr1.cxx:3487` (shared by COUNTA, COUNT, and others)
46- Dispatch: `interpr4.cxx:3591` (ocCount2 → ScCount2), `interpr4.cxx:3640` (ocCountEmptyCells → ScCountEmptyCells)
47- Declaration: `main/sc/source/core/inc/interpre.hxx:505` (ScCount2), `:526` (ScCountEmptyCells)
48
49### F.1.3 Execution Path — COUNTA
50
51`ScCount2()` calls `IterateParameters(ifCOUNT2)` which iterates over parameters via a `switch(GetStackType())`:
52
53| Stack Type | Code Path | Behavior |
54|---|---|---|
55| `svString` (literal string, incl. `""`) | interpr1.cxx:3506-3543 → `default` branch | `Pop(); nCount++;` — **counts string argument** (empty string counted) |
56| `svDouble` (numeric literal) | interpr1.cxx:3546 | Counts |
57| `svSingleRef` (single cell) | interpr1.cxx:3567-3624 | `eCellType != CELLTYPE_NONE && eCellType != CELLTYPE_NOTE` → counts non-empty cell |
58| `svDoubleRef` / `svRefList` (range) | interpr1.cxx:3626-3711 | `ScCellIterator` over range; `eType != CELLTYPE_NONE && eType != CELLTYPE_NOTE` → counts non-empty cells |
59| `svMatrix` (array) | interpr1.cxx:3713-3760 | `nCount += nC * nR` — **counts ALL matrix elements** including strings (no `IsString` check for COUNT2) |
60| `svError` | interpr1.cxx:3762-3774 | `nCount++` — counts error values |
61
62### F.1.4 Execution Path — COUNTBLANK
63
64`ScCountEmptyCells()`:
65
66| Stack Type | Code Path | Behavior |
67|---|---|---|
68| `svSingleRef` | interpr1.cxx:4768-4775 | `lcl_IsCountBlankEmpty(GetCell(aAdr))` — cell-type + formula-result check |
69| `svDoubleRef` / `svRefList` | interpr1.cxx:4777-4801 | `ScCellIterator` over range; `lcl_IsCountBlankEmpty(pCell)` per cell; result = `nMaxCount - nCount` |
70| `default` | interpr1.cxx:4803 | `SetError(errIllegalParameter)` — scalar args not supported (COUNTBLANK takes ReferenceList per §6.13.8) |
71
72`lcl_IsCountBlankEmpty()` (interpr1.cxx:4745-4758):
73
74- `CELLTYPE_NONE` / `CELLTYPE_NOTE` / NULL pointer → returns true (blank)
75- Non-FORMULA cell types → returns false (not blank)
76- `CELLTYPE_FORMULA`: if error code or IsValue() → returns false (not blank); otherwise checks `GetString().Len() == 0` — formula cell returning `""` counts as blank
77
78### F.1.5 Current Behavior vs ODF 1.4
79
80| Scenario | ODF 1.4 Normative | AOO Behavior | Match? |
81|---|---|---|---|
82| Truly empty cell (CELLTYPE_NONE) | COUNTA: not counted; COUNTBLANK: blank | Cell type CELLTYPE_NONE → not counted by COUNTA, blank by COUNTBLANK | Yes |
83| Cell with text | COUNTA: counted; COUNTBLANK: not blank | CELLTYPE_STRING → counted/not blank | Yes |
84| Cell with number | COUNTA: counted; COUNTBLANK: not blank | CELLTYPE_VALUE → counted/not blank | Yes |
85| Scalar `""` argument | COUNTA: counted (not blank) | svString → counted | Yes |
86| Formula cell returning `""` | COUNTBLANK: implementation-defined whether blank | CELLTYPE_FORMULA, formula result `""` → blank by COUNTBLANK (via `lcl_IsCountBlankEmpty` inspecting formula result) | Yes (implementation-defined choice exercised) |
87| Formula cell returning non-empty text | Not blank | CELLTYPE_FORMULA, formula result non-empty → not blank | Yes |
88| Numeric zero (0) | COUNTBLANK: not blank | CELLTYPE_VALUE → not blank | Yes |
89| Logical value | Not blank | CELLTYPE_VALUE → not blank | Yes |
90| Error cell | COUNTBLANK: does not propagate errors; returns FALSE for error cases | CELLTYPE_FORMULA with error → not blank | Yes |
91| Scalar `""` to COUNTBLANK | Not applicable (COUNTBLANK takes ReferenceList only) | `SetError(errIllegalParameter)` — only reference types accepted | N/A |
92| Matrix with empty-string cells | COUNTA: not specified explicitly | `nCount += nC * nR` counts all elements including strings | Counts empty-string cells as non-empty |
93| Empty reference/range with mixture | Per-cell evaluation | `lcl_IsCountBlankEmpty` per cell via `ScCellIterator` | Yes |
94
95### F.1.6 Conformance Classification
96
97- **COUNTA scalar `""`**: Required by ODF 1.4 — matches (empty string counted as non-blank).
98- **COUNTA empty cells**: Required by ODF 1.4 — matches (CELLTYPE_NONE not counted).
99- **COUNTBLANK truly empty cells**: Required by ODF 1.4 — matches.
100- **COUNTBLANK formula cell returning `""`**: Implementation-defined (§6.13.8) — AOO treats formula cell returning `""` as blank (via `lcl_IsCountBlankEmpty` inspecting formula result at interpr1.cxx:4752-4757). This is an implementation-defined choice permitted by the standard; not a conformance defect.
101- **COUNTBLANK numeric zero**: Required not blank (§6.13.8) — matches.
102- **COUNTBLANK error cell**: Not propagated (§6.13.8 / ISBLANK §6.13.14) — matches.
103- **COUNTBLANK scalar argument**: Only ReferenceList accepted (§6.13.8) — `errIllegalParameter` for non-reference args, matches.
104- **COUNTA matrix with strings**: ODF 1.4 does not explicitly address matrix empty-string handling — AOO counts all matrix elements including strings.
105
106### F.1.7 Known Compatibility Risks
107
108- Changing COUNTBLANK to NOT inspect formula results (treating `""`-returning formulas as non-blank) would be a behavior change affecting existing documents and would diverge from other major spreadsheet applications.
109- AOO's choice to treat formula-cell-returning-`""` as blank is implementation-defined per §6.13.8 and consistent with ISBLANK returning FALSE for such cells (§6.13.14: "A cell with the empty string is not considered blank").
110
111### F.1.8 Recommended Implementation Changes
112
113None required for ODF 1.4 conformance. The implementation-defined behavior for formula-cell-returning-`""` is exercised (treated as blank). No production code changes needed; runtime verification pending (no AOO build tree available).
114
115### F.1.9 Suggested Regression Tests
116
117- `COUNTA` over range with truly empty cells, text, numbers, and `""` scalar argument
118- `COUNTBLANK` over range with truly empty cells vs. cells containing text/numbers
119- `COUNTBLANK` over formula cells returning `""` (document current behavior as implementation-defined)
120
121---
122
123## F.2 INDEX Row-Vector Behavior (§6.14.6)
124
125### F.2.1 Normative Requirement
126
127**ODF 1.4 §6.14.6:** `INDEX( ReferenceList|Array DataSource ; [ Integer Row ] [ ; [ Integer Column ] ] [ ; Integer AreaNumber = 1 ] )`. Row and Column are 1-based, relative to the top-left of DataSource. If Row is omitted/empty/0, an entire column is returned. If Column is omitted/empty/0, an entire row is returned. If Row or Column exceeds the dimension of the area, an Error is returned. There is NO special row-vector shortcut: `INDEX(H1:L1;3)` (Row=3 on a 1-row range) returns an Error.
128
129**ODF 1.2 (§6.14.6):** Had an explicit row-vector shortcut: "If DataSource is a one-dimensional row vector, Row is optional, which effectively makes Row act as the column offset into the vector." This text was deleted in ODF 1.4 (OASIS issue OFFICE-4144, fixed in ODF 1.4).
130
131**ODF 1.3 (§6.14.6):** "If DataSource is a one-dimensional row vector, Row is optional, which effectively makes Row act as the column offset into the vector." Retained the ODF 1.2 row-vector shortcut. Confirmed via direct ODF 1.3 spec text.
132
133**Version comparison:**
134
135| Specification | Relevant rule | `INDEX(H1:L1;3)` interpretation | Evidence |
136|---|---|---|---|
137| ODF 1.2 | Row acts as column offset on single-row range | Returns column 3 (value 30) | OFFICE-4144 "Delete" text (ODF 1.2 §6.14.6) |
138| ODF 1.3 | "If DataSource is a one-dimensional row vector, Row is optional, which effectively makes Row act as the column offset into the vector" | Returns column 3 (value 30) | ODF 1.3 §6.14.6 (§6.14.6 INDEX, part 4-formula) |
139| ODF 1.4 | Row and Column both 1-based; Row > dimension → Error | Error (Row=3 > 1 row dimension) | ODF 1.4 §6.14.6 (lines 7637-7639 of spec) |
140
141### F.2.2 AOO Implementation Location
142
143- `ScIndex()` — `main/sc/source/core/tool/interpr1.cxx:7448`
144- Dispatch: `interpr4.cxx:3650` (ocIndex → ScIndex)
145- Declaration: `main/sc/source/core/inc/interpre.hxx:564`
146- Parameter class: `main/sc/source/core/tool/parclass.cxx:123` (`ocIndex: {{ Reference, Value, Value, Value }, 0}`)
147
148### F.2.3 Execution Path — ScIndex
149
150```
151nParamCount = GetByte()           // number of arguments
152nArea     = (nParamCount == 4) ? GetDouble() : 1
153nCol      = (nParamCount >= 3) ? GetDouble() : 0
154nRow      = (nParamCount >= 2) ? GetDouble() : 0
155```
156
157Then `switch(GetStackType())`:
158
159| Stack Type | Behavior |
160|---|---|
161| `svMatrix` | Bounds check against matrix dimensions; vector access when nCol==0 or nRow==0 |
162| `svSingleRef` | `if (nCol > 1 \|\| nRow > 1) PushIllegalArgument();` — single cell, only row/col 0 or 1 valid |
163| `svDoubleRef` / `svRefList` | Full range bounds checking; returns sub-reference or single cell |
164
165### F.2.4 Historical Implementation — bRowArray Shortcut
166
167**Milestone A** (commit bb58e28fc2): Removed the `bRowArray` shortcut from `ScIndex()`, making `INDEX(H1:L1;3)` return an error per ODF 1.4.
168
169**Undo** (commit 8f3b3b25a2): Restored the `bRowArray` shortcut, with commit message "INDEX on a row vector keeps the Excel rule, a documented deviation."
170
171**Current state:** `bRowArray` IS present in `main/sc/source/core/tool/interpr1.cxx:7588-7612`. When `nParamCount == 2 && nRow1 == nRow2` (single-row range with row argument):
172
173- Row bounds check is skipped: `(nRow > 0 && nRow1+nRow-1 > nRow2 && !bRowArray)`
174- Alternative row bounds: `(nRow > nCol2 - nCol1 + 1 && bRowArray)` — checked against column width
175- Row argument reinterpreted as column: `nCol = (SCCOL) nRow; nRow = 1;`
176
177Effect: `INDEX(H1:L1;3)` returns the 3rd column (value 30) — ODF 1.3/Excel compatible, NOT ODF 1.4 compliant.
178
179### F.2.5 Conformance Classification
180
181**Required by ODF 1.4** — NOT currently conformant. `bRowArray` shortcut was removed in Milestone A (bb58e28fc2) but restored in the undo commit (8f3b3b25a2). `INDEX(H1:L1;3)` returns a value (30) instead of an Error as required by ODF 1.4 §6.14.6.
182
183### F.2.6 Known Compatibility Risks
184
185- **ODF 1.4 non-conformance:** `INDEX(H1:L1;3)` returns column 3 value instead of Error.
186- **Legacy ODF 1.3 documents:** Documents relying on `INDEX(rowvector; n)` returning column n will break if bRowArray is removed.
187- **Test mismatch:** calcval test `INDEX.row.rowonly` expects `#ERR` (ODF 1.4) but current implementation returns `30` (ODF 1.3) via bRowArray.
188
189### F.2.7 Recommended Implementation Changes
190
191None for this milestone (compatibility audit only). Two options exist:
192
1931. **Remove bRowArray** — ODF 1.4 compliant, breaks legacy ODF 1.3 documents using `INDEX(rowvector; n)`.
1942. **Keep bRowArray** — Legacy compatible, but not ODF 1.4 conformant; document as a known deviation.
195
196A document-compatibility option (version-aware or import-time handling) could be considered if corpus testing shows significant legacy document impact. This is out of scope for G.4.
197
198### F.2.8 Suggested Regression Tests
199
200- `INDEX(H1:L1;3)` → value 30 (current bRowArray behavior) / error (ODF 1.4)
201- `INDEX(H1:L1;;3)` → column value 30 (column-only arg)
202- `INDEX(D1:D5;6)` → error (row out of range)
203- `INDEX(D1:F3;2;3)` → 2D result
204
205---
206
207## F.3 Criteria Syntax (§4.11.11) — Database Functions
208
209### F.3.1 Normative Requirement
210
211ODF 1.4 §4.11.11: Criteria syntax supported in database functions (DCOUNT, DCOUNTA, DSUM, DAVERAGE, DMAX, DMIN, etc.). Criteria support comparison operators (`<`, `<=`, `>`, `>=`, `=`, `<>`), text criteria, wildcards, and criteria ranges.
212
213### F.3.2 AOO Implementation Locations
214
215- `GetDBParams()` — `main/sc/source/core/tool/interpr1.cxx:6664` (parses database + field + criteria range)
216- `DBIterator()` — `main/sc/source/core/tool/interpr1.cxx:6803` (iterates matching records for DBSum, DBAverage, DBMax, DBMin, DBProduct)
217- `ScDBCount()` — `main/sc/source/core/tool/interpr1.cxx:6828` (DCOUNT)
218- `ScDBCount2()` — `main/sc/source/core/tool/interpr1.cxx:6882` (DCOUNTA)
219- `ScDBSum()` — `main/sc/source/core/tool/interpr1.cxx:6821` (DSUM)
220- `ScDBAverage()` — `main/sc/source/core/tool/interpr1.cxx:6909` (DAVERAGE)
221- `ScDBMax()` — `main/sc/source/core/tool/interpr1.cxx:6916` (DMAX)
222- `ScDBMin()` — `main/sc/source/core/tool/interpr1.cxx:6923` (DMIN)
223- Operator prefix parsing — `main/sc/source/core/tool/queryparam.cxx:106-144`
224- `ScQueryEntry` struct — `main/sc/inc/global.hxx:797`
225- `ScQueryOp` enum — `main/sc/inc/global.hxx:733-740` (SC_EQUAL, SC_LESS, SC_GREATER, SC_LESS_EQUAL, SC_GREATER_EQUAL, SC_NOT_EQUAL)
226
227### F.3.3 Function-to-Opcode Mapping
228
229| Function | Opcode | Implementation |
230|---|---|---|
231| DCOUNT | ocDBCount → SC_OPCODE_DB_COUNT | ScDBCount() |
232| DCOUNTA | ocDBCount2 → SC_OPCODE_DB_COUNT_2 | ScDBCount2() |
233| DSUM | ocDBSum → SC_OPCODE_DB_SUM | ScDBSum() → DBIterator(ifSUM) |
234| DAVERAGE | ocDBAverage → SC_OPCODE_DB_AVERAGE | ScDBAverage() → DBIterator(ifAVERAGE) |
235| DMAX | ocDBMax → SC_OPCODE_DB_MAX | ScDBMax() → DBIterator(ifMAX) |
236| DMIN | ocDBMin → SC_OPCODE_DB_MIN | ScDBMin() → DBIterator(ifMIN) |
237
238Name mapping: `main/formula/source/core/resource/core_resource.src:227-228` (`DCOUNT` → SC_OPCODE_DB_COUNT, `DCOUNTA` → SC_OPCODE_DB_COUNT_2)
239
240### F.3.4 Criteria Parsing Execution Path
241
2421. Formula compiler parses `DCOUNT(database, field, criteria)` into opcodes with three Reference parameters.
2432. `GetDBParams()` pops:
244   - Criteria range (double ref)
245   - Field (double, string, single ref, double ref, or missing)
246   - Database range (double ref)
2473. For each criteria entry, `queryparam.cxx:106-144` parses operator prefixes:
248   - `<>` → SC_NOT_EQUAL
249   - `<=` → SC_LESS_EQUAL
250   - `<` → SC_LESS
251   - `>=` → SC_GREATER_EQUAL
252   - `>` → SC_GREATER
253   - `=` or default → SC_EQUAL
2544. `bQueryByString` set via `IsNumberFormat()` (GetDBParams :6745-6746) — determines if criteria is text or numeric
2555. `bRegExp` set via `MayBeRegExp()` (GetDBParams :6748) — enables wildcard/RegExp matching
2566. `DBIterator()` iterates matching records using `ScDBQueryDataIterator`
257
258### F.3.5 Current Behavior vs ODF 1.4
259
260| Requirement | ODF 1.4 Normative | AOO Behavior | Match? |
261|---|---|---|---|
262| Comparison operators `<, <=, >, >=, =, <>` | Required | Parsed from criteria cell prefix (queryparam.cxx:106-144) | Yes |
263| Text criteria | Required | `bQueryByString` via `IsNumberFormat` | Yes |
264| Wildcards / RegExp | Required | `bRegExp` via `MayBeRegExp` | Yes |
265| Empty criteria field | Field may be omitted (count all matching) | `bMissingField` path in ScDBCount | Yes |
266| Criteria range with multiple rows | AND across rows | ScQueryParamBase entries | Yes |
267| DCOUNT without field counts all matching records | Required | ScDBCount: bMissingField + INTERNAL type → counts all matching | Yes; the empty-cell undercount is fixed via CountRecords() (dociter.cxx:685-716), see calcval `DB.DCOUNT.*` |
268| DCOUNT with field counts values in field | Required | ScDBQueryDataIterator over field column | Yes |
269
270### F.3.6 Known Limitations
271
272None for database function empty-cell matching. The ScDBCount empty-cell limitation was fixed: `ScDBCount()` (interpr1.cxx:6871-6902) and `ScDBCount2()` (interpr1.cxx:6905-6935) now use `ScDBQueryDataIterator::CountRecords()` (dociter.cxx:685-716), which tests every row against the criteria using `IsQueryValid()`. Rows with no content are not records; rows with an empty cell in a criteria column are counted.
273
274### F.3.7 Conformance Classification
275
276**Required by ODF 1.4** — Criteria syntax parsing and database function evaluation are implemented, including empty-cell matching for DCOUNT/DCOUNTA without a field.
277
278### F.3.8 Recommended Implementation Changes
279
280None required. The ScDBCount empty-cell fix (F-GAP-004) is in (commits b5a1b43b5b and 30877e2746). With an empty criteria cell the count is now all records (`DB.DCOUNT.nf.nocrit` gives 3, was 0).
281
282### F.3.9 Suggested Regression Tests
283
284- `DCOUNT(R1:T6;;V1:V2)` with `Age>=30` → 4 (B,C,D,E)
285- `DSUM` with criteria
286- `DAVERAGE`, `DMAX`, `DMIN` with criteria
287- Text criteria, wildcard criteria, empty criteria cell
288
289---
290
291## F.4 Basic Limits and Syntax (§3.7, §5)
292
293### F.4.1 Basic Limits (§3.7)
294
295**Normative reference:** ODF 1.4 §3.7 — "Evaluators which claim to support 'basic limits' shall support at least the following limits:
296
2971. formulas up to at least 1024 characters long
2982. at least 30 parameters per function when the function prototype permits a list of parameters
2993. permit strings of ASCII characters of up to 32,767 (2^15-1) characters
3004. support at least 7 nesting levels of functions"
301
302---
303
304#### Formula Length — at least 1024 characters
305
306**Source finding:**
307
308- No explicit formula text length limit (no MAXFORMULA or equivalent check on total formula characters).
309- `main/sc/inc/compiler.hxx:59`: `MAXCODE = 2048` — maximum number of **tokens** in a formula.
310- `main/sc/inc/compiler.hxx:60`: `MAXSTRLEN = 1024` — maximum length of **one symbol** (individual token/string literal), not the formula as a whole.
311- `main/sc/source/core/tool/compiler.cxx:3973-3978`: Token array overflow (`errCodeOverflow`) triggers when `aArr.GetLen() >= MAXCODE`.
312- `main/sc/source/core/tool/compiler.cxx:2689-2691`: String literal overflow (`errStringOverflow`) when a symbol exceeds `MAXSTRLEN-1` (1023 chars); a string literal may now reach `MAXSTRLITLEN` (32767).
313- A 1026-character formula like `=1+1+...+1` (512 `+1` repetitions) requires ~1025 tokens, well under MAXCODE=2048. Each token (`1` or `+`) is well under MAXSTRLEN=1024.
314- A single string literal could not exceed 1021 characters because of MAXSTRLEN=1024; `MAXSTRLITLEN` (32767) now applies to literals. Other symbols are still limited by MAXSTRLEN.
315
316**Classification:** RUNTIME_PENDING — Source appears capable (no formula-text cap; MAXCODE=2048 tokens supports 1024+ char formulas with short tokens), but runtime test `SG.BL-001-1024chars` not executed.
317
318---
319
320#### Function Parameters — at least 30
321
322**Source finding:**
323
324- `main/sc/source/core/inc/interpre.hxx:897-927`: `MustHaveParamCount()` family enforces per-function min/max parameter counts.
325- `main/sc/source/core/tool/interpr1.cxx:3396-3400` (`ScMax`): Uses `MustHaveParamCountMin(nParamCount, 1)` — minimum 1 parameter, **no upper cap** specified.
326- `main/sc/source/core/tool/interpr1.cxx:1290-1294` (`ScMin`): Uses `MustHaveParamCount(nParamCount, NUMBER_OF_ARGUMENTS)` — exact count.
327- `main/sc/source/core/tool/interpr1.cxx:2292-2293`: Functions like `ScAbs` use `MustHaveParamCount(nParamCount, 1, 2)` — bounded 1-2.
328- No global 30-parameter cap found anywhere in source.
329- Parameter count is read via `GetByte()` (`sal_uInt8`), theoretically supporting up to 255 parameters per call. MAXCODE=2048 tokens is the practical ceiling (30 params ≈ 59 tokens).
330- `test/odf-validate/calcval-cases14.tsv:201`: `SG.BL-255args` (`=SUM(1;1;...;255 times)`) — expected result 255 (unverified; no runtime execution possible).
331- `test/odf-validate/calcval-cases14.tsv:202`: `SG.BL-256args` — expected `#ERR` (unverified; described in TSV as an AOO guard, not ODF-mandated).
332
333**Classification:** RUNTIME_PENDING — Source supports ≥30 parameters for functions whose prototypes permit lists (MAX uses `MustHaveParamCountMin`, no upper cap). Runtime test `SG.BL-002-30params` not executed.
334
335---
336
337#### ASCII Strings — at least 32767 characters
338
339**Source finding:**
340
341- `main/tools/inc/tools/string.hxx:110-120`: `STRING_MAXLEN` definition. `STRING32` is **not defined** anywhere in the codebase, so default applies: `STRING_MAXLEN = 0xFFFF = 65,535` (> 32,767 ODF minimum).
342- `main/sc/source/core/inc/interpre.hxx:930-936`: `CheckStringResultLen()` enforces STRING_MAXLEN at string concatenation (REPT, `&` operator, etc.).
343- `main/sc/source/core/tool/compiler.cxx:2689-2691`: string literals in formulas were limited by MAXSTRLEN=1024 to 1021 characters; they now use `MAXSTRLITLEN` (32767).
344- `main/sc/source/core/tool/interpr1.cxx:7777-7790` (REPT), `:8296` (CONCATENATE), `:8324`: Use STRING_MAXLEN for result length checks.
345- `LEN(REPT("a";32767))` — the "a" literal is 1 char (well under MAXSTRLEN), REPT creates 32,767-char string at runtime (under STRING_MAXLEN=65,535).
346- A direct 32,767-character string literal like `="aaa...a"` used to fail at compile time (Err:513); it is now accepted.
347
348**Classification:** RUNTIME_PENDING — Source supports runtime strings ≥32,767 chars (STRING_MAXLEN=65,535; REPT creates them). Since this audit, string literals were raised to 32767 chars; `SG.BL-003-32767chars`, `SG.BL-003-literal1022` and `SG.BL-003-literal32767` were run and match.
349
350---
351
352#### Nesting Depth — at least 7 levels
353
354**Source finding:**
355
356- The recursive-descent parser is in `main/formula/source/core/api/FormulaCompiler.cxx`. `GetToken()` (:782) and `Expression()` (:1341) stop with errStackOverflow once the recursion count passes `nRecursionMax = 42`.
357- `main/sc/inc/compiler.hxx:61`: `MAXJUMPCOUNT = 32` — limits the jump targets of CHOOSE; IF and IFNA use the same table with at most 3 and 2 jump targets (FormulaCompiler.cxx:1101-1103).
358- Evaluator is stack-based (`ScInterpreter::Push()`/`Pop()`) with no explicit evaluation depth limit beyond MAXCODE=2048 total tokens.
359- 7 nested `IF` levels uses ~15 tokens, well under MAXCODE=2048.
360- `test/odf-validate/calcval-cases14.tsv:198`: `SG.BL-004-7nesting` — 7 nested `IF` calls, expected result 1.
361
362**Classification:** RUNTIME_PENDING — Source has no nesting depth limit; parser recursion and evaluator stack have no depth guard. Runtime test `SG.BL-004-7nesting` not executed.
363
364---
365
366### F.4.2 Remaining Syntax Requirements (§5)
367
368**Normative reference:** ODF 1.4 §2.3.2.B requires Small Group Evaluators to implement syntax from: Criteria §4.11.11; 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.
369
370| Requirement | Section | AOO Implementation | Source Location | Status |
371|---|---|---|---|---|
372| Parenthesized expressions / Expression grammar | §5.2 | Formula ::= Intro? Expression; Expression ::= Number \| String \| Array \| PrefixOp Expression \| Expression PostfixOp \| Expression InfixOp Expression \| '(' Expression ')' \| FunctionName '(' ParameterList ')' \| Reference \| QuotedLabel \| AutomaticIntersection \| NamedExpression \| Error | `main/sc/source/core/tool/compiler.cxx:3570` (NextNewToken), :3780 (CompileString) | RUNTIME_PENDING |
373| Constant Numbers | §5.3 | `Number ::= StandardNumber \| '.' [0-9]+ ([eE] [-+]? [0-9]+)?`, `StandardNumber ::= [0-9]+ ('.' [0-9]+)? ([eE] [-+]? [0-9]+)?`. Decimal separator '.', scientific notation E/e. Negative numbers are prefix '-' on positive numbers. | `main/sc/source/core/tool/compiler.cxx:2650+` (IsValue, number parsing) | RUNTIME_PENDING |
374| Constant Strings | §5.4 | `String ::= '"' ([^"#x00] \| '""')* '"'`. Double-quote escaped by duplication. | `main/sc/source/core/tool/compiler.cxx:2682` (IsString), :2689-2691 (string literal overflow at MAXSTRLEN-1) | RUNTIME_PENDING |
375| Operators | §5.5 | PrefixOp '+', '-'; PostfixOp '%'; InfixOp: ArithmeticOp (+-\*/^), ComparisonOp (=<> <> < > <= >=), StringOp (&), ReferenceOp (! ~ :). Precedence per Table 1: ! > : > prefix +,- > ^ > \*,/ > +,- > & > comparison. | `main/sc/source/core/tool/compiler.cxx` RangeLine → IntersectionLine → RangeLine → UnaryLine → binary ops; `main/sc/inc/compiler.hxx:61` (MAXJUMPCOUNT=32, CHOOSE only) | RUNTIME_PENDING |
376| Functions and Function Parameters | §5.6 | `FunctionName ::= LetterXML (LetterXML \| DigitXML \| '_' \| '.' \| CombiningCharXML)*`. Case-insensitive. Semicolon ';' separator. Empty parameters allowed (considered 0 params, not one empty param). | `main/sc/source/core/tool/compiler.cxx:3648` (function name detection), :3661-3668 (must be followed by '('); `main/sc/source/core/inc/interpre.hxx:897-927` (MustHaveParamCount family) | RUNTIME_PENDING |
377| Nonstandard Function Names | §5.7 | Function names not in spec need prefix (e.g., COM.FOO.BAR). Unknown functions → Error value other than #N/A. | `main/sc/source/core/tool/compiler.cxx:3741,:4029,:4072,:4091,:4101,:5493,:5501` (errNoName); `main/formula/source/core/api/FormulaCompiler.cxx:891-895` (unknown name followed by '(' gives errNoName) | RUNTIME_PENDING |
378| References | §5.8 | `Reference ::= '[' (Source? RangeAddress) \| ReferenceError ']'`. RangeAddress supports cell, row, column, whole-row, whole-column. References begin with '[' to disambiguate from function names. | `main/sc/source/core/tool/compiler.cxx` (IsReference, PopDoubleRef/PopSingleRef); `main/sc/inc/compiler.hxx` | RUNTIME_PENDING |
379| Simple Named Expressions | §5.11 | `SimpleNamedExpression ::= Identifier \| '$$' (Identifier \| SingleQuoted)`. Global scope, case-consistent matching. | `main/sc/source/core/tool/compiler.cxx` (NameLine, ocName opcode); `main/sc/source/core/inc/interpre.hxx` | RUNTIME_PENDING |
380| Constant Errors | §5.12 | `#N/A` required; other Errors optional. Error syntax: `'#' [A-Z0-9]+ ([!?] \| ('/' ([A-Z] \| ([0-9] [!?])))`. Functions propagate Errors unless stated otherwise. | `main/formula/inc/formula/compiler.hrc:58-64` (SC_OPCODE_ERROR_NULL through SC_OPCODE_ERROR_NA); `main/sc/source/core/tool/interpr4.cxx` (PushError, NOTAVAILABLE) | RUNTIME_PENDING |
381| Whitespace | §5.14 | Whitespace ::= #x20 \| #x09 \| #x0a \| #x0d. Ignored outside strings, around operators, before/after =, before function names (but not between name and '('). | `main/sc/source/core/tool/compiler.cxx:3583-3593` (NextNewToken generates ocSpaces), :3655-3667 (whitespace before '(' for function names). Only #x20 is set as whitespace in the compiler character table (`compiler.cxx:448`); #x09, #x0a and #x0d are unverified. | RUNTIME_PENDING |
382
383### Coverage note: Criteria §4.11.11
384
385Criteria syntax (§4.11.11) is also required by §2.3.2.B but is covered under **F-GAP-004** (G.4 — DCOUNT/ScDBCount empty-cell fix) rather than G.6, because its primary interface is through database functions rather than general expression syntax. See the Criteria Syntax section in F-GAP-004.
386
387---
388
389### Cross-Cutting Finding
390
391**Static source tracing confirms implementation presence and absence of blocking limits, not semantic equivalence.** All Small Group syntax infrastructure exists in source with correct grammar structure for all 11 §2.3.2.B syntax requirements plus Criteria §4.11.11. None has been verified against ODF 1.4 normative expected results at runtime. All syntax requirements are RUNTIME_PENDING pending runtime execution.
392
393---
394
395## Conformance Summary
396
397| Category | Count | Status |
398|---|---|---|
399| Basic Limits (§3.7) | 4 | Run on Linux aarch64: 3 MET, 1 PARTIAL (string literals stop at about 1021 characters) |
400| Syntax (§5) | 11 | RUNTIME_PENDING — implementation present for all 11; runtime verification blocked (no build tree) |
401| COUNTA/COUNTBLANK (§6.13.7-8) | 2 | Fully matches; formula-cell `""` treated as blank per implementation-defined choice (§6.13.8) |
402| INDEX (§6.14.6) | 1 | NOT ODF 1.4 compliant — bRowArray shortcut present (undone by commit 8f3b3b25a2); INDEX(H1:L1;3) returns value instead of Error |
403| Criteria Syntax (§4.11.11) | 1 | Implemented; ScDBCount empty-cell fix applied (source-level; runtime-unverified) |
404| Operators (§6.4) | 14 | Implementation present; runtime-unverified |
405| Functions (§2.3.2.E) | 110 | Implementation present; runtime-unverified |
406
407**No production code changes are recommended at this audit stage.** Milestone G should implement targeted fixes based on this audit's findings, prioritized by dependency and risk.
408