@mpeggroup/mpeg-sdl-parser 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +337 -0
- package/bun.lock +65 -0
- package/dist/index.js +11829 -0
- package/grammar/sdl.ebnf.grammar +399 -0
- package/grammar/sdl.lezer.grammar +629 -0
- package/index.ts +83 -0
- package/package.json +61 -0
- package/src/analyser/checks/check-array-definition.ts +90 -0
- package/src/analyser/checks/check-array-element-access.ts +31 -0
- package/src/analyser/checks/check-class-declaration.ts +417 -0
- package/src/analyser/checks/check-computed-array-definition.ts +44 -0
- package/src/analyser/checks/check-computed-elementary-type-definition.ts +45 -0
- package/src/analyser/checks/check-elementary-type-definition.ts +167 -0
- package/src/analyser/checks/check-expression-binary.ts +242 -0
- package/src/analyser/checks/check-expression-lengthof.ts +34 -0
- package/src/analyser/checks/check-expression-unary.ts +166 -0
- package/src/analyser/checks/check-identifier.ts +71 -0
- package/src/analyser/checks/check-if-statement.ts +164 -0
- package/src/analyser/checks/check-map-declaration.ts +180 -0
- package/src/analyser/checks/check-map-definition.ts +118 -0
- package/src/analyser/checks/check-number-literal-float.ts +28 -0
- package/src/analyser/checks/check-parameter-list.ts +42 -0
- package/src/analyser/checks/check-specification.ts +53 -0
- package/src/analyser/checks/check-switch-statement.ts +206 -0
- package/src/analyser/checks/check.ts +20 -0
- package/src/analyser/create-sdl-analyser.ts +85 -0
- package/src/analyser/node-handler/abstract-analysis-node-handler.ts +626 -0
- package/src/analyser/node-handler/build-symbol-table-node-handler.ts +649 -0
- package/src/analyser/node-handler/specific-check-node-handler.ts +46 -0
- package/src/analyser/node-handler/validate-scope-node-handler.ts +290 -0
- package/src/analyser/node-handler/validate-type-node-handler.ts +497 -0
- package/src/analyser/sdl-analyser.ts +119 -0
- package/src/analyser/symbol-table.ts +388 -0
- package/src/analyser/util/symbol-table-utils.ts +458 -0
- package/src/analyser/util/type-utils.ts +238 -0
- package/src/ast/build/consume/consume-abstract-node.ts +199 -0
- package/src/ast/build/consume/consume-ast-node.ts +400 -0
- package/src/ast/build/consume/consume-primitive.ts +59 -0
- package/src/ast/build/consume/consume-trivia.ts +96 -0
- package/src/ast/build/consume/consume-white-space-and-missing-errors.ts +27 -0
- package/src/ast/build/node/build-aggregate-output-value.ts +57 -0
- package/src/ast/build/node/build-aligned-modifier.ts +99 -0
- package/src/ast/build/node/build-array-definition.ts +131 -0
- package/src/ast/build/node/build-array-element-access.ts +45 -0
- package/src/ast/build/node/build-base64-string-literal.ts +41 -0
- package/src/ast/build/node/build-binary-expression.ts +113 -0
- package/src/ast/build/node/build-binary-literal.ts +37 -0
- package/src/ast/build/node/build-bit-modifier.ts +86 -0
- package/src/ast/build/node/build-case-clause.ts +101 -0
- package/src/ast/build/node/build-class-declaration.ts +124 -0
- package/src/ast/build/node/build-class-definition.ts +56 -0
- package/src/ast/build/node/build-class-id-range.ts +32 -0
- package/src/ast/build/node/build-class-id.ts +19 -0
- package/src/ast/build/node/build-class-member-access.ts +27 -0
- package/src/ast/build/node/build-compound-statement.ts +33 -0
- package/src/ast/build/node/build-computed-array-definition.ts +53 -0
- package/src/ast/build/node/build-computed-elementary-type-definition.ts +100 -0
- package/src/ast/build/node/build-decimal-literal.ts +15 -0
- package/src/ast/build/node/build-default-clause.ts +76 -0
- package/src/ast/build/node/build-do-statement.ts +71 -0
- package/src/ast/build/node/build-elementary-type-definition.ts +164 -0
- package/src/ast/build/node/build-elementary-type-output-value.ts +25 -0
- package/src/ast/build/node/build-elementary-type.ts +36 -0
- package/src/ast/build/node/build-expandable-modifier.ts +68 -0
- package/src/ast/build/node/build-explicit-array-dimension.ts +37 -0
- package/src/ast/build/node/build-expression-statement.ts +31 -0
- package/src/ast/build/node/build-extended-class-id-range.ts +27 -0
- package/src/ast/build/node/build-extends-modifier.ts +41 -0
- package/src/ast/build/node/build-floating-point-literal.ts +15 -0
- package/src/ast/build/node/build-for-statement.ts +117 -0
- package/src/ast/build/node/build-hexadecimal-literal.ts +38 -0
- package/src/ast/build/node/build-identifier.ts +8 -0
- package/src/ast/build/node/build-if-statement.ts +82 -0
- package/src/ast/build/node/build-implicit-array-dimension.ts +78 -0
- package/src/ast/build/node/build-integer-literal.ts +15 -0
- package/src/ast/build/node/build-length-attribute.ts +48 -0
- package/src/ast/build/node/build-lengthof-expression.ts +45 -0
- package/src/ast/build/node/build-map-declaration.ts +110 -0
- package/src/ast/build/node/build-map-definition.ts +103 -0
- package/src/ast/build/node/build-map-entry.ts +33 -0
- package/src/ast/build/node/build-missing-error.ts +10 -0
- package/src/ast/build/node/build-multiple-character-literal.ts +65 -0
- package/src/ast/build/node/build-parameter-list.ts +50 -0
- package/src/ast/build/node/build-parameter-value-list.ts +54 -0
- package/src/ast/build/node/build-parameter.ts +47 -0
- package/src/ast/build/node/build-partial-array-dimension.ts +55 -0
- package/src/ast/build/node/build-specification.ts +24 -0
- package/src/ast/build/node/build-string-definition.ts +106 -0
- package/src/ast/build/node/build-switch-statement.ts +84 -0
- package/src/ast/build/node/build-token.ts +26 -0
- package/src/ast/build/node/build-unary-expression.ts +109 -0
- package/src/ast/build/node/build-unexpected-error.ts +14 -0
- package/src/ast/build/node/build-utf-string-literal.ts +110 -0
- package/src/ast/build/node/build-while-statement.ts +55 -0
- package/src/ast/build/util/array-dimension-kind-by-token-type-id-map.ts +167 -0
- package/src/ast/build/util/binary-operator-kind-by-token-type-id-map.ts +152 -0
- package/src/ast/build/util/build-context.ts +36 -0
- package/src/ast/build/util/class-id-kind-by-token-type-id-map.ts +160 -0
- package/src/ast/build/util/expression-kind-by-token-type-id-map.ts +168 -0
- package/src/ast/build/util/fetch-node.ts +433 -0
- package/src/ast/build/util/node-kind-by-token-type-id-map.ts +202 -0
- package/src/ast/build/util/statement-kind-by-token-type-id-map.ts +210 -0
- package/src/ast/build/util/string-literal-kind-by-token-type-id-map.ts +162 -0
- package/src/ast/build/util/token-kind-by-token-type-id-map.ts +337 -0
- package/src/ast/build-ast.ts +114 -0
- package/src/ast/node/abstract-array-definition.ts +17 -0
- package/src/ast/node/abstract-array-dimension.ts +20 -0
- package/src/ast/node/abstract-class-id.ts +13 -0
- package/src/ast/node/abstract-composite-node.ts +58 -0
- package/src/ast/node/abstract-elementary-type-definition.ts +29 -0
- package/src/ast/node/abstract-expression.ts +13 -0
- package/src/ast/node/abstract-leaf-node.ts +10 -0
- package/src/ast/node/abstract-node.ts +16 -0
- package/src/ast/node/abstract-statement.ts +13 -0
- package/src/ast/node/aggregate-output-value.ts +28 -0
- package/src/ast/node/aligned-modifier.ts +21 -0
- package/src/ast/node/array-definition.ts +44 -0
- package/src/ast/node/array-element-access.ts +24 -0
- package/src/ast/node/binary-expression.ts +28 -0
- package/src/ast/node/bit-modifier.ts +24 -0
- package/src/ast/node/case-clause.ts +30 -0
- package/src/ast/node/class-declaration.ts +39 -0
- package/src/ast/node/class-definition.ts +23 -0
- package/src/ast/node/class-id-range.ts +17 -0
- package/src/ast/node/class-id.ts +14 -0
- package/src/ast/node/class-member-access.ts +19 -0
- package/src/ast/node/compound-statement.ts +19 -0
- package/src/ast/node/computed-array-definition.ts +26 -0
- package/src/ast/node/computed-elementary-type-definition.ts +34 -0
- package/src/ast/node/default-clause.ts +26 -0
- package/src/ast/node/do-statement.ts +28 -0
- package/src/ast/node/elementary-type-definition.ts +49 -0
- package/src/ast/node/elementary-type-output-value.ts +19 -0
- package/src/ast/node/elementary-type.ts +18 -0
- package/src/ast/node/enum/array-dimension-kind.ts +11 -0
- package/src/ast/node/enum/binary-operator-kind.ts +41 -0
- package/src/ast/node/enum/class-id-kind.ts +12 -0
- package/src/ast/node/enum/elementary-type-kind.ts +13 -0
- package/src/ast/node/enum/expression-kind.ts +11 -0
- package/src/ast/node/enum/node-kind.ts +57 -0
- package/src/ast/node/enum/number-literal-kind.ts +17 -0
- package/src/ast/node/enum/statement-kind.ts +37 -0
- package/src/ast/node/enum/string-literal-kind.ts +13 -0
- package/src/ast/node/enum/string-variable-kind.ts +25 -0
- package/src/ast/node/enum/token-kind.ts +87 -0
- package/src/ast/node/expandable-modifier.ts +21 -0
- package/src/ast/node/explicit-array-dimension.ts +26 -0
- package/src/ast/node/expression-statement.ts +23 -0
- package/src/ast/node/extended-class-id-range.ts +20 -0
- package/src/ast/node/extends-modifier.ts +21 -0
- package/src/ast/node/for-statement.ts +29 -0
- package/src/ast/node/identifier.ts +12 -0
- package/src/ast/node/if-statement.ts +28 -0
- package/src/ast/node/implicit-array-dimension.ts +34 -0
- package/src/ast/node/length-attribute.ts +24 -0
- package/src/ast/node/length-of-expression.ts +21 -0
- package/src/ast/node/map-declaration.ts +34 -0
- package/src/ast/node/map-definition.ts +27 -0
- package/src/ast/node/map-entry.ts +18 -0
- package/src/ast/node/missing-error.ts +9 -0
- package/src/ast/node/number-literal.ts +18 -0
- package/src/ast/node/parameter-list.ts +25 -0
- package/src/ast/node/parameter-value-list.ts +29 -0
- package/src/ast/node/parameter.ts +20 -0
- package/src/ast/node/partial-array-dimension.ts +28 -0
- package/src/ast/node/specification.ts +21 -0
- package/src/ast/node/string-definition.ts +28 -0
- package/src/ast/node/string-literal.ts +21 -0
- package/src/ast/node/switch-statement.ts +32 -0
- package/src/ast/node/token.ts +20 -0
- package/src/ast/node/trivia.ts +13 -0
- package/src/ast/node/unary-expression.ts +31 -0
- package/src/ast/node/unexpected-error.ts +12 -0
- package/src/ast/node/while-statement.ts +26 -0
- package/src/ast/util/types.ts +138 -0
- package/src/ast/visitor/node-handler.ts +15 -0
- package/src/ast/visitor/node-visitor.ts +13 -0
- package/src/ast/visitor/traversing-visitor.ts +69 -0
- package/src/completion/completion-rules.ts +447 -0
- package/src/completion/get-potential-syntactic-tokens.ts +54 -0
- package/src/completion/get-potential-token-type-ids.ts +116 -0
- package/src/completion/hierarchical-map.ts +43 -0
- package/src/completion/rules/abstract-types.ts +174 -0
- package/src/completion/rules/aggregate-output-value-rules.ts +48 -0
- package/src/completion/rules/aligned-modifier-rules.ts +45 -0
- package/src/completion/rules/array-definition-rules.ts +87 -0
- package/src/completion/rules/array-element-access-rules.ts +22 -0
- package/src/completion/rules/assignment-expression-rules.ts +19 -0
- package/src/completion/rules/binary-expression-rules.ts +23 -0
- package/src/completion/rules/bit-modifier-rules.ts +25 -0
- package/src/completion/rules/case-clause-rules.ts +39 -0
- package/src/completion/rules/class-declaration-rules.ts +81 -0
- package/src/completion/rules/class-definition-rules.ts +28 -0
- package/src/completion/rules/class-id-range-rules.ts +17 -0
- package/src/completion/rules/class-id-rules.ts +9 -0
- package/src/completion/rules/class-member-access-rules.ts +7 -0
- package/src/completion/rules/compound-statement-rules.ts +25 -0
- package/src/completion/rules/computed-array-definition-rules.ts +25 -0
- package/src/completion/rules/computed-elementary-type-rules.ts +44 -0
- package/src/completion/rules/default-clause-rules.ts +23 -0
- package/src/completion/rules/do-statement-rules.ts +38 -0
- package/src/completion/rules/elementary-type-definition-rules.ts +62 -0
- package/src/completion/rules/elementary-type-output-value-rules.ts +13 -0
- package/src/completion/rules/elementary-type-rules.ts +18 -0
- package/src/completion/rules/expandable-modifier-rules.ts +21 -0
- package/src/completion/rules/explicit-array-dimension-rules.ts +22 -0
- package/src/completion/rules/expression-statement-rules.ts +22 -0
- package/src/completion/rules/extended-class-id-range-rules.ts +17 -0
- package/src/completion/rules/extends-modifier-rules.ts +17 -0
- package/src/completion/rules/for-statement-rules.ts +51 -0
- package/src/completion/rules/if-statement-rules.ts +42 -0
- package/src/completion/rules/implicit-array-dimension-rules.ts +21 -0
- package/src/completion/rules/length-attribute-rules.ts +19 -0
- package/src/completion/rules/lengthof-expression-rules.ts +23 -0
- package/src/completion/rules/map-declaration-rules.ts +45 -0
- package/src/completion/rules/map-definition-rules.ts +46 -0
- package/src/completion/rules/map-entry-rules.ts +17 -0
- package/src/completion/rules/parameter-list-rules.ts +21 -0
- package/src/completion/rules/parameter-rules.ts +17 -0
- package/src/completion/rules/parameter-value-list-rules.ts +27 -0
- package/src/completion/rules/partial-array-dimension-rules.ts +33 -0
- package/src/completion/rules/specification-rules.ts +37 -0
- package/src/completion/rules/string-definition-rules.ts +103 -0
- package/src/completion/rules/switch-statement-rules.ts +50 -0
- package/src/completion/rules/unary-expression-rules.ts +41 -0
- package/src/completion/rules/utf-string-literal-rules.ts +17 -0
- package/src/completion/rules/while-statement-rules.ts +38 -0
- package/src/lezer/context-tracker.ts +45 -0
- package/src/lezer/create-sdl-parser.ts +88 -0
- package/src/lezer/create-syntax-error-from-text-and-cursor.ts +110 -0
- package/src/lezer/create-syntax-error-from-text-and-position.ts +36 -0
- package/src/lezer/parser.terms.ts +129 -0
- package/src/lezer/parser.ts +63 -0
- package/src/lezer/props/fold-node-prop-source.ts +27 -0
- package/src/lezer/props/primitive-node-prop-source.ts +19 -0
- package/src/lezer/props/style-tags-node-prop-source.ts +188 -0
- package/src/lezer/props/syntactic-token-node-prop-source.ts +298 -0
- package/src/lezer/sdl-string-input.ts +46 -0
- package/src/location.ts +13 -0
- package/src/parse-helper.ts +93 -0
- package/src/prettier/prettier-plugin-sdl.ts +89 -0
- package/src/prettier/print-abstract-array-dimension.ts +84 -0
- package/src/prettier/print-abstract-class-id.ts +53 -0
- package/src/prettier/print-abstract-expression.ts +168 -0
- package/src/prettier/print-abstract-node.ts +224 -0
- package/src/prettier/print-abstract-statement.ts +124 -0
- package/src/prettier/print-aggregate-output-value.ts +35 -0
- package/src/prettier/print-aligned-modifier.ts +50 -0
- package/src/prettier/print-array-definition.ts +95 -0
- package/src/prettier/print-array-element-access.ts +14 -0
- package/src/prettier/print-bit-modifier.ts +48 -0
- package/src/prettier/print-case-clause.ts +58 -0
- package/src/prettier/print-class-declaration.ts +99 -0
- package/src/prettier/print-class-definition.ts +44 -0
- package/src/prettier/print-class-member-access.ts +13 -0
- package/src/prettier/print-computed-array-definition.ts +33 -0
- package/src/prettier/print-computed-elementary-type-definition.ts +60 -0
- package/src/prettier/print-default-clause.ts +39 -0
- package/src/prettier/print-do-statement.ts +31 -0
- package/src/prettier/print-elementary-type-definition.ts +108 -0
- package/src/prettier/print-elementary-type-output-value.ts +13 -0
- package/src/prettier/print-elementary-type.ts +28 -0
- package/src/prettier/print-expandable-modifier.ts +41 -0
- package/src/prettier/print-extends-modifier.ts +29 -0
- package/src/prettier/print-for-statement.ts +64 -0
- package/src/prettier/print-identifier.ts +10 -0
- package/src/prettier/print-if-statement.ts +76 -0
- package/src/prettier/print-length-attribute.ts +14 -0
- package/src/prettier/print-map-declaration.ts +75 -0
- package/src/prettier/print-map-definition.ts +67 -0
- package/src/prettier/print-map-entry.ts +22 -0
- package/src/prettier/print-number-literal.ts +84 -0
- package/src/prettier/print-parameter-list.ts +20 -0
- package/src/prettier/print-parameter-value-list.ts +20 -0
- package/src/prettier/print-parameter.ts +34 -0
- package/src/prettier/print-specification.ts +51 -0
- package/src/prettier/print-string-definition.ts +114 -0
- package/src/prettier/print-string-literal.ts +57 -0
- package/src/prettier/print-switch-statement.ts +46 -0
- package/src/prettier/print-token.ts +7 -0
- package/src/prettier/print-unexpected-error.ts +10 -0
- package/src/prettier/print-while-statement.ts +26 -0
- package/src/prettier/util/print-utils.ts +607 -0
- package/src/prettier/util/types.ts +40 -0
- package/src/scanner-error.ts +65 -0
- package/src/util/location-utils.ts +16 -0
- package/src/util/logger.ts +165 -0
- package/tests/analyser/create-sdl-analyser.test.ts +54 -0
- package/tests/analyser/get-sdl-analyser-test-scenarios.ts +80 -0
- package/tests/analyser/sdl-analyser-scenarios.test.ts +67 -0
- package/tests/analyser/semantic-error-scenarios.test.ts +40 -0
- package/tests/analyser/symbol-table.test.ts +188 -0
- package/tests/analyser/test-cases/array_definition.txt +50 -0
- package/tests/analyser/test-cases/class_declaration.txt +112 -0
- package/tests/analyser/test-cases/class_definition.txt +60 -0
- package/tests/analyser/test-cases/compound_statement.txt +63 -0
- package/tests/analyser/test-cases/computed_array_definition.txt +12 -0
- package/tests/analyser/test-cases/computed_elementary_type_definition.txt +39 -0
- package/tests/analyser/test-cases/do_statement.txt +16 -0
- package/tests/analyser/test-cases/elementary_type_definition.txt +58 -0
- package/tests/analyser/test-cases/expression.txt +159 -0
- package/tests/analyser/test-cases/for_statement.txt +55 -0
- package/tests/analyser/test-cases/if_statement.txt +57 -0
- package/tests/analyser/test-cases/map_declaration.txt +89 -0
- package/tests/analyser/test-cases/map_definition.txt +35 -0
- package/tests/analyser/test-cases/number_literal.txt +31 -0
- package/tests/analyser/test-cases/parameter_list.txt +16 -0
- package/tests/analyser/test-cases/scopes.txt +239 -0
- package/tests/analyser/test-cases/specification.txt +28 -0
- package/tests/analyser/test-cases/string_definition.txt +40 -0
- package/tests/analyser/test-cases/switch_statement.txt +96 -0
- package/tests/analyser/test-cases/while_statement.txt +16 -0
- package/tests/analyser/util/symbol-table-utils.test.ts +65 -0
- package/tests/ast/__snapshots__/build-ast.test.ts.snap +38897 -0
- package/tests/ast/build-ast.test.ts +463 -0
- package/tests/ast/visitor/traversing-visitor.test.ts +36 -0
- package/tests/completion/get-potential-syntactic-tokens.test.ts +89 -0
- package/tests/completion/get-potential-token-type-ids.test.ts +76 -0
- package/tests/completion/test-potential-syntactic-tokens-scenario.ts +24 -0
- package/tests/completion/test-potential-token-type-ids-scenario.ts +33 -0
- package/tests/fixtures/history-recording-node-handler.ts +232 -0
- package/tests/lezer/create-parse-error-from-text-and-position.test.ts +129 -0
- package/tests/lezer/create-sdl-parser.test.ts +15 -0
- package/tests/lezer/sdl-parser-scenarios.test.ts +24 -0
- package/tests/lezer/sdl-string-input.test.ts +12 -0
- package/tests/lezer/syntax-error-scenarios.test.ts +114 -0
- package/tests/lezer/test-cases/array_definition.txt +109 -0
- package/tests/lezer/test-cases/class_declaration.txt +141 -0
- package/tests/lezer/test-cases/class_definition.txt +89 -0
- package/tests/lezer/test-cases/comment.txt +335 -0
- package/tests/lezer/test-cases/compound_statement.txt +109 -0
- package/tests/lezer/test-cases/computed_array_definition.txt +33 -0
- package/tests/lezer/test-cases/computed_elementary_type_definition.txt +59 -0
- package/tests/lezer/test-cases/do_statement.txt +48 -0
- package/tests/lezer/test-cases/elementary_type_definition.txt +158 -0
- package/tests/lezer/test-cases/expression.txt +1203 -0
- package/tests/lezer/test-cases/for_statement.txt +183 -0
- package/tests/lezer/test-cases/if_statement.txt +183 -0
- package/tests/lezer/test-cases/invalid.txt +97 -0
- package/tests/lezer/test-cases/map_declaration.txt +152 -0
- package/tests/lezer/test-cases/map_definition.txt +59 -0
- package/tests/lezer/test-cases/number_literal.txt +273 -0
- package/tests/lezer/test-cases/specification.txt +38 -0
- package/tests/lezer/test-cases/string_definition.txt +263 -0
- package/tests/lezer/test-cases/string_literal.txt +303 -0
- package/tests/lezer/test-cases/switch_statement.txt +407 -0
- package/tests/lezer/test-cases/while_statement.txt +45 -0
- package/tests/parse-helper.test.ts +361 -0
- package/tests/prettier/__snapshots__/prettier-plugin-sdl.test.ts.snap +127 -0
- package/tests/prettier/prettier-plugin-sdl.test.ts +58 -0
- package/tests/prettier/print-array.test.ts +29 -0
- package/tests/prettier/print-class.test.ts +15 -0
- package/tests/prettier/print-do.test.ts +25 -0
- package/tests/prettier/print-elementary-type.test.ts +62 -0
- package/tests/prettier/print-error.test.ts +40 -0
- package/tests/prettier/print-expression.test.ts +17 -0
- package/tests/prettier/print-for.test.ts +23 -0
- package/tests/prettier/print-if.test.ts +71 -0
- package/tests/prettier/print-number-literal.test.ts +28 -0
- package/tests/prettier/print-specification.test.ts +54 -0
- package/tests/prettier/print-string.test.ts +36 -0
- package/tests/prettier/print-switch.test.ts +69 -0
- package/tests/prettier/print-while.test.ts +23 -0
- package/tests/prettier/test-prettier-scenario.ts +41 -0
- package/tests/prettier/util/print-utils.test.ts +665 -0
- package/tests/prettier/util/types.test.ts +38 -0
- package/tests/sample-specifications/invalid.sdl +24 -0
- package/tests/sample-specifications/prettified-invalid.sdl +28 -0
- package/tests/sample-specifications/prettified-various-elements-narrow.sdl +97 -0
- package/tests/sample-specifications/prettified-various-elements.sdl +90 -0
- package/tests/sample-specifications/sample.sdl +24 -0
- package/tests/sample-specifications/various-elements.sdl +88 -0
- package/tests/util/logger.test.ts +36 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,649 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AddSymbolResult,
|
|
3
|
+
NumericType,
|
|
4
|
+
type Symbol,
|
|
5
|
+
type SymbolAttributes,
|
|
6
|
+
SymbolKind,
|
|
7
|
+
SymbolTable,
|
|
8
|
+
} from "../symbol-table.ts";
|
|
9
|
+
import { NodeKind } from "../../ast/node/enum/node-kind.ts";
|
|
10
|
+
import { StatementKind } from "../../ast/node/enum/statement-kind.ts";
|
|
11
|
+
import type { ClassDeclaration } from "../../ast/node/class-declaration.ts";
|
|
12
|
+
import type { MapDeclaration } from "../../ast/node/map-declaration.ts";
|
|
13
|
+
import type { Parameter } from "../../ast/node/parameter.ts";
|
|
14
|
+
import type { ElementaryTypeDefinition } from "../../ast/node/elementary-type-definition.ts";
|
|
15
|
+
import type { ComputedElementaryTypeDefinition } from "../../ast/node/computed-elementary-type-definition.ts";
|
|
16
|
+
import type { ArrayDefinition } from "../../ast/node/array-definition.ts";
|
|
17
|
+
import type { ComputedArrayDefinition } from "../../ast/node/computed-array-definition.ts";
|
|
18
|
+
import type { StringDefinition } from "../../ast/node/string-definition.ts";
|
|
19
|
+
import type { ClassDefinition } from "../../ast/node/class-definition.ts";
|
|
20
|
+
import type { MapDefinition } from "../../ast/node/map-definition.ts";
|
|
21
|
+
import { SemanticError } from "../../scanner-error.ts";
|
|
22
|
+
import { AbstractAnalysisNodeHandler } from "./abstract-analysis-node-handler.ts";
|
|
23
|
+
import {
|
|
24
|
+
getElementaryTypeKind,
|
|
25
|
+
getRequiredElementaryType,
|
|
26
|
+
getRequiredIdentifier,
|
|
27
|
+
getRequiredToken,
|
|
28
|
+
getStringVariableKind,
|
|
29
|
+
} from "../util/symbol-table-utils.ts";
|
|
30
|
+
import { isElementaryType, isIdentifier } from "../../ast/util/types.ts";
|
|
31
|
+
import {
|
|
32
|
+
getNumericTypeFromElementaryTypeKind,
|
|
33
|
+
getStringTypeFromStringVariableKind,
|
|
34
|
+
} from "../util/type-utils.ts";
|
|
35
|
+
import type { ExpandableModifier } from "../../ast/node/expandable-modifier.ts";
|
|
36
|
+
|
|
37
|
+
export class BuildSymbolTableNodeHandler extends AbstractAnalysisNodeHandler {
|
|
38
|
+
constructor(symbolTable: SymbolTable, strict: boolean) {
|
|
39
|
+
super(symbolTable, strict);
|
|
40
|
+
|
|
41
|
+
this.registerBeforeNodeHandler(
|
|
42
|
+
NodeKind.PARAMETER,
|
|
43
|
+
undefined,
|
|
44
|
+
(node) => this.addParameterSymbol(node as Parameter),
|
|
45
|
+
);
|
|
46
|
+
this.registerBeforeNodeHandler(
|
|
47
|
+
NodeKind.STATEMENT,
|
|
48
|
+
StatementKind.CLASS_DECLARATION,
|
|
49
|
+
(node) => this.addClassDeclarationSymbol(node as ClassDeclaration),
|
|
50
|
+
);
|
|
51
|
+
this.registerBeforeNodeHandler(
|
|
52
|
+
NodeKind.STATEMENT,
|
|
53
|
+
StatementKind.MAP_DECLARATION,
|
|
54
|
+
(node) => this.addMapDeclarationSymbol(node as MapDeclaration),
|
|
55
|
+
);
|
|
56
|
+
this.registerBeforeNodeHandler(
|
|
57
|
+
NodeKind.STATEMENT,
|
|
58
|
+
StatementKind.ELEMENTARY_TYPE_DEFINITION,
|
|
59
|
+
(node) =>
|
|
60
|
+
this.addElementaryTypeDefinitionSymbol(
|
|
61
|
+
node as ElementaryTypeDefinition,
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
this.registerBeforeNodeHandler(
|
|
65
|
+
NodeKind.STATEMENT,
|
|
66
|
+
StatementKind.COMPUTED_ELEMENTARY_TYPE_DEFINITION,
|
|
67
|
+
(node) =>
|
|
68
|
+
this.addComputedElementaryTypeDefinitionSymbol(
|
|
69
|
+
node as ComputedElementaryTypeDefinition,
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
this.registerBeforeNodeHandler(
|
|
73
|
+
NodeKind.STATEMENT,
|
|
74
|
+
StatementKind.ARRAY_DEFINITION,
|
|
75
|
+
(node) => this.addArrayDefinitionSymbol(node as ArrayDefinition),
|
|
76
|
+
);
|
|
77
|
+
this.registerBeforeNodeHandler(
|
|
78
|
+
NodeKind.STATEMENT,
|
|
79
|
+
StatementKind.COMPUTED_ARRAY_DEFINITION,
|
|
80
|
+
(node) =>
|
|
81
|
+
this.addComputedArrayDefinitionSymbol(node as ComputedArrayDefinition),
|
|
82
|
+
);
|
|
83
|
+
this.registerBeforeNodeHandler(
|
|
84
|
+
NodeKind.STATEMENT,
|
|
85
|
+
StatementKind.STRING_DEFINITION,
|
|
86
|
+
(node) => this.addStringDefinitionSymbol(node as StringDefinition),
|
|
87
|
+
);
|
|
88
|
+
this.registerBeforeNodeHandler(
|
|
89
|
+
NodeKind.STATEMENT,
|
|
90
|
+
StatementKind.CLASS_DEFINITION,
|
|
91
|
+
(node) => this.addClassDefinitionSymbol(node as ClassDefinition),
|
|
92
|
+
);
|
|
93
|
+
this.registerBeforeNodeHandler(
|
|
94
|
+
NodeKind.STATEMENT,
|
|
95
|
+
StatementKind.MAP_DEFINITION,
|
|
96
|
+
(node) => this.addMapDefinitionSymbol(node as MapDefinition),
|
|
97
|
+
);
|
|
98
|
+
this.registerBeforeNodeHandler(
|
|
99
|
+
NodeKind.EXPANDABLE_MODIFIER,
|
|
100
|
+
undefined,
|
|
101
|
+
(node) => this.addExpandableModifierSymbol(node as ExpandableModifier),
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private defineSymbol(symbol: Symbol) {
|
|
106
|
+
const addSymbolResult = this.symbolTable.addSymbol(symbol);
|
|
107
|
+
|
|
108
|
+
if (addSymbolResult === AddSymbolResult.SUCCESS) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
let error: SemanticError | undefined;
|
|
113
|
+
|
|
114
|
+
if (addSymbolResult === AddSymbolResult.DUPLICATE) {
|
|
115
|
+
error = new SemanticError(
|
|
116
|
+
`Variable: ${symbol.name} is already declared in scope: ${this.symbolTable.getCurrentScope().name}`,
|
|
117
|
+
symbol.location,
|
|
118
|
+
);
|
|
119
|
+
} else if (addSymbolResult === AddSymbolResult.MEMBER_CONFLICT) {
|
|
120
|
+
const classScope = this.symbolTable.getEnclosingClassScope();
|
|
121
|
+
|
|
122
|
+
error = new SemanticError(
|
|
123
|
+
`Duplicate member variable: ${symbol.name} conflicts with type defined in different conditional branch within scope: ${
|
|
124
|
+
classScope!.name
|
|
125
|
+
}`,
|
|
126
|
+
symbol.location,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (this.strict) {
|
|
131
|
+
throw error;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
this.semanticErrors.push(error!);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
private addElementaryTypeDefinitionSymbol(
|
|
138
|
+
elementaryTypeDefinition: ElementaryTypeDefinition,
|
|
139
|
+
): void {
|
|
140
|
+
const identifier = getRequiredIdentifier(
|
|
141
|
+
elementaryTypeDefinition.identifier,
|
|
142
|
+
elementaryTypeDefinition,
|
|
143
|
+
this.strict,
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
if (!identifier) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const elementaryType = getRequiredElementaryType(
|
|
151
|
+
elementaryTypeDefinition.elementaryType,
|
|
152
|
+
elementaryTypeDefinition,
|
|
153
|
+
this.strict,
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
if (!elementaryType) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const elementaryTypeKind = getElementaryTypeKind(
|
|
161
|
+
elementaryType,
|
|
162
|
+
this.strict,
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
if (elementaryTypeKind === undefined) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const name = identifier.name;
|
|
170
|
+
const location = identifier.startToken!.getLocation();
|
|
171
|
+
const attributes: SymbolAttributes = {
|
|
172
|
+
isConst: !!elementaryTypeDefinition.constKeyword,
|
|
173
|
+
numericType: getNumericTypeFromElementaryTypeKind(elementaryTypeKind),
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
this.defineSymbol({
|
|
177
|
+
node: elementaryTypeDefinition,
|
|
178
|
+
name,
|
|
179
|
+
kind: SymbolKind.VARIABLE,
|
|
180
|
+
attributes,
|
|
181
|
+
location,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private addComputedElementaryTypeDefinitionSymbol(
|
|
186
|
+
computedElementaryTypeDefinition: ComputedElementaryTypeDefinition,
|
|
187
|
+
): void {
|
|
188
|
+
const identifier = getRequiredIdentifier(
|
|
189
|
+
computedElementaryTypeDefinition.identifier,
|
|
190
|
+
computedElementaryTypeDefinition,
|
|
191
|
+
this.strict,
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
if (!identifier) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const elementaryType = getRequiredElementaryType(
|
|
199
|
+
computedElementaryTypeDefinition.elementaryType,
|
|
200
|
+
computedElementaryTypeDefinition,
|
|
201
|
+
this.strict,
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
if (!elementaryType) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const elementaryTypeKind = getElementaryTypeKind(
|
|
209
|
+
elementaryType,
|
|
210
|
+
this.strict,
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
if (elementaryTypeKind === undefined) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const name = identifier.name;
|
|
218
|
+
const location = identifier.startToken!.getLocation();
|
|
219
|
+
const attributes: SymbolAttributes = {
|
|
220
|
+
isConst: !!computedElementaryTypeDefinition.constKeyword,
|
|
221
|
+
numericType: getNumericTypeFromElementaryTypeKind(elementaryTypeKind),
|
|
222
|
+
isComputed: true,
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
this.defineSymbol({
|
|
226
|
+
node: computedElementaryTypeDefinition,
|
|
227
|
+
name,
|
|
228
|
+
kind: SymbolKind.VARIABLE,
|
|
229
|
+
attributes,
|
|
230
|
+
location,
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
private addArrayDefinitionSymbol(arrayDefinition: ArrayDefinition): void {
|
|
235
|
+
const identifier = getRequiredIdentifier(
|
|
236
|
+
arrayDefinition.identifier,
|
|
237
|
+
arrayDefinition,
|
|
238
|
+
this.strict,
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
if (!identifier) {
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const name = identifier.name;
|
|
246
|
+
const location = identifier.startToken!.getLocation();
|
|
247
|
+
const attributes: SymbolAttributes = {
|
|
248
|
+
isArray: true,
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
if (isElementaryType(arrayDefinition.elementaryType)) {
|
|
252
|
+
const elementaryTypeKind = getElementaryTypeKind(
|
|
253
|
+
arrayDefinition.elementaryType,
|
|
254
|
+
this.strict,
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
if (elementaryTypeKind !== undefined) {
|
|
258
|
+
attributes.numericType = getNumericTypeFromElementaryTypeKind(
|
|
259
|
+
elementaryTypeKind,
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
} else if (isIdentifier(arrayDefinition.classIdentifier)) {
|
|
263
|
+
attributes.classType = arrayDefinition.classIdentifier.name;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// check that at least one of elementaryType or classIdentifier is present
|
|
267
|
+
if (
|
|
268
|
+
(attributes.numericType === undefined) &&
|
|
269
|
+
!attributes.classType
|
|
270
|
+
) {
|
|
271
|
+
const error = new SemanticError(
|
|
272
|
+
`Array definition must have either an elementary type or a class identifier`,
|
|
273
|
+
identifier.startToken!.getLocation(),
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
if (this.strict) {
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
this.semanticErrors.push(error);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
this.defineSymbol({
|
|
285
|
+
node: arrayDefinition,
|
|
286
|
+
name,
|
|
287
|
+
kind: SymbolKind.VARIABLE,
|
|
288
|
+
attributes,
|
|
289
|
+
location,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private addComputedArrayDefinitionSymbol(
|
|
294
|
+
computedArrayDefinition: ComputedArrayDefinition,
|
|
295
|
+
): void {
|
|
296
|
+
const identifier = getRequiredIdentifier(
|
|
297
|
+
computedArrayDefinition.identifier,
|
|
298
|
+
computedArrayDefinition,
|
|
299
|
+
this.strict,
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
if (!identifier) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
const elementaryType = getRequiredElementaryType(
|
|
307
|
+
computedArrayDefinition.elementaryType,
|
|
308
|
+
computedArrayDefinition,
|
|
309
|
+
this.strict,
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
if (!elementaryType) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const elementaryTypeKind = getElementaryTypeKind(
|
|
317
|
+
elementaryType,
|
|
318
|
+
this.strict,
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
if (elementaryTypeKind === undefined) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const name = identifier.name;
|
|
326
|
+
const location = identifier.startToken!.getLocation();
|
|
327
|
+
const attributes: SymbolAttributes = {
|
|
328
|
+
isArray: true,
|
|
329
|
+
isComputed: true,
|
|
330
|
+
numericType: getNumericTypeFromElementaryTypeKind(elementaryTypeKind),
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
this.defineSymbol({
|
|
334
|
+
node: computedArrayDefinition,
|
|
335
|
+
name,
|
|
336
|
+
kind: SymbolKind.VARIABLE,
|
|
337
|
+
attributes,
|
|
338
|
+
location,
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
private addStringDefinitionSymbol(stringDefinition: StringDefinition): void {
|
|
343
|
+
const identifier = getRequiredIdentifier(
|
|
344
|
+
stringDefinition.identifier,
|
|
345
|
+
stringDefinition,
|
|
346
|
+
this.strict,
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
if (!identifier) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const stringVariableKindToken = getRequiredToken(
|
|
354
|
+
stringDefinition.stringVariableKindToken,
|
|
355
|
+
stringDefinition,
|
|
356
|
+
this.strict,
|
|
357
|
+
);
|
|
358
|
+
|
|
359
|
+
if (!stringVariableKindToken) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
const stringVariableKind = getStringVariableKind(
|
|
364
|
+
stringVariableKindToken,
|
|
365
|
+
this.strict,
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
if (stringVariableKind === undefined) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const name = identifier.name;
|
|
373
|
+
const location = identifier.startToken!.getLocation();
|
|
374
|
+
const attributes: SymbolAttributes = {
|
|
375
|
+
isString: true,
|
|
376
|
+
isConst: !!stringDefinition.constKeyword,
|
|
377
|
+
stringType: getStringTypeFromStringVariableKind(stringVariableKind),
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
this.defineSymbol({
|
|
381
|
+
node: stringDefinition,
|
|
382
|
+
name,
|
|
383
|
+
kind: SymbolKind.VARIABLE,
|
|
384
|
+
attributes,
|
|
385
|
+
location,
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
private addClassDeclarationSymbol(classDeclaration: ClassDeclaration): void {
|
|
390
|
+
const identifier = getRequiredIdentifier(
|
|
391
|
+
classDeclaration.identifier,
|
|
392
|
+
classDeclaration,
|
|
393
|
+
this.strict,
|
|
394
|
+
);
|
|
395
|
+
|
|
396
|
+
if (!identifier) {
|
|
397
|
+
return;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const name = identifier.name;
|
|
401
|
+
const location = identifier.startToken!.getLocation();
|
|
402
|
+
const attributes: SymbolAttributes = {};
|
|
403
|
+
|
|
404
|
+
this.defineSymbol({
|
|
405
|
+
node: classDeclaration,
|
|
406
|
+
name,
|
|
407
|
+
kind: SymbolKind.CLASS,
|
|
408
|
+
attributes,
|
|
409
|
+
location,
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
private addExpandableModifierSymbol(
|
|
414
|
+
expandableModifier: ExpandableModifier,
|
|
415
|
+
): void {
|
|
416
|
+
const sizeOfInstanceLocation = expandableModifier!.startToken!
|
|
417
|
+
.getLocation();
|
|
418
|
+
|
|
419
|
+
const sizeOfInstanceAttributes: SymbolAttributes = {
|
|
420
|
+
isComputed: true,
|
|
421
|
+
isConst: true,
|
|
422
|
+
numericType: NumericType.INTEGER,
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
this.defineSymbol({
|
|
426
|
+
node: expandableModifier,
|
|
427
|
+
name: "sizeOfInstance",
|
|
428
|
+
kind: SymbolKind.VARIABLE,
|
|
429
|
+
attributes: sizeOfInstanceAttributes,
|
|
430
|
+
location: sizeOfInstanceLocation,
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
private addMapDeclarationSymbol(mapDeclaration: MapDeclaration): void {
|
|
435
|
+
const identifier = getRequiredIdentifier(
|
|
436
|
+
mapDeclaration.identifier,
|
|
437
|
+
mapDeclaration,
|
|
438
|
+
this.strict,
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
if (!identifier) {
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const name = identifier.name;
|
|
446
|
+
const location = identifier.startToken!.getLocation();
|
|
447
|
+
const attributes: SymbolAttributes = {};
|
|
448
|
+
|
|
449
|
+
if (isElementaryType(mapDeclaration.outputElementaryType)) {
|
|
450
|
+
const elementaryTypeKind = getElementaryTypeKind(
|
|
451
|
+
mapDeclaration.outputElementaryType,
|
|
452
|
+
this.strict,
|
|
453
|
+
);
|
|
454
|
+
|
|
455
|
+
if (elementaryTypeKind !== undefined) {
|
|
456
|
+
attributes.numericType = getNumericTypeFromElementaryTypeKind(
|
|
457
|
+
elementaryTypeKind,
|
|
458
|
+
);
|
|
459
|
+
}
|
|
460
|
+
} else if (isIdentifier(mapDeclaration.outputClassIdentifier)) {
|
|
461
|
+
attributes.classType = mapDeclaration.outputClassIdentifier.name;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// check that at least one of elementaryType or classIdentifier is present
|
|
465
|
+
if (
|
|
466
|
+
(attributes.numericType === undefined) &&
|
|
467
|
+
!attributes.classType
|
|
468
|
+
) {
|
|
469
|
+
const error = new SemanticError(
|
|
470
|
+
`Map declaration must have either an elementary type or a class identifier`,
|
|
471
|
+
identifier.startToken!.getLocation(),
|
|
472
|
+
);
|
|
473
|
+
|
|
474
|
+
if (this.strict) {
|
|
475
|
+
throw error;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
this.semanticErrors.push(error);
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
this.defineSymbol({
|
|
483
|
+
node: mapDeclaration,
|
|
484
|
+
name,
|
|
485
|
+
kind: SymbolKind.MAP,
|
|
486
|
+
attributes,
|
|
487
|
+
location,
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
private addClassDefinitionSymbol(classDefinition: ClassDefinition): void {
|
|
492
|
+
const identifier = getRequiredIdentifier(
|
|
493
|
+
classDefinition.identifier,
|
|
494
|
+
classDefinition,
|
|
495
|
+
this.strict,
|
|
496
|
+
);
|
|
497
|
+
|
|
498
|
+
if (!identifier) {
|
|
499
|
+
return;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
const classIdentifier = getRequiredIdentifier(
|
|
503
|
+
classDefinition.classIdentifier,
|
|
504
|
+
classDefinition,
|
|
505
|
+
this.strict,
|
|
506
|
+
);
|
|
507
|
+
|
|
508
|
+
if (!classIdentifier) {
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
const name = identifier.name;
|
|
513
|
+
const location = identifier.startToken!.getLocation();
|
|
514
|
+
const attributes: SymbolAttributes = {
|
|
515
|
+
classType: classIdentifier.name,
|
|
516
|
+
};
|
|
517
|
+
|
|
518
|
+
this.defineSymbol({
|
|
519
|
+
node: classDefinition,
|
|
520
|
+
name,
|
|
521
|
+
kind: SymbolKind.VARIABLE,
|
|
522
|
+
attributes,
|
|
523
|
+
location,
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
private addMapDefinitionSymbol(mapDefinition: MapDefinition): void {
|
|
528
|
+
const identifier = getRequiredIdentifier(
|
|
529
|
+
mapDefinition.identifier,
|
|
530
|
+
mapDefinition,
|
|
531
|
+
this.strict,
|
|
532
|
+
);
|
|
533
|
+
|
|
534
|
+
if (!identifier) {
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
const mapIdentifier = getRequiredIdentifier(
|
|
539
|
+
mapDefinition.mapIdentifier,
|
|
540
|
+
mapDefinition,
|
|
541
|
+
this.strict,
|
|
542
|
+
);
|
|
543
|
+
|
|
544
|
+
if (!mapIdentifier) {
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
const name = identifier.name;
|
|
549
|
+
const location = identifier.startToken!.getLocation();
|
|
550
|
+
const attributes: SymbolAttributes = {
|
|
551
|
+
mapType: mapIdentifier.name,
|
|
552
|
+
};
|
|
553
|
+
|
|
554
|
+
if (isElementaryType(mapDefinition.elementaryType)) {
|
|
555
|
+
const elementaryTypeKind = getElementaryTypeKind(
|
|
556
|
+
mapDefinition.elementaryType,
|
|
557
|
+
this.strict,
|
|
558
|
+
);
|
|
559
|
+
|
|
560
|
+
if (elementaryTypeKind !== undefined) {
|
|
561
|
+
attributes.numericType = getNumericTypeFromElementaryTypeKind(
|
|
562
|
+
elementaryTypeKind,
|
|
563
|
+
);
|
|
564
|
+
}
|
|
565
|
+
} else if (isIdentifier(mapDefinition.classIdentifier)) {
|
|
566
|
+
attributes.classType = mapDefinition.classIdentifier.name;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// check that at least one of elementaryType or classIdentifier is present
|
|
570
|
+
if ((attributes.numericType === undefined) && !attributes.classType) {
|
|
571
|
+
const error = new SemanticError(
|
|
572
|
+
`Map definition must have either an elementary type or a class identifier`,
|
|
573
|
+
identifier.startToken!.getLocation(),
|
|
574
|
+
);
|
|
575
|
+
|
|
576
|
+
if (this.strict) {
|
|
577
|
+
throw error;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
this.semanticErrors.push(error);
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
this.defineSymbol({
|
|
585
|
+
node: mapDefinition,
|
|
586
|
+
name,
|
|
587
|
+
kind: SymbolKind.VARIABLE,
|
|
588
|
+
attributes,
|
|
589
|
+
location,
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
private addParameterSymbol(parameter: Parameter): void {
|
|
594
|
+
const identifier = getRequiredIdentifier(
|
|
595
|
+
parameter.identifier,
|
|
596
|
+
parameter,
|
|
597
|
+
this.strict,
|
|
598
|
+
);
|
|
599
|
+
|
|
600
|
+
if (!identifier) {
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
const name = identifier.name;
|
|
605
|
+
const location = identifier.startToken!.getLocation();
|
|
606
|
+
const attributes: SymbolAttributes = {};
|
|
607
|
+
|
|
608
|
+
if (isElementaryType(parameter.elementaryType)) {
|
|
609
|
+
const elementaryTypeKind = getElementaryTypeKind(
|
|
610
|
+
parameter.elementaryType,
|
|
611
|
+
this.strict,
|
|
612
|
+
);
|
|
613
|
+
|
|
614
|
+
if (elementaryTypeKind !== undefined) {
|
|
615
|
+
attributes.numericType = getNumericTypeFromElementaryTypeKind(
|
|
616
|
+
elementaryTypeKind,
|
|
617
|
+
);
|
|
618
|
+
}
|
|
619
|
+
} else if (isIdentifier(parameter.classIdentifier)) {
|
|
620
|
+
attributes.classType = parameter.classIdentifier.name;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
// check that at least one of elementaryType or classIdentifier is present
|
|
624
|
+
if (
|
|
625
|
+
(attributes.numericType === undefined) &&
|
|
626
|
+
!attributes.classType
|
|
627
|
+
) {
|
|
628
|
+
const error = new SemanticError(
|
|
629
|
+
`Parameter must have either an elementary type or a class identifier`,
|
|
630
|
+
identifier.startToken!.getLocation(),
|
|
631
|
+
);
|
|
632
|
+
|
|
633
|
+
if (this.strict) {
|
|
634
|
+
throw error;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
this.semanticErrors.push(error);
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
this.defineSymbol({
|
|
642
|
+
node: parameter,
|
|
643
|
+
name,
|
|
644
|
+
kind: SymbolKind.VARIABLE,
|
|
645
|
+
attributes,
|
|
646
|
+
location,
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { SymbolTable } from "../symbol-table.ts";
|
|
2
|
+
import { AbstractAnalysisNodeHandler } from "./abstract-analysis-node-handler.ts";
|
|
3
|
+
import type { Check } from "../checks/check.ts";
|
|
4
|
+
import { SemanticError, SemanticWarning } from "../../scanner-error.ts";
|
|
5
|
+
|
|
6
|
+
export class SpecificCheckNodeHandler extends AbstractAnalysisNodeHandler {
|
|
7
|
+
constructor(
|
|
8
|
+
public readonly symbolTable: SymbolTable,
|
|
9
|
+
strict: boolean,
|
|
10
|
+
private readonly checks: Check[],
|
|
11
|
+
) {
|
|
12
|
+
super(symbolTable, strict);
|
|
13
|
+
|
|
14
|
+
this.checks.forEach((check) => {
|
|
15
|
+
this.registerBeforeNodeHandler(
|
|
16
|
+
check.nodeKind,
|
|
17
|
+
check.subKind,
|
|
18
|
+
(node) => {
|
|
19
|
+
const checkResults = check.checkFunc(node, symbolTable, strict);
|
|
20
|
+
|
|
21
|
+
for (const checkResult of checkResults) {
|
|
22
|
+
if (checkResult.isWarning) {
|
|
23
|
+
const warning = new SemanticWarning(
|
|
24
|
+
checkResult.message,
|
|
25
|
+
checkResult.location,
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
this.semanticWarnings.push(warning);
|
|
29
|
+
} else {
|
|
30
|
+
const error = new SemanticError(
|
|
31
|
+
checkResult.message,
|
|
32
|
+
checkResult.location,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
if (this.strict) {
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
this.semanticErrors.push(error);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|