diff --git a/Cargo.lock b/Cargo.lock index dd301e6..21e3046 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -595,7 +595,7 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "xs-check" -version = "0.1.2" +version = "0.1.3" dependencies = [ "ariadne", "chrono", diff --git a/Cargo.toml b/Cargo.toml index ef275cb..aa46193 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "xs-check" -version = "0.1.2" +version = "0.1.3" authors = ["Alian713"] edition = "2021" description = "A linter for AoE2:DE's flavour of XS" diff --git a/src/lint/gen_info.rs b/src/lint/gen_info.rs index a1b5ad8..3bfab7b 100644 --- a/src/lint/gen_info.rs +++ b/src/lint/gen_info.rs @@ -52,7 +52,7 @@ pub fn gen_info_from_src( ignores: &HashSet, ) -> (Vec, bool) { let (tokens, errs) = lexer() - .parse(src) + .parse(src.trim()) .into_output_errors(); let mut tc_errs = vec![]; diff --git a/src/prelude.xs b/src/prelude.xs index 5368ef0..419274e 100644 --- a/src/prelude.xs +++ b/src/prelude.xs @@ -1,5 +1,5 @@ // + --------------------------------- + -// | Generated on: 2024/11/17 18:34:01 | +// | Generated on: 2024/12/07 01:18:56 | // | Made by: Alian713 | // + --------------------------------- + @@ -2423,18 +2423,18 @@ int xsGetVictoryTimeForSecondaryGameMode() {} /** * Returns an integer corresponding to different victory settings ingame. These are: - - 0: Standard - -1: Conquest - -2: Time Limit - -3: Score - -4: Custom (scenarios only). - -Last Man Standing returns 0 as well. +* +* 0: Standard +* +* 1: Conquest +* +* 2: Time Limit +* +* 3: Score +* +* 4: Custom (scenarios only). +* +* Last Man Standing returns 0 as well. * * @returns int */ @@ -2511,8 +2511,8 @@ void xsSetTriggerVariable(int variableID = -1, int value = -1) {} /** * Adds a new (or edits an existing) task with the fields previously defined by calls to [xsTaskAmount](./#532-xstaskamount) for the specified unit at the end of the task list (see A.G.E.). If a task with the specified `actionType`, `unitId`, and `Search Wait Time` (set by `xsTaskAmount`) already exists, it is edited instead of a new one being added. - -Note that `xsTaskAmount` modifies a global task struct which is re-used every time `#!cpp xsTask` is called (For non programmers, this is similar to filling out a form once (the calls to [xsTaskAmount](./#532-xstaskamount)) and then submitting multiple copies of it for different people) +* +* Note that `xsTaskAmount` modifies a global task struct which is re-used every time `#!cpp xsTask` is called (For non programmers, this is similar to filling out a form once (the calls to [xsTaskAmount](./#532-xstaskamount)) and then submitting multiple copies of it for different people) * * @param unitId The unit to add the task to * @param actionType Task type. Eg.: 105 for heal, 155 for aura and etc. Look in the A.G.E. @@ -2524,16 +2524,16 @@ Note that `xsTaskAmount` modifies a global task struct which is re-used every ti void xsTask(int unitId = -1, int actionType = -1, int targetUnitId = -1, int playerId = -1) {} /** -* Sets the value of the given field of the global XS task struct to the provided value. See also [#!cpp xsTask](./#531-xstask) +* Sets the value of the given field of the global XS task struct to the provided value. See also [xsTask](./#531-xstask). It is recommended to always set all values before inserting or updating a task otherwise the insert/update might fail. * -* @param taskFieldId Specifies which property of the task to change - - 0: Work Value 1 - - 1: Work Value 2 - - 2: Work Range - - 3: Work Flag - - 4: Search Wait Time - - 5: Unused Flag (it is not actually unused, just what it's called in A.G.E.) - - 6: Target Diplomacy +* @param taskFieldId Specifies which property of the task to change (names correspond with A.G.E.): +* - 0: Work Value 1 (Task 155 - Quantity to mul/add to the attribute modified) +* - 1: Work Value 2 (Task 155 - Min number of units required to activate the effect. See Monaspa) +* - 2: Work Range +* - 3: Work Flag 2 +* - 4: Search Wait Time (Task 155 - Attribute to modify. Only some attributes are supported: [Movement Speed](../../attributes/attributes/#5-movement-speed), [Attack](../../attributes/attributes/#9-attack), [Attack Reload Time](../../attributes/attributes/#10-attack-reload-time), [Work Rate](../../attributes/attributes/#13-work-rate), [Regeneration Rate](../../attributes/attributes/#109-regeneration-rate), 116 - Melee Armor, 117 - Pierce Armor) +* - 5: Unused Flag (Task 155 - Combinable bitfield: 1 - Multiply instead of Add, 2 - Circular instead of Rectangular radius, 4 - Range indicator shown, 8 - Unused, 16 - Unused, 32 - Translucent) +* - 6: Target Diplomacy * @param value The value to set the task field to * * @returns void diff --git a/src/static/type_check/statement.rs b/src/static/type_check/statement.rs index 71de5ae..77e3bd7 100644 --- a/src/static/type_check/statement.rs +++ b/src/static/type_check/statement.rs @@ -51,7 +51,7 @@ pub fn xs_tc_stmt( } ASTreeNode::VarDef { is_extern, - is_static: _is_static, + is_static, is_const, type_, name: spanned_name, @@ -87,7 +87,6 @@ pub fn xs_tc_stmt( vec!["const"], )); } - return; }; @@ -113,6 +112,19 @@ pub fn xs_tc_stmt( } } } + + if *is_static { + match expr { + Expr::Literal(_) | Expr::Neg(_) | Expr::Vec { .. } => { } + _ => { + errs.push(XSError::syntax( + expr_span, + "{0} variable initializers must be literals", + vec!["static"], + )); + } + } + } let Some(init_type) = xs_tc_expr(spanned_expr, local_env, type_env, errs) else { return; diff --git a/test_xs/test.xs b/test_xs/test.xs index c5e27f2..d59df77 100644 --- a/test_xs/test.xs +++ b/test_xs/test.xs @@ -1,14 +1,3 @@ -void test(float f = 0.0) { - int cp = xsGetContextPlayer(); - xsChatData("cp: %d", cp); -} - -void test(float f = 0.0) { - int b = "Oops"; -} - void main() { - test(1); - - float c = 4 + 5.5; + int test = 1234567890; } \ No newline at end of file