Skip to content

Commit dd12a5a

Browse files
committed
add multiple sanity checks, clean-up
1 parent 0cb9c39 commit dd12a5a

File tree

8 files changed

+436
-218
lines changed

8 files changed

+436
-218
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
You are tasked with checking P language code files for COLLECTION OPERATIONS compliance. Follow these steps:
2+
3+
COLLECTION OPERATIONS CHECK:
4+
- CRITICAL: P does NOT support these operations:
5+
* NO append() function exists - use seq = seq + (element,)
6+
* NO inline initialization like var seq: seq[int] = {};
7+
8+
- Sequence Operations in P:
9+
```p
10+
var seq: seq[T];
11+
var x: T, i: int;
12+
13+
// CORRECT - Add element x at index i
14+
seq += (i, x);
15+
16+
// CORRECT - Add element to end of sequence
17+
seq += (sizeof(seq), x);
18+
19+
// WRONG - These are not supported:
20+
seq = seq + (x,); // Wrong: Cannot concatenate with tuple
21+
seq = append(seq, x); // Wrong: No append function
22+
seq = seq + default(seq[T]) + (x,); // Wrong: Cannot concatenate sequences
23+
```
24+
25+
CORRECT COLLECTION SYNTAX:
26+
- Sequence operations: `seq + (elem,)`, `seq += (index, elem)`
27+
- Set operations: `set + (elem)`, `set - (elem)`
28+
- Map operations: `map + (key, value)`, `map - (key)`
29+
30+
CORRECTION PROCESS:
31+
1. Scan the entire file to identify collection operation issues
32+
2. Create a list of required changes for collections only
33+
3. Make changes ensuring:
34+
- Use correct P syntax for all collection operations
35+
- Replace unsupported functions with supported syntax
36+
- Maintain original functionality
37+
4. Verify all collection operations compile correctly
38+
39+
OUTPUT FORMAT:
40+
Return only the corrected P code with collection operation fixes applied.
41+
Return the P code enclosed in XML tags where the tag name is the filename.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
You are tasked with checking P language code files for DUPLICATE DECLARATIONS compliance. Follow these steps:
2+
3+
DUPLICATE DECLARATION CHECK:
4+
- Scan across ALL files for duplicate declarations
5+
- Check for duplicate spec/monitor names across PSpec files
6+
- Common error: Same spec declared in multiple files
7+
- Check for duplicate:
8+
* Event declarations
9+
* Type definitions
10+
* Machine names
11+
* Function names
12+
* Spec/Monitor names
13+
14+
CORRECTION PROCESS:
15+
1. Scan the entire file and compare with Enums_Types_Events.p
16+
2. Identify all duplicate declarations
17+
3. Create a list of required changes for duplicates only
18+
4. Make changes by either:
19+
- Removing duplicate declarations
20+
- Renaming conflicting declarations
21+
- Moving declarations to appropriate files
22+
5. Ensure no functionality is lost during duplicate removal
23+
24+
OUTPUT FORMAT:
25+
Return only the corrected P code with duplicate declaration fixes applied.
26+
Return the P code enclosed in XML tags where the tag name is the filename.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
You are tasked with checking P language code files for EVENT DECLARATIONS compliance. Follow these steps:
2+
3+
EVENT DECLARATIONS CHECK:
4+
- Analyze Enums_Types_Events.p to understand existing declarations
5+
- Cross-reference with machine names to understand the system structure
6+
- Scan the target file for event declarations and usage
7+
- Module definitions: Only reference existing/declared machines in module lists
8+
- DO NOT DEFINE ANY NEW MACHINES OR SPECS OR TESTS IN modules
9+
- Verify that every event used is either:
10+
* Declared in Enums_Types_Events.p, or in any other available files in the context or
11+
* Properly declared within the current file
12+
- Check for duplicate declarations against Enums_Types_Events.p
13+
- If an event is used but not declared anywhere, add its declaration to the current file
14+
15+
CORRECTION PROCESS:
16+
1. Scan the entire file to identify event declaration issues
17+
2. Create a list of required changes for events only
18+
3. Make changes ensuring:
19+
- All events are properly declared before use
20+
- No duplicate declarations exist
21+
- Module definitions only reference existing machines
22+
4. Verify all event references have corresponding declarations
23+
24+
OUTPUT FORMAT:
25+
Return only the corrected P code with event declaration fixes applied.
26+
Return the P code enclosed in XML tags where the tag name is the filename.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
You are tasked with checking P language code files for VARIABLE INITIALIZATION compliance. Follow these steps:
2+
3+
VARIABLE INITIALIZATION CHECK:
4+
- Declare First, Initialize Later Pattern:
5+
```p
6+
// CORRECT P Syntax
7+
// ✅ Declaration only
8+
var participantsArray: seq[machine];
9+
var counter: int;
10+
var isReady: bool;
11+
12+
// ✅ Initialize separately
13+
fun InitializeVariables() {
14+
participantsArray = default(seq[machine]);
15+
counter = 0;
16+
isReady = false;
17+
}
18+
```
19+
20+
- P Auto-Defaults (Often No Initialization Needed):
21+
```p
22+
var counter: int; // Automatically 0
23+
var sequence: seq[int]; // Automatically empty
24+
var mapping: map[int, string]; // Automatically empty
25+
```
26+
27+
- Initialize collections properly:
28+
* Sets: `var mySet: set[int]; mySet = {};`
29+
* Sequences: `var mySeq: seq[int]; mySeq = default(seq[int]);`
30+
* Maps: `var myMap: map[int, string]; myMap = default(map[int, string]);`
31+
- Initialize at appropriate scope level, not mixed with other statements
32+
33+
CRITICAL - P does NOT support these operations:
34+
* NO append() function exists
35+
* NO inline initialization like var seq: seq[int] = {};
36+
37+
CORRECTION PROCESS:
38+
1. Scan the entire file to identify initialization issues
39+
2. Create a list of required changes for initialization only
40+
3. Make changes ensuring:
41+
- Proper collection initialization syntax
42+
- Separate declaration from initialization
43+
- Use of default() for complex types
44+
4. Remove any unsupported initialization patterns
45+
46+
OUTPUT FORMAT:
47+
Return only the corrected P code with initialization fixes applied.
48+
Return the P code enclosed in XML tags where the tag name is the filename.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
You are tasked with checking P language code files for TYPE DEFINITIONS compliance. Follow these steps:
2+
3+
TYPE DEFINITIONS CHECK:
4+
- Analyze Enums_Types_Events.p for existing type definitions
5+
- Create a dependency graph of type usage in the current file
6+
- For each type reference:
7+
* Check if it's defined in Enums_Types_Events.p
8+
* If not, verify it's defined in the current file before usage
9+
* For types defined in the current file:
10+
- Ensure the types appear before their first usage
11+
- Check for conflicts with types in Enums_Types_Events.p
12+
- Move definitions earlier if needed
13+
14+
TYPE COMPATIBILITY CHECK:
15+
- Check operations between different types:
16+
* Set operations must be between same set types
17+
* Cannot directly convert between set and sequence
18+
* Sequence element types must match exactly
19+
* When using set elements in sequence, convert properly:
20+
- Use helper functions like SetToSeq for conversion
21+
- Ensure return types match expected types
22+
* Example:
23+
```p
24+
fun SetToSeq(s: set[int]) : seq[int] {
25+
var result: seq[int];
26+
foreach (elem in s) {
27+
result = result + (elem,);
28+
}
29+
return result;
30+
}
31+
```
32+
33+
CORRECTION PROCESS:
34+
1. Scan the entire file to identify type definition and compatibility issues
35+
2. Create a list of required changes for types only
36+
3. Make changes ensuring:
37+
- Type definitions appear before usage
38+
- No type conflicts exist
39+
- Type compatibility is maintained across operations
40+
4. Add helper functions for type conversions if needed
41+
42+
OUTPUT FORMAT:
43+
Return only the corrected P code with type definition fixes applied.
44+
Return the P code enclosed in XML tags where the tag name is the filename.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
You are tasked with checking P language code files for VARIABLE DECLARATIONS AND SCOPE compliance. Follow these steps:
2+
3+
VARIABLE DECLARATIONS AND SCOPE CHECK:
4+
- Common Error Pattern 1 - Variables Declared Mid-Block:
5+
```p
6+
// INCORRECT
7+
machine Client {
8+
start state Init {
9+
entry {
10+
DoSomething();
11+
var temp: int; // Declaration after code
12+
temp = 5;
13+
}
14+
}
15+
}
16+
17+
// CORRECT
18+
machine Client {
19+
start state Init {
20+
entry {
21+
var temp: int; // Declaration at start
22+
DoSomething();
23+
temp = 5;
24+
}
25+
}
26+
}
27+
```
28+
29+
- Common Error Pattern 2 - Variables in Wrong Scope:
30+
```p
31+
// INCORRECT
32+
machine Server {
33+
fun ProcessRequest() {
34+
while (HasMore()) {
35+
var request: Request; // Wrong scope
36+
HandleRequest(request);
37+
}
38+
}
39+
}
40+
41+
// CORRECT
42+
machine Server {
43+
fun ProcessRequest() {
44+
var request: Request; // Correct scope
45+
while (HasMore()) {
46+
HandleRequest(request);
47+
}
48+
}
49+
}
50+
```
51+
52+
VARIABLE SCOPE CHECK:
53+
- Declare all variables at the start of their scope
54+
- Move any var declarations found mid-function to the top
55+
- Ensure variables used in foreach loops are properly declared
56+
- CRITICAL: P does NOT allow inline initialization in declarations
57+
58+
Example:
59+
```p
60+
fun ProcessNextInQueue(resourceId: int) {
61+
// ALL variable declarations first - NO inline initialization
62+
var nextClient: machine;
63+
var nextClientId: int;
64+
var i: int;
65+
var newQueue: seq[machine];
66+
var lockRequest: tLockRequest;
67+
68+
// Then initialization separately
69+
newQueue = default(seq[machine]);
70+
i = 0;
71+
72+
// Rest of function logic...
73+
}
74+
```
75+
76+
Fix parser errors like "mismatched input '=' expecting ';'":
77+
```p
78+
// WRONG - Causes parser error
79+
var lockQueue: seq[tLockRequest] = default(seq[tLockRequest]);
80+
81+
// CORRECT - Separate declaration and initialization
82+
var lockQueue: seq[tLockRequest];
83+
lockQueue = default(seq[tLockRequest]);
84+
```
85+
86+
CORRECTION PROCESS:
87+
1. Scan the entire file to identify variable declaration and scope issues
88+
2. Create a list of required changes for variables only
89+
3. Make changes ensuring:
90+
- All variables declared at scope start
91+
- No inline initialization in declarations
92+
- Proper variable scoping
93+
4. Maintain original functionality while fixing syntax
94+
95+
OUTPUT FORMAT:
96+
Return only the corrected P code with variable declaration fixes applied.
97+
Return the P code enclosed in XML tags where the tag name is the filename.

0 commit comments

Comments
 (0)