feat: Harbour RTL vs Go math comparison example + analyzer IMPORT fix

- examples/go_math_compare.prg: Side-by-side comparison of
  Harbour RTL (Abs, Sqrt, Round, Int, Max, Min, Log, Exp, Mod)
  vs Go math package (Sin, Cos, Pow, Pi, Floor, Ceil, Hypot, ...)
- Combined usage: normal distribution, compound interest, distance
- Analyzer: recognize IMPORT package names as valid identifiers
- Analyzer: add math RTL functions (ABS, SQRT, etc.) to known list

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-31 10:35:40 +09:00
parent e04ae563ef
commit 0828d17159
3 changed files with 206 additions and 4 deletions

View File

@@ -369,6 +369,15 @@ func (a *Analyzer) checkVarUsage(name string, pos token.Position) {
return
}
// Check if it's an IMPORT package name
for _, imp := range a.file.Imports {
parts := strings.Split(imp.Path, "/")
pkgName := parts[len(parts)-1]
if strings.EqualFold(pkgName, name) || (imp.Alias != "" && imp.Alias == name) {
return
}
}
// Not declared — warn (could be MEMVAR, FIELD, or typo)
a.warn(pos, "undeclared variable '%s' (missing LOCAL?)", name)
}
@@ -407,6 +416,8 @@ func (a *Analyzer) isKnownFunction(name string) bool {
"SLEEP": true, "HB_IDLEADD": true, "SECONDS": true,
"ERRORBLOCK": true, "BREAK": true, "PCOUNT": true, "PROCNAME": true,
"SETPOS": true, "ROW": true, "COL": true, "MAXROW": true, "MAXCOL": true,
"ABS": true, "INT": true, "ROUND": true, "SQRT": true, "LOG": true, "EXP": true,
"MAX": true, "MIN": true, "MOD": true,
"SETCOLOR": true, "DISPBOX": true, "DISPBEGIN": true, "DISPEND": true,
"HB_SYMBOL_UNUSED": true, "HB_DEFAULT": true, "HB_NTOS": true,
}