├── .github ├── ISSUE_TEMPLATE │ ├── bug---parser--valid-c-snippet-accepted--but-malformed-ast.md │ ├── bug---parser--valid-c-snippet-not-accepted.md │ ├── bug.md │ └── feature_request.md └── workflows │ ├── build.yml │ ├── compilability-tests.yml_DISABLED │ ├── inference-tests.yml_DISABLED │ ├── solver-build.yml_DISABLED │ └── test-suite.yml ├── .gitignore ├── C ├── API.h ├── CMakeLists.txt ├── Fwds.h ├── infra │ ├── List.h │ ├── Managed.cpp │ ├── Managed.h │ ├── MemoryPool.cpp │ └── MemoryPool.h ├── parser │ ├── DiagnosticsReporter_Lexer.cpp │ ├── DiagnosticsReporter_Parser.cpp │ ├── Keywords.cpp │ ├── LanguageDialect.cpp │ ├── LanguageDialect.h │ ├── LanguageExtensions.cpp │ ├── LanguageExtensions.h │ ├── LexedTokens.cpp │ ├── LexedTokens.h │ ├── Lexer.cpp │ ├── Lexer.h │ ├── LineDirective.cpp │ ├── LineDirective.h │ ├── MacroTranslations.cpp │ ├── MacroTranslations.h │ ├── ParseOptions.cpp │ ├── ParseOptions.h │ ├── Parser.cpp │ ├── Parser.h │ ├── Parser_Common.cpp │ ├── Parser_Declarations.cpp │ ├── Parser_Expressions.cpp │ ├── Parser_Statements.cpp │ ├── Parser__IMPL__.inc │ ├── TextCompleteness.h │ ├── TextPreprocessingState.h │ ├── Unparser.cpp │ └── Unparser.h ├── plugin-api │ ├── DeclarationInterceptor.h │ ├── PluginConfig.h │ └── SourceInspector.h ├── reparser │ ├── Disambiguator.cpp │ ├── Disambiguator.h │ ├── Disambiguator_GuidelineImposition.cpp │ ├── Disambiguator_GuidelineImposition.h │ ├── Disambiguator_SyntaxCorrelation.cpp │ ├── Disambiguator_SyntaxCorrelation.h │ ├── Disambiguator_TypeSynonymsVerification.cpp │ ├── Disambiguator_TypeSynonymsVerification.h │ ├── NameCatalog.cpp │ ├── NameCatalog.h │ ├── NameCataloger.cpp │ ├── NameCataloger.h │ ├── Reparser.cpp │ └── Reparser.h ├── sema │ ├── Compilation.cpp │ ├── Compilation.h │ ├── DeclarationBinder.cpp │ ├── DeclarationBinder.h │ ├── DeclarationBinder_Declarators.cpp │ ├── DeclarationBinder_End.cpp │ ├── DeclarationBinder_Specifiers.cpp │ ├── DeclarationBinder__MACROS__.inc │ ├── DiagnosticsReporter_DeclarationBinder.cpp │ ├── DiagnosticsReporter_TypeCanonicalizer.cpp │ ├── DiagnosticsReporter_TypeChecker.cpp │ ├── InferenceOptions.cpp │ ├── InferenceOptions.h │ ├── LegacyOptions.cpp │ ├── LegacyOptions.h │ ├── NameSpace.h │ ├── NameSpaces.h │ ├── PlatformOptions.cpp │ ├── PlatformOptions.h │ ├── Scope.cpp │ ├── Scope.h │ ├── ScopeKind.h │ ├── SemanticModel.cpp │ ├── SemanticModel.h │ ├── TypeCanonicalizer.cpp │ ├── TypeCanonicalizer.h │ ├── TypeChecker.cpp │ ├── TypeChecker.h │ ├── TypeInfo.cpp │ ├── TypeInfo.h │ ├── TypedefNameTypeResolver.cpp │ └── TypedefNameTypeResolver.h ├── stdlib-support │ ├── CMakeLists.txt │ ├── CnippetPlugin.cpp │ ├── StdLibIndex.cpp │ ├── StdLibIndex.h │ ├── StdLibInspector.cpp │ ├── StdLibInspector.h │ ├── StdLibInterceptor.cpp │ └── StdLibInterceptor.h ├── symbols │ ├── DeclarationCategory.h │ ├── Declaration_Function.cpp │ ├── Declaration_Function.h │ ├── Declaration_Member.cpp │ ├── Declaration_Member.h │ ├── Declaration_Object.cpp │ ├── Declaration_Object.h │ ├── Declaration_Type.cpp │ ├── Declaration_Type.h │ ├── Declaration__IMPL__.inc │ ├── MIXIN_NameableDeclarationSymbol.cpp │ ├── MIXIN_NameableDeclarationSymbol.h │ ├── MIXIN_TypeableDeclarationSymbol.cpp │ ├── MIXIN_TypeableDeclarationSymbol.h │ ├── MemberDeclaration_Enumerator.cpp │ ├── MemberDeclaration_Enumerator.h │ ├── MemberDeclaration_Field.cpp │ ├── MemberDeclaration_Field.h │ ├── ObjectDeclaration_Parameter.cpp │ ├── ObjectDeclaration_Parameter.h │ ├── ObjectDeclaration_Variable.cpp │ ├── ObjectDeclaration_Variable.h │ ├── StructOrUnionDeclaration_Struct.cpp │ ├── StructOrUnionDeclaration_Struct.h │ ├── StructOrUnionDeclaration_Union.cpp │ ├── StructOrUnionDeclaration_Union.h │ ├── Symbol.cpp │ ├── Symbol.h │ ├── SymbolCategory.h │ ├── SymbolKind.h │ ├── Symbol_ALL.h │ ├── Symbol_Declaration.cpp │ ├── Symbol_Declaration.h │ ├── Symbol_Program.cpp │ ├── Symbol_Program.h │ ├── Symbol_TranslationUnit.cpp │ ├── Symbol_TranslationUnit.h │ ├── Symbol__IMPL__.inc │ ├── TagDeclarationCategory.h │ ├── TagDeclaration_Enum.cpp │ ├── TagDeclaration_Enum.h │ ├── TagDeclaration_StructOrUnion.cpp │ ├── TagDeclaration_StructOrUnion.h │ ├── TypeDeclarationCategory.h │ ├── TypeDeclaration_Tag.cpp │ ├── TypeDeclaration_Tag.h │ ├── TypeDeclaration_Typedef.cpp │ ├── TypeDeclaration_Typedef.h │ └── TypeDeclaration__IMPL__.inc ├── syntax │ ├── Lexeme.cpp │ ├── Lexeme.h │ ├── Lexeme_ALL.h │ ├── Lexeme_Constant.cpp │ ├── Lexeme_Constant.h │ ├── Lexeme_Identifier.cpp │ ├── Lexeme_Identifier.h │ ├── Lexeme_StringLiteral.cpp │ ├── Lexeme_StringLiteral.h │ ├── SyntaxDumper.h │ ├── SyntaxFacts.h │ ├── SyntaxHolder.cpp │ ├── SyntaxHolder.h │ ├── SyntaxKind.h │ ├── SyntaxLexemes.cpp │ ├── SyntaxNamePrinter.cpp │ ├── SyntaxNamePrinter.h │ ├── SyntaxNode.cpp │ ├── SyntaxNode.h │ ├── SyntaxNodeList.cpp │ ├── SyntaxNodeList.h │ ├── SyntaxNodes.h │ ├── SyntaxNodes_Common.h │ ├── SyntaxNodes_Declarations.h │ ├── SyntaxNodes_Expressions.h │ ├── SyntaxNodes_MIXIN.h │ ├── SyntaxNodes_Statements.h │ ├── SyntaxReference.cpp │ ├── SyntaxReference.h │ ├── SyntaxToken.cpp │ ├── SyntaxToken.h │ ├── SyntaxTree.cpp │ ├── SyntaxTree.h │ ├── SyntaxUtilities.cpp │ ├── SyntaxUtilities.h │ ├── SyntaxVisitor.cpp │ ├── SyntaxVisitor.h │ ├── SyntaxVisitor__MACROS__.inc │ ├── SyntaxWriterDOTFormat.cpp │ └── SyntaxWriterDOTFormat.h ├── tests │ ├── DeclarationBinderTester.cpp │ ├── DeclarationBinderTester.h │ ├── DeclarationBinderTester_0000_0999.cpp │ ├── DeclarationBinderTester_1000_1999.cpp │ ├── DeclarationBinderTester_2000_2999.cpp │ ├── DeclarationBinderTester_3000_3999.cpp │ ├── DeclarationBinderTester_4000_4999.cpp │ ├── ParserTester.cpp │ ├── ParserTester.h │ ├── ParserTester_0000_0999.cpp │ ├── ParserTester_1000_1999.cpp │ ├── ParserTester_2000_2999.cpp │ ├── ParserTester_3000_3999.cpp │ ├── ReparserTester.cpp │ ├── ReparserTester.h │ ├── SemanticModelTester.cpp │ ├── SemanticModelTester.h │ ├── TestExpectation.cpp │ ├── TestExpectation.h │ ├── TestSuite_API.cpp │ ├── TestSuite_API.h │ ├── TestSuite_Internals.cpp │ ├── TestSuite_Internals.h │ ├── TypeCanonicalizerAndResolverTester.cpp │ ├── TypeCanonicalizerAndResolverTester.h │ ├── TypeCheckerTester.cpp │ └── TypeCheckerTester.h └── types │ ├── Type.cpp │ ├── Type.h │ ├── TypeKind.h │ ├── TypeKind_Basic.h │ ├── TypeKind_Tag.h │ ├── Type_ALL.h │ ├── Type_Array.cpp │ ├── Type_Array.h │ ├── Type_Basic.cpp │ ├── Type_Basic.h │ ├── Type_Error.cpp │ ├── Type_Error.h │ ├── Type_Function.cpp │ ├── Type_Function.h │ ├── Type_Pointer.cpp │ ├── Type_Pointer.h │ ├── Type_Qualified.cpp │ ├── Type_Qualified.h │ ├── Type_Tag.cpp │ ├── Type_Tag.h │ ├── Type_TypedefName.cpp │ ├── Type_TypedefName.h │ ├── Type_Void.cpp │ ├── Type_Void.h │ └── Type__IMPL__.inc ├── CMakeLists.txt ├── Doxyfile ├── LICENSE ├── README.md ├── TestSuiteRunner.cpp ├── cnippet ├── CompilerFrontend.cpp ├── CompilerFrontend.h ├── CompilerFrontend_C.cpp ├── CompilerFrontend_C.h ├── Configuration.cpp ├── Configuration.h ├── Configuration_C.cpp ├── Configuration_C.h ├── Driver.cpp ├── Driver.h ├── Main.cpp ├── Plugin.cpp ├── Plugin.h └── wrapper │ └── Python │ ├── Algorithms.py │ ├── CCompilerFacade.py │ ├── CommandSummary.py │ ├── Diagnostics.py │ ├── Driver.py │ ├── Environment.py │ ├── LicenseFile.py │ ├── Logger.py │ ├── Main.py │ ├── Process.py │ ├── PsycheCFacade.py │ ├── Singleton.py │ ├── Unit.py │ ├── Version.py │ ├── __init__.py │ └── setup.cfg ├── command └── cxxopts │ ├── .gitignore │ ├── .travis.yml │ ├── CMakeLists.txt │ ├── INSTALL │ ├── LICENSE │ ├── README.md │ ├── biicode.conf │ ├── include │ └── cxxopts.hpp │ ├── src │ ├── .gitignore │ ├── CMakeLists.txt │ └── example.cpp │ └── test │ ├── .gitignore │ ├── CMakeLists.txt │ ├── catch.hpp │ └── options.cpp ├── common ├── API.h ├── CMakeLists.txt ├── diagnostics │ ├── Diagnostic.cpp │ ├── Diagnostic.h │ ├── DiagnosticCategory.cpp │ ├── DiagnosticCategory.h │ ├── DiagnosticDescriptor.cpp │ ├── DiagnosticDescriptor.h │ ├── DiagnosticSeverity.cpp │ └── DiagnosticSeverity.h ├── infra │ ├── AccessSpecifiers.h │ ├── Assertions.h │ └── Pimpl.h ├── location │ ├── FileLinePositionSpan.cpp │ ├── FileLinePositionSpan.h │ ├── LinePosition.cpp │ ├── LinePosition.h │ ├── LinePositionSpan.cpp │ ├── LinePositionSpan.h │ ├── Location.cpp │ └── Location.h └── text │ ├── SourceText.cpp │ ├── SourceText.h │ ├── TextElement.cpp │ ├── TextElement.h │ ├── TextElementTable.h │ ├── TextSpan.cpp │ └── TextSpan.h ├── data-structures ├── Substitution.cpp ├── Substitution.h └── VersionedMap.h ├── formalism ├── LICENSE ├── muC.hs ├── test001.c ├── test002.c ├── test003.c ├── test004.c ├── test005.c ├── test006.c ├── test007.c ├── test008.c ├── test009.c ├── test010.c ├── test011.c ├── test012.c ├── test013.c ├── test014.c ├── test015.c ├── test016.c ├── test017.c ├── test018.c ├── test019.c ├── test020.c ├── test021.c ├── test022.c ├── test023.c ├── test024.c ├── test025.c ├── test026.c ├── test027.c ├── test028.c ├── test029.c ├── test030.c ├── test031.c ├── test032.c ├── test033.c ├── test034.c ├── test035.c ├── test036.c ├── test037.c ├── test038.c ├── test039.c ├── test040.c ├── test041.c ├── test042.c ├── test043.c ├── test044.c ├── test045.c ├── test046.c ├── test047.c ├── test048.c ├── test049.c ├── test050.c ├── test051.c ├── test052.c ├── test053.c ├── test054.c ├── test055.c ├── test056.c ├── test057.c ├── test058.c ├── test059.c ├── test060.c ├── test061.c ├── test062.c ├── test063.c ├── test064.c ├── test065.c ├── test066.c ├── test067.c ├── test068.c ├── test069.c ├── test070.c ├── test071.c ├── test072.c ├── test073.c ├── test074.c ├── test075.c ├── test076.c ├── test077.c ├── test078.c ├── test079.c ├── test080.c ├── test081.c ├── test082.c ├── test083.c ├── test084.c ├── test085.c ├── test086.c ├── test087.c ├── test088.c ├── test089.c ├── test090.c ├── test091.c ├── test092.c ├── test093.c ├── test094.c ├── test096.c ├── test097.c ├── test098.c ├── test099.c ├── test100.c ├── test101.c ├── test102.c ├── test103.c ├── test104.c ├── test105.c ├── test106.c ├── test107.c ├── test108.c ├── test109.c ├── test110.c ├── test111.c └── test_muC.sh ├── tests ├── TestSuite.cpp ├── TestSuite.h ├── Tester.h └── scripts │ ├── libpng.sh │ ├── lua.sh │ ├── tinycc.sh │ └── zlib.sh ├── tools ├── GNUCompilerFacade.cpp └── GNUCompilerFacade.h └── utility ├── FileInfo.cpp ├── FileInfo.h ├── IO.cpp ├── IO.h ├── Process.cpp └── Process.h /.github/ISSUE_TEMPLATE/bug---parser--valid-c-snippet-accepted--but-malformed-ast.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 'Bug — Parser: valid C snippet accepted, but malformed AST' 3 | about: AST of a (valid) successfully parsed snippet is malformed 4 | title: '' 5 | labels: AST, bug, parser 6 | assignees: '' 7 | 8 | --- 9 | 10 | BEWARE: Parsing of the snippet for which the AST is malformed must not diagnose any errors or warnings! 11 | 12 | **Version** 13 | Tag, branch, commit, or screenshot of `git show --summary`: 14 | 15 | **The snippet** 16 | As minimal as possible… 17 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug---parser--valid-c-snippet-not-accepted.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 'Bug — Parser: valid C snippet not accepted' 3 | about: Error and/or warning in snippet cleanly compiled by both GCC and Clang 4 | title: '' 5 | labels: bug, parser 6 | assignees: '' 7 | 8 | --- 9 | 10 | BEWARE: The snippet which fails with Psyche must be compiled without errors with GCC and Clang with options -c and -pedantic! 11 | 12 | **ISO C Standard** 13 | `-std=` 14 | 15 | **Version** 16 | Tag, branch, commit, or screenshot of `git show --summary`: 17 | 18 | **The snippet** 19 | As minimal as possible… 20 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug 3 | about: A generic bug, without any specific component association 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Description** 11 | Steps to reproduce the behavior: 12 | 13 | **Version** 14 | Tag, branch, commit, or screenshot of `git show --summary`: 15 | 16 | **Expected behavior** 17 | A clear and concise description of what you expected to happen. 18 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ${{ matrix.os }} 12 | strategy: 13 | matrix: 14 | os: [macos-latest, ubuntu-latest] 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: run cmake 18 | run: | 19 | cmake CMakeLists.txt 20 | - name: run make 21 | run: make 22 | -------------------------------------------------------------------------------- /.github/workflows/compilability-tests.yml_DISABLED: -------------------------------------------------------------------------------- 1 | name: compilability-tests 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - uses: actions/setup-python@v1 17 | with: 18 | python-version: '3.8' 19 | - name: configure 20 | run: cmake CMakeLists.txt 21 | - name: make 22 | run: make 23 | - name: build solver 24 | run: | 25 | cd solver 26 | stack build 27 | - name: test 28 | run: | 29 | export PATH=$PATH:$PWD 30 | python test_compilability.py 31 | -------------------------------------------------------------------------------- /.github/workflows/inference-tests.yml_DISABLED: -------------------------------------------------------------------------------- 1 | name: inference-tests 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: configure 17 | run: cmake CMakeLists.txt 18 | - name: make 19 | run: make 20 | - name: test inference 21 | run: | 22 | cd solver 23 | stack test 24 | -------------------------------------------------------------------------------- /.github/workflows/solver-build.yml_DISABLED: -------------------------------------------------------------------------------- 1 | name: solver-build 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - name: setup 17 | run: | 18 | cd solver 19 | stack setup 20 | - name: build 21 | run: | 22 | cd solver 23 | stack build 24 | -------------------------------------------------------------------------------- /.github/workflows/test-suite.yml: -------------------------------------------------------------------------------- 1 | name: test-suite 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | runs-on: ${{ matrix.os }} 12 | strategy: 13 | matrix: 14 | os: [macos-latest, ubuntu-latest] 15 | steps: 16 | - uses: actions/checkout@v2 17 | - name: run cmake 18 | run: cmake CMakeLists.txt 19 | - name: run make 20 | run: make 21 | - name: run tests 22 | run: ./test-suite 23 | 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.glob 3 | *.aux 4 | *.bbl 5 | *.bc 6 | *.blg 7 | *.dylib 8 | *.dyn_o 9 | *.dyn_hi 10 | *.dot 11 | *.exe 12 | *.hi 13 | *.hp 14 | *.ll 15 | *.log 16 | *.o 17 | *.out 18 | *.prof 19 | *.status 20 | *.swp 21 | *.thm 22 | *.cstr 23 | .DS_Store 24 | 25 | psychecgen 26 | psychecsolver-exe 27 | 28 | # Qt Creator project files 29 | *.creator 30 | *.creator.user 31 | *.config 32 | *.files 33 | *.includes 34 | 35 | # CMake stuff 36 | *CMakeCache.txt 37 | *CMakeFiles 38 | *cmake_install.cmake 39 | *Makefile 40 | 41 | # The test file! ;-) 42 | test.c 43 | test.c.ctr 44 | test.c.cstr 45 | test.c.gen.h 46 | test_fixed.c 47 | test_gen.h 48 | 49 | solver/dist 50 | solver/cabal-dev 51 | solver/.hpc 52 | solver/.hsenv 53 | solver/.cabal-sandbox/ 54 | solver/.stack-work/ 55 | solver/cabal.sandbox.config 56 | solver/test/cases/*.ctr 57 | solver/test/cases/*.cstr 58 | solver/test/cases/*.fixed.c 59 | solver/test/cases/*.gen.h 60 | solver/test/cases/*_fixed.c 61 | solver/test/cases/*_gen.h -------------------------------------------------------------------------------- /C/API.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PYSCHE_C_API_H__ 22 | #define PYSCHE_C_API_H__ 23 | 24 | // From https://gcc.gnu.org/wiki/Visibility 25 | #if defined _WIN32 || defined __CYGWIN__ 26 | #ifdef EXPORT_C_API 27 | #ifdef __GNUC__ 28 | #define PSY_C_API __attribute__ ((dllexport)) 29 | #else 30 | #define PSY_C_API __declspec(dllexport) 31 | #endif 32 | #else 33 | #ifdef __GNUC__ 34 | #define PSY_C_API __attribute__ ((dllimport)) 35 | #else 36 | #define PSY_C_API __declspec(dllimport) 37 | #endif 38 | #endif 39 | #define PSY_C_INTERNAL_API 40 | #else 41 | #if __GNUC__ >= 4 42 | #define PSY_C_API __attribute__ ((visibility ("default"))) 43 | #define PSY_C_INTERNAL_API __attribute__ ((visibility ("hidden"))) 44 | #else 45 | #define PSY_C_API 46 | #define PSY_C_INTERNAL_API 47 | #endif 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /C/infra/Managed.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // Copyright (c) 2008 Roberto Raggi 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #include "Managed.h" 23 | 24 | #include "MemoryPool.h" 25 | 26 | using namespace psy; 27 | using namespace C; 28 | 29 | Managed::Managed() 30 | {} 31 | 32 | Managed::~Managed() 33 | {} 34 | 35 | void* Managed::operator new(size_t size, MemoryPool* pool) 36 | { 37 | return pool->allocate(size); 38 | } 39 | 40 | void Managed::operator delete(void*) 41 | {} 42 | 43 | void Managed::operator delete(void*, MemoryPool*) 44 | {} 45 | -------------------------------------------------------------------------------- /C/infra/Managed.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // Copyright (c) 2008 Roberto Raggi 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #ifndef PSYCHE_C_MANAGED_H__ 23 | #define PSYCHE_C_MANAGED_H__ 24 | 25 | #include "API.h" 26 | 27 | #include 28 | #include 29 | 30 | namespace psy { 31 | namespace C { 32 | 33 | class MemoryPool; 34 | 35 | class PSY_C_INTERNAL_API Managed 36 | { 37 | public: 38 | Managed(); 39 | virtual ~Managed(); 40 | 41 | // Unavailable 42 | Managed(const Managed&) = delete; 43 | Managed& operator=(const Managed&) = delete; 44 | 45 | void* operator new(size_t size, MemoryPool* pool); 46 | void operator delete(void*); 47 | void operator delete(void*, MemoryPool*); 48 | }; 49 | 50 | } // C 51 | } // psy 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /C/parser/LexedTokens.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "LexedTokens.h" 22 | 23 | using namespace psy; 24 | using namespace C; 25 | 26 | void LexedTokens::add(SyntaxToken tk) 27 | { 28 | tks_.emplace_back(tk); 29 | } 30 | 31 | SyntaxToken& LexedTokens::tokenAt(LexedTokens::IndexType tkIdx) 32 | { 33 | return tks_[tkIdx]; 34 | } 35 | 36 | LexedTokens::IndexType LexedTokens::freeSlot() const 37 | { 38 | return IndexType(tks_.size() - 1); 39 | } 40 | 41 | LexedTokens::SizeType LexedTokens::count() const 42 | { 43 | return tks_.size(); 44 | } 45 | 46 | void LexedTokens::clear() 47 | { 48 | tks_.clear(); 49 | } 50 | 51 | LexedTokens::IndexType LexedTokens::invalidIndex() 52 | { 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /C/parser/LexedTokens.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_LEXED_TOKENS_H__ 22 | #define PSYCHE_C_LEXED_TOKENS_H__ 23 | 24 | #include "API.h" 25 | 26 | #include "syntax/SyntaxToken.h" 27 | 28 | #include "../common/infra/AccessSpecifiers.h" 29 | 30 | #include 31 | 32 | namespace psy { 33 | namespace C { 34 | 35 | /** 36 | * \brief The LexedTokens class. 37 | * 38 | * The container of all tokens lexed by the Lexer. 39 | */ 40 | class PSY_C_INTERNAL_API LexedTokens 41 | { 42 | public: 43 | using SizeType = std::vector::size_type; 44 | using IndexType = SizeType; 45 | 46 | SyntaxToken& tokenAt(IndexType tkIdx); 47 | SizeType count() const; 48 | 49 | static IndexType invalidIndex(); 50 | 51 | PSY_INTERNAL: 52 | PSY_GRANT_INTERNAL_ACCESS(SyntaxTree); 53 | 54 | IndexType freeSlot() const; 55 | void add(SyntaxToken tk); 56 | 57 | private: 58 | std::vector tks_; 59 | 60 | void clear(); 61 | }; 62 | 63 | } // C 64 | } // psy 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /C/parser/LineDirective.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // Copyright (c) 2008 Roberto Raggi 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #include "LineDirective.h" 23 | 24 | using namespace psy; 25 | using namespace C; 26 | 27 | LineDirective::LineDirective(unsigned int lineno, 28 | const std::string& fileName, 29 | unsigned int offset) 30 | : lineno_(lineno) 31 | , fileName_(fileName) 32 | , offset_(offset) 33 | {} 34 | 35 | std::string LineDirective::fileName() const 36 | { 37 | return fileName_; 38 | } 39 | 40 | unsigned int LineDirective::lineno() const 41 | { 42 | return lineno_; 43 | } 44 | 45 | unsigned int LineDirective::offset() const 46 | { 47 | return offset_; 48 | } 49 | -------------------------------------------------------------------------------- /C/parser/MacroTranslations.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "MacroTranslations.h" 22 | 23 | using namespace psy; 24 | using namespace C; 25 | 26 | MacroTranslations::MacroTranslations() 27 | : BF_all_(~0) 28 | {} 29 | 30 | #define DEFINE_ENABLE_ISENABLED(FLAG) \ 31 | MacroTranslations& MacroTranslations::enable_##FLAG(bool enable) \ 32 | { BF_.FLAG##_ = enable; return *this; } \ 33 | bool MacroTranslations::isEnabled_##FLAG() const \ 34 | { return BF_.FLAG##_; } 35 | 36 | DEFINE_ENABLE_ISENABLED(Translate_static_assert_AsKeyword) 37 | DEFINE_ENABLE_ISENABLED(Translate_complex_AsKeyword) 38 | DEFINE_ENABLE_ISENABLED(Translate_operatorNames) 39 | DEFINE_ENABLE_ISENABLED(Translate_alignas_AsKeyword) 40 | DEFINE_ENABLE_ISENABLED(Translate_alignof_AsKeyword) 41 | DEFINE_ENABLE_ISENABLED(Translate_va_arg_AsKeyword) 42 | DEFINE_ENABLE_ISENABLED(Translate_offsetof_AsKeyword) 43 | DEFINE_ENABLE_ISENABLED(Translate_bool_AsKeyword) 44 | DEFINE_ENABLE_ISENABLED(Translate_thread_local_AsKeyword) 45 | 46 | #undef DEFINE_ENABLE_ISENABLED 47 | -------------------------------------------------------------------------------- /C/parser/TextCompleteness.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_TEXT_COMPLETENESS_H__ 22 | #define PSYCHE_C_TEXT_COMPLETENESS_H__ 23 | 24 | #include "API.h" 25 | 26 | #include 27 | 28 | namespace psy { 29 | namespace C { 30 | 31 | /** 32 | * \brief The alternatives for the TextCompleteness of the parsed text. 33 | */ 34 | enum class PSY_C_API TextCompleteness : std::uint8_t 35 | { 36 | Unknown, 37 | Full, 38 | Fragment 39 | }; 40 | 41 | } // C 42 | } // psy 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /C/parser/TextPreprocessingState.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_TEXT_PREPROCESSING_STATE_H__ 22 | #define PSYCHE_C_TEXT_PREPROCESSING_STATE_H__ 23 | 24 | #include "API.h" 25 | 26 | #include 27 | 28 | namespace psy { 29 | namespace C { 30 | 31 | /** 32 | * \brief The alternatives for the TextPreprocessingState of the parsed text. 33 | */ 34 | enum class PSY_C_API TextPreprocessingState : std::uint8_t 35 | { 36 | Unknown, 37 | Preprocessed, 38 | Unpreprocessed 39 | }; 40 | 41 | } // C 42 | } // psy 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /C/parser/Unparser.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "Unparser.h" 22 | 23 | #include "syntax/SyntaxTree.h" 24 | 25 | #include "syntax/Lexeme_ALL.h" 26 | #include "syntax/SyntaxNodes.h" 27 | 28 | #include 29 | 30 | using namespace psy; 31 | using namespace C; 32 | 33 | void Unparser::unparse(const SyntaxNode* node, std::ostream& os) 34 | { 35 | os_ = &os; 36 | visit(node); 37 | } 38 | 39 | void Unparser::terminal(const SyntaxToken& tk, const SyntaxNode*) 40 | { 41 | if (tk.kind() == SyntaxKind::EndOfFile) 42 | return; 43 | 44 | *os_ << tk.valueText_c_str(); 45 | 46 | if (tk.kind() == SyntaxKind::CloseBraceToken 47 | || tk.kind() == SyntaxKind::OpenBraceToken 48 | || tk.kind() == SyntaxKind::SemicolonToken) 49 | *os_ << "\n"; 50 | else 51 | *os_ << " "; 52 | } 53 | -------------------------------------------------------------------------------- /C/parser/Unparser.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_UNPARSER_H__ 22 | #define PSYCHE_UNPARSER_H__ 23 | 24 | #include "API.h" 25 | 26 | #include "syntax/SyntaxDumper.h" 27 | 28 | #include 29 | 30 | namespace psy { 31 | namespace C { 32 | 33 | class PSY_C_INTERNAL_API Unparser : public SyntaxDumper 34 | { 35 | public: 36 | using SyntaxDumper::SyntaxDumper; 37 | 38 | void unparse(const SyntaxNode* node, std::ostream& os); 39 | 40 | protected: 41 | void terminal(const SyntaxToken& tk, const SyntaxNode* node) override; 42 | 43 | std::ostream* os_; 44 | }; 45 | 46 | } // C 47 | } // psy 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /C/plugin-api/DeclarationInterceptor.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_DECLARATION_INTERCEPTOR_H__ 22 | #define PSYCHE_C_DECLARATION_INTERCEPTOR_H__ 23 | 24 | #include "PluginConfig.h" 25 | #include "Fwds.h" 26 | 27 | namespace psy { 28 | namespace C { 29 | 30 | class PLUGIN_API DeclarationInterceptor 31 | { 32 | public: 33 | virtual ~DeclarationInterceptor() = default; 34 | 35 | virtual bool intercept(DeclaratorDeclarationSyntax*) { return false; } 36 | virtual bool intercept(FunctionDefinitionSyntax*) { return false; } 37 | }; 38 | 39 | } // C 40 | } // psy 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /C/plugin-api/PluginConfig.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PLUGIN_C_CONFIG_H__ 22 | #define PLUGIN_C_CONFIG_H__ 23 | 24 | // From https://gcc.gnu.org/wiki/Visibility 25 | #if defined _WIN32 || defined __CYGWIN__ 26 | #ifdef EXPORT_PLUGIN_API 27 | #ifdef __GNUC__ 28 | #define PLUGIN_API __attribute__ ((dllexport)) 29 | #else 30 | #define PLUGIN_API __declspec(dllexport) 31 | #endif 32 | #else 33 | #ifdef __GNUC__ 34 | #define PLUGIN_API __attribute__ ((dllimport)) 35 | #else 36 | #define PLUGIN_API __declspec(dllimport) 37 | #endif 38 | #endif 39 | #define PLUGIN_API_LOCAL 40 | #else 41 | #if __GNUC__ >= 4 42 | #define PLUGIN_API __attribute__ ((visibility ("default"))) 43 | #define PLUGIN_API_LOCAL __attribute__ ((visibility ("hidden"))) 44 | #else 45 | #define PLUGIN_API 46 | #define PLUGIN_API_LOCAL 47 | #endif 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /C/plugin-api/SourceInspector.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_SOURCE_INSPECTOR_H__ 22 | #define PSYCHE_C_SOURCE_INSPECTOR_H__ 23 | 24 | #include "PluginConfig.h" 25 | #include "Fwds.h" 26 | 27 | #include 28 | #include 29 | 30 | namespace psy { 31 | namespace C { 32 | 33 | class PLUGIN_API SourceInspector 34 | { 35 | public: 36 | virtual ~SourceInspector() = default; 37 | 38 | virtual std::vector detectRequiredHeaders(const std::string&) = 0; 39 | }; 40 | 41 | } // C 42 | } // psy 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /C/reparser/Disambiguator_GuidelineImposition.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_GUIDELINE_IMPOSITION_DISAMBIGUATOR_H__ 22 | #define PSYCHE_C_GUIDELINE_IMPOSITION_DISAMBIGUATOR_H__ 23 | 24 | #include "API.h" 25 | 26 | #include "reparser/Disambiguator.h" 27 | 28 | #include "../common/infra/AccessSpecifiers.h" 29 | 30 | namespace psy { 31 | namespace C { 32 | 33 | class PSY_C_INTERNAL_API GuidelineImpositionDisambiguator : public Disambiguator 34 | { 35 | PSY_INTERNAL: 36 | PSY_GRANT_INTERNAL_ACCESS(Reparser); 37 | 38 | private: 39 | GuidelineImpositionDisambiguator(SyntaxTree* tree); 40 | 41 | virtual Disambiguation disambiguateExpression(const AmbiguousCastOrBinaryExpressionSyntax*) const override; 42 | virtual Disambiguation disambiguateStatement(const AmbiguousExpressionOrDeclarationStatementSyntax*) const override; 43 | virtual Disambiguation disambiguateTypeReference(const AmbiguousTypeNameOrExpressionAsTypeReferenceSyntax*) const override; 44 | }; 45 | 46 | } // C 47 | } // psy 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /C/reparser/Disambiguator_TypeSynonymsVerification.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /C/reparser/Disambiguator_TypeSynonymsVerification.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_TYPE_SYNONYS_VERIFICATION_DISAMBIGUATOR_H__ 22 | #define PSYCHE_C_TYPE_SYNONYS_VERIFICATION_DISAMBIGUATOR_H__ 23 | 24 | #include "API.h" 25 | 26 | #include "syntax/SyntaxVisitor.h" 27 | 28 | namespace psy { 29 | namespace C { 30 | 31 | class PSY_C_INTERNAL_API TypeSynonymsVerificationReparser : public SyntaxVisitor 32 | { 33 | public: 34 | TypeSynonymsVerificationReparser(SyntaxTree* tree); 35 | }; 36 | 37 | } // C 38 | } // psy 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /C/sema/InferenceOptions.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "InferenceOptions.h" 22 | 23 | using namespace psy; 24 | using namespace C; 25 | 26 | InferenceOptions::InferenceOptions() 27 | : BD_(0) 28 | { 29 | F_.DeclarationAndTypeInference_ = 0; 30 | } 31 | 32 | #define DEFINE_ENABLE_ISENABLED(FLAG) \ 33 | InferenceOptions& InferenceOptions::enable_##FLAG(bool enable) \ 34 | { F_.FLAG##_ = enable; return *this; } \ 35 | bool InferenceOptions::isEnabled_##FLAG() const \ 36 | { return F_.FLAG##_; } 37 | 38 | DEFINE_ENABLE_ISENABLED(DeclarationAndTypeInference) 39 | 40 | #undef DEFINE_ENABLE_ISENABLED 41 | -------------------------------------------------------------------------------- /C/sema/InferenceOptions.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_INFERENCE_OPTIONS_H__ 22 | #define PSYCHE_C_INFERENCE_OPTIONS_H__ 23 | 24 | #include "API.h" 25 | 26 | #include 27 | 28 | namespace psy { 29 | namespace C { 30 | 31 | /** 32 | * \brief The InferenceOptions class. 33 | */ 34 | class PSY_C_API InferenceOptions 35 | { 36 | public: 37 | InferenceOptions(); 38 | 39 | //!@{ 40 | /** 41 | * Whether to enable the inference of declarations and types. 42 | */ 43 | InferenceOptions& enable_DeclarationAndTypeInference(bool enable); 44 | bool isEnabled_DeclarationAndTypeInference() const; 45 | //!@} 46 | 47 | private: 48 | struct BD 49 | { 50 | std::uint8_t DeclarationAndTypeInference_ : 1; 51 | }; 52 | union 53 | { 54 | std::uint32_t BD_; 55 | BD F_; 56 | }; 57 | }; 58 | 59 | } // C 60 | } // psy 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /C/sema/LegacyOptions.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "LegacyOptions.h" 22 | 23 | #include "../common/infra/Assertions.h" 24 | 25 | 26 | using namespace psy; 27 | using namespace C; 28 | 29 | LegacyOptions::LegacyOptions() 30 | {} 31 | 32 | #define DEFINE_ENABLE_ISENABLED(FLAG) \ 33 | LegacyOptions& LegacyOptions::enable_##FLAG(bool enable) \ 34 | { F_.FLAG##_ = enable; return *this; } \ 35 | bool LegacyOptions::isEnabled_##FLAG() const \ 36 | { return F_.FLAG##_; } 37 | 38 | DEFINE_ENABLE_ISENABLED(orderedComparisonBetweenPointerAndZero) 39 | DEFINE_ENABLE_ISENABLED(orderedComparisonBetweenPointerAndInteger) 40 | -------------------------------------------------------------------------------- /C/sema/NameSpaces.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_NAMES_SPACES_H__ 22 | #define PSYCHE_C_NAMES_SPACES_H__ 23 | 24 | #include "API.h" 25 | #include "Fwds.h" 26 | 27 | namespace psy { 28 | namespace C { 29 | 30 | class PSY_C_API NameSpaces 31 | { 32 | private: 33 | NameSpaces(); 34 | }; 35 | 36 | } // C 37 | } // psy 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /C/sema/TypeInfo.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION for the SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "TypeInfo.h" 22 | 23 | using namespace psy; 24 | using namespace C; 25 | 26 | TypeInfo::TypeInfo(const Type* ty, TypeOrigin tyOrig) 27 | : ty_(ty) 28 | , tyOrig_(tyOrig) 29 | {} 30 | 31 | TypeInfo::~TypeInfo() 32 | {} 33 | 34 | TypeInfo::TypeOrigin TypeInfo::typeOrigin() const 35 | { 36 | return tyOrig_; 37 | } 38 | 39 | const Type* TypeInfo::type() const 40 | { 41 | return ty_; 42 | } 43 | -------------------------------------------------------------------------------- /C/stdlib-support/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | project(psychecstd) 4 | 5 | # C++ standard. 6 | set(CMAKE_CXX_STANDARD 17) 7 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 8 | 9 | # Compiler flags. 10 | set(STD_CXX_FLAGS) 11 | set(STD_CXX_FLAGS "${STD_CXX_FLAGS} -g") 12 | set(STD_CXX_FLAGS "${STD_CXX_FLAGS} -Wall \ 13 | -Wsign-compare") 14 | 15 | set(STD_CXX_FLAGS "${STD_CXX_FLAGS} -DEXPORT_C_API -DEXPORT_PLUGIN_API") 16 | 17 | set(CMAKE_MACOSX_RPATH TRUE) 18 | set(CMAKE_INSTALL_RPATH "\$ORIGIN;@executable_path;@loader_path") 19 | 20 | set(STD_SOURCES 21 | ${PROJECT_SOURCE_DIR}/CnippetPlugin.cpp 22 | ${PROJECT_SOURCE_DIR}/StdLibInterceptor.h 23 | ${PROJECT_SOURCE_DIR}/StdLibInterceptor.cpp 24 | ${PROJECT_SOURCE_DIR}/StdLibIndex.h 25 | ${PROJECT_SOURCE_DIR}/StdLibIndex.cpp 26 | ${PROJECT_SOURCE_DIR}/StdLibInspector.h 27 | ${PROJECT_SOURCE_DIR}/StdLibInspector.cpp 28 | ) 29 | 30 | foreach(file ${STD_SOURCES}) 31 | set_source_files_properties( 32 | ${file} PROPERTIES 33 | COMPILE_FLAGS "${STD_CXX_FLAGS}" 34 | ) 35 | endforeach() 36 | 37 | include_directories( 38 | ${PROJECT_SOURCE_DIR} 39 | ${PROJECT_SOURCE_DIR}/.. 40 | ) 41 | 42 | set(PLUGIN psychecstd) 43 | add_library(${PLUGIN} SHARED ${STD_SOURCES}) 44 | set_target_properties(${PLUGIN} 45 | PROPERTIES 46 | LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../) 47 | 48 | # Link against the frontend. 49 | target_link_libraries(${PLUGIN} psychecfe) 50 | 51 | # Install setup 52 | install(TARGETS ${PLUGIN} DESTINATION ${PROJECT_SOURCE_DIR}/../) 53 | -------------------------------------------------------------------------------- /C/stdlib-support/CnippetPlugin.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "StdLibInterceptor.h" 22 | #include "StdLibInspector.h" 23 | 24 | using namespace psy; 25 | using namespace C; 26 | 27 | extern "C" { 28 | 29 | PLUGIN_API StdLibInterceptor* newInterceptor() { return new StdLibInterceptor; } 30 | PLUGIN_API void deleteInterceptor(StdLibInterceptor* p) { delete p; } 31 | 32 | PLUGIN_API StdLibInspector* newInspector() { return new StdLibInspector; } 33 | PLUGIN_API void deleteInspector(StdLibInspector* p) { delete p; } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /C/stdlib-support/StdLibInspector.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "StdLibInspector.h" 22 | 23 | using namespace psy; 24 | using namespace C; 25 | 26 | std::vector StdLibInspector::detectRequiredHeaders(const std::string& source) 27 | { 28 | return { }; 29 | } 30 | -------------------------------------------------------------------------------- /C/stdlib-support/StdLibInspector.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_STDLIB_SOURCE_INSPECTOR_H__ 22 | #define PSYCHE_STDLIB_SOURCE_INSPECTOR_H__ 23 | 24 | #include "plugin-api/SourceInspector.h" 25 | 26 | namespace psy { 27 | namespace C { 28 | 29 | class StdLibInspector final : SourceInspector 30 | { 31 | public: 32 | std::vector detectRequiredHeaders(const std::string&) override; 33 | }; 34 | 35 | } // C 36 | } // psy 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /C/stdlib-support/StdLibInterceptor.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "StdLibInterceptor.h" 22 | 23 | #include "syntax/Lexeme_ALL.h" 24 | #include "syntax/SyntaxNodes.h" 25 | 26 | #include 27 | #include 28 | 29 | using namespace psy; 30 | using namespace C; 31 | 32 | bool StdLibInterceptor::intercept(DeclaratorDeclarationSyntax*) 33 | { 34 | return false; 35 | } 36 | 37 | bool StdLibInterceptor::intercept(FunctionDefinitionSyntax*) 38 | { 39 | return false; 40 | } 41 | -------------------------------------------------------------------------------- /C/stdlib-support/StdLibInterceptor.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_STDLIB_INTERCEPTOR_H__ 22 | #define PSYCHE_STDLIB_INTERCEPTOR_H__ 23 | 24 | #include "StdLibIndex.h" 25 | #include "plugin-api/DeclarationInterceptor.h" 26 | 27 | namespace psy { 28 | namespace C { 29 | 30 | class StdLibInterceptor final : public DeclarationInterceptor 31 | { 32 | public: 33 | bool intercept(DeclaratorDeclarationSyntax*) override; 34 | bool intercept(FunctionDefinitionSyntax*) override; 35 | 36 | private: 37 | 38 | StdLibIndex index_ { StdLibIndex::Version::C99 }; // TODO: Config appropriately. 39 | }; 40 | 41 | } // C 42 | } // psy 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /C/symbols/Declaration__IMPL__.inc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "Symbol__IMPL__.inc" 22 | #include "Symbol_Declaration.h" 23 | 24 | using namespace psy; 25 | using namespace C; 26 | 27 | struct DeclarationSymbol::DeclarationImpl : SymbolImpl 28 | { 29 | DeclarationImpl(SymbolKind symK, 30 | const Symbol* containingSym, 31 | const SyntaxTree* tree, 32 | const Scope* enclosingScope, 33 | NameSpace ns) 34 | : SymbolImpl(symK, containingSym) 35 | , tree_(tree) 36 | , enclosingScope_(enclosingScope) 37 | , denotedTy_(nullptr) 38 | { 39 | F_.ns_ = static_cast(ns); 40 | } 41 | 42 | const SyntaxTree* tree_; 43 | const Scope* enclosingScope_; 44 | const Type* denotedTy_; 45 | }; 46 | -------------------------------------------------------------------------------- /C/symbols/MIXIN_NameableDeclarationSymbol.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "MIXIN_NameableDeclarationSymbol.h" 22 | 23 | #include "Symbol_Declaration.h" 24 | 25 | using namespace psy; 26 | using namespace C; 27 | 28 | MIXIN_NameableDeclarationSymbol* MIXIN_NameableDeclarationSymbol 29 | ::from(DeclarationSymbol* decl) 30 | { 31 | return dynamic_cast(decl); 32 | } 33 | -------------------------------------------------------------------------------- /C/symbols/MIXIN_NameableDeclarationSymbol.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_NAMEABLE_DECLARATION_SYMBOL_H__ 22 | #define PSYCHE_C_NAMEABLE_DECLARATION_SYMBOL_H__ 23 | 24 | #include "API.h" 25 | #include "Fwds.h" 26 | 27 | #include "../common/infra/AccessSpecifiers.h" 28 | 29 | #include 30 | 31 | namespace psy { 32 | namespace C { 33 | 34 | class PSY_C_INTERNAL_API MIXIN_NameableDeclarationSymbol 35 | { 36 | public: 37 | virtual ~MIXIN_NameableDeclarationSymbol() {} 38 | 39 | static MIXIN_NameableDeclarationSymbol* from(DeclarationSymbol*); 40 | 41 | virtual const Identifier* name() const = 0; 42 | 43 | PSY_INTERNAL: 44 | PSY_GRANT_INTERNAL_ACCESS(DeclarationBinder); 45 | 46 | virtual void setName(const Identifier* name) = 0; 47 | }; 48 | 49 | } // C 50 | } // psy 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /C/symbols/MIXIN_TypeableDeclarationSymbol.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "MIXIN_TypeableDeclarationSymbol.h" 22 | 23 | #include "Symbol_Declaration.h" 24 | 25 | using namespace psy; 26 | using namespace C; 27 | 28 | MIXIN_TypeableDeclarationSymbol* MIXIN_TypeableDeclarationSymbol:: 29 | from(DeclarationSymbol* decl) 30 | { 31 | return dynamic_cast(decl); 32 | } 33 | 34 | const MIXIN_TypeableDeclarationSymbol* MIXIN_TypeableDeclarationSymbol:: 35 | from(const DeclarationSymbol* decl) 36 | { 37 | return dynamic_cast(decl); 38 | } 39 | -------------------------------------------------------------------------------- /C/symbols/MIXIN_TypeableDeclarationSymbol.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_TYPEABLE_DECLARATION_SYMBOL_H__ 22 | #define PSYCHE_C_TYPEABLE_DECLARATION_SYMBOL_H__ 23 | 24 | #include "API.h" 25 | #include "Fwds.h" 26 | 27 | #include "../common/infra/AccessSpecifiers.h" 28 | 29 | #include 30 | 31 | namespace psy { 32 | namespace C { 33 | 34 | class PSY_C_INTERNAL_API MIXIN_TypeableDeclarationSymbol 35 | { 36 | public: 37 | virtual ~MIXIN_TypeableDeclarationSymbol() {} 38 | 39 | static MIXIN_TypeableDeclarationSymbol* from(DeclarationSymbol*); 40 | static const MIXIN_TypeableDeclarationSymbol* from(const DeclarationSymbol*); 41 | 42 | virtual const Type* type() const = 0; 43 | 44 | PSY_INTERNAL: 45 | PSY_GRANT_INTERNAL_ACCESS(DeclarationBinder); 46 | PSY_GRANT_INTERNAL_ACCESS(TypeCanonicalizer); 47 | 48 | virtual void setType(const Type* ty) = 0; 49 | }; 50 | 51 | } // C 52 | } // psy 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /C/symbols/SymbolCategory.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_SYMBOL_CATEGORY_H__ 22 | #define PSYCHE_C_SYMBOL_CATEGORY_H__ 23 | 24 | #include "API.h" 25 | #include "Fwds.h" 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | namespace psy { 32 | namespace C { 33 | 34 | /** 35 | * \brief The SymbolCategory enum. 36 | */ 37 | enum class PSY_C_API SymbolCategory : std::uint8_t 38 | { 39 | Program, 40 | TranslationUnit, 41 | Declaration, 42 | }; 43 | 44 | } // C 45 | } // psy 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /C/symbols/Symbol_ALL.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_SYMBOL_ALL_H__ 22 | #define PSYCHE_C_SYMBOL_ALL_H__ 23 | 24 | #include "Symbol_Program.h" 25 | #include "Symbol_TranslationUnit.h" 26 | #include "Symbol_Declaration.h" 27 | #include "Declaration_Function.h" 28 | #include "StructOrUnionDeclaration_Struct.h" 29 | #include "StructOrUnionDeclaration_Union.h" 30 | #include "TagDeclaration_Enum.h" 31 | #include "TypeDeclaration_Typedef.h" 32 | #include "MemberDeclaration_Enumerator.h" 33 | #include "MemberDeclaration_Field.h" 34 | #include "ObjectDeclaration_Parameter.h" 35 | #include "ObjectDeclaration_Variable.h" 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /C/symbols/Symbol_Program.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "Symbol__IMPL__.inc" 22 | #include "Symbol_Program.h" 23 | 24 | using namespace psy; 25 | using namespace C; 26 | 27 | struct ProgramSymbol::ProgramImpl : SymbolImpl 28 | { 29 | ProgramImpl() 30 | : SymbolImpl(SymbolKind::Program) 31 | {} 32 | }; 33 | 34 | ProgramSymbol::ProgramSymbol() 35 | : Symbol(new ProgramImpl) 36 | { 37 | } 38 | 39 | namespace psy { 40 | namespace C { 41 | 42 | std::ostream& operator<<(std::ostream& os, const ProgramSymbol* prog) 43 | { 44 | if (!prog) 45 | return os << ""; 46 | os << ""; 47 | return os; 48 | } 49 | 50 | } // C 51 | } // psi 52 | -------------------------------------------------------------------------------- /C/symbols/Symbol_TranslationUnit.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "Symbol__IMPL__.inc" 22 | #include "Symbol_TranslationUnit.h" 23 | #include "Symbol_Program.h" 24 | 25 | using namespace psy; 26 | using namespace C; 27 | 28 | TranslationUnitSymbol::TranslationUnitSymbol( 29 | const ProgramSymbol* prog, 30 | const SyntaxTree* tree) 31 | : Symbol(new SymbolImpl(SymbolKind::TranslationUnit, prog)) 32 | , tree_(tree) 33 | 34 | {} 35 | 36 | namespace psy { 37 | namespace C { 38 | 39 | std::ostream& operator<<(std::ostream& os, const TranslationUnitSymbol* unit) 40 | { 41 | if (!unit) 42 | return os << ""; 43 | os << ""; 44 | return os; 45 | } 46 | 47 | } // C 48 | } // psy 49 | -------------------------------------------------------------------------------- /C/symbols/Symbol__IMPL__.inc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "Symbol.h" 22 | 23 | using namespace psy; 24 | using namespace C; 25 | 26 | struct Symbol::SymbolImpl 27 | { 28 | SymbolImpl(SymbolKind symK, const Symbol* containingSym) 29 | : containingSym_(containingSym) 30 | { 31 | F_.symK_ = static_cast(symK); 32 | } 33 | 34 | SymbolImpl(SymbolKind symK) : SymbolImpl(symK, nullptr) 35 | {} 36 | 37 | const Symbol* containingSym_; 38 | 39 | struct BD 40 | { 41 | std::uint32_t symK_ : 8; 42 | 43 | // DeclarationSymbol. 44 | std::uint32_t ns_ : 2; 45 | std::uint32_t static_ : 1; 46 | }; 47 | union 48 | { 49 | std::uint32_t BD_; 50 | BD F_; 51 | }; 52 | }; 53 | -------------------------------------------------------------------------------- /C/symbols/TypeDeclarationCategory.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_TYPE_DECLARATION_CATEGORY_H__ 22 | #define PSYCHE_C_TYPE_DECLARATION_CATEGORY_H__ 23 | 24 | #include "API.h" 25 | #include "Fwds.h" 26 | 27 | #include "../common/infra/Assertions.h" 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | namespace psy { 34 | namespace C { 35 | 36 | /** 37 | * \brief The TypeDeclarationCategory enum. 38 | */ 39 | enum class PSY_C_API TypeDeclarationCategory : std::uint8_t 40 | { 41 | Tag, 42 | Typedef 43 | }; 44 | 45 | PSY_C_API inline std::ostream& operator<<(std::ostream& os, TypeDeclarationCategory tyDeclK) 46 | { 47 | switch (tyDeclK) { 48 | case TypeDeclarationCategory::Tag: 49 | return os << "Tag"; 50 | case TypeDeclarationCategory::Typedef: 51 | return os << "Typedef"; 52 | } 53 | PSY_ASSERT_1(false); 54 | return os << ""; 55 | } 56 | 57 | } // C 58 | } // psy 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /C/symbols/TypeDeclaration__IMPL__.inc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "Declaration__IMPL__.inc" 22 | #include "Declaration_Type.h" 23 | #include "TagDeclarationCategory.h" 24 | 25 | using namespace psy; 26 | using namespace C; 27 | 28 | struct TypeDeclarationSymbol::TypeDeclarationImpl : DeclarationImpl 29 | { 30 | TypeDeclarationImpl(SymbolKind symK, 31 | const Symbol* containingSym, 32 | const SyntaxTree* tree, 33 | const Scope* enclosingScope, 34 | NameSpace ns, 35 | Type* ty) 36 | : DeclarationImpl(symK, 37 | containingSym, 38 | tree, 39 | enclosingScope, 40 | ns) 41 | , ty_(ty) 42 | {} 43 | 44 | Type* ty_; 45 | }; 46 | -------------------------------------------------------------------------------- /C/syntax/Lexeme_ALL.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // Copyright (c) 2008 Roberto Raggi 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #ifndef PSYCHE_C_LEXEMES_H__ 23 | #define PSYCHE_C_LEXEMES_H__ 24 | 25 | #include "Lexeme_Identifier.h" 26 | #include "Lexeme_Constant.h" 27 | #include "Lexeme_StringLiteral.h" 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /C/syntax/Lexeme_Identifier.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // Copyright (c) 2008 Roberto Raggi 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #include "Lexeme_Identifier.h" 23 | 24 | using namespace psy; 25 | using namespace C; 26 | 27 | Identifier::Identifier(const char* chars, unsigned int size) 28 | : Lexeme(chars, 29 | size, 30 | LexemeKind::Identifier) 31 | {} 32 | -------------------------------------------------------------------------------- /C/syntax/Lexeme_Identifier.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // Copyright (c) 2008 Roberto Raggi 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #ifndef PSYCHE_C_IDENTIFIER_LEXEME_H__ 23 | #define PSYCHE_C_IDENTIFIER_LEXEME_H__ 24 | 25 | #include "Lexeme.h" 26 | 27 | #include 28 | #include 29 | 30 | namespace psy { 31 | namespace C { 32 | 33 | /** 34 | * \brief The Identifier class. 35 | */ 36 | class PSY_C_API Identifier final : public Lexeme 37 | { 38 | public: 39 | //!@{ 40 | /** 41 | * Cast \c this Lexeme as an Identifier. 42 | */ 43 | virtual Identifier* asIdentifier() override { return this; } 44 | virtual const Identifier* asIdentifier() const override { return this; } 45 | //!@} 46 | 47 | // TODO: Make internal. 48 | Identifier(const char* chars, unsigned int size); 49 | }; 50 | 51 | } // C 52 | } // psy 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /C/syntax/Lexeme_StringLiteral.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // Copyright (c) 2008 Roberto Raggi 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #include "Lexeme_StringLiteral.h" 23 | 24 | using namespace psy; 25 | using namespace C; 26 | 27 | StringLiteral::StringLiteral(const char* chars, unsigned int size) 28 | : Lexeme(chars, 29 | size, 30 | LexemeKind::StringLiteral) 31 | {} 32 | 33 | StringLiteral::EncodingPrefix StringLiteral::encodingPrefix() const 34 | { 35 | if (F_.u8_) 36 | return EncodingPrefix::u8; 37 | if (F_.u_) 38 | return EncodingPrefix::u; 39 | if (F_.U_) 40 | return EncodingPrefix::U; 41 | if (F_.L_) 42 | return EncodingPrefix::L; 43 | return EncodingPrefix::None; 44 | } 45 | -------------------------------------------------------------------------------- /C/syntax/SyntaxLexemes.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltcmelo/psychec/14f45120fd3519d2c64e519c202fccebd95c3a07/C/syntax/SyntaxLexemes.cpp -------------------------------------------------------------------------------- /C/syntax/SyntaxNamePrinter.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_SYNTAX_NAME_PRINTER_H__ 22 | #define PSYCHE_C_SYNTAX_NAME_PRINTER_H__ 23 | 24 | #include "API.h" 25 | 26 | #include "SyntaxDumper.h" 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | namespace psy { 33 | namespace C { 34 | 35 | class PSY_C_API SyntaxNamePrinter final : public SyntaxDumper 36 | { 37 | public: 38 | using SyntaxDumper::SyntaxDumper; 39 | 40 | enum class Style : char 41 | { 42 | Plain, 43 | Decorated 44 | }; 45 | 46 | void print(const SyntaxNode* node, Style style); 47 | void print(const SyntaxNode* node, Style style, std::ostream& os); 48 | 49 | private: 50 | virtual void nonterminal(const SyntaxNode* node) override; 51 | 52 | std::vector> dump_; 53 | }; 54 | 55 | } // C 56 | } // psy 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /C/syntax/SyntaxReference.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "SyntaxReference.h" 22 | 23 | using namespace psy; 24 | using namespace C; 25 | 26 | const SyntaxTree* SyntaxReference::syntaxTree() const 27 | { 28 | return nullptr; 29 | } 30 | 31 | const SyntaxNode* SyntaxReference::syntax() const 32 | { 33 | return nullptr; 34 | } 35 | -------------------------------------------------------------------------------- /C/syntax/SyntaxReference.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_SYNTAX_REFERENCE_H__ 22 | #define PSYCHE_C_SYNTAX_REFERENCE_H__ 23 | 24 | #include "API.h" 25 | #include "Fwds.h" 26 | 27 | namespace psy { 28 | namespace C { 29 | 30 | /** 31 | * \brief The SyntaxReference class. 32 | * 33 | * \note Resembles: 34 | * \c Microsoft.CodeAnalysis.SyntaxReference from Roslyn. 35 | */ 36 | class PSY_C_API SyntaxReference 37 | { 38 | public: 39 | /** 40 | * The SyntaxTree referenced by \c this SyntaxReference. 41 | */ 42 | const SyntaxTree* syntaxTree() const; 43 | 44 | /** 45 | * The SyntaxNode referenced by \c this SyntaxReference. 46 | */ 47 | const SyntaxNode* syntax() const; 48 | }; 49 | 50 | } // C 51 | } // psy 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /C/syntax/SyntaxVisitor.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // Copyright (c) 2008 Roberto Raggi 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #include "SyntaxVisitor.h" 23 | 24 | #include "SyntaxNodes.h" 25 | #include "syntax/SyntaxTree.h" 26 | 27 | using namespace psy; 28 | using namespace C; 29 | 30 | SyntaxVisitor::SyntaxVisitor(const SyntaxTree* tree) 31 | : tree_(tree) 32 | {} 33 | 34 | SyntaxVisitor::~SyntaxVisitor() 35 | {} 36 | 37 | SyntaxVisitor::Action SyntaxVisitor::visit(const SyntaxNode* node) 38 | { 39 | return SyntaxNode::acceptVisitor(node, this); 40 | } 41 | 42 | SyntaxVisitor::Action SyntaxVisitor::visitChildNodes(const SyntaxNode* node) 43 | { 44 | return SyntaxNode::acceptVisitorInChildNodes(node, this); 45 | } 46 | -------------------------------------------------------------------------------- /C/syntax/SyntaxVisitor__MACROS__.inc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2025 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #define VISIT(NODE) do { if (visit(NODE) == Action::Quit) return Action::Quit; } while (0) 22 | -------------------------------------------------------------------------------- /C/tests/DeclarationBinderTester.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "DeclarationBinderTester.h" 22 | 23 | #include "symbols/Symbol.h" 24 | #include "parser/Unparser.h" 25 | #include "symbols/Symbol_ALL.h" 26 | #include "syntax/Lexeme_ALL.h" 27 | #include "syntax/SyntaxNamePrinter.h" 28 | #include "syntax/SyntaxNodes.h" 29 | 30 | using namespace psy; 31 | using namespace C; 32 | 33 | const std::string DeclarationBinderTester::Name = "DECLARATION-BINDER"; 34 | 35 | void DeclarationBinderTester::testDeclarationBinder() 36 | { 37 | return run(tests_); 38 | } 39 | 40 | void DeclarationBinderTester::bind(std::string text, Expectation X) 41 | { 42 | (static_cast(suite_)->bindDeclarations(text, X)); 43 | } 44 | 45 | void DeclarationBinderTester::setUp() 46 | {} 47 | 48 | void DeclarationBinderTester::tearDown() 49 | {} 50 | -------------------------------------------------------------------------------- /C/tests/TestSuite_API.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "TestSuite_API.h" 22 | 23 | #include "SemanticModelTester.h" 24 | 25 | using namespace psy; 26 | using namespace C; 27 | 28 | APITestSuite::~APITestSuite() 29 | {} 30 | 31 | std::tuple APITestSuite::testAll() 32 | { 33 | auto SM = std::make_unique(this); 34 | SM->testSemanticModel(); 35 | 36 | auto res = std::make_tuple(SM->totalPassed(), 37 | SM->totalFailed()); 38 | 39 | testers_.emplace_back(SM.release()); 40 | 41 | return res; 42 | } 43 | 44 | std::string APITestSuite::description() const 45 | { 46 | return "C API test suite"; 47 | } 48 | 49 | void APITestSuite::printSummary() const 50 | { 51 | for (auto const& tester : testers_) { 52 | std::cout << " " << tester->name() << std::endl 53 | << " passed: " << tester->totalPassed() << std::endl 54 | << " failed: " << tester->totalFailed() << std::endl; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /C/tests/TestSuite_API.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_API_TEST_SUITE_H__ 22 | #define PSYCHE_C_API_TEST_SUITE_H__ 23 | 24 | #include "Fwds.h" 25 | 26 | #include "tests/TestSuite.h" 27 | #include "tests/Tester.h" 28 | 29 | #include "C/syntax/SyntaxTree.h" 30 | #include "C/syntax/SyntaxNodes.h" 31 | #include "C/sema/Compilation.h" 32 | #include "C/sema/SemanticModel.h" 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | namespace psy { 39 | namespace C { 40 | 41 | class APITestSuite : public TestSuite 42 | { 43 | friend class SemanticModelTester; 44 | 45 | public: 46 | virtual ~APITestSuite(); 47 | 48 | virtual std::tuple testAll() override; 49 | virtual std::string description() const override; 50 | virtual void printSummary() const override; 51 | 52 | private: 53 | std::vector> testers_; 54 | }; 55 | 56 | } // C 57 | } // psy 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /C/types/Type_ALL.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021/22/23/24 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_TYPE_ALL_H__ 22 | #define PSYCHE_C_TYPE_ALL_H__ 23 | 24 | #include "Type_Array.h" 25 | #include "Type_Basic.h" 26 | #include "Type_Function.h" 27 | #include "Type_Pointer.h" 28 | #include "Type_TypedefName.h" 29 | #include "Type_Tag.h" 30 | #include "Type_Void.h" 31 | #include "Type_Qualified.h" 32 | #include "Type_Error.h" 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /C/types/Type_Basic.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021/22/23/24 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "Type_Basic.h" 22 | #include "Type__IMPL__.inc" 23 | 24 | #include 25 | #include 26 | 27 | using namespace psy; 28 | using namespace C; 29 | 30 | BasicType::BasicType(BasicTypeKind basicTyK) 31 | : Type(new TypeImpl(TypeKind::Basic)) 32 | { 33 | resetBasicTypeKind(basicTyK); 34 | } 35 | 36 | BasicTypeKind BasicType::kind() const 37 | { 38 | return BasicTypeKind(P->F_.basicTyK_); 39 | } 40 | 41 | void BasicType::resetBasicTypeKind(BasicTypeKind basicTyK) 42 | { 43 | P->F_.basicTyK_ = static_cast(basicTyK); 44 | } 45 | 46 | namespace psy { 47 | namespace C { 48 | 49 | PSY_C_API std::ostream& operator<<(std::ostream& os, const BasicType* basicTy) 50 | { 51 | if (!basicTy) 52 | return os << ""; 53 | os << "kind(); 55 | os << ">"; 56 | return os; 57 | } 58 | 59 | } // C 60 | } // psy 61 | -------------------------------------------------------------------------------- /C/types/Type_Error.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021/22/23/24 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "Type_Error.h" 22 | #include "Type__IMPL__.inc" 23 | 24 | using namespace psy; 25 | using namespace C; 26 | 27 | #include 28 | #include 29 | 30 | ErrorType::ErrorType() 31 | : Type(new TypeImpl(TypeKind::Error)) 32 | {} 33 | 34 | namespace psy { 35 | namespace C { 36 | 37 | PSY_C_API std::ostream& operator<<(std::ostream& os, const ErrorType* unknownTy) 38 | { 39 | if (!unknownTy) 40 | return os << ""; 41 | return os << ""; 42 | } 43 | 44 | } // C 45 | } // psy 46 | -------------------------------------------------------------------------------- /C/types/Type_Error.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021/22/23/24 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_TYPE_ERROR_H__ 22 | #define PSYCHE_C_TYPE_ERROR_H__ 23 | 24 | #include "API.h" 25 | #include "Fwds.h" 26 | 27 | #include "Type.h" 28 | 29 | namespace psy { 30 | namespace C { 31 | 32 | /** 33 | * \brief The ErrorType class. 34 | */ 35 | class PSY_C_API ErrorType final : public Type 36 | { 37 | public: 38 | //!@{ 39 | /** 40 | * Cast \c this Type as an ErrorType. 41 | */ 42 | virtual ErrorType* asErrorType() override { return this; } 43 | virtual const ErrorType* asErrorType() const override { return this; } 44 | //!@} 45 | 46 | PSY_INTERNAL: 47 | PSY_GRANT_INTERNAL_ACCESS(Compilation); 48 | PSY_GRANT_INTERNAL_ACCESS(DeclarationBinder); 49 | PSY_GRANT_INTERNAL_ACCESS(TypeCanonicalizer); 50 | PSY_GRANT_INTERNAL_ACCESS(TypeChecker); 51 | 52 | ErrorType(); 53 | }; 54 | 55 | PSY_C_API std::ostream& operator<<(std::ostream& os, const ErrorType* unknownTy); 56 | 57 | } // C 58 | } // psy 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /C/types/Type_Void.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021/22/23/24 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "Type_Void.h" 22 | #include "Type__IMPL__.inc" 23 | 24 | using namespace psy; 25 | using namespace C; 26 | 27 | #include 28 | #include 29 | 30 | VoidType::VoidType() : Type(new TypeImpl(TypeKind::Void)) 31 | {} 32 | 33 | namespace psy { 34 | namespace C { 35 | 36 | PSY_C_API std::ostream& operator<<(std::ostream& os, const VoidType* voidTy) 37 | { 38 | if (!voidTy) 39 | return os << ""; 40 | return os << ""; 41 | } 42 | 43 | } // C 44 | } // psy 45 | -------------------------------------------------------------------------------- /C/types/Type_Void.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021/22/23/24 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_C_TYPE_VOID_H__ 22 | #define PSYCHE_C_TYPE_VOID_H__ 23 | 24 | #include "API.h" 25 | #include "Fwds.h" 26 | 27 | #include "Type.h" 28 | 29 | namespace psy { 30 | namespace C { 31 | 32 | /** 33 | * \brief The VoidType class. 34 | * 35 | * \remark 6.2.5-14 36 | */ 37 | class PSY_C_API VoidType final : public Type 38 | { 39 | public: 40 | //!@{ 41 | /** 42 | * Cast \c this Type as an VoidType. 43 | */ 44 | virtual VoidType* asVoidType() override { return this; } 45 | virtual const VoidType* asVoidType() const override { return this; } 46 | //!@} 47 | 48 | PSY_INTERNAL: 49 | PSY_GRANT_INTERNAL_ACCESS(Compilation); 50 | PSY_GRANT_INTERNAL_ACCESS(DeclarationBinder); 51 | 52 | VoidType(); 53 | }; 54 | 55 | PSY_C_API std::ostream& operator<<(std::ostream& os, const VoidType* voidTy); 56 | 57 | } // C 58 | } // psy 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /C/types/Type__IMPL__.inc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2021/22/23/24 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "Type.h" 22 | 23 | using namespace psy; 24 | using namespace C; 25 | 26 | struct Type::TypeImpl 27 | { 28 | TypeImpl(TypeKind tyK) 29 | : BD_(0) 30 | { 31 | F_.tyK_ = static_cast(tyK); 32 | } 33 | 34 | struct BD 35 | { 36 | // Type 37 | std::uint32_t tyK_ : 4; 38 | 39 | // BasicType 40 | std::uint32_t basicTyK_: 5; 41 | 42 | // PointerType 43 | std::uint32_t ariseFromArrayDecay_ : 1; 44 | std::uint32_t ariseFromFuncDecay_ : 1; 45 | 46 | // TagType 47 | std::uint32_t tagTyK_ : 2; 48 | 49 | // FunctionType 50 | std::uint32_t parmListForm_ : 2; 51 | std::uint32_t isVariadic_ : 1; 52 | }; 53 | union 54 | { 55 | std::uint32_t BD_; 56 | BD F_; 57 | }; 58 | }; 59 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2021 Leandro T. C. Melo 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | 7 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | 9 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 10 | 11 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /TestSuiteRunner.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "tests/TestSuite.h" 22 | 23 | #include 24 | 25 | using namespace psy; 26 | 27 | int main() 28 | { 29 | try 30 | { 31 | TestSuite::runTests(); 32 | } 33 | catch (...) 34 | { 35 | std::cerr << "Unhandled exception during tests!" << std::endl; 36 | return 1; 37 | } 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /cnippet/CompilerFrontend.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "CompilerFrontend.h" 22 | 23 | #include "Configuration.h" 24 | 25 | using namespace cnip; 26 | 27 | CompilerFrontend::~CompilerFrontend() 28 | {} 29 | 30 | CompilerFrontend::CompilerFrontend() 31 | {} 32 | -------------------------------------------------------------------------------- /cnippet/CompilerFrontend.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef CNIPPET_COMPILER_FRONTEND_H__ 22 | #define CNIPPET_COMPILER_FRONTEND_H__ 23 | 24 | #include "Configuration.h" 25 | 26 | #include "FileInfo.h" 27 | 28 | #include "cxxopts.hpp" 29 | 30 | #include 31 | 32 | namespace cnip { 33 | 34 | /*! 35 | * \brief The CompilerFrontend class. 36 | */ 37 | class CompilerFrontend 38 | { 39 | public: 40 | virtual ~CompilerFrontend(); 41 | 42 | virtual bool setup() = 0; 43 | virtual int run(const std::string& srcText, const psy::FileInfo& fi) = 0; 44 | 45 | protected: 46 | CompilerFrontend(); 47 | }; 48 | 49 | } // cnip 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /cnippet/Configuration.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "Configuration.h" 22 | 23 | using namespace cnip; 24 | 25 | Configuration::~Configuration() 26 | {} 27 | 28 | Configuration::Configuration(const cxxopts::ParseResult& parsedCmdLine) 29 | : dumpAst(parsedCmdLine.count("dump-AST")) 30 | , WIP_(parsedCmdLine.count("WIP")) 31 | {} 32 | -------------------------------------------------------------------------------- /cnippet/Configuration.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef CNIPPET_CONFIGURATION_H__ 22 | #define CNIPPET_CONFIGURATION_H__ 23 | 24 | #include "cxxopts.hpp" 25 | 26 | namespace cnip { 27 | 28 | /*! 29 | * \brief The Configuration class. 30 | */ 31 | class Configuration 32 | { 33 | public: 34 | virtual ~Configuration(); 35 | 36 | // TODO: API 37 | bool dumpAst; 38 | bool WIP_; 39 | 40 | protected: 41 | Configuration(const cxxopts::ParseResult& parsedCmdLine); 42 | }; 43 | 44 | } // cnip 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /cnippet/Driver.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef CNIPPET_DRIVER_H__ 22 | #define CNIPPET_DRIVER_H__ 23 | 24 | const char* const kCnip = "cnip: "; 25 | 26 | namespace cnip { 27 | 28 | /*! 29 | * \brief The Driver class. 30 | */ 31 | class Driver final 32 | { 33 | public: 34 | Driver(); 35 | ~Driver(); 36 | 37 | int execute(int argc, char* argv[]); 38 | 39 | private: 40 | static constexpr int SUCCESS = 0; 41 | 42 | static constexpr int ERROR = 1; 43 | static constexpr int ERROR_UnrecognizedCmdLineFlag = 2; 44 | static constexpr int ERROR_InvalidCmdLineFlagValue = 3; 45 | static constexpr int ERROR_NoInputFile = 4; 46 | static constexpr int ERROR_FileNotFound = 5; 47 | static constexpr int ERROR_CannotLoadPluging = 6; 48 | static constexpr int ERROR_LanguageNotRecognized = 7; 49 | }; 50 | 51 | } // cnip 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /cnippet/Main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "Driver.h" 22 | 23 | #include 24 | 25 | using namespace cnip; 26 | 27 | int main(int argc, char* argv[]) 28 | { 29 | try 30 | { 31 | Driver driver; 32 | return driver.execute(argc, argv); 33 | } 34 | catch (...) 35 | { 36 | std::cerr << "unhandled exception" << std::endl; 37 | return 1; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /cnippet/wrapper/Python/Algorithms.py: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # Copyright (c) 2017 Leandro T. C. Melo (LTCMELO@GMAIL.COM) 3 | # 4 | # All rights reserved. Unauthorized copying of this file, through any 5 | # medium, is strictly prohibited. 6 | # 7 | # This software is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | # CONDITIONS OF ANY KIND, explicit or implicit. In no event shall the 9 | # author be liable for any claim or damages. 10 | # ----------------------------------------------------------------------------- 11 | 12 | 13 | import os 14 | import shutil 15 | import sys 16 | from Diagnostics import (DiagnosticReporter, 17 | EXCEPTION_COPYING_FILE_OBJECT, 18 | EXCEPTION_COPYING_FILE_PATH) 19 | 20 | 21 | def maybe_append(value, condition, sequence): 22 | return sequence.append(value) if condition else sequence 23 | 24 | 25 | def delete_files(*files_path): 26 | for p in files_path: 27 | try: 28 | os.remove(p) 29 | except OSError: 30 | pass 31 | 32 | 33 | def concat_file(src_path, dst_path): 34 | with open(dst_path, 'ab') as dst: 35 | with open(src_path, 'rb') as src: 36 | try: 37 | shutil.copyfileobj(src, dst) 38 | except: 39 | sys.exit(DiagnosticReporter.fatal(EXCEPTION_COPYING_FILE_OBJECT, 40 | src_path, dst_path)) 41 | 42 | 43 | def copy_file(src_path, dst_path): 44 | try: 45 | shutil.copyfile(src_path, dst_path) 46 | except: 47 | sys.exit(DiagnosticReporter.fatal(EXCEPTION_COPYING_FILE_PATH, src_path, dst_path)) 48 | 49 | 50 | def flatten(l): 51 | return ' '.join(l) 52 | -------------------------------------------------------------------------------- /cnippet/wrapper/Python/Logger.py: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # Copyright (c) 2017 Leandro T. C. Melo (LTCMELO@GMAIL.COM) 3 | # 4 | # All rights reserved. Unauthorized copying of this file, through any 5 | # medium, is strictly prohibited. 6 | # 7 | # This software is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | # CONDITIONS OF ANY KIND, explicit or implicit. In no event shall the 9 | # author be liable for any claim or damages. 10 | # ----------------------------------------------------------------------------- 11 | 12 | 13 | from Singleton import Singleton 14 | from typing import Set 15 | 16 | 17 | def xtrace(parent, cmd): 18 | return Logger().xtrace(parent, cmd) 19 | 20 | 21 | def debug(parent, msg): 22 | Logger().debug(parent, msg) 23 | 24 | 25 | class Logger(metaclass=Singleton): 26 | 27 | def __init__(self): 28 | self.xtrace_enabled: bool = False 29 | self.debug_enabled: Set[str] = set() 30 | 31 | def configure(self, xtrace, debug): 32 | self.xtrace_enabled = xtrace 33 | if debug: 34 | self.debug_enabled = set(debug) 35 | 36 | class Handle: 37 | def __init__(self, ctx): 38 | self.ctx = ctx 39 | 40 | def __enter__(self): 41 | return self 42 | 43 | def __exit__(self, exc_type, exc_val, exc_tb): 44 | if self.ctx: 45 | print(f'... {self.r}\n') 46 | 47 | def report(self, r): 48 | self.r = r 49 | 50 | @staticmethod 51 | def prefix(parent: str): 52 | return f'' 53 | 54 | def xtrace(self, parent, cmd): 55 | if self.xtrace_enabled: 56 | print(f'{Logger.prefix(parent)} $\n{cmd}') 57 | return Logger.Handle(self.xtrace_enabled) 58 | 59 | def debug(self, parent, msg): 60 | if parent in self.debug_enabled or 'all' in self.debug_enabled: 61 | print(f'{Logger.prefix(parent)} {msg}\n') 62 | -------------------------------------------------------------------------------- /cnippet/wrapper/Python/Process.py: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # Copyright (c) 2017 Leandro T. C. Melo (LTCMELO@GMAIL.COM) 3 | # 4 | # All rights reserved. Unauthorized copying of this file, through any 5 | # medium, is strictly prohibited. 6 | # 7 | # This software is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | # CONDITIONS OF ANY KIND, explicit or implicit. In no event shall the 9 | # author be liable for any claim or damages. 10 | # ----------------------------------------------------------------------------- 11 | 12 | 13 | import subprocess 14 | import sys 15 | from Algorithms import flatten 16 | from Diagnostics import DiagnosticReporter, EXCEPTION_EXECUTING_PROCESS 17 | from Logger import xtrace 18 | 19 | 20 | def execute(parent, cmd, *args, **kwargs): 21 | """ 22 | Execute an external process with the given command. 23 | """ 24 | 25 | with xtrace(parent, flatten(cmd)) as h: 26 | try: 27 | code = subprocess.call(cmd, *args, **kwargs) 28 | except: 29 | sys.exit( 30 | DiagnosticReporter.fatal(EXCEPTION_EXECUTING_PROCESS, cmd[0])) 31 | finally: 32 | h.report(code) 33 | return code 34 | 35 | -------------------------------------------------------------------------------- /cnippet/wrapper/Python/Singleton.py: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # Copyright (c) 2017 Leandro T. C. Melo (LTCMELO@GMAIL.COM) 3 | # 4 | # All rights reserved. Unauthorized copying of this file, through any 5 | # medium, is strictly prohibited. 6 | # 7 | # This software is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | # CONDITIONS OF ANY KIND, explicit or implicit. In no event shall the 9 | # author be liable for any claim or damages. 10 | # ----------------------------------------------------------------------------- 11 | 12 | 13 | class Singleton(type): 14 | 15 | _instances = {} 16 | 17 | def __call__(cls, *args, **kwargs): 18 | if cls not in cls._instances: 19 | cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) 20 | return cls._instances[cls] 21 | -------------------------------------------------------------------------------- /cnippet/wrapper/Python/Unit.py: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # Copyright (c) 2017 Leandro T. C. Melo (LTCMELO@GMAIL.COM) 3 | # 4 | # All rights reserved. Unauthorized copying of this file, through any 5 | # medium, is strictly prohibited. 6 | # 7 | # This software is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | # CONDITIONS OF ANY KIND, explicit or implicit. In no event shall the 9 | # author be liable for any claim or damages. 10 | # ----------------------------------------------------------------------------- 11 | 12 | 13 | import os 14 | from collections import namedtuple 15 | 16 | 17 | Unit = namedtuple( 18 | 'Unit', [ 19 | 'c_file', # The original C file. 20 | 'i_file', # A preprocessed version of the original C file. 21 | 'cstr_file', # The constraints file. 22 | 'inc_file', # A file with a list of stdlib `#include's. 23 | 'poly_file', # A "polymorphic" version of the original C file. 24 | 'cnip_file' # The file containing inference results. 25 | ]) 26 | 27 | 28 | def make_unit(c_file, out_dir): 29 | """ 30 | Make a compilation unit. 31 | """ 32 | 33 | (_, c_file_name) = os.path.split(c_file) 34 | (c_file_base_name, _) = os.path.splitext(c_file_name) 35 | out_file_base_name = out_dir + c_file_base_name 36 | 37 | return Unit(c_file, 38 | out_file_base_name + '.i', 39 | out_file_base_name + '.cstr', 40 | out_file_base_name + '.inc', 41 | out_file_base_name + '.poly', 42 | out_file_base_name + '.cnip.c') 43 | -------------------------------------------------------------------------------- /cnippet/wrapper/Python/Version.py: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # Copyright (c) 2017 Leandro T. C. Melo (LTCMELO@GMAIL.COM) 3 | # 4 | # All rights reserved. Unauthorized copying of this file, through any 5 | # medium, is strictly prohibited. 6 | # 7 | # This software is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR 8 | # CONDITIONS OF ANY KIND, explicit or implicit. In no event shall the 9 | # author be liable for any claim or damages. 10 | # ----------------------------------------------------------------------------- 11 | 12 | 13 | import subprocess 14 | import sys 15 | from Diagnostics import DiagnosticReporter, ERROR_FETCHING_GIT_SHA 16 | 17 | 18 | class Version: 19 | """ Cnippet's version information """ 20 | 21 | _id = 'version' 22 | 23 | major = 1 24 | minor = 0 25 | patch = 0 26 | 27 | description = 'pre-alpha evaluation' 28 | 29 | def __str__(self): 30 | return self.__repr__() 31 | 32 | def __repr__(self): 33 | return '%s.%s.%s %s' % (Version.major, 34 | Version.minor, 35 | Version.patch, 36 | Version.description) 37 | 38 | @staticmethod 39 | def number(): 40 | return '%s.%s.%s' % (Version.major, 41 | Version.minor, 42 | Version.patch) 43 | 44 | @staticmethod 45 | def git_sha(): 46 | """ 47 | Get git HEAD's sha. 48 | """ 49 | 50 | cmd = ['git', 'rev-parse', 'HEAD'] 51 | process = subprocess.Popen(cmd, stdout=subprocess.PIPE) 52 | out, err = process.communicate() 53 | if err: 54 | sys.exit(DiagnosticReporter.fatal(ERROR_FETCHING_GIT_SHA)) 55 | return out[:7] 56 | -------------------------------------------------------------------------------- /cnippet/wrapper/Python/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltcmelo/psychec/14f45120fd3519d2c64e519c202fccebd95c3a07/cnippet/wrapper/Python/__init__.py -------------------------------------------------------------------------------- /cnippet/wrapper/Python/setup.cfg: -------------------------------------------------------------------------------- 1 | # Style/formatting 2 | 3 | [flake8] 4 | max-line-length = 100 5 | ignore = E127, E128, E251, E252, E722, W503 6 | 7 | [pycodestyle] 8 | max_line_length = 100 9 | ignore = E127, E128, E251, E252, E722, W503 10 | 11 | # Correctness 12 | 13 | [mypy] 14 | -------------------------------------------------------------------------------- /command/cxxopts/.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | build* 3 | CMakeCache.txt 4 | Makefile 5 | CMakeFiles/ 6 | Testing/ 7 | CTestTestfile.cmake 8 | cmake_install.cmake 9 | -------------------------------------------------------------------------------- /command/cxxopts/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | dist: trusty 3 | language: cpp 4 | os: 5 | - osx 6 | env: 7 | - 8 | - > 9 | UNICODE_OPTIONS=-DCXXOPTS_USE_UNICODE_HELP=Yes 10 | PKG_CONFIG_PATH=/usr/local/opt/icu4c/lib/pkgconfig 11 | matrix: 12 | include: 13 | - os: linux 14 | env: COMPILER=g++-5 15 | addons: 16 | apt: 17 | packages: 18 | - g++-5 19 | sources: &sources 20 | - llvm-toolchain-precise-3.8 21 | - ubuntu-toolchain-r-test 22 | - os: linux 23 | env: COMPILER=g++-5 UNICODE_OPTIONS=-DCXXOPTS_USE_UNICODE_HELP=Yes 24 | addons: 25 | apt: 26 | packages: 27 | - g++-5 28 | sources: *sources 29 | - os: linux 30 | env: COMPILER=clang++-3.8 CXXFLAGS=-stdlib=libc++ 31 | addons: 32 | apt: 33 | packages: 34 | - clang-3.8 35 | - libc++-dev 36 | sources: *sources 37 | - os: linux 38 | env: COMPILER=clang++-3.8 CXXFLAGS=-stdlib=libc++ UNICODE_OPTIONS=-DCXXOPTS_USE_UNICODE_HELP=Yes 39 | addons: 40 | apt: 41 | packages: 42 | - clang-3.8 43 | - libc++-dev 44 | sources: *sources 45 | script: > 46 | cmake -DCXXOPTS_BUILD_TESTS=ON -DCMAKE_CXX_COMPILER=$COMPILER 47 | -DCMAKE_CXX_FLAGS=$CXXFLAGS $UNICODE_OPTIONS . 48 | && make && make ARGS=--output-on-failure test 49 | 50 | before_install: 51 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi 52 | - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install icu4c; fi 53 | -------------------------------------------------------------------------------- /command/cxxopts/INSTALL: -------------------------------------------------------------------------------- 1 | == System installation == 2 | 3 | This library is header only. So you can either copy `include/cxxopts.hpp` to `/usr/include` or `/usr/local/include`, or add `include` to your search path. 4 | 5 | == Building the examples and tests == 6 | 7 | It is preferable to build out of source. Make a build directory somewhere, and then 8 | do the following, where `${CXXOPTS_DIR}` is the path that you checked out `cxxopts` 9 | to: 10 | 11 | cmake ${CXXOPTS_DIR} 12 | make 13 | 14 | You can use another build tool, such as ninja. 15 | 16 | cmake -G Ninja ${CXXOPTS_DIR} 17 | ninja 18 | 19 | 20 | To run the tests, you have to configure `cxxopts` with another flag: 21 | cmake -D CXXOPTS_BUILD_TESTS=On ${CXXOPTS_DIR} 22 | make 23 | make test 24 | -------------------------------------------------------------------------------- /command/cxxopts/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Jarryd Beck 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /command/cxxopts/biicode.conf: -------------------------------------------------------------------------------- 1 | # Biicode configuration file 2 | 3 | [requirements] 4 | biicode/cmake: 3 5 | -------------------------------------------------------------------------------- /command/cxxopts/src/.gitignore: -------------------------------------------------------------------------------- 1 | example 2 | -------------------------------------------------------------------------------- /command/cxxopts/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2014 Jarryd Beck 2 | # 3 | # Permission is hereby granted, free of charge, to any person obtaining a copy 4 | # of this software and associated documentation files (the "Software"), to deal 5 | # in the Software without restriction, including without limitation the rights 6 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | # copies of the Software, and to permit persons to whom the Software is 8 | # furnished to do so, subject to the following conditions: 9 | # 10 | # The above copyright notice and this permission notice shall be included in 11 | # all copies or substantial portions of the Software. 12 | # 13 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | # THE SOFTWARE. 20 | 21 | if(CXXOPTS_BUILD_EXAMPLES) 22 | add_executable(example example.cpp) 23 | target_link_libraries(example cxxopts) 24 | endif() 25 | -------------------------------------------------------------------------------- /command/cxxopts/test/.gitignore: -------------------------------------------------------------------------------- 1 | options_test 2 | -------------------------------------------------------------------------------- /command/cxxopts/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if (CXXOPTS_BUILD_TESTS) 2 | add_executable(options_test main.cpp options.cpp) 3 | target_link_libraries(options_test cxxopts) 4 | add_test(options options_test) 5 | 6 | # test if the targets are findable from the build directory 7 | add_test(find-package-test ${CMAKE_CTEST_COMMAND} 8 | -C ${CMAKE_BUILD_TYPE} 9 | --build-and-test 10 | "${CMAKE_CURRENT_SOURCE_DIR}/find-package-test" 11 | "${CMAKE_CURRENT_BINARY_DIR}/find-package-test" 12 | --build-generator ${CMAKE_GENERATOR} 13 | --build-makeprogram ${CMAKE_MAKE_PROGRAM} 14 | --build-options 15 | "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" 16 | "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" 17 | "-Dcxxopts_DIR=${PROJECT_BINARY_DIR}" 18 | ) 19 | 20 | # test if the targets are findable when add_subdirectory is used 21 | add_test(add-subdirectory-test ${CMAKE_CTEST_COMMAND} 22 | -C ${CMAKE_BUILD_TYPE} 23 | --build-and-test 24 | "${CMAKE_CURRENT_SOURCE_DIR}/add-subdirectory-test" 25 | "${CMAKE_CURRENT_BINARY_DIR}/add-subdirectory-test" 26 | --build-generator ${CMAKE_GENERATOR} 27 | --build-makeprogram ${CMAKE_MAKE_PROGRAM} 28 | --build-options 29 | "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" 30 | "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}" 31 | ) 32 | 33 | add_executable(link_test link_a.cpp link_b.cpp) 34 | target_link_libraries(link_test cxxopts) 35 | endif() 36 | -------------------------------------------------------------------------------- /common/API.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_API_H__ 22 | #define PSYCHE_API_H__ 23 | 24 | // From https://gcc.gnu.org/wiki/Visibility 25 | #if defined _WIN32 || defined __CYGWIN__ 26 | #ifdef EXPORT_PSY_API 27 | #ifdef __GNUC__ 28 | #define PSY_API __attribute__ ((dllexport)) 29 | #else 30 | #define PSY_API __declspec(dllexport) 31 | #endif 32 | #else 33 | #ifdef __GNUC__ 34 | #define PSY_API __attribute__ ((dllimport)) 35 | #else 36 | #define PSY_API __declspec(dllimport) 37 | #endif 38 | #endif 39 | #define PSY_API_LOCAL 40 | #else 41 | #if __GNUC__ >= 4 42 | #define PSY_API __attribute__ ((visibility ("default"))) 43 | #define PSY_API_LOCAL __attribute__ ((visibility ("hidden"))) 44 | #else 45 | #define PSY_API 46 | #define PSY_API_LOCAL 47 | #endif 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /common/diagnostics/DiagnosticCategory.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "DiagnosticCategory.h" 22 | 23 | #include "../infra/Assertions.h" 24 | 25 | namespace psy { 26 | 27 | std::ostream& operator<<(std::ostream& os, DiagnosticCategory category) 28 | { 29 | switch (category) { 30 | case DiagnosticCategory::Syntax: 31 | os << "syntax"; 32 | break; 33 | case DiagnosticCategory::Binding: 34 | os << "declaration"; 35 | break; 36 | case DiagnosticCategory::TypeChecking: 37 | os << "type checking"; 38 | break; 39 | case DiagnosticCategory::TypeResolution: 40 | os << "type resolution"; 41 | break; 42 | case DiagnosticCategory::UNSPECIFIED: 43 | os << "generic"; 44 | break; 45 | } 46 | PSY_ASSERT_1(false); 47 | return os; 48 | } 49 | 50 | } // psy 51 | -------------------------------------------------------------------------------- /common/diagnostics/DiagnosticCategory.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_DIAGNOSTIC_CATEGORY_H__ 22 | #define PSYCHE_DIAGNOSTIC_CATEGORY_H__ 23 | 24 | #include 25 | 26 | namespace psy { 27 | 28 | enum class DiagnosticCategory : char 29 | { 30 | UNSPECIFIED = 0, 31 | 32 | Syntax, 33 | Binding, 34 | TypeResolution, 35 | TypeChecking, 36 | }; 37 | 38 | std::ostream& operator<<(std::ostream& os, DiagnosticCategory category); 39 | 40 | } // psy 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /common/diagnostics/DiagnosticSeverity.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "DiagnosticSeverity.h" 22 | 23 | #include "../infra/Assertions.h" 24 | 25 | namespace psy { 26 | 27 | std::ostream& operator<<(std::ostream& os, DiagnosticSeverity severity) 28 | { 29 | switch (severity) 30 | { 31 | case DiagnosticSeverity::Warning: 32 | os << "warning"; 33 | break; 34 | case DiagnosticSeverity::Error: 35 | os << "error"; 36 | break; 37 | default: 38 | PSY_ASSERT_FAIL_1(return os); 39 | } 40 | return os; 41 | } 42 | 43 | } // psy 44 | -------------------------------------------------------------------------------- /common/diagnostics/DiagnosticSeverity.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_DIAGNOSTIC_SEVERITY_H__ 22 | #define PSYCHE_DIAGNOSTIC_SEVERITY_H__ 23 | 24 | #include 25 | 26 | namespace psy { 27 | 28 | enum class DiagnosticSeverity : char 29 | { 30 | UNSPECIFIED = 0, 31 | 32 | Warning, 33 | Error 34 | }; 35 | 36 | std::ostream& operator<<(std::ostream& os, DiagnosticSeverity severity); 37 | 38 | } // psy 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /common/infra/AccessSpecifiers.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2022 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_ACCESS_SPCECIFIERS_H__ 22 | #define PSYCHE_ACCESS_SPCECIFIERS_H__ 23 | 24 | #define PSY_INTERNAL private 25 | #define PSY_GRANT_INTERNAL_ACCESS(NAME) friend class NAME 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /common/infra/Pimpl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-20 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | /*-------------------------------------------------------------*/ 22 | /* File "borrowed" from the UASIO project: */ 23 | /* */ 24 | /* https://github.com/ltcmelo/uaiso/blob/master/Common/Pimpl.h */ 25 | /*-------------------------------------------------------------*/ 26 | 27 | #ifndef PSYCHE_PIMPL_H__ 28 | #define PSYCHE_PIMPL_H__ 29 | 30 | #include 31 | 32 | #define DECL_PIMPL(CLASS) \ 33 | struct CLASS##Impl; \ 34 | std::unique_ptr impl_; 35 | 36 | #define DECL_PIMPL_SUB(CLASS) \ 37 | struct CLASS##Impl; \ 38 | CLASS##Impl* CAST() const { return ((CLASS##Impl*)impl_.get()); } 39 | 40 | #define DECL_SHARED_DATA(CLASS) \ 41 | struct CLASS##Impl; \ 42 | std::shared_ptr impl_; 43 | 44 | #define P impl_ 45 | #define P_CAST CAST() 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /common/location/FileLinePositionSpan.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "FileLinePositionSpan.h" 22 | 23 | namespace psy { 24 | 25 | bool operator==(const FileLinePositionSpan& a, const FileLinePositionSpan& b) 26 | { 27 | return a.path() == b.path() && a.span() == b.span(); 28 | } 29 | 30 | std::ostream& operator<<(std::ostream& os, const FileLinePositionSpan& span) 31 | { 32 | os << span.path() << ":" << span.span(); 33 | return os; 34 | } 35 | 36 | } // psy 37 | -------------------------------------------------------------------------------- /common/location/LinePosition.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "LinePosition.h" 22 | 23 | namespace psy { 24 | 25 | bool operator==(const LinePosition& a, const LinePosition& b) 26 | { 27 | return a.line() == b.line() && a.character() == b.character(); 28 | } 29 | 30 | bool operator<(const LinePosition& a, const LinePosition& b) 31 | { 32 | const int al = a.line(); 33 | const int bl = b.line(); 34 | 35 | return al != bl ? al < bl : a.character() < b.character(); 36 | } 37 | 38 | std::ostream& operator<<(std::ostream& os, const LinePosition& pos) 39 | { 40 | os << pos.line() << ":" << pos.character(); 41 | return os; 42 | } 43 | 44 | } // psy 45 | -------------------------------------------------------------------------------- /common/location/LinePositionSpan.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "LinePositionSpan.h" 22 | 23 | namespace psy { 24 | 25 | bool operator==(const LinePositionSpan& a, const LinePositionSpan& b) 26 | { 27 | return a.start() == b.start() && a.end() == b.end(); 28 | } 29 | 30 | std::ostream& operator<<(std::ostream& os, const LinePositionSpan& span) 31 | { 32 | os << span.start() << "-" << span.end(); 33 | return os; 34 | } 35 | 36 | } // psy 37 | -------------------------------------------------------------------------------- /common/location/Location.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "Location.h" 22 | 23 | using namespace psy; 24 | 25 | Location::Location(std::string filePath, LinePositionSpan lineSpan) 26 | : fileLineSpan_(filePath, lineSpan) 27 | {} 28 | 29 | Location::Location(FileLinePositionSpan fileLineSpan) 30 | : fileLineSpan_(std::move(fileLineSpan)) 31 | {} 32 | 33 | Location Location::create(std::string filePath, LinePositionSpan span) 34 | { 35 | Location loc(filePath, span); 36 | return loc; 37 | } 38 | 39 | Location Location::create(FileLinePositionSpan fileLineSpan) 40 | { 41 | return Location(std::move(fileLineSpan)); 42 | } 43 | 44 | namespace psy { 45 | 46 | bool operator==(const Location& a, const Location& b) 47 | { 48 | return a.lineSpan() == b.lineSpan(); 49 | } 50 | 51 | std::ostream& operator<<(std::ostream& os, const Location& loc) 52 | { 53 | os << loc.lineSpan(); 54 | return os; 55 | } 56 | 57 | } // psy 58 | -------------------------------------------------------------------------------- /common/text/SourceText.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "SourceText.h" 22 | 23 | using namespace psy; 24 | 25 | SourceText::SourceText(std::string rawText) 26 | : rawText_(std::move(rawText)) 27 | {} 28 | 29 | const std::string& SourceText::rawText() const 30 | { 31 | return rawText_; 32 | } 33 | -------------------------------------------------------------------------------- /common/text/SourceText.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | /* 22 | * This API is inspired by the API of Roslyn (the .NET Compiler Platform). 23 | */ 24 | 25 | #ifndef PSYCHE_SOURCE_TEXT_H__ 26 | #define PSYCHE_SOURCE_TEXT_H__ 27 | 28 | #include "../API.h" 29 | 30 | #include 31 | 32 | namespace psy { 33 | 34 | /** 35 | * \brief The SourceText class. 36 | */ 37 | class PSY_API SourceText 38 | { 39 | public: 40 | SourceText(std::string rawText); 41 | 42 | const std::string& rawText() const; 43 | 44 | private: 45 | std::string rawText_; 46 | }; 47 | 48 | } // psy 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /common/text/TextSpan.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // Copyright (c) 2008 Roberto Raggi 3 | // 4 | // Permission is hereby granted, free of charge, to any person obtaining a copy 5 | // of this software and associated documentation files (the "Software"), to deal 6 | // in the Software without restriction, including without limitation the rights 7 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | // copies of the Software, and to permit persons to whom the Software is 9 | // furnished to do so, subject to the following conditions: 10 | // 11 | // The above copyright notice and this permission notice shall be included in 12 | // all copies or substantial portions of the Software. 13 | // 14 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | // THE SOFTWARE. 21 | 22 | #include "TextSpan.h" 23 | 24 | namespace psy { 25 | 26 | bool operator==(const TextSpan& a, const TextSpan& b) 27 | { 28 | return a.start() == b.start() && a.end() == b.end(); 29 | } 30 | 31 | std::ostream& operator<<(std::ostream& os, const TextSpan& span) 32 | { 33 | os << span.start() << ".." << span.end(); 34 | return os; 35 | } 36 | 37 | } // psy 38 | -------------------------------------------------------------------------------- /formalism/test001.c: -------------------------------------------------------------------------------- 1 | T f() { return 1; } 2 | -------------------------------------------------------------------------------- /formalism/test002.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | T abc; 4 | abc = 2; 5 | return abc; 6 | } 7 | -------------------------------------------------------------------------------- /formalism/test003.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | T2 a; 4 | a = 10; 5 | return a; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /formalism/test004.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | T2 x; 4 | *x = 99; 5 | return *x; 6 | } 7 | -------------------------------------------------------------------------------- /formalism/test005.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | T2 a; 4 | a = 99; 5 | T3 b; 6 | b = &a; 7 | return a; 8 | } 9 | -------------------------------------------------------------------------------- /formalism/test006.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | T2 a; 4 | T3 b; 5 | T4 c; 6 | a = b; 7 | c = a; 8 | b = 10; 9 | return c; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test007.c: -------------------------------------------------------------------------------- 1 | RT f(PT1 param) 2 | { 3 | param = 42; 4 | return param; 5 | } 6 | -------------------------------------------------------------------------------- /formalism/test008.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | T2* r; 4 | r->x = 42; 5 | return r->x; 6 | } 7 | -------------------------------------------------------------------------------- /formalism/test009.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | T2 x; 4 | x = 42; 5 | T3 y; 6 | y = 3.14; 7 | x = y; 8 | return x; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test010.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | T2 r; 4 | r->x = 42; 5 | return r->x; 6 | } 7 | -------------------------------------------------------------------------------- /formalism/test011.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | int x; 4 | return x; 5 | } 6 | -------------------------------------------------------------------------------- /formalism/test012.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | int* x; 4 | return x; 5 | } 6 | -------------------------------------------------------------------------------- /formalism/test013.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | const int x; 4 | return x; 5 | } 6 | -------------------------------------------------------------------------------- /formalism/test014.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | const int x; 4 | T1 y; 5 | y = x; 6 | return y; 7 | } 8 | -------------------------------------------------------------------------------- /formalism/test015.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | const int* x; 4 | T1 y; 5 | y = x; 6 | return y; 7 | } 8 | -------------------------------------------------------------------------------- /formalism/test016.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | const int* x; 4 | T1 y; 5 | x = y; 6 | return y; 7 | } 8 | -------------------------------------------------------------------------------- /formalism/test017.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | T1 x; 4 | int* y; 5 | const int* z; 6 | x = y; 7 | x = z; 8 | return x; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test018.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | T1 x; 4 | int* y; 5 | const int* z; 6 | x = z; 7 | x = y; 8 | return x; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test019.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | T x; 4 | return x; 5 | } 6 | -------------------------------------------------------------------------------- /formalism/test020.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | T1 r; 4 | r->x = 42; 5 | T2 q; 6 | q = r; 7 | return r->x; 8 | } 9 | -------------------------------------------------------------------------------- /formalism/test021.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | T1 r; 4 | r->x = 42; 5 | T2 q; 6 | q = r; 7 | q->x = r->x; 8 | return r->x; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test022.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | T1 r; 4 | r->x = 42; 5 | T2 q; 6 | q->x = r->x; 7 | return r->x; 8 | } 9 | -------------------------------------------------------------------------------- /formalism/test023.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | T2 x; 4 | x = 42; 5 | T3 y; 6 | y = 3.14; 7 | y = x; 8 | return x; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test024.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | const int* cip; 4 | T1 x; 5 | x = cip; 6 | 7 | const double* cdp; 8 | T2 y; 9 | y = cdp; 10 | 11 | y = x; 12 | 13 | return 42; 14 | } 15 | -------------------------------------------------------------------------------- /formalism/test025.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | const int* cip; 4 | T1 x; 5 | x = cip; 6 | 7 | const double* cdp; 8 | T2 y; 9 | y = cdp; 10 | 11 | x = y; 12 | 13 | return 42; 14 | } 15 | -------------------------------------------------------------------------------- /formalism/test026.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | const int* cip; 4 | T1 x; 5 | x = cip; 6 | 7 | int* ip; 8 | T2 y; 9 | y = ip; 10 | 11 | x = y; 12 | return 42; 13 | } 14 | -------------------------------------------------------------------------------- /formalism/test027.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | int* ip; 4 | T1 y; 5 | y = ip; 6 | const int* cip; 7 | T2 x; 8 | x = cip; 9 | 10 | x = y; 11 | return 42; 12 | } 13 | -------------------------------------------------------------------------------- /formalism/test028.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ltcmelo/psychec/14f45120fd3519d2c64e519c202fccebd95c3a07/formalism/test028.c -------------------------------------------------------------------------------- /formalism/test029.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | const int* x; 4 | int* y; 5 | x = y; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /formalism/test030.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | const int* cip; 4 | T1 x; 5 | x = cip; 6 | T11 xx; 7 | xx = x; 8 | 9 | int* ip; 10 | T2 y; 11 | y = ip; 12 | T22 yy; 13 | yy = y; 14 | 15 | xx = yy; 16 | return 42; 17 | } 18 | -------------------------------------------------------------------------------- /formalism/test031.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | const int* x; 4 | T1* xx; 5 | xx = x; 6 | 7 | int* y; 8 | T2* yy; 9 | yy = y; 10 | 11 | xx = yy; 12 | 13 | return 1; 14 | } 15 | -------------------------------------------------------------------------------- /formalism/test032.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | const int* x; 4 | T1* xx; 5 | xx = x; 6 | 7 | int* y; 8 | T2* yy; 9 | yy = y; 10 | 11 | yy = xx; 12 | 13 | return 1; 14 | } 15 | -------------------------------------------------------------------------------- /formalism/test033.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | const int* x; 4 | T1* xx; 5 | xx = x; 6 | T11 xxx; 7 | xxx = xx; 8 | 9 | int* y; 10 | T2* yy; 11 | yy = y; 12 | 13 | xxx = yy; 14 | 15 | return 1; 16 | } 17 | -------------------------------------------------------------------------------- /formalism/test034.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | const int x; 4 | x = 10; 5 | return x; 6 | } 7 | -------------------------------------------------------------------------------- /formalism/test035.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | const int* cip; 4 | int* ip; 5 | cip = ip; 6 | return 42; 7 | } 8 | -------------------------------------------------------------------------------- /formalism/test036.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | const int* cip; 4 | int* ip; 5 | ip = cip; 6 | return 42; 7 | } 8 | -------------------------------------------------------------------------------- /formalism/test037.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int a; 4 | a = 10; 5 | int b; 6 | a = 88; 7 | T c; 8 | c = a || b; 9 | return 42; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /formalism/test038.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int a; 4 | a = 33; 5 | double b; 6 | b = 3.14; 7 | T c; 8 | c = a || b; 9 | return 42; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test039.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | double a; 4 | a = 3.14; 5 | int b; 6 | b = 44; 7 | T c; 8 | c = a || b; 9 | return 42; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test040.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | double a; 4 | a = 3.14; 5 | T1 aa; 6 | aa = a; 7 | int b; 8 | b = 9; 9 | T c; 10 | c = aa || b; 11 | return 42; 12 | } 13 | -------------------------------------------------------------------------------- /formalism/test041.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | double a; 4 | a = 3.14; 5 | T1 aa; 6 | aa = a; 7 | int b; 8 | b = 48; 9 | T c; 10 | c = b || aa; 11 | return 42; 12 | } 13 | -------------------------------------------------------------------------------- /formalism/test042.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | double a; 4 | a = 3.14; 5 | T1 aa; 6 | aa = a; 7 | int b; 8 | b = 8; 9 | T2 bb; 10 | bb = b; 11 | T c; 12 | c = bb || aa; 13 | return 42; 14 | } 15 | -------------------------------------------------------------------------------- /formalism/test043.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | double a; 4 | a = 3.14; 5 | T1 aa; 6 | aa = a; 7 | int b; 8 | b = 77; 9 | T2 bb; 10 | bb = b; 11 | T c; 12 | c = aa || bb; 13 | return 42; 14 | } 15 | -------------------------------------------------------------------------------- /formalism/test044.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | double a; 4 | a = 3.14; 5 | T1 aa; 6 | aa = a; 7 | double b; 8 | b = 1.61; 9 | T2 bb; 10 | bb = b; 11 | T c; 12 | c = aa || bb; 13 | return 42; 14 | } 15 | -------------------------------------------------------------------------------- /formalism/test045.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | double a; 4 | a = 3.14; 5 | double b; 6 | b = 3.14; 7 | T1 c; 8 | c = a || b; 9 | return 42; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test046.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | T1 a; 4 | a = 3.14; 5 | T2 b; 6 | b = 88; 7 | T3 c; 8 | c = a / b; 9 | return 42; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test047.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | T1 a; 4 | a = 3.14; 5 | T2 b; 6 | b = 88; 7 | T3 c; 8 | c = b / a; 9 | return 42; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test048.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | T1 a; 4 | a = 3.14; 5 | int b; 6 | b = 88; 7 | T3 c; 8 | c = b / a; 9 | return 42; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test049.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | T1 a; 4 | a = 3.14; 5 | int b; 6 | b = 88; 7 | T3 c; 8 | c = a / b; 9 | return 42; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test050.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | const int* x; 4 | T1 y; 5 | y = x; 6 | T2 z; 7 | z = y; 8 | T3 w; 9 | w = z; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /formalism/test051.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | const int* x; 4 | T1 y; 5 | y = x; 6 | T2 z; 7 | z = x; 8 | T3 w; 9 | w = x; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /formalism/test052.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | int* x; 4 | T1 y; 5 | y = x; 6 | T2 z; 7 | z = x; 8 | const int* w; 9 | w = z; 10 | T3 k; 11 | k = w; 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /formalism/test053.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | int* x; 4 | T1 y; 5 | y = x; 6 | T2 z; 7 | z = x; 8 | const int* w; 9 | y = w; 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /formalism/test054.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | const int* w; 4 | T1 y; 5 | y = w; 6 | int* x; 7 | y = x; 8 | T2 z; 9 | z = x; 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /formalism/test055.c: -------------------------------------------------------------------------------- 1 | T fun() 2 | { 3 | int* ip; 4 | const int* cip; 5 | T1 a; 6 | T2 b; 7 | T3 c; 8 | T4 d; 9 | T5 e; 10 | T6 f; 11 | T7 g; 12 | T8 h; 13 | T9 i; 14 | 15 | a = cip; 16 | b = ip; 17 | 18 | c = b; 19 | d = c; 20 | e = d; 21 | f = e; 22 | 23 | g = a; 24 | h = g; 25 | i = h; 26 | i = e; 27 | 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /formalism/test056.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | T1 rec; 4 | rec->x = 42; 5 | rec->next = rec; 6 | return rec->x; 7 | } 8 | -------------------------------------------------------------------------------- /formalism/test057.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | T1 x; 4 | x->i = 42; 5 | T2 y; 6 | y->f = 3.14; 7 | x->other = y; 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test058.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | T a; 4 | return 1; 5 | } 6 | -------------------------------------------------------------------------------- /formalism/test059.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | struct T a; 4 | return 1; 5 | } 6 | -------------------------------------------------------------------------------- /formalism/test060.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | T c; 4 | c = 0; 5 | *c = 10; 6 | return 1; 7 | } 8 | -------------------------------------------------------------------------------- /formalism/test061.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | T1 x; 4 | *x = 100; 5 | T2 y; 6 | y = x + 30; 7 | return y; 8 | } 9 | -------------------------------------------------------------------------------- /formalism/test062.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | T1 x; 4 | *x = 100; 5 | T2 y; 6 | T3 z; 7 | z = x + y; 8 | return y; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test063.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | T1 x; 4 | x = 100; 5 | T2 y; 6 | T3 z; 7 | z = x + y; 8 | return y; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test064.c: -------------------------------------------------------------------------------- 1 | T f() 2 | { 3 | T1 x; 4 | *x = 100; 5 | T2 y; 6 | T3 z; 7 | z = y + x; 8 | return y; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test065.c: -------------------------------------------------------------------------------- 1 | double f() 2 | { 3 | T1* p; 4 | *p; 5 | T2 d; 6 | T3* q; 7 | q = p + d; 8 | return *p; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test066.c: -------------------------------------------------------------------------------- 1 | double f() 2 | { 3 | T1* p; 4 | *p; 5 | T2 d; 6 | T3* q; 7 | q = p + d; 8 | return *q; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test067.c: -------------------------------------------------------------------------------- 1 | typedef double* T; 2 | int f() 3 | { 4 | T x; 5 | T2 y; 6 | y = x; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /formalism/test068.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int a; 4 | a = 33; 5 | double b; 6 | b = 3.14; 7 | T c; 8 | c = a + b; 9 | return 42; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test069.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int a; 4 | a = 33; 5 | double b; 6 | b = 3.14; 7 | T c; 8 | c = a / b; 9 | return 42; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test070.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int a; 4 | a = 33; 5 | double b; 6 | b = 3.14; 7 | T c; 8 | c = b + a; 9 | return 42; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test071.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int a; 4 | a = 33; 5 | double b; 6 | b = 3.14; 7 | T c; 8 | c = b / a; 9 | return 42; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test072.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | const int* a; 4 | int* b; 5 | b = a; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /formalism/test073.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int* p; 4 | p = 0; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /formalism/test074.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | T* i; 4 | i = 0; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /formalism/test075.c: -------------------------------------------------------------------------------- 1 | int* f() 2 | { 3 | T p; 4 | return p; 5 | } 6 | -------------------------------------------------------------------------------- /formalism/test076.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | int* p; 4 | return *p; 5 | } 6 | -------------------------------------------------------------------------------- /formalism/test077.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | const int* p; 4 | return *p; 5 | } 6 | -------------------------------------------------------------------------------- /formalism/test078.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | const int x; 4 | return x; 5 | } 6 | -------------------------------------------------------------------------------- /formalism/test079.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | const int v; 4 | int w; 5 | w = v; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /formalism/test080.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | const int* p; 4 | int v; 5 | v = *p; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /formalism/test081.c: -------------------------------------------------------------------------------- 1 | int* f() 2 | { 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /formalism/test082.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | T1 r; 4 | r->m = 42; 5 | r->n = r; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /formalism/test083.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | T1 r; 4 | r->o = 42; 5 | r->n = r; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /formalism/test084.c: -------------------------------------------------------------------------------- 1 | int f() { 2 | T c; 3 | c = 0; 4 | *c = 10; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /formalism/test085.c: -------------------------------------------------------------------------------- 1 | node_t new_node(value_t value, node_t next) 2 | { 3 | node_t node; 4 | node = 0; 5 | node->next = next; 6 | node->value = value; 7 | return node; 8 | } 9 | -------------------------------------------------------------------------------- /formalism/test086.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | const int x; 4 | double y; 5 | y = x; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /formalism/test087.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | const int* x; 4 | double* y; 5 | x = y; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /formalism/test088.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | T* v; 4 | v->next = v; 5 | v->next->next = v; 6 | v->next->next->next = v; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /formalism/test089.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | T* v; 4 | v->next = v; 5 | v->next->next = v; 6 | v->next->next->next = v; 7 | v->next->next->next->next = v; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test090.c: -------------------------------------------------------------------------------- 1 | int main() 2 | { 3 | T* v; 4 | v->next = v; 5 | v->next->next = v; 6 | v->next->next->next = v; 7 | v->next->next->next->next = v; 8 | v->next->next = v->next->next; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test091.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | T1 e1; 4 | T2 e2; 5 | T3 e; 6 | e = e1 /e2; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /formalism/test092.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | int x; 4 | x = 42; 5 | T3 y; 6 | y = 3.14; 7 | x = y; 8 | return x; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test093.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | double x; 4 | x = 42; 5 | T3 y; 6 | y = 3.14; 7 | x = y; 8 | return x; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test094.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | T1 e1; 4 | T2 e2; 5 | T x; 6 | e1 = 123; 7 | e2 = 44; 8 | x = e1 / e2; 9 | return x; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test096.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | int x; 4 | x = 42; 5 | T3 y; 6 | y = 3.14; 7 | x = y; 8 | return x; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test097.c: -------------------------------------------------------------------------------- 1 | T1 f() 2 | { 3 | int x; 4 | x = 42; 5 | T3 y; 6 | y = 3.14; 7 | y = x; 8 | return x; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test098.c: -------------------------------------------------------------------------------- 1 | int fff() 2 | { 3 | int iii; 4 | SSS www; 5 | iii = www; 6 | www = iii; 7 | 8 | double ddd; 9 | QQQ uuu; 10 | uuu = ddd; 11 | 12 | TTT* aaa; 13 | aaa = &www; 14 | aaa = &uuu; 15 | 16 | return iii; 17 | } 18 | -------------------------------------------------------------------------------- /formalism/test099.c: -------------------------------------------------------------------------------- 1 | int fff() 2 | { 3 | int iii; 4 | iii = 0; 5 | return iii; 6 | } 7 | -------------------------------------------------------------------------------- /formalism/test100.c: -------------------------------------------------------------------------------- 1 | int fff() 2 | { 3 | int* i; 4 | double* d; 5 | T* v; 6 | v = i; 7 | v = d; 8 | 9 | return 10; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test101.c: -------------------------------------------------------------------------------- 1 | int g() 2 | { 3 | const int i; 4 | const int c; 5 | T1 v1; 6 | v1 = i + c; 7 | 8 | return 10; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test102.c: -------------------------------------------------------------------------------- 1 | int g() 2 | { 3 | const int i; 4 | const double d; 5 | T v; 6 | v = d/i; 7 | 8 | return 10; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test103.c: -------------------------------------------------------------------------------- 1 | int g() 2 | { 3 | const int i; 4 | const double d; 5 | T v; 6 | v = i/d; 7 | 8 | return 10; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test104.c: -------------------------------------------------------------------------------- 1 | int k() 2 | { 3 | const int x; 4 | int y; 5 | x = y; 6 | 7 | return 23; 8 | } 9 | -------------------------------------------------------------------------------- /formalism/test105.c: -------------------------------------------------------------------------------- 1 | int k() 2 | { 3 | const int x; 4 | T y; 5 | x = y; 6 | 7 | return 23; 8 | } 9 | -------------------------------------------------------------------------------- /formalism/test106.c: -------------------------------------------------------------------------------- 1 | int k() 2 | { 3 | const double x; 4 | int y; 5 | x = y; 6 | 7 | return 23; 8 | } 9 | -------------------------------------------------------------------------------- /formalism/test107.c: -------------------------------------------------------------------------------- 1 | int k() 2 | { 3 | const int x; 4 | const int y; 5 | int z; 6 | 7 | T1 m; 8 | m = x || y; 9 | T2 n; 10 | n = x || z; 11 | T3 p; 12 | p = z || x; 13 | T4 q; 14 | q = x + z; 15 | T5 s; 16 | s = z + x; 17 | T6 t; 18 | t = z / x; 19 | T7 l; 20 | l = x / z; 21 | 22 | return 23; 23 | } 24 | -------------------------------------------------------------------------------- /formalism/test108.c: -------------------------------------------------------------------------------- 1 | int k() 2 | { 3 | const int* p; 4 | const int cv; 5 | 6 | T1 x; 7 | x = p + cv; 8 | T2 y; 9 | y = cv + p; 10 | 11 | return 23; 12 | } 13 | -------------------------------------------------------------------------------- /formalism/test109.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | const int* ppp; 4 | int* const qqq; 5 | return 1; 6 | } 7 | -------------------------------------------------------------------------------- /formalism/test110.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | T a; 4 | a / 2; 5 | 6 | T b; 7 | 2/b; 8 | 9 | return 1; 10 | } 11 | -------------------------------------------------------------------------------- /formalism/test111.c: -------------------------------------------------------------------------------- 1 | int f() 2 | { 3 | T1 a; 4 | T1* b; 5 | T2 c; 6 | c = a * 2; 7 | 8 | return 1; 9 | } 10 | -------------------------------------------------------------------------------- /formalism/test_muC.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | CC=gcc 4 | 5 | for FIXED_FILE in new_*; do 6 | rm "$FIXED_FILE" 7 | done 8 | 9 | echo "building..." 10 | ghc -prof -fprof-auto -fprof-cafs -o runner muC.hs 11 | OK=$? 12 | if [ $OK -ne 0 ]; then 13 | echo "error in Haskell" 14 | exit 1 15 | fi 16 | 17 | FAIL_EXPECT=('new_test024.c' 18 | 'new_test025.c' 19 | 'new_test034.c' 20 | 'new_test036.c' 21 | 'new_test072.c' 22 | 'new_test087.c' 23 | 'new_test092.c' 24 | 'new_test096.c' 25 | 'new_test104.c' 26 | 'new_test105.c' 27 | 'new_test106.c') 28 | 29 | for C_FILE in *.c ; do 30 | echo " " 31 | 32 | echo "type inference for ${C_FILE}" 33 | ./runner "$C_FILE" &> /dev/null 34 | 35 | FIXED_FILE="new_${C_FILE}" 36 | 37 | for CUR in "${FAIL_EXPECT[@]}"; do 38 | if [ $FIXED_FILE = $CUR ]; then 39 | echo " !!!!! EXPECT ERROR !!!!!" 40 | fi 41 | done 42 | 43 | echo "compile ${FIXED_FILE}" 44 | "$CC"\ 45 | -Wall\ 46 | -Werror\ 47 | -Wconversion\ 48 | -Wfloat-conversion\ 49 | -Wno-unused-but-set-variable\ 50 | -Wno-incompatible-library-redeclaration\ 51 | -Wno-uninitialized\ 52 | -Wno-unused-variable\ 53 | -Wno-unused-function\ 54 | -Wno-switch\ 55 | -Wno-unused-value\ 56 | -Wno-implicit-int\ 57 | -Wno-return-type\ 58 | -Wno-builtin-requires-header\ 59 | -Wno-infinite-recursion\ 60 | -c "$FIXED_FILE" # &> /dev/null 61 | OK=$? 62 | if [ $OK -ne 0 ]; then 63 | printf " <>\n" 64 | fi 65 | done 66 | -------------------------------------------------------------------------------- /tests/TestSuite.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "TestSuite.h" 22 | 23 | #include "C/tests/TestSuite_Internals.h" 24 | #include "C/tests/TestSuite_API.h" 25 | 26 | #include 27 | 28 | using namespace psy; 29 | 30 | void TestSuite::runTests() 31 | { 32 | std::cout << "TESTS..." << std::endl; 33 | 34 | C::InternalsTestSuite suite0; 35 | auto [passed0, failed0] = suite0.testAll(); 36 | 37 | C::APITestSuite suite1; 38 | auto [passed1, failed1] = suite1.testAll(); 39 | 40 | std::cout << suite0.description() << std::endl; 41 | suite0.printSummary(); 42 | 43 | std::cout << suite1.description() << std::endl; 44 | suite1.printSummary(); 45 | 46 | auto accErrorCnt = failed0 + failed1; 47 | if (!accErrorCnt) 48 | std::cout << "All passed" << std::endl; 49 | else 50 | std::cout << std::string(17, '.') << " \n" 51 | << "> Total failures: " 52 | << failed0 + failed1 53 | << std::endl; 54 | } 55 | -------------------------------------------------------------------------------- /tests/TestSuite.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016-2020 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_TEST_SUITE_H__ 22 | #define PSYCHE_TEST_SUITE_H__ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | namespace psy { 29 | 30 | class TestSuite 31 | { 32 | public: 33 | virtual ~TestSuite() {} 34 | virtual std::string description() const = 0; 35 | virtual std::tuple testAll() = 0; 36 | virtual void printSummary() const = 0; 37 | 38 | static void runTests(); 39 | }; 40 | 41 | } // psy 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /tests/scripts/libpng.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | set -u 5 | set -x 6 | 7 | git clone --depth 1 --branch v1.6.44 git@github.com:pnggroup/libpng.git 8 | cd libpng 9 | 10 | ./configure 11 | make -j 5 12 | 13 | cnip() { 14 | ../../../cnip --C-pp-includes --WIP "$@" 15 | } 16 | 17 | echo "\n\n\n******" 18 | 19 | cnip png.c 20 | cnip pngerror.c 21 | cnip pngget.c 22 | cnip pngmem.c 23 | cnip pngpread.c 24 | cnip pngread.c 25 | cnip pngrio.c 26 | cnip pngrtran.c 27 | cnip pngrutil.c 28 | cnip pngset.c 29 | cnip pngtest.c 30 | cnip pngtrans.c 31 | cnip pngwio.c 32 | cnip pngwrite.c 33 | cnip pngwtran.c 34 | cnip pngwutil.c 35 | 36 | cd .. 37 | rm -rf libpng 38 | echo "libpng ok" 39 | -------------------------------------------------------------------------------- /tests/scripts/lua.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | set -u 5 | set -x 6 | 7 | git clone --depth 1 --branch v5.4.7 git@github.com:lua/lua.git 8 | cd lua 9 | 10 | make -j 5 MYLDFLAGS='$(LOCAL) -Wl,-export_dynamic' 11 | 12 | cnip() { 13 | ../../../cnip --C-pp-includes --WIP "$@" 14 | } 15 | 16 | echo "\n\n\n******" 17 | 18 | cnip lapi.c 19 | cnip lcode.c 20 | cnip lctype.c 21 | cnip ldebug.c 22 | cnip ldo.c 23 | cnip ldump.c 24 | cnip lfunc.c 25 | cnip lgc.c 26 | cnip llex.c 27 | cnip lmem.c 28 | cnip lobject.c 29 | cnip lparser.c 30 | cnip lstate.c 31 | cnip lstring.c 32 | cnip ltable.c 33 | cnip ltm.c 34 | cnip lundump.c 35 | cnip lvm.c 36 | cnip lzio.c 37 | cnip ltests.c 38 | cnip lauxlib.c 39 | cnip lbaselib.c 40 | cnip ldblib.c 41 | cnip liolib.c 42 | cnip lmathlib.c 43 | cnip loslib.c 44 | cnip ltablib.c 45 | cnip lstrlib.c 46 | cnip lutf8lib.c 47 | cnip loadlib.c 48 | cnip lcorolib.c 49 | cnip linit.c 50 | 51 | cd .. 52 | rm -rf lua 53 | echo "lua ok" 54 | -------------------------------------------------------------------------------- /tests/scripts/tinycc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | set -u 5 | set -x 6 | 7 | git clone --depth 1 --branch release_0_9_27 git@github.com:TinyCC/tinycc.git 8 | cd tinycc 9 | 10 | ./configure 11 | make -j 5 12 | 13 | cnip() { 14 | ../../../cnip --C-pp-includes --WIP "$@" 15 | } 16 | 17 | echo "\n\n\n******" 18 | 19 | cnip tcc.c 20 | cnip libtcc.c 21 | cnip tccpp.c 22 | cnip tccgen.c 23 | cnip tccelf.c 24 | cnip tccasm.c 25 | cnip tccrun.c 26 | cnip x86_64-gen.c 27 | cnip x86_64-link.c 28 | cnip i386-asm.c 29 | 30 | cd .. 31 | rm -rf tinycc 32 | echo "tinycc ok" 33 | -------------------------------------------------------------------------------- /tests/scripts/zlib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | set -u 5 | set -x 6 | 7 | git clone --depth 1 --branch v1.3.1 git@github.com:madler/zlib.git 8 | cd zlib 9 | 10 | ./configure 11 | make -j 5 12 | 13 | cnip() { 14 | ../../../cnip --C-pp-includes --WIP "$@" 15 | } 16 | 17 | echo "\n\n\n******" 18 | 19 | cnip adler32.c 20 | cnip crc32.c 21 | cnip deflate.c 22 | cnip infback.c 23 | cnip inffast.c 24 | cnip inflate.c 25 | cnip inftrees.c 26 | cnip trees.c 27 | cnip zutil.c 28 | cnip compress.c 29 | cnip uncompr.c 30 | cnip gzclose.c 31 | cnip gzlib.c 32 | cnip gzread.c 33 | cnip gzwrite.c 34 | 35 | cd .. 36 | rm -rf zlib 37 | echo "zlib ok" 38 | -------------------------------------------------------------------------------- /utility/IO.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "IO.h" 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | namespace psy { 28 | 29 | std::pair readFile(const std::string& fileName) 30 | { 31 | std::ifstream ifs(fileName); 32 | if (!ifs) { 33 | std::cerr << "file input error: " << fileName << std::endl; 34 | return std::make_pair(1, ""); 35 | } 36 | 37 | std::stringstream ss; 38 | ss << ifs.rdbuf(); 39 | ifs.close(); 40 | return std::make_pair(0, ss.str()); 41 | } 42 | 43 | int writeFile(const std::string& fileName, const std::string& content) 44 | { 45 | std::ofstream ofs(fileName); 46 | if (!ofs) { 47 | std::cerr << "file output error: " << fileName << std::endl; 48 | return 1; 49 | } 50 | 51 | ofs << content; 52 | ofs.close(); 53 | return 0; 54 | } 55 | 56 | } // psy 57 | -------------------------------------------------------------------------------- /utility/IO.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_IO_H__ 22 | #define PSYCHE_IO_H__ 23 | 24 | #include 25 | #include 26 | 27 | namespace psy { 28 | 29 | std::pair readFile(const std::string& filePath); 30 | 31 | int writeFile(const std::string& filePath, const std::string& content); 32 | 33 | } // psy 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /utility/Process.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #include "Process.h" 22 | 23 | #include 24 | #include // Using POSIX's `popen'. 25 | #include 26 | 27 | using namespace psy; 28 | 29 | namespace { 30 | 31 | std::pair execute_CORE(const char* cmd) 32 | { 33 | FILE* pipe = popen(cmd, "r"); 34 | if (!pipe) 35 | return std::make_pair(1, ""); 36 | 37 | std::string all; 38 | while (!feof(pipe)) { 39 | std::array buf; 40 | if (fgets(buf.data(), 512, pipe)) 41 | all += buf.data(); 42 | } 43 | 44 | return std::make_pair(pclose(pipe), all); 45 | } 46 | 47 | } // anonymous 48 | 49 | std::pair Process::execute(std::string&& s) 50 | { 51 | return execute_CORE(s.c_str()); 52 | } 53 | 54 | std::pair Process::execute(const std::string &s) 55 | { 56 | return execute_CORE(s.c_str()); 57 | } 58 | -------------------------------------------------------------------------------- /utility/Process.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016/17/18/19/20/21/22 Leandro T. C. Melo 2 | // 3 | // Permission is hereby granted, free of charge, to any person obtaining a copy 4 | // of this software and associated documentation files (the "Software"), to deal 5 | // in the Software without restriction, including without limitation the rights 6 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | // copies of the Software, and to permit persons to whom the Software is 8 | // furnished to do so, subject to the following conditions: 9 | // 10 | // The above copyright notice and this permission notice shall be included in 11 | // all copies or substantial portions of the Software. 12 | // 13 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | // THE SOFTWARE. 20 | 21 | #ifndef PSYCHE_PROCESS_H__ 22 | #define PSYCHE_PROCESS_H__ 23 | 24 | #include 25 | #include 26 | 27 | namespace psy { 28 | 29 | class Process final 30 | { 31 | public: 32 | std::pair execute(const std::string& cmd); 33 | std::pair execute(std::string&& cmd); 34 | }; 35 | 36 | } // psy 37 | 38 | #endif 39 | --------------------------------------------------------------------------------