Skip to content

Commit

Permalink
Fixed empty file tok errors and static var literal init errors, Updat…
Browse files Browse the repository at this point in the history
…ed prelude
  • Loading branch information
Divy1211 committed Dec 9, 2024
1 parent d5d1ff1 commit 601cd3d
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/lint/gen_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn gen_info_from_src(
ignores: &HashSet<u32>,
) -> (Vec<XSError>, bool) {
let (tokens, errs) = lexer()
.parse(src)
.parse(src.trim())
.into_output_errors();

let mut tc_errs = vec![];
Expand Down
48 changes: 24 additions & 24 deletions src/prelude.xs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// + --------------------------------- +
// | Generated on: 2024/11/17 18:34:01 |
// | Generated on: 2024/12/07 01:18:56 |
// | Made by: Alian713 |
// + --------------------------------- +

Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down
16 changes: 14 additions & 2 deletions src/static/type_check/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -87,7 +87,6 @@ pub fn xs_tc_stmt(
vec!["const"],
));
}

return;
};

Expand All @@ -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;
Expand Down
13 changes: 1 addition & 12 deletions test_xs/test.xs
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 601cd3d

Please sign in to comment.