-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add assign float to int casting
- Loading branch information
Showing
7 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { TokenType } from '../shared/TokenTypes'; | ||
import { isMathOpToken } from './isMathOpToken'; | ||
|
||
/** | ||
* Checks if token can perform numeric expression | ||
*/ | ||
export function isFloatMathOpToken(type: TokenType): boolean { | ||
switch (type) { | ||
case TokenType.BIT_SHIFT_LEFT: | ||
case TokenType.BIT_SHIFT_RIGHT: | ||
case TokenType.BIT_OR: | ||
case TokenType.BIT_AND: | ||
case TokenType.POW: | ||
case TokenType.NOT: | ||
return false; | ||
|
||
default: | ||
return isMathOpToken(type); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { CTypeCheckErrorCode } from './utils'; | ||
|
||
const BIT_OPERATORS = ['<<', '>>', '^', '|', '&']; | ||
|
||
describe('Float typechecks', () => { | ||
test.each(BIT_OPERATORS)( | ||
'non math %s operator not work with floats in math expression', | ||
operator => { | ||
expect(/* cpp */ ` | ||
int main() { | ||
float b = 4; | ||
float a = b ${operator} 3; | ||
} | ||
`).toHaveCompilerError( | ||
CTypeCheckErrorCode.MATH_EXPRESSION_MUST_BE_INTEGRAL_TYPE, | ||
); | ||
}, | ||
); | ||
|
||
test.each(BIT_OPERATORS)( | ||
'non math %s operator not work with floats in math assign expression', | ||
operator => { | ||
expect(/* cpp */ ` | ||
int main() { | ||
float b = 4; | ||
float a = 4; | ||
a ${operator}= 3; | ||
} | ||
`).toHaveCompilerError( | ||
CTypeCheckErrorCode.MATH_EXPRESSION_MUST_BE_INTEGRAL_TYPE, | ||
); | ||
}, | ||
); | ||
}); |