From 2915cd9118e1af0fd7f82d37df8afd83d881e15f Mon Sep 17 00:00:00 2001 From: Don Cross Date: Wed, 4 Oct 2023 21:03:21 -0400 Subject: [PATCH] Improved contributor source editing experience by improved code generator markers. I suddenly realized today that I could eliminate lots of red wavy lines in the source editor when working on generate/template/astronomy.* files, by tweaking the $ASTRO_... tokens to look like comments. For some reason, I didn't think of doing this before now. I was motivated by the Go language support, where the tokens were breaking `go fmt`. --- generate/codegen.c | 18 +++++++++++++++--- generate/template/astronomy.c | 26 +++++++++++++------------- generate/template/astronomy.cs | 24 ++++++++++++------------ generate/template/astronomy.py | 24 ++++++++++++------------ generate/template/astronomy.ts | 8 ++++---- 5 files changed, 56 insertions(+), 44 deletions(-) diff --git a/generate/codegen.c b/generate/codegen.c index 46a84aa9..ea095144 100644 --- a/generate/codegen.c +++ b/generate/codegen.c @@ -137,13 +137,13 @@ static int IndexOf(const char *text, int offset, const char *pattern) return -1; } -static int ScanDirective( +static int ScanDirectiveVariant( char *line, const char **verb_text, const char **args_text, - const char **tail_text) + const char **tail_text, + const char *prefix) { - static const char prefix[] = "$ASTRO_"; static const char delim[] = "("; static const char suffix[] = ")"; int prefix_length = (int)strlen(prefix); @@ -198,6 +198,18 @@ static int ScanDirective( return 1; } +static int ScanDirective( + char *line, + const char **verb_text, + const char **args_text, + const char **tail_text) +{ + return + ScanDirectiveVariant(line, verb_text, args_text, tail_text, "//$ASTRO_") || + ScanDirectiveVariant(line, verb_text, args_text, tail_text, "#$ASTRO_") || + ScanDirectiveVariant(line, verb_text, args_text, tail_text, "$ASTRO_"); +} + static int ParseVsopBodyName(const cg_context_t *context, const char *name, vsop_body_t *body) { if (!strcmp(name, "Sun")) { *body = VSOP_SUN; return 0; } diff --git a/generate/template/astronomy.c b/generate/template/astronomy.c index 8b4b624f..1eecda0b 100644 --- a/generate/template/astronomy.c +++ b/generate/template/astronomy.c @@ -55,7 +55,7 @@ extern "C" { /** @cond DOXYGEN_SKIP */ #define PI 3.14159265358979323846 -$ASTRO_C_PLUTO_CONST() +//$ASTRO_C_PLUTO_CONST() typedef enum { @@ -2133,7 +2133,7 @@ static void CalcMoon( context.t = centuries_since_j2000; Init(ctx); -$ASTRO_ADDSOL() +//$ASTRO_ADDSOL() SolarN(ctx); Planetary(ctx); S = F + DS/ARC; @@ -2536,14 +2536,14 @@ typedef struct jupiter_moon_t; /** @endcond */ -$ASTRO_C_VSOP(Mercury); -$ASTRO_C_VSOP(Venus); -$ASTRO_C_VSOP(Earth); -$ASTRO_C_VSOP(Mars); -$ASTRO_C_VSOP(Jupiter); -$ASTRO_C_VSOP(Saturn); -$ASTRO_C_VSOP(Uranus); -$ASTRO_C_VSOP(Neptune); +//$ASTRO_C_VSOP(Mercury); +//$ASTRO_C_VSOP(Venus); +//$ASTRO_C_VSOP(Earth); +//$ASTRO_C_VSOP(Mars); +//$ASTRO_C_VSOP(Jupiter); +//$ASTRO_C_VSOP(Saturn); +//$ASTRO_C_VSOP(Uranus); +//$ASTRO_C_VSOP(Neptune); /** @cond DOXYGEN_SKIP */ #define VSOPFORMULA(x) { ASTRO_ARRAYSIZE(x), x } @@ -3544,7 +3544,7 @@ void Astronomy_GravSimFree(astro_grav_sim_t *sim) /*------------------ begin Pluto integrator ------------------*/ -$ASTRO_PLUTO_TABLE(); +//$ASTRO_PLUTO_TABLE(); /* FIXFIXFIX - Using a global is not thread-safe. Either add thread-locks or change API to accept a cache pointer. */ static body_segment_t *pluto_cache[PLUTO_NUM_STATES-1]; @@ -3707,7 +3707,7 @@ static astro_status_t CalcPluto(body_state_t *bstate, astro_time_t time, int hel /*---------------------- begin Jupiter moons ----------------------*/ -$ASTRO_JUPITER_MOONS(); +//$ASTRO_JUPITER_MOONS(); static astro_state_vector_t JupiterMoon_elem2pv(astro_time_t time, double mu, const double elem[6]) { @@ -9505,7 +9505,7 @@ typedef struct constel_boundary_t; /** @endcond */ -$ASTRO_CONSTEL() +//$ASTRO_CONSTEL() /** * @brief diff --git a/generate/template/astronomy.cs b/generate/template/astronomy.cs index 56de4ebb..ebb988f4 100644 --- a/generate/template/astronomy.cs +++ b/generate/template/astronomy.cs @@ -2334,7 +2334,7 @@ internal MoonContext(double centuries_since_j2000) internal MoonResult CalcMoon() { ++Astronomy.CalcMoonCount; -$ASTRO_ADDSOL() +//$ASTRO_ADDSOL() SolarN(); Planetary(); S = F + DS/Astronomy.ARC; @@ -3209,14 +3209,14 @@ public vsop_model_t(vsop_series_t[] lon, vsop_series_t[] lat, vsop_series_t[] ra } }; -$ASTRO_CSHARP_VSOP(Mercury) -$ASTRO_CSHARP_VSOP(Venus) -$ASTRO_CSHARP_VSOP(Earth) -$ASTRO_CSHARP_VSOP(Mars) -$ASTRO_CSHARP_VSOP(Jupiter) -$ASTRO_CSHARP_VSOP(Saturn) -$ASTRO_CSHARP_VSOP(Uranus) -$ASTRO_CSHARP_VSOP(Neptune) +//$ASTRO_CSHARP_VSOP(Mercury) +//$ASTRO_CSHARP_VSOP(Venus) +//$ASTRO_CSHARP_VSOP(Earth) +//$ASTRO_CSHARP_VSOP(Mars) +//$ASTRO_CSHARP_VSOP(Jupiter) +//$ASTRO_CSHARP_VSOP(Saturn) +//$ASTRO_CSHARP_VSOP(Uranus) +//$ASTRO_CSHARP_VSOP(Neptune) private static readonly vsop_model_t[] vsop = new vsop_model_t[] { @@ -3525,7 +3525,7 @@ private static body_state_t CalcVsopPosVel(vsop_model_t model, double tt) #region Pluto -$ASTRO_PLUTO_TABLE(); +//$ASTRO_PLUTO_TABLE(); internal static TerseVector UpdatePosition(double dt, TerseVector r, TerseVector v, TerseVector a) { @@ -3753,7 +3753,7 @@ private struct jupiter_moon_t public vsop_term_t[] zeta; } -$ASTRO_JUPITER_MOONS(); +//$ASTRO_JUPITER_MOONS(); private static StateVector JupiterMoon_elem2pv( AstroTime time, @@ -10583,7 +10583,7 @@ public static ConstellationInfo Constellation(double ra, double dec) throw new InternalError($"Unable to find constellation for coordinates: RA={ra}, DEC={dec}"); } -$ASTRO_CONSTEL() +//$ASTRO_CONSTEL() } } diff --git a/generate/template/astronomy.py b/generate/template/astronomy.py index 04f157cc..a1a83b14 100644 --- a/generate/template/astronomy.py +++ b/generate/template/astronomy.py @@ -1586,7 +1586,7 @@ def Frac(x: float) -> float: I += 1 -$ASTRO_ADDSOL() +#$ASTRO_ADDSOL() def ADDN(coeffn: float, p: int, q: int, r: int, s: int) -> float: return coeffn * (ex[p][1] * ex[q][2] * ex[r][3] * ex[s][4]).imag @@ -1804,14 +1804,14 @@ def __init__(self, lon: _vsop_formula_t, lat: _vsop_formula_t, rad: _vsop_formul self.rad = rad _vsop: List[_vsop_model_t] = [ -$ASTRO_PYTHON_VSOP(Mercury), -$ASTRO_PYTHON_VSOP(Venus), -$ASTRO_PYTHON_VSOP(Earth), -$ASTRO_PYTHON_VSOP(Mars), -$ASTRO_PYTHON_VSOP(Jupiter), -$ASTRO_PYTHON_VSOP(Saturn), -$ASTRO_PYTHON_VSOP(Uranus), -$ASTRO_PYTHON_VSOP(Neptune), +#$ASTRO_PYTHON_VSOP(Mercury), +#$ASTRO_PYTHON_VSOP(Venus), +#$ASTRO_PYTHON_VSOP(Earth), +#$ASTRO_PYTHON_VSOP(Mars), +#$ASTRO_PYTHON_VSOP(Jupiter), +#$ASTRO_PYTHON_VSOP(Saturn), +#$ASTRO_PYTHON_VSOP(Uranus), +#$ASTRO_PYTHON_VSOP(Neptune), ] def _VsopFormula(formula: _vsop_formula_t, t: float, clamp_angle: bool) -> float: @@ -1968,7 +1968,7 @@ def __init__(self, tt: float, pos: Tuple[float, float, float], vel: Tuple[float, self.pos = _TerseVector(pos[0], pos[1], pos[2]) self.vel = _TerseVector(vel[0], vel[1], vel[2]) -$ASTRO_PLUTO_TABLE() +#$ASTRO_PLUTO_TABLE() def _AdjustBarycenterPosVel(ssb: _body_state_t, tt: float, body: Body, planet_gm: float) -> _body_state_t: shift = planet_gm / (planet_gm + _SUN_GM) @@ -2205,7 +2205,7 @@ def __init__(self, mu: float, al0: float, al1: float, a: _js, l: _js, z: _js, ze self.z = z self.zeta = zeta -$ASTRO_JUPITER_MOONS() +#$ASTRO_JUPITER_MOONS() class JupiterMoonsInfo: """Holds the positions and velocities of Jupiter's major 4 moons. @@ -6438,7 +6438,7 @@ def __repr__(self) -> str: _ConstelRot = None _Epoch2000 = None -$ASTRO_CONSTEL() +#$ASTRO_CONSTEL() def Constellation(ra: float, dec: float) -> ConstellationInfo: diff --git a/generate/template/astronomy.ts b/generate/template/astronomy.ts index 7fd4aedc..e8b005c8 100644 --- a/generate/template/astronomy.ts +++ b/generate/template/astronomy.ts @@ -1005,7 +1005,7 @@ function CalcMoon(time: AstroTime) { SINPI += coeffp * result.x; } -$ASTRO_ADDSOL() +//$ASTRO_ADDSOL() function ADDN(coeffn: number, p: number, q: number, r: number, s: number) { return coeffn * Term(p, q, r, s).y; @@ -2596,7 +2596,7 @@ function CalcSolarSystemBarycenter(time: AstroTime): Vector { // Pluto integrator begins ---------------------------------------------------- -$ASTRO_PLUTO_TABLE() +//$ASTRO_PLUTO_TABLE() class TerseVector { constructor( @@ -2958,7 +2958,7 @@ interface jupiter_moon_t { zeta: jm_series_t; }; -$ASTRO_JUPITER_MOONS(); +//$ASTRO_JUPITER_MOONS(); /** * @brief Holds the positions and velocities of Jupiter's major 4 moons. @@ -6836,7 +6836,7 @@ export function Rotation_GAL_EQJ(): RotationMatrix { } -$ASTRO_CONSTEL() +//$ASTRO_CONSTEL() let ConstelRot: RotationMatrix; let Epoch2000 : AstroTime;