diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..2b29902f --- /dev/null +++ b/.clang-format @@ -0,0 +1,10 @@ +UseTab: Never +IndentWidth: 4 +BreakBeforeBraces: Allman +AllowShortIfStatementsOnASingleLine: false +IndentCaseLabels: false +ColumnLimit: 0 +AccessModifierOffset: -4 +AllowShortFunctionsOnASingleLine: false + +AlignTrailingComments: true diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 00000000..2b0c9fe4 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,26 @@ +--- +name: Bug report +about: Report any issue here +title: '' +labels: 'bug' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. +Before you start, ensure you have the latest sw client (run `sw --self-upgrade`) and the bug is present there. + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**To Reproduce** +Steps to reproduce the behavior: +1. ... + +**Information:** + - Paste `sw --version` output. + - Write OS, its version (host/target) + - Describe your compiler, its version + - (optional, nix systems) Post backtrace if you know how to (using gdb, lldb). + - (optional) Post sw logs using `-trace` parameter. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 00000000..36014cde --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: 'enhancement' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/ISSUE_TEMPLATE/question.md b/.github/ISSUE_TEMPLATE/question.md new file mode 100644 index 00000000..e5835c00 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question.md @@ -0,0 +1,8 @@ +--- +name: Question +about: Ask something about this project +title: '' +labels: 'question' +assignees: '' + +--- diff --git a/.github/workflows/sw.yml b/.github/workflows/sw.yml new file mode 100644 index 00000000..75f50ed3 --- /dev/null +++ b/.github/workflows/sw.yml @@ -0,0 +1,42 @@ +name: sw + +on: [push, pull_request] + +jobs: + build: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [windows-latest, ubuntu-20.04, macOS-latest] + + steps: + - uses: actions/checkout@v1 + - uses: egorpugin/sw-action@master + + - name: Install (Linux) + if: runner.os == 'Linux' + run: | + sudo apt update + sudo apt install flex bison + + - name: Install (macOS) + if: runner.os == 'macOS' + run: | + brew install flex bison + + - name: build (non macOS) + if: runner.os != 'macOS' + run: ./sw -static build + + - name: build (macOS) + if: runner.os == 'macOS' + run: | + export PATH="/usr/local/opt/flex/bin:$PATH" + export PATH="/usr/local/opt/bison/bin:$PATH" + ./sw -static build + + - uses: actions/upload-artifact@v1 + with: + name: sw + path: .sw/out diff --git a/.gitignore b/.gitignore index 43360e1a..10585698 100644 --- a/.gitignore +++ b/.gitignore @@ -1,24 +1,45 @@ +# tex generated files +*.log +*.synctex.gz +*.aux +*.toc +*.pdf +*.blg +*.tar*.* + # build files and directories /build* -/win* -/bin* -cppan -.cppan* -.vs* -.* - -*.kdev* +/temp* +bin* -/packages +.build +.cppan +.sw +.s -/*.bat +*.bat +*.sh *~ -*.user* +*.user +*.sln +*.aps +*.exe +*.dll *.lnk +*.pdb + +*.diff +*.patch + +ddl2cpp +doc/build +cppan-build* -# bison generated -*.output +sw.config +sw.creator +sw.files +sw.includes -CMakeSettings.json +*.lock* \ No newline at end of file diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 791ac09a..00000000 --- a/.gitmodules +++ /dev/null @@ -1,9 +0,0 @@ -[submodule "dep/yaml-cpp"] - path = dep/yaml-cpp - url = https://github.com/jbeder/yaml-cpp.git -[submodule "dep/libarchive"] - path = dep/libarchive - url = https://github.com/libarchive/libarchive.git -[submodule "dep/curl"] - path = dep/curl - url = https://github.com/curl/curl.git diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b9b3ca20..00000000 --- a/.travis.yml +++ /dev/null @@ -1,62 +0,0 @@ -language: cpp - -notifications: - email: false - -#sudo: required -dist: trusty -#osx_image: xcode9.4 - -os: - - linux - #- osx - -branches: - only: - - master - -cache: - directories: - - $HOME/.cppan/storage - -addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - gcc-8 - - g++-8 - - ninja-build - - cmake - -before_install: - - if [[ $TRAVIS_OS_NAME == linux ]]; then LINUX=true; fi - - if [[ $TRAVIS_OS_NAME == osx ]]; then OSX=true; fi - -install: - #- if [[ $LINUX ]]; then sudo apt-get update; fi - #- if [[ $LINUX ]]; then wget --no-check-certificate http://www.cmake.org/files/v3.10/cmake-3.10.1-Linux-x86_64.sh; fi - #- if [[ $LINUX ]]; then sudo sh cmake-3.10.1-Linux-x86_64.sh --skip-license --prefix=/usr; fi - #- wget -O master.zip https://github.com/cppan/tests/archive/master.zip - #- unzip master.zip -d . - - if [[ $LINUX ]]; then wget https://cppan.org/client/cppan-master-Linux-client.deb; fi - - if [[ $LINUX ]]; then sudo dpkg -i cppan-master-Linux-client.deb; fi - - #- if [[ $OSX ]]; then brew upgrade cmake; fi - - if [[ $OSX ]]; then wget https://cppan.org/client/cppan-master-macOS-client.zip; fi - - if [[ $OSX ]]; then unzip cppan-master-macOS-client.zip; fi - - if [[ $OSX ]]; then sudo mv cppan /usr/local/bin/cppan; fi - -script: - - cppan -s - - mkdir build - - cd build - - if [[ $LINUX ]]; then cmake .. -DCMAKE_C_COMPILER=gcc-8 -DCMAKE_CXX_COMPILER=g++-8 -DCMAKE_BUILD_TYPE=Release 2> /dev/null; fi - - if [[ $OSX ]]; then cmake .. -DCMAKE_BUILD_TYPE=Release 2> /dev/null; fi - - make - - ctest -C Release || echo ok - #- sudo cp bin/cppan /usr/bin - #- cd .. - #- cd tests-master/tests/ok - #- for i in *.cpp; do cppan --build $i; done - diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index d4e72cb6..00000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,258 +0,0 @@ -# -# cppan -# - -################################################################################ -# -# cmake settings -# -################################################################################ - -cmake_minimum_required(VERSION 2.8.12) - -# In-source builds are not possible and so disabled. -if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) - message(FATAL_ERROR - "CMake generation for Firebird is not possible within the source directory!" - "\n Remove the CMakeCache.txt file and try again from another folder, e.g.:" - "\n " - "\n rm CMakeCache.txt" - "\n mkdir build" - "\n cd build" - "\n cmake .." - ) -endif() - -set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) - -if (NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release CACHE STRING "" FORCE) -endif() - -# Use solution folders. -set_property(GLOBAL PROPERTY USE_FOLDERS ON) -set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake Targets") - -################################################################################ -# -# project settings -# -################################################################################ - -project(cppan_client C CXX) - -if (NOT DEFINED VERSION_MAJOR) - set(VERSION_MAJOR 0) - set(VERSION_MINOR 2) - set(VERSION_PATCH 5) - set(BUILD_NUMBER 0) - set(CPPAN_VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) - - find_program(git git) - if (NOT "${git}" STREQUAL "git-NOTFOUND") - execute_process( - COMMAND git rev-list --count HEAD - OUTPUT_VARIABLE BUILD_NUMBER2 - OUTPUT_STRIP_TRAILING_WHITESPACE - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - ) - if (BUILD_NUMBER2) - set(BUILD_NUMBER ${BUILD_NUMBER2}) - endif() - endif() -endif() - -# Output directory settings -set(output_dir ${CMAKE_BINARY_DIR}/bin) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${output_dir}) - -find_package(BISON 3.0) -find_package(FLEX) - -################################################################################ -# -# compiler & linker settings -# -################################################################################ - -if (CPPAN_TEST) -add_definitions(/DCPPAN_TEST) -endif() - -if (WIN32) - add_definitions(/DUNICODE) - if (MSVC) - set(disable_msvc_warnings "/W3 /wd4458 /wd4714 /wd4127 /wd4275 /D_SCL_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS /D_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${disable_msvc_warnings}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${disable_msvc_warnings}") - - if (NOT CLANG) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP") - endif() - - if (MSVC_STATIC_RUNTIME) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd") - set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") - endif() - endif(MSVC) -endif(WIN32) - -if(UNIX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") - #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -stdlib=libc++") - #set(CMAKE_EXE_LINKER_FLAGS "-lc++abi") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") -endif() -if(MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std:c++17") -endif() - -if (CLANG) - set(flags "-Wno-assume -Wno-potentially-evaluated-expression -Wno-delete-non-virtual-dtor") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flags}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flags}") -endif() - -################################################################################ -# -# dependencies -# -################################################################################ - -if (NOT DEFINED CPPAN_BUILD_SHARED_LIBS) - set(CPPAN_BUILD_SHARED_LIBS 0) -endif() -if (NOT WIN32) - set(CPPAN_USE_CACHE 1) -endif() - -find_package(CPPAN REQUIRED) -cppan_add_package( - pvt.cppan.demo.boost.program_options-1 - pvt.cppan.demo.boost.property_tree-1 - pvt.cppan.demo.boost.stacktrace-1 - pvt.cppan.demo.sqlite3-3 - pvt.cppan.demo.yhirose.cpp_linenoise-master - pvt.cppan.demo.fmt-4 - - pvt.egorpugin.primitives.command-master - pvt.egorpugin.primitives.string-master - pvt.egorpugin.primitives.filesystem-master - pvt.egorpugin.primitives.context-master - pvt.egorpugin.primitives.date_time-master - pvt.egorpugin.primitives.executor-master - pvt.egorpugin.primitives.hash-master - pvt.egorpugin.primitives.http-master - pvt.egorpugin.primitives.lock-master - pvt.egorpugin.primitives.log-master - pvt.egorpugin.primitives.pack-master - pvt.egorpugin.primitives.yaml-master - pvt.egorpugin.primitives.win32helpers-master - - pvt.egorpugin.primitives.embedder-master - - pvt.cppan.demo.imageworks.pystring-1 - pvt.cppan.demo.giovannidicanio.winreg-master - pvt.cppan.demo.mpark.variant-1 - - pvt.cppan.demo.catchorg.catch2-2 -) -#set(CPPAN_FORCE 1) -cppan_execute() - -################################################################################ -# -# build -# -################################################################################ - -add_subdirectory(src) -set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT client) - -enable_testing() -add_subdirectory(test) - -############################################################################### -# -# install & uninstall -# -############################################################################### - -configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake.in" - "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" - IMMEDIATE @ONLY) - -add_custom_target(uninstall - COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) - -############################################################################### -# -# pack & distcheck -# -############################################################################### - -if (WIN32) - #set(CPACK_GENERATOR "ZIP") - #set(CPACK_COMPONENTS_ALL client) -else() - #set(CPACK_GENERATOR "ZIP;TGZ;DEB;RPM") - set(CPACK_SOURCE_GENERATOR "TGZ") - #set(CPACK_COMPONENTS_ALL client) -endif() - -set(CPACK_ARCHIVE_COMPONENT_INSTALL 1) - -set(CPACK_DEB_COMPONENT_INSTALL 1) -set(CPACK_DEBIAN_PACKAGE_NAME cppan) -set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE amd64) -set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Egor Pugin") -set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "C++ Archive Network (CPPAN) components") -#set(CPACK_DEBIAN_PACKAGE_DEPENDS "gcc-5") # , cmake (>= 3.2)") - -set(CPACK_RPM_COMPONENT_INSTALL 1) -set(CPACK_RPM_PACKAGE_SUMMARY CPPAN) -set(CPACK_RPM_PACKAGE_NAME cppan) -set(CPACK_RPM_PACKAGE_ARCHITECTURE amd64) - -set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR}) -set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR}) -set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH}) -set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}) - -set(CPACK_PACKAGE_FILE_NAME "cppan-master-${CMAKE_SYSTEM_NAME}") - -if (WIN32) -add_custom_target(package_client - COMMAND ${CMAKE_CPACK_COMMAND} - -G ZIP - -D CPACK_COMPONENTS_ALL=client -) -elseif (APPLE) -add_custom_target(package_client - COMMAND zip -FS -j -9 cppan-master-macOS-client.zip $ -) -elseif (EXISTS "/etc/centos-release" OR EXISTS "/etc/fedora-release") -add_custom_target(package_client - COMMAND ${CMAKE_CPACK_COMMAND} - -G RPM - -D CPACK_COMPONENTS_ALL=client -) -else() -add_custom_target(package_client - COMMAND ${CMAKE_CPACK_COMMAND} - -G DEB - -D CPACK_COMPONENTS_ALL=client - COMMAND zip -FS -j -9 cppan-master-Linux-client.zip $ -) -endif() - -set_property(TARGET - package_client - uninstall -PROPERTY FOLDER misc) - -include(CPack) - -################################################################################ diff --git a/COPYING b/COPYING new file mode 100644 index 00000000..c2ad587a --- /dev/null +++ b/COPYING @@ -0,0 +1,9 @@ +Different parts of SW project (this repository) are subject to different licences. + +core libraries: GPLv3+ (src/sw/[manager,builder,core]) +client library and tools: AGPLv3+ (src/sw/client) +server code: AGPLv3+ (src/sw/server) +small libs: MPLv2 (src/sw/[protocol,support]) +utilities, helpers: APLv2 + +See specific files for detailed information about their license. diff --git a/LICENSE b/LICENSE.APLv2 similarity index 99% rename from LICENSE rename to LICENSE.APLv2 index 8dada3ed..d6456956 100644 --- a/LICENSE +++ b/LICENSE.APLv2 @@ -1,3 +1,4 @@ + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -178,7 +179,7 @@ APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" + boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a @@ -186,7 +187,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright {yyyy} {name of copyright owner} + Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/LICENSE.GPLv3 b/LICENSE.GPLv3 new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/LICENSE.GPLv3 @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/LICENSE.MPLv2 b/LICENSE.MPLv2 new file mode 100644 index 00000000..fa0086a9 --- /dev/null +++ b/LICENSE.MPLv2 @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. \ No newline at end of file diff --git a/README.md b/README.md index 54371ebf..d9e7b02c 100644 --- a/README.md +++ b/README.md @@ -1,98 +1,34 @@ -## [C++ Archive Network](https://cppan.org/) +# [Software Network (SW)](https://software-network.org/) -[![Build Status](https://travis-ci.org/cppan/cppan.svg?branch=master)](https://travis-ci.org/cppan/cppan) -[![Build status](https://ci.appveyor.com/api/projects/status/iacnrt6byhy8ox5v?svg=true)](https://ci.appveyor.com/project/egorpugin/cppan) + -### Resources +![Build status](https://github.com/SoftwareNetwork/sw/workflows/sw/badge.svg) -- Homepage: https://cppan.org/ -- Docs: https://github.com/cppan/cppan/blob/master/doc/ -- Download: https://cppan.org/client/ -- Issue tracking: https://github.com/cppan/cppan/issues -- Forum: https://groups.google.com/forum/#!forum/cppan +## Resources +- Homepage: https://software-network.org/ +- Documentation: https://software-network.org/client/sw.pdf +- Download: https://github.com/SoftwareNetwork/binaries +- Issue tracking: https://github.com/SoftwareNetwork/sw/issues +- Forum: https://groups.google.com/forum/#!forum/software-network -### Quick Start +## Build -1. Download the latest client application, unpack and put it to PATH. -1. (!) Run once `cppan` from any directory without any arguments to perform initial configuration. -1. In your `CMakeLists.txt` write: -``` -find_package(CPPAN REQUIRED) -cppan_add_package( - pvt.cppan.demo.sqlite3 - pvt.cppan.demo.fmt-4 - pvt.cppan.demo.madler.zlib-* - pvt.cppan.demo.boost.asio-1.66 - ... - libs you want to add -) -cppan_execute() +### Using SW (self build) -# near your target -add_executable(myexe ...) -target_link_libraries(myexe - pvt.cppan.demo.sqlite3 - pvt.cppan.demo.madler.zlib - pvt.cppan.demo.boost.asio - ... -) +1. Download client from https://software-network.org/client/ +2. Unpack, add to PATH +3. Run ``` -4. Perform other usual CMake steps. - - -### Dependencies - -- `CMake >= 3.2` - -### Download & Install - -#### Linux - -##### Ubuntu 16.04 - -``` -sudo apt install cmake -wget https://cppan.org/client/cppan-master-Linux-client.deb -sudo dpkg -i cppan-master-Linux-client.deb +git clone https://github.com/SoftwareNetwork/sw +cd sw +sw build -static ``` -##### Ubuntu 14.04 +(optional) Run `sw generate -static` to generate VS solution. -``` -wget https://www.cmake.org/files/v3.6/cmake-3.6.1-Linux-x86_64.sh -sudo sh cmake-3.6.1-Linux-x86_64.sh --skip-license --prefix=/usr -sudo add-apt-repository ppa:ubuntu-toolchain-r/test -sudo apt-get update && sudo apt-get install gcc-5 -wget https://cppan.org/client/cppan-master-Linux-client.deb -sudo dpkg -i cppan-master-Linux-client.deb -``` - -#### Windows - -[Download client](https://cppan.org/client/cppan-master-Windows-client.zip), unzip it and put under PATH. - -#### macOS - -``` -wget https://cppan.org/client/cppan-master-macOS-client.zip -unzip cppan-master-macOS-client.zip -sudo cp cppan /usr/local/bin/ -``` - -### Build - -``` -git clone https://github.com/cppan/cppan cppan_client -cd cppan_client -cppan -mkdir build && cd build -cmake .. -# for linux -# cmake .. -DCMAKE_C_COMPILER=gcc-5 -DCMAKE_CXX_COMPILER=g++-5 -make -j4 -``` +(optional) Run `sw override org.sw` for smooth development. -### Support CPPAN +### Support SW -More info about supporting C++ Archive Network can be found [here](https://github.com/cppan/cppan/blob/master/doc/support.md). +More info about supporting Software Network can be found [here](https://github.com/SoftwareNetwork/sw/blob/master/doc/support.md). diff --git a/appveyor.yml b/appveyor.yml index 946a5894..e6f82a13 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,11 +1,15 @@ -image: Visual Studio 2017 - -platform: - - Win32 - - Win64 +environment: + APPVEYOR_SAVE_CACHE_ON_ERROR: true + matrix: + #- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + #platform: Win32 + #- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + #platform: Win64 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 + platform: Win64 cache: - - c:/Users/appveyor/.cppan/storage + - c:/Users/appveyor/.sw -> appveyor.yml configuration: - Release @@ -15,37 +19,19 @@ install: - set PATH=C:\Program Files\Git\mingw64\bin;%PATH% before_build: - - if %platform%==Win32 set generator=Visual Studio 15 2017 - - if %platform%==Win64 set generator=Visual Studio 15 2017 Win64 - - if %platform%==Win32 set vcplatform=Win32 - - if %platform%==Win64 set vcplatform=x64 - - - curl -fsS -L -o cppan.zip https://cppan.org/client/cppan-master-Windows-client.zip - - 7z x cppan.zip + - curl -fsS -L -o dl.zip https://github.com/SoftwareNetwork/binaries/raw/master/sw-master-windows-client.zip + - 7z x dl.zip - set PATH=%PATH%;%cd% - - cppan # dummy run to create %USERPROFILE%\.cppan\cppan.yml - #- ps: 'Add-Content $env:USERPROFILE\.cppan\cppan.yml "`n`nbuild_warning_level: 0`n"' - #- ps: 'Add-Content $env:USERPROFILE\.cppan\cppan.yml "`n`nbuild_system_verbose: false`n"' - - ps: 'Add-Content $env:USERPROFILE\.cppan\cppan.yml "`n`nvar_check_jobs: 1`n"' - build_script: - - mkdir build - - mkdir build\bin - - mkdir build\bin\Release - - cd build - #- cmd: 'echo local_settings: > cppan.yml' - #- cmd: 'echo generator: %generator% >> cppan.yml' - #- cmd: 'echo use_shared_libs: true >> cppan.yml' - #- cppan --build .. - - cmake .. -G "%generator%" - #- cmake --build . --config Release > bin\Release\log.txt 2>&1 - - cmake --build . --config Release - -#test_script: - #- ctest -C Release + - sw -platform %platform% -static build -time-limit 45m artifacts: - - path: build\bin\Release - #- path: build - name: cppan-$(APPVEYOR_BUILD_VERSION) + - path: sw.zip + name: sw-$(APPVEYOR_BUILD_VERSION) + +after_build: + - 7z a sw.zip %APPVEYOR_BUILD_FOLDER%\.sw\out\**\*.exe + #- 7z a sw.zip %APPVEYOR_BUILD_FOLDER%\.sw\windows_*_msvc_*_static_Release\*.exe +# - ps: Get-ChildItem .sw/windows_*_msvc_*_static_Release_*/*.exe | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name -DeploymentName sw-$(APPVEYOR_BUILD_VERSION) } + diff --git a/cmake/uninstall.cmake.in b/cmake/uninstall.cmake.in deleted file mode 100644 index 27ed4ace..00000000 --- a/cmake/uninstall.cmake.in +++ /dev/null @@ -1,22 +0,0 @@ -if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") - message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") -endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") - -file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) -string(REGEX REPLACE "\n" ";" files "${files}") -foreach(file ${files}) - message(STATUS "Uninstalling $ENV{DESTDIR}${file}") - if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") - exec_program( - "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" - OUTPUT_VARIABLE rm_out - RETURN_VALUE rm_retval - ) - if(NOT "${rm_retval}" STREQUAL 0) - message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") - endif(NOT "${rm_retval}" STREQUAL 0) - else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") - message(STATUS "File $ENV{DESTDIR}${file} does not exist.") - endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") -endforeach(file) - diff --git a/cppan.yml b/cppan.yml deleted file mode 100644 index e2c334e2..00000000 --- a/cppan.yml +++ /dev/null @@ -1,195 +0,0 @@ -local_settings: - #storage_dir: .cppan_storage - - use_shared_libs: false - build: - generator: Visual Studio 15 2017 - configuration: Debug - -root_project: pvt.cppan.client - -common_settings: - c++: 17 - -projects: - common: - type: lib - static_only: true - - files: - - src/common/.* - - src/printers/.* - - src/comments/.* - - src/bazel/.* - - src/inserts/.* - - src/support/.* - - src/gen/.* - - exclude_from_package: - - src/bazel/test/test.cpp - - src/bazel/.*\.txt - - src/comments/.*\.txt - - exclude_from_build: - - src/gen/.* - - include_directories: - public: - - src - - src/common - - src/support - - dependencies: - public: - - pvt.cppan.demo.boost.optional: 1 - - pvt.cppan.demo.boost.property_tree: 1 - - pvt.cppan.demo.sqlite3: 3 - - pvt.cppan.demo.boost.stacktrace: 1 - - - pvt.egorpugin.primitives.string: master - - pvt.egorpugin.primitives.filesystem: master - - pvt.egorpugin.primitives.context: master - - pvt.egorpugin.primitives.date_time: master - - pvt.egorpugin.primitives.executor: master - - pvt.egorpugin.primitives.hash: master - - pvt.egorpugin.primitives.http: master - - pvt.egorpugin.primitives.lock: master - - pvt.egorpugin.primitives.log: master - - pvt.egorpugin.primitives.pack: master - - pvt.egorpugin.primitives.command: master - - pvt.egorpugin.primitives.yaml: master - - pvt.egorpugin.primitives.win32helpers: master - - pvt.cppan.demo.fmt: "*" - - pvt.cppan.demo.imageworks.pystring: 1 - #win32: - - pvt.cppan.demo.giovannidicanio.winreg: master - - name: pvt.egorpugin.primitives.embedder - version: master - ref: embedder - - options: - any: - definitions: - public: - - VERSION_MAJOR=0 - - VERSION_MINOR=2 - - VERSION_PATCH=5 - - BUILD_NUMBER=0 - - CPPAN_VERSION_STRING=${CPPAN_VERSION_STRING} - win32: - public: - - UNICODE - - post_sources: | - set(CPPAN_VERSION_STRING ${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_PATCH}) - - add_executable(stamp_generator ${SDIR}/src/gen/stamp_gen.cpp) - set_property(TARGET stamp_generator PROPERTY FOLDER gen) - set(stamp ${BDIR}/stamp.h.in) - # to run every time - # do not change to command - add_custom_target(gen_stamp - COMMAND stamp_generator > ${stamp} - ) - set_property(TARGET gen_stamp PROPERTY FOLDER gen) - set_source_files_properties(${stamp} PROPERTIES GENERATED True) - set(src ${src} ${stamp}) - - set(gen - ${SDIR}/src/inserts/cppan.h - ${SDIR}/src/inserts/build.cmake - ${SDIR}/src/inserts/functions.cmake - ${SDIR}/src/inserts/generate.cmake - ${SDIR}/src/inserts/exports.cmake - ${SDIR}/src/inserts/header.cmake - ${SDIR}/src/inserts/version.rc.in - ${SDIR}/src/inserts/branch.rc.in - ) - add_custom_target(gen_inserts - COMMAND ${embedder} ${SDIR}/src/inserts/inserts.cpp.in ${BDIR}/inserts.cpp - # FIXME: not working on dll build - # it could not find deps dlls - WORKING_DIRECTORY ${SDIR}/src - DEPENDS ${embedder} ${gen} - SOURCES ${gen} - ) - set_property(TARGET gen_inserts PROPERTY FOLDER gen) - set_source_files_properties(${BDIR}/inserts.cpp PROPERTIES GENERATED TRUE) - set(src ${src} ${BDIR}/inserts.cpp) - - ######################################## - - find_package(BISON 3.0) - find_package(FLEX) - - ######################################## - # bazel_parser - ######################################## - - execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${BDIR}/src/bazel) - - if (FLEX_FOUND AND BISON_FOUND AND 0) - BISON_TARGET(grammar_b - "${SDIR}/src/bazel/grammar.yy" - "${BDIR}/src/bazel/grammar.cpp" - ) - FLEX_TARGET(lexer_b - "${SDIR}/src/bazel/lexer.ll" - "${BDIR}/src/bazel/lexer.cpp" - COMPILE_FLAGS --header-file=${BDIR}/src/bazel/lexer.h - ) - ADD_FLEX_BISON_DEPENDENCY(lexer_b grammar_b) - - set(parser_src - ${BISON_grammar_b_OUTPUTS} - ${FLEX_lexer_b_OUTPUTS} - ${BDIR}/src/bazel/lexer.h - ) - set_source_files_properties(${BDIR}/src/bazel/lexer.h PROPERTIES GENERATED TRUE) - endif() - set(src ${src} ${parser_src}) - - ######################################## - # extract_comments - ######################################## - - execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${BDIR}/src/comments) - - if (FLEX_FOUND AND BISON_FOUND AND 0) - BISON_TARGET(grammar_c - "${SDIR}/src/comments/grammar.yy" - "${BDIR}/src/comments/grammar.cpp" - ) - FLEX_TARGET(lexer_c - "${SDIR}/src/comments/lexer.ll" - "${BDIR}/src/comments/lexer.cpp" - COMPILE_FLAGS --header-file=${BDIR}/src/comments/lexer.h - ) - ADD_FLEX_BISON_DEPENDENCY(lexer_c grammar_c) - - set(parser_src - ${BISON_grammar_c_OUTPUTS} - ${FLEX_lexer_c_OUTPUTS} - ${BDIR}/src/comments/lexer.h - ) - set_source_files_properties(${BDIR}/src/comments/lexer.h PROPERTIES GENERATED TRUE) - endif() - set(src ${src} ${parser_src}) - - post_target: | - target_include_directories(${this} PRIVATE ${BDIR}/src) - target_sources(${this} PUBLIC ${SDIR}/src/common/cppan.natvis) - add_dependencies(${this} gen_stamp gen_inserts) - - cppan: - rc_enabled: false - files: - - src/client/.* - - exclude_from_package: - - src/client/.*\.txt - - dependencies: - - common - - pvt.cppan.demo.boost.program_options: 1 - - pvt.cppan.demo.yhirose.cpp_linenoise: master diff --git a/doc/comparison.md b/doc/comparison.md new file mode 100644 index 00000000..7371c71d --- /dev/null +++ b/doc/comparison.md @@ -0,0 +1,24 @@ +# Build System & Package Manager comparison + +## General + +| Feature | sw | conan | vcpkg | build2 | cmake | b2 (boost) | meson | +|---|---|---|---|---|---|---|---| +| package manager | ![](https://img.shields.io/badge/yes-brightgreen.svg) | ![](https://img.shields.io/badge/yes-brightgreen.svg) | ![](https://img.shields.io/badge/yes-brightgreen.svg) | ![](https://img.shields.io/badge/yes-brightgreen.svg) |![](https://img.shields.io/badge/no-red.svg) |![](https://img.shields.io/badge/no-red.svg) | ![](https://img.shields.io/badge/yes-brightgreen.svg) | +| build system | ![](https://img.shields.io/badge/yes-brightgreen.svg) | ![](https://img.shields.io/badge/no-red.svg) | ![](https://img.shields.io/badge/no-red.svg) | ![](https://img.shields.io/badge/yes-brightgreen.svg) |![](https://img.shields.io/badge/yes-brightgreen.svg) |![](https://img.shields.io/badge/yes-brightgreen.svg) | ![](https://img.shields.io/badge/yes-brightgreen.svg) | +| multilang | ![](https://img.shields.io/badge/yes-brightgreen.svg) |![](https://img.shields.io/badge/yes-brightgreen.svg) |![](https://img.shields.io/badge/yes-brightgreen.svg) |![](https://img.shields.io/badge/yes-brightgreen.svg) |![](https://img.shields.io/badge/yes-brightgreen.svg) |![](https://img.shields.io/badge/no-red.svg) |![](https://img.shields.io/badge/yes-brightgreen.svg) | + +## Compilers & OSes + +| Feature | +|---| +| | + + +## Native fetures (ASM/C/C++) + +| Feature | +|---| +| shared pchs | + +## Other Languages diff --git a/doc/config.md b/doc/config.md deleted file mode 100644 index bdef3de7..00000000 --- a/doc/config.md +++ /dev/null @@ -1,149 +0,0 @@ -# THIS FILE IS OUTDATED! Use this document https://github.com/cppan/cppan/blob/master/doc/cppan.yml - -This page describes `cppan.yml` command file and its directives. See working examples in this repository https://github.com/cppan/packages. - -### files - -In `files` directive you specify what files to include into the distributable package. It can be a regex expression or a relative file name. - - files: - - include/.* - - src/.* -or - - files: - - sqlite3.h - - sqlite3ext.h - - sqlite3.c - -or just - - files: include/.* - -or - - files: # from google.protobuf - - src/.*\.h - - src/google/protobuf/arena.cc - - src/google/protobuf/arenastring.cc - - src/google/protobuf/extension_set.cc - -### dependencies - -`dependencies` contains a list of all dependencies required by your project. Can be `private` and `public`. `public` are exported when you add you project to C++ Archive Network. `private` stays private and can be used by your project's tools and other stuff. - -For example when you develop an application, you want to add unit tests, regression tests, benchmarks etc. You can specify test frameworks as dependencies too. For example, `pvt.cppan.demo.google.googletest.gtest` or `pvt.cppan.demo.google.googletest.gmock`. - -But when you develop a library and want export it to CPPAN, you won't those libraries in the public dependency list. -You can write: - - dependencies: - public: - org.boost.filesystem: 1 - private: - pvt.cppan.demo.google.googletest.gtest: master - -By default all deps are public. - - dependencies: - org.boost.filesystem: 1.60 # public - pvt.cppan.demo.google.googletest.gtest: master # public now - -### include_directories - -Include directories are needed by your project and project users. You must always write `private` or `public` keywords. `private` include dirs available for your lib only. `public` available for your lib and its users. - - include_directories: # boost.math example - public: - - include - private: - - src/tr1 - -### license - -Include license file if you have it in the project tree. - - license: LICENSE.txt - -### root_directory - -When adding version from remote file (archive) often there is a root dir inside the archive. You can use this directive to specify a path to be added to all relative files and dirs. - - root_directory: sqlite-amalgamation-3110000 # sqlite3 example - -### exclude_from_build - -Sometimes you want to ship a source file, but do not want to include it into build. Maybe it will be conditionally included from config header or whatever. - - exclude_from_build: # from boost.thread - - src/pthread/once_atomic.cpp - -### options - -In `options` you can provide predefined macros for specific configurations. -`any`, `static` and `shared` are available. -Inside them you can use `definitions` to provide compile defines. You must write `public` or `private` near each define. `private` is only for current library. `public` define will see all users and the current lib. - - options: # from boost.log - any: - definitions: - public: BOOST_LOG_WITHOUT_EVENT_LOG - private: BOOST_LOG_BUILDING_THE_LIB=1 - shared: - definitions: - public: BOOST_LOG_DYN_LINK - private: BOOST_LOG_DLL - -But try to minimize use of such options. - -### pre_sources, post_sources, post_target, post_alias - -You can provide your custom build system insertions with these directives. - - post_sources: | # custom step from boost.config - if (WIN32) - file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/include/boost/config/auto_link.hpp "") - endif() - -Can be used in options too near with `definitions`. - -### root_project, projects - -Can be used when you're exporting more than one project from one repository. Inside `projects` you should describe all exported projects. Relative name of each should be specified after this. Inside each project, write usual command. - - root_project: pvt.cppan.demo.google.googletest - projects: - gtest: # use relative name here - absolute will be pvt.cppan.demo.google.googletest.gtest - license: googletest/LICENSE - files: - - googletest/include/.*\.h - - googletest/src/.* - gmock: # use relative name here - # ... - -### package_dir - -Can be used to choose storage of downloaded packages. Could be `system`, `user`, `local`. Default is `user`. `system` requires root right when running cppan, deps will go to `/usr/share/cppan/packages`. `user` stores deps in `$HOME/.cppan/packages`. `local` will store deps in cppan/ in local dir. - - package_dir: local - -You can selectively choose what deps should go to one of those locations. - - dependencies: - org.boost.filesystem: - version: "*" - package_dir: local - -It is convenient when you want to apply your patches to some dependency. - -### check_function_exists, check_include_exists, check_type_size, check_symbol_exists, check_library_exists - -These use cmake facilities to provide a way of checking headers, symbols, functions etc. Cannot be under `projects` directive. Can be only under root. They will be gathered during `cppan` run, duplicates will be removed, so not duplicate work. - - check_function_exists: # from libressl - - asprintf - - inet_pton - - reallocarray - - check_include_exists: - - err.h diff --git a/doc/cpp_definitions.md b/doc/cpp_definitions.md deleted file mode 100644 index 5240d2ca..00000000 --- a/doc/cpp_definitions.md +++ /dev/null @@ -1,5 +0,0 @@ -`CPPAN=1`, `CPPAN_BUILD=1` - defined when sources are compiled under CPPAN build. - -`CPPAN_EXPORT` - automatically set to proper export/import definition when building shared library on any platform. - -`CPPAN_CONFIG` - string with current compiler configuration. For example, `"amd64-msvc-19.0-32"`, `"armv7-a-gnu-4.9-32"`. diff --git a/doc/cppan.yml b/doc/cppan.yml deleted file mode 100644 index c321dec4..00000000 --- a/doc/cppan.yml +++ /dev/null @@ -1,544 +0,0 @@ -# This file shows all available options for cppan.yml file. -# cppan.yml should be written in YAML language. -# Place it near your sources (to repository root) to simplify uploading to CPPAN. - -#################################################################################################### -# -# project settings -# -#################################################################################################### - -# These settings will be used by server to gather input files. - -# license - path to license file. -# Usually this will a file in root dir: COPYING, LICENSE, LICENSE.txt -# Can be omitted. -license: COPYING - -# empty - flag that tells the server that there will be no files in projects. -# This is only configuration project. -# For example, see cppan.yml spec at https://cppan.org/pvt.cppan.demo.cmake.postgresql/version/master -# Such projects can be used to setup system's libs. -# Default value: false. -empty: true - -# shared_only - the project never won't be built as static. -# Default value: false. -shared_only: true - -# static_only - the project never won't be built as shared lib. -# Default value: false. -static_only: true - -# header_only - force project to be never built, use as header only storage. -# CPPAN will track header only projects automatically. -# This options is only for convenience when header dir contain .cpp files. -# So, you set it do discard them. -# Default value: false. -header_only: true - -# import_from_bazel - try to parse bazel's BUILD file to get files from it. -# Bazel is Google's build system. In some aspects CPPAN is similar to it. -# This option is only useful when uploading from some Google's project. -# Default value: false. -import_from_bazel: true - -# root_directory - tells that server must enter this dir before processing any files. -# Sometimes in your git repository there's more than one project stored. -# This options is very helpful in this case. No need to manually prefix all files with this dir. -# Default value: empty. -root_directory: some_dir_in_project - -# files - main directive to specify which files will be taken from your project. -# You can use regular expressions here. -files: - - include/.* - - src/.*\.cpp - - src/.*\.hpp - - src2/my_other_file.cpp -# or -# Second variant contains file groups. Each group consists of 'root' directory and 'files' directive. -files: - my_group1: - root: some/dir/in/project - files: - - files.cpp - - relative.h - - to_current_root.cpp - - directive.h - my_grp2: - root: other/dir - files: - - other_file.cpp - -# exclude_from_build - exclude some files from building, but keep in archive. -# Sometimes you want to add files based on OS: you exclude them here and add later. -exclude_from_build: - - my_windows_file.cpp - - my_unix_file.cpp - -# include_directories - specify project's include dirs. -# Can be private, public and interface. -# - private is seen only by project. -# - public is seen both by project and projects that depend on this -# - interface is seen only by projects that depend on this -# Default values: 'include', '${CMAKE_CURRENT_BINARY_DIR}' -# If you provide any value 'include' will be removed and '${CMAKE_CURRENT_BINARY_DIR}' will not. -include_directories: - public: - - include_dir1 - - include/dir2 - private: - - src - interface: - - some_dir - -# build - files to build. When build is seen, 'files' are not used for building anymore. -build: - my.cpp - my.h - -#################################################################################################### -# -# Build system (BS) insertions -# -#################################################################################################### - -# This directives provides raw interface to underlying build system (currently CMake). -# So you can control it on a very precise level. -# These BS insertions are on the project level. - -# pre_sources - inserted before all sources gathered -# all these options should go into multiline YAML comment -pre_sources: | - file(WRITE some_file.txt "contents") - string(REGEX ...) - -# post_sources - inserted after all sources gathered. You'll be using this options more frequent than others. -post_sources: ... - -# post_target - inserted after target is defined -post_sources: ... - -# post_alias - inserted after aliases are defined -post_sources: ... - -#################################################################################################### -# -# build options -# -#################################################################################################### - -# These options control definitions, compiler and linker flags. - -# options - root of options directive. -options: - # any - will be applied with any build type (static or shared). - any: - # definitions - C/C++ preprocessor definitions. - # Can be 'private', 'public', 'interface' or build system value. - definitions: - # private - available only for project itself - private: - - BUILDING_MY_LIBRARY - - OTHER_PRIVATE_DEF="my string" - - # public - available for project and its users - public: - - MY_LIBRARY=1 - - # interface - available for project users - interface: - - LINKING_MY_LIBRARY - - # following keys will be conditions in build system. - # Example: 'win32' will be 'if (WIN32)' in cmake. - # You can use any strings here. - win32: - # But here the key can be only one of the following: - # 'private', 'public', 'interface' - private: - - MY_DEF_ON_WIN32_ONLY=0 - unix: - public: - - MY_UNIX_DEF - apple: - interface: - - OTHER_DEF - cygwin: - public: - - CYGWIN_DEF - # mingw etc. - - # compile_options - options passed to compiler - compile_options: - # same as for definitions - - # link_options - options passed to linker - link_options: - # same as for definitions - - # link_libraries - specific libraries (Ws2_32, pthread etc.) linked to your project - link_libraries: - # same as for definitions - - # include_directories - specific include directories for 'any' - include_directories: - - idir1 - - # link_directories - specific link directories for 'any' - link_directories: - - idir1 - - # global_definitions - global definitions for 'any'. - # TODO: clarify this statements - # They will be added to the every target. - global_definitions: - - DEF1=1 - - DEF2 - - # specific bs insertions for 'any' - pre_sources: ... - post_sources: ... - post_sources: ... - post_sources: ... - - # static - options will be available only when building static library - static: - # same as for 'any' - - # shared - options will be available only when building shared library - shared: - # same as for 'any' - -#################################################################################################### -# -# dependencies -# -#################################################################################################### - -# This is the main directive that will control you project's dependencies. -# Specify full names (paths) of projects and their versions your project rely on. -dependencies: - # dependency on the specific version - pvt.cppan.demo.zlib: 1.2.8 - - # dependency on the 1.61.* version - # If newer than local version is available, it will be automatically downloaded and included. - pvt.cppan.demo.boost.filesystem: 1.61 - - # dependency on the 3.*.* version - # If newer than local version is available, it will be automatically downloaded and included. - pvt.cppan.demo.google.protobuf: 3 - - # dependency on the *.*.* version - # If newer than local version is available, it will be automatically downloaded and included. - pvt.cppan.demo.sqlite3: "*" # YAML syntax requires star in quotes - - # dependency on a branch, will be updated frequently - pvt.cppan.demo.range_v3: master - -# second form - use all "*" - *.*.* star deps; no branches allowed -dependencies: - - pvt.cppan.demo.zlib - - pvt.cppan.demo.boost.filesystem - -# third form - set private and public dependencies. -# Private dependencies won't be available for users. -# It may be useful when including depency for tests (test frameworks like gtest, gmock). -depedencies: - public: - # Users will see zlib. - pvt.cppan.demo.zlib: 1 - private: - # Users won't see gtest. - pvt.cppan.demo.google.googletest.gtest: 1 - -#################################################################################################### - -# aliases - only for executables. -# They can be helpful to shorten you exe name for further use during build. -# BUT BE CAREFUL to not get same aliases from different projects. -aliases: - # For example, for 'pvt.cppan.demo.google.protobuf.protoc-3.0.0' the shorter name will be nice. - - protobuf - - protoc - -#################################################################################################### -# -# Config settings -# -#################################################################################################### - -# root_project - this option can be used to specify root project when uploading multiple children -# from the same cppan.yml file. -# With it you can use relative paths in 'projects' directive. -root_project: pvt.cppan.demo.google.protobuf - -# projects - specify multiple projects in single cppan.yml -projects: - # if no 'root_project' is given, use full paths. - pvt.cppan.demo.google.protobuf.protobuf_lite: - # protobuf_lite project settings go here -# or -# if 'root_project' is given, use relative paths. -projects: - protobuf_lite: - # protobuf_lite project settings go here - protoc: - # protoc project settings go here - -# check_function_exists - specify list of functions that will be checked for availability with current settings. -# After successful check a definition in form of HAVE_CAPSED_FUNCTION_NAME will be available. -check_function_exists: - - strcasecmp - - strlcat - - strlcpy - -# check_include_exists - check includes existence -# After successful check a definition in form of HAVE_MY_HEADER_H will be available. -check_include_exists: - - unistd.h - - pthread.h - - windows.h - -# check_type_size - check type size -# After successful check a definition in form of HAVE_TYPE will be available. -# After successful check a definition in form of SIZEOF_TYPE=N will be available, N - sizeof(type). -# After successful check a definition in form of SIZE_OF_TYPE=N will be available, N - sizeof(type). -check_type_size: - # SIZEOF_VOID_P - - "void *" - - # SIZEOF_LONG_LONG - - long long - -# check_library_exists - check library existence -# After successful check a definition in form of HAVE_LIBRARY will be available. -check_library_exists: - - m - - pthread - - dl - - Ws2_32.lib - - kernel32.lin - -# check_symbol_exists - check symbol's existence. -# After successful check a definition in form of HAVE_MY_SYMBOL will be available. -check_symbol_exists: - - my_symbol - - ... - -# BS insertions - will be applied to every project in current cppan.yml file. -# These BS insertions are on the config level. -# See chapter above for more infomation on these. - -pre_sources: ... -post_sources: ... -post_sources: ... -post_sources: ... - - -#################################################################################################### -# -# source & version options -# -#################################################################################################### - -# source directive specifies the source of files in the internet. -# At the moment only git and remote files are supported. - -# For git case you must write: -# - git: - your git repository url; -# - one of the following: -# - tag: name of the tag to be retrieved -# - branch: name of the branch to be retrieved -source: - git: https://github.com/boostorg/core - branch: master -# or -source: - git: https://github.com/boostorg/core - tag: boost-1.61.0 - -# For remote file case you must write one 'remote' value - direct link to file archive. -# .tag.* and .zip archives are supported. -source: - remote: http://zlib.net/zlib-1.2.8.tar.gz - -# If you put cppan.yml to your sources, there's no need to specify 'source' directive. -# Its values will be set by server. - -######################################## - -# version directive states the version of uploaded sources. -# It can be: -# 1. Real version in format X.Y.Z in according to semantic versioning https://semver.org. -# 2. Branch name: [a-zA-Z_][a-zA-Z0-9_-]* -# -# Versions will be fixed later. They're not updatable. -# Branches can be updated to the latest sources. -# Examples of branch names are: master, develop, unstable, windows_port etc. -# - -version: 1.2.8 -# or -version: master - -#################################################################################################### -# -# local_settings -# -#################################################################################################### - -# local_settings directive provides options that won't be delivered to project users. -# For user or system CPPAN config suboptions from 'local_settings' available at global level. - -local_settings: - # host: server address in form host or host:port ; host is url or ip address - host: https://cppan.org - - # proxy provides access to proxy options - proxy: - # host - same for local_settings.host - host: my_local_network_proxy_server:3128 - - # user - proxy auth options in form user:password - user: my_username:my_password - - # storage_dir - CPPAN root directory in which it will store all its data. - # Default value: $HOME/.cppan/ - storage_dir: /home/user/.cppan/ - - # storage_dir_type - gives you ability to select predefined storage_dir. - # Can be: - # 1. local - store all data in 'storage_dir' value from current config (not recommended); - # 2. user - store data in 'storage_dir' from your user config; (recommended) - # 3. system - store data in 'storage_dir' from your system config; (this will require sudo invocations of CPPAN) - # Default value: user. - storage_dir_type: user - - # show_ide_projects - with this option you'll be able to navigate through dependencies projects in you IDE (VS, Xcode) - # Boolean, default value - false - show_ide_projects: false - - ################################################ - # following settings control program builds which are driven by CPPAN - ################################################ - - # build_dir - directory for storing generated build files and current project's objects files. - # Default value: $TEMP/cppan/build/ - build_dir: /tmp/my_dir - - # build_dir_type - gives you ability to select predefined build_dir. - # Can be: - # 1. local - store all data in 'build_dir' value from current config; - # 2. user - store data in 'build_dir' from your user config; - # 3. system - store data in 'build_dir' from your system config; - # Default value: system. - # If 'build_dir' value is specified, 'build_dir_type' won't be considered. - build_dir_type: system - - # local_build - turn on building of all dependencies in build directory instead of CPPAN storage. - # This will build all deps in this dir. - # Default value: false - local_build: false - - # add_run_cppan_target - this will add 'run-cppan' target that will track changes of cppan.yml - # and re-run CPPAN program automatically - # Default value: false. - add_run_cppan_target: false - - ################################################ - # build directive configures compilation settings under CPPAN control - ################################################ - - build: - # c_compiler - specify C family compiler. - # Should be either full program path or name of the program available in PATH. - # Default compiler is selected by CMake from your system. - c_compiler: gcc-5 - - # cxx_compiler - specify C++ family compiler. - # Should be either full program path or name of the program available in PATH. - # Default compiler is selected by CMake from your system. - cxx_compiler: g++-5 - - # compiler - specify C/C++ family compiler. - # Should be either full program path or name of the program available in PATH. - # Default compiler is selected by CMake from your system. - compiler: clang-3.9 - - # c_compiler_flags - options passed to C compiler. - c_compiler_flags: -Wall - - # C++ - cxx_compiler_flags: -Wall -W... - - # C and C++ - compiler_flags: -Wall -W... - - # compiler flags for configuration builds. - # Used when applicable (MSVC, Xcode). - c_compiler_flags_debug: ... - c_compiler_flags_relwithdebinfo: ... - c_compiler_flags_release: ... - c_compiler_flags_minsizerel: ... - - cxx_compiler_flags_{debug|relwithdebinfo|release|minsizerel}: ... - compiler_flags_{debug|relwithdebinfo|release|minsizerel}: ... - - # link_flags - flags that passed to linker - link_flags: ... - link_flags_{debug|relwithdebinfo|release|minsizerel}: ... - - # configuration - Debug|RelWithDebInfo|Release|MinSizeRel - # Default value - Release - configuration: Debug - - # generator - CMake generator. See https://cmake.org/cmake/help/v3.6/manual/cmake-generators.7.html - # Default value is selected by CMake. - generator: Visual Studio 14 2015 Win64 - - # toolset - CMake's toolset for generator - toolset: v140_xp - - # type - type of program. - # Can be: - # 1. executable (default) - # 2. library - type: library - - # library_type - library type. - # Can be: - # 1. shared - # 2. static (default) - library_type: shared - - # executable_type - additional executable type. - # On Windows can be 'WIN32'. This will result in producing GUI application. - # Default value is empty (console executable). - executable_type: WIN32 - - # use_shared_libs - how to link dependencies to your program. - # Can be: - # 1. true - link shared (default): you should distribute deps' .dll or .so files. - # 2. false - link static. - use_shared_libs: true - - # silent - produce a link to project or solution file in current folder. - # Set to false for easy development and debugging. - # Default value: true - silent: false - - # cmake_options - a set of strings that will be passed to CMake directly. - cmake_options: - - -DCMAKE_MAKE_PROGRAM="make" - - -DCMAKE_COOL_OPTION="some string" - - -DANOTHER_OPTION=ON - - # env - set specific envorinment variables - env: - PATH=$PATH: /my/dir - ANDROID_NDK: /path/to/ndk - -#################################################################################################### diff --git a/doc/doxyfile b/doc/doxyfile new file mode 100644 index 00000000..95e0333b --- /dev/null +++ b/doc/doxyfile @@ -0,0 +1,322 @@ + +DOXYFILE_ENCODING = UTF-8 +PROJECT_NAME = "Software Network" +PROJECT_NUMBER = +PROJECT_BRIEF = +PROJECT_LOGO = +OUTPUT_DIRECTORY = doc/build +CREATE_SUBDIRS = NO +ALLOW_UNICODE_NAMES = NO +OUTPUT_LANGUAGE = English +BRIEF_MEMBER_DESC = YES +REPEAT_BRIEF = YES +ABBREVIATE_BRIEF = "The $name class" \ + "The $name widget" \ + "The $name file" \ + is \ + provides \ + specifies \ + contains \ + represents \ + a \ + an \ + the +ALWAYS_DETAILED_SEC = NO +INLINE_INHERITED_MEMB = NO +FULL_PATH_NAMES = YES +STRIP_FROM_PATH = +STRIP_FROM_INC_PATH = +SHORT_NAMES = NO +JAVADOC_AUTOBRIEF = NO +QT_AUTOBRIEF = NO +MULTILINE_CPP_IS_BRIEF = NO +INHERIT_DOCS = YES +SEPARATE_MEMBER_PAGES = NO +TAB_SIZE = 4 +ALIASES = +TCL_SUBST = +OPTIMIZE_OUTPUT_FOR_C = NO +OPTIMIZE_OUTPUT_JAVA = NO +OPTIMIZE_FOR_FORTRAN = NO +OPTIMIZE_OUTPUT_VHDL = NO +EXTENSION_MAPPING = +MARKDOWN_SUPPORT = YES +TOC_INCLUDE_HEADINGS = 0 +AUTOLINK_SUPPORT = YES +BUILTIN_STL_SUPPORT = NO +CPP_CLI_SUPPORT = NO +SIP_SUPPORT = NO +IDL_PROPERTY_SUPPORT = YES +DISTRIBUTE_GROUP_DOC = NO +GROUP_NESTED_COMPOUNDS = NO +SUBGROUPING = YES +INLINE_GROUPED_CLASSES = NO +INLINE_SIMPLE_STRUCTS = NO +TYPEDEF_HIDES_STRUCT = NO +LOOKUP_CACHE_SIZE = 0 +EXTRACT_ALL = NO +EXTRACT_PRIVATE = NO +EXTRACT_PACKAGE = NO +EXTRACT_STATIC = NO +EXTRACT_LOCAL_CLASSES = YES +EXTRACT_LOCAL_METHODS = NO +EXTRACT_ANON_NSPACES = NO +HIDE_UNDOC_MEMBERS = YES +HIDE_UNDOC_CLASSES = YES +HIDE_FRIEND_COMPOUNDS = NO +HIDE_IN_BODY_DOCS = NO +INTERNAL_DOCS = NO +CASE_SENSE_NAMES = NO +HIDE_SCOPE_NAMES = NO +HIDE_COMPOUND_REFERENCE= NO +SHOW_INCLUDE_FILES = YES +SHOW_GROUPED_MEMB_INC = NO +FORCE_LOCAL_INCLUDES = NO +INLINE_INFO = YES +SORT_MEMBER_DOCS = YES +SORT_BRIEF_DOCS = YES +SORT_MEMBERS_CTORS_1ST = YES +SORT_GROUP_NAMES = YES +SORT_BY_SCOPE_NAME = YES +STRICT_PROTO_MATCHING = NO +GENERATE_TODOLIST = YES +GENERATE_TESTLIST = YES +GENERATE_BUGLIST = YES +GENERATE_DEPRECATEDLIST= YES +ENABLED_SECTIONS = +MAX_INITIALIZER_LINES = 30 +SHOW_USED_FILES = NO +SHOW_FILES = NO +SHOW_NAMESPACES = YES +FILE_VERSION_FILTER = +LAYOUT_FILE = +CITE_BIB_FILES = +QUIET = NO +WARNINGS = YES +WARN_IF_UNDOCUMENTED = YES +WARN_IF_DOC_ERROR = YES +WARN_NO_PARAMDOC = NO +WARN_AS_ERROR = NO +WARN_FORMAT = "$file:$line: $text" +WARN_LOGFILE = +INPUT = include src +INPUT_ENCODING = UTF-8 +FILE_PATTERNS = *.c \ + *.cc \ + *.cxx \ + *.cpp \ + *.c++ \ + *.java \ + *.ii \ + *.ixx \ + *.ipp \ + *.i++ \ + *.inl \ + *.idl \ + *.ddl \ + *.odl \ + *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.h++ \ + *.cs \ + *.d \ + *.php \ + *.php4 \ + *.php5 \ + *.phtml \ + *.inc \ + *.m \ + *.markdown \ + *.md \ + *.mm \ + *.dox \ + *.py \ + *.pyw \ + *.f90 \ + *.f95 \ + *.f03 \ + *.f08 \ + *.f \ + *.for \ + *.tcl \ + *.vhd \ + *.vhdl \ + *.ucf \ + *.qsf +RECURSIVE = YES +EXCLUDE = +EXCLUDE_SYMLINKS = NO +EXCLUDE_PATTERNS = +EXCLUDE_SYMBOLS = +EXAMPLE_PATH = +EXAMPLE_PATTERNS = * +EXAMPLE_RECURSIVE = NO +IMAGE_PATH = +INPUT_FILTER = +FILTER_PATTERNS = +FILTER_SOURCE_FILES = NO +FILTER_SOURCE_PATTERNS = +USE_MDFILE_AS_MAINPAGE = +SOURCE_BROWSER = NO +INLINE_SOURCES = NO +STRIP_CODE_COMMENTS = YES +REFERENCED_BY_RELATION = NO +REFERENCES_RELATION = NO +REFERENCES_LINK_SOURCE = YES +SOURCE_TOOLTIPS = YES +USE_HTAGS = NO +VERBATIM_HEADERS = YES +CLANG_ASSISTED_PARSING = NO +CLANG_OPTIONS = +ALPHABETICAL_INDEX = YES +COLS_IN_ALPHA_INDEX = 5 +IGNORE_PREFIX = +GENERATE_HTML = YES +HTML_OUTPUT = html +HTML_FILE_EXTENSION = .html +HTML_HEADER = +HTML_FOOTER = +HTML_STYLESHEET = +HTML_EXTRA_STYLESHEET = +HTML_EXTRA_FILES = +HTML_COLORSTYLE_HUE = 220 +HTML_COLORSTYLE_SAT = 100 +HTML_COLORSTYLE_GAMMA = 80 +HTML_TIMESTAMP = NO +HTML_DYNAMIC_SECTIONS = NO +HTML_INDEX_NUM_ENTRIES = 100 +GENERATE_DOCSET = NO +DOCSET_FEEDNAME = "Doxygen generated docs" +DOCSET_BUNDLE_ID = org.doxygen.Project +DOCSET_PUBLISHER_ID = org.doxygen.Publisher +DOCSET_PUBLISHER_NAME = Publisher +GENERATE_HTMLHELP = NO +CHM_FILE = +HHC_LOCATION = +GENERATE_CHI = NO +CHM_INDEX_ENCODING = +BINARY_TOC = NO +TOC_EXPAND = NO +GENERATE_QHP = NO +QCH_FILE = +QHP_NAMESPACE = org.doxygen.Project +QHP_VIRTUAL_FOLDER = doc +QHP_CUST_FILTER_NAME = +QHP_CUST_FILTER_ATTRS = +QHP_SECT_FILTER_ATTRS = +QHG_LOCATION = +GENERATE_ECLIPSEHELP = NO +ECLIPSE_DOC_ID = org.doxygen.Project +DISABLE_INDEX = NO +GENERATE_TREEVIEW = NO +ENUM_VALUES_PER_LINE = 4 +TREEVIEW_WIDTH = 250 +EXT_LINKS_IN_WINDOW = NO +FORMULA_FONTSIZE = 10 +FORMULA_TRANSPARENT = YES +USE_MATHJAX = NO +MATHJAX_FORMAT = HTML-CSS +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest +MATHJAX_EXTENSIONS = +MATHJAX_CODEFILE = +SEARCHENGINE = YES +SERVER_BASED_SEARCH = NO +EXTERNAL_SEARCH = NO +SEARCHENGINE_URL = +SEARCHDATA_FILE = searchdata.xml +EXTERNAL_SEARCH_ID = +EXTRA_SEARCH_MAPPINGS = +GENERATE_LATEX = NO +LATEX_OUTPUT = latex +LATEX_CMD_NAME = latex +MAKEINDEX_CMD_NAME = makeindex +COMPACT_LATEX = NO +PAPER_TYPE = a4 +EXTRA_PACKAGES = +LATEX_HEADER = +LATEX_FOOTER = +LATEX_EXTRA_STYLESHEET = +LATEX_EXTRA_FILES = +PDF_HYPERLINKS = YES +USE_PDFLATEX = YES +LATEX_BATCHMODE = NO +LATEX_HIDE_INDICES = NO +LATEX_SOURCE_CODE = NO +LATEX_BIB_STYLE = plain +LATEX_TIMESTAMP = NO +GENERATE_RTF = NO +RTF_OUTPUT = rtf +COMPACT_RTF = NO +RTF_HYPERLINKS = NO +RTF_STYLESHEET_FILE = +RTF_EXTENSIONS_FILE = +RTF_SOURCE_CODE = NO +GENERATE_MAN = NO +MAN_OUTPUT = man +MAN_EXTENSION = .3 +MAN_SUBDIR = +MAN_LINKS = NO +GENERATE_XML = NO +XML_OUTPUT = xml +XML_PROGRAMLISTING = YES +GENERATE_DOCBOOK = NO +DOCBOOK_OUTPUT = docbook +DOCBOOK_PROGRAMLISTING = NO +GENERATE_AUTOGEN_DEF = NO +GENERATE_PERLMOD = NO +PERLMOD_LATEX = NO +PERLMOD_PRETTY = YES +PERLMOD_MAKEVAR_PREFIX = +ENABLE_PREPROCESSING = YES +MACRO_EXPANSION = YES +EXPAND_ONLY_PREDEF = NO +SEARCH_INCLUDES = YES +INCLUDE_PATH = +INCLUDE_FILE_PATTERNS = +PREDEFINED = +EXPAND_AS_DEFINED = +SKIP_FUNCTION_MACROS = YES +TAGFILES = +GENERATE_TAGFILE = +ALLEXTERNALS = NO +EXTERNAL_GROUPS = YES +EXTERNAL_PAGES = YES +PERL_PATH = /usr/bin/perl +CLASS_DIAGRAMS = YES +MSCGEN_PATH = +DIA_PATH = +HIDE_UNDOC_RELATIONS = YES +HAVE_DOT = NO +DOT_NUM_THREADS = 0 +DOT_FONTNAME = Helvetica +DOT_FONTSIZE = 10 +DOT_FONTPATH = +CLASS_GRAPH = YES +COLLABORATION_GRAPH = YES +GROUP_GRAPHS = YES +UML_LOOK = NO +UML_LIMIT_NUM_FIELDS = 10 +TEMPLATE_RELATIONS = NO +INCLUDE_GRAPH = YES +INCLUDED_BY_GRAPH = YES +CALL_GRAPH = NO +CALLER_GRAPH = NO +GRAPHICAL_HIERARCHY = YES +DIRECTORY_GRAPH = YES +DOT_IMAGE_FORMAT = png +INTERACTIVE_SVG = NO +DOT_PATH = +DOTFILE_DIRS = +MSCFILE_DIRS = +DIAFILE_DIRS = +PLANTUML_JAR_PATH = +PLANTUML_CFG_FILE = +PLANTUML_INCLUDE_PATH = +DOT_GRAPH_MAX_NODES = 50 +MAX_DOT_GRAPH_DEPTH = 0 +DOT_TRANSPARENT = NO +DOT_MULTI_TARGETS = NO +GENERATE_LEGEND = YES +DOT_CLEANUP = YES diff --git a/doc/faq.md b/doc/faq.md deleted file mode 100644 index 2d71dc80..00000000 --- a/doc/faq.md +++ /dev/null @@ -1,11 +0,0 @@ -#### What is `pvt.cppan.demo` namespace? - -`pvt.cppan` is a utility CPPAN account and `pvt.cppan.demo` contains many projects, but they're not official. You could use them as a starting point in uploading your packages. And official packages will be in `pvt.your_name.*` namespace. Also for orgs: `org.boost.*`, `org.google.*`, `org.facebook.*`, `com.ibm.*`. - -#### Where does cppan download/generate stuff? - -By default, in your user home directory. Like `$HOME/.cppan/storage` on *nix or `%USERPROFILE%/.cppan/storage` on Windows. - -#### How to change that directory? - -Open `$HOME/.cppan/cppan.yml`, add `storage_dir: your/favourite/dir/for/cppan`. diff --git a/doc/getting_started.md b/doc/getting_started.md deleted file mode 100644 index 82d9e6d0..00000000 --- a/doc/getting_started.md +++ /dev/null @@ -1,46 +0,0 @@ -CPPAN uses [CMake](cmake.org) build system at the moment. Minimum required version is 3.2. Later other build systems can be added. - -We'll describe initial setup and usage based on this demo project https://github.com/cppan/demo_project. - -To start work with cppan install its client into the system. On all systems and work can be done without root privileges. - 1. Create your project's initial structure, `CMakeLists.txt` file etc. - 2. Create `cppan.yml` file in the project's root directory. - 3. Open it and write dependencies on which your project depends. - -`cppan.yml` files use YAML syntax which is very simple. Example of this file can be: - - dependencies: - pvt.cppan.demo.gsl: master - pvt.cppan.demo.yaml_cpp: "*" - - pvt.cppan.demo.boost.asio: 1 - pvt.cppan.demo.boost.filesystem: 1.60 - pvt.cppan.demo.boost.log: 1.60.0 - -`dependencies` directive tells the CPPAN which projects are used by your project. `*` means any latest fixed (not a branch) version. Textual name is a branch name (`master`). Versions can be `1.2.8` - exact version, `1.2` means `1.2.*` any version in 1.2 series, `1` means `1.*.*` and version in 1 series. When the new version is available it will be downloaded and replace your current one only in case if you use series versions. If you use strict fixed version, it won't be updated, so no surprises. - -Now you should run `cppan` client in project's root directory where `cppan.yml` is located. It will download necessary packages and do initial build system setup. - -After this you should include `.cppan` subdirectory in your `CMakeLists.txt` file. - - add_subdirectory(.cppan) - -You can do this after `project()` directive. In this case all dependencies won't be re-built after any compile flags. If you need your special compile flags to have influence on deps, write `add_subdirectory(.cppan)` after compiler setup. - -For your target(s) add `cppan` to `target_link_libraries()`: - - target_link_libraries(your_target cppan) - -CMake will try to link all deps into this target. To be more specific you can provide only necessary deps tothis target: - - target_link_libraries(your_target org.boost.algorithm-1.60.0) # or - target_link_libraries(your_target org.boost.algorithm-1.60) # or - target_link_libraries(your_target org.boost.algorithm-1) # or - target_link_libraries(your_target org.boost.algorithm) # or - -All these names are aliases to full name. So, when you have more that 1 version of library (what is really really bad!), you can specify correct version. -For custom build steps you may use executables by their shortest name. - -Internally cppan generate a `CMakeLists.txt` file for dependency. It will use all files it found in the dependency dir. - - file(GLOB_RECURSE src "*") diff --git a/doc/intro.md b/doc/intro.md deleted file mode 100644 index 42836ad4..00000000 --- a/doc/intro.md +++ /dev/null @@ -1,28 +0,0 @@ -The idea comes from: - -1. Comprehensive Perl Archive Network (CPAN), CRAN (R-language), CTAN (TeX). -2. Java packages and build systems (Maven). -3. C++ Modules proposals and presentations by Gabriel Dos Reis. - -In the beginning project aimed on C++ project with Modules only. So, the project should evolve by their release. But during development, CPPAN shows great capabilities of handling current C++98/C++11/C++14 projects and even some C libraries. - -General principles of CPPAN are listed below. - -1. Source code only! You do not include your other stuff like tests, benchmarks, utilities etc. Only headers and sources (if any). On exception here: project's license file. Include it if you have one in the project tree. -1. [Semantic versioning](http://semver.org). -2. Zero-configure (zero-conf.) projects. Projects should contain their configurations in headers (relying on toolchain macros) or rely on CPPAN utilities (macros, different checkers in configuration file) or have no config steps at all (header only projects). Still CPPAN provides inlining of user configuration steps, compiler flags etc. -3. All or Nothing rule for dependencies. Many projects have optional dependencies. In CPPAN they should list them and they'll be always included to the build or not included at all. So, no optional dependencies. - -Projects' naming - -Project names are like Modules from this C++ proposal http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0143r1.pdf. Words are delimeted by points `.`. - -Root names are: - -1. pvt - for users' projects. E.g. `pvt.cppan.some_lib`. -2. org - for organization projects with open source licenses. E.g. `org.boost.algorithm`. -3. com - for organization projects with commercial licenses. E.g. `com.some_org.some_proprietary_lib`. - -Project versions - -Each project will have its versions. Version can be a semver number `1.2.8` or a branch name `master`, `dev`. Branches always considered as unstable unless it is stated by maintainer. Branches can be updated to the latest commit. And fixed versions can not. diff --git a/doc/latex/client.tex b/doc/latex/client.tex new file mode 100644 index 00000000..292a68a3 --- /dev/null +++ b/doc/latex/client.tex @@ -0,0 +1,853 @@ +% !TEX root = sw.tex +% !TeX spellcheck = en_US + + +\chapter{Client tools (SW and others)} + +Main client tool is SW. + +A gui frontend is also available. It is Qt-based and widgets-based (no QML). + +\section{Quick Start} + + + +\subsection{Package Management} + +SW uses packages paths to uniquely identify projects on the web. +Project path is similar to Java packages. Version is appended to it. + +`org.username.path.to.project.target-version` + +It contains: +\begin{enumerate} +\item +Namespace: `org` +\item +User name: `username` +\item +Path to target: `path.to.project.target` +\end{enumerate} + +Allowed namespaces are: +\begin{enumerate} +\item +`org` - organization's public projects with open (free) software license. +\item +`com` - organization's projects with commercial license. +\item +`pub` - user's public projects. +\item +`pvt` - user's private projects. +\end{enumerate} + +`version` - is a **semver-like** version. + +\subsection{Build process} + +SW uses configuration files to describe build process (Build). + +Build contains several solutions (Solution). +Each Solution is responsible for exactly one configuration. For example, x86+dll+Release or arm64+static+Debug (plus sign is used only for this document). + +Solution consists of targets, projects and directories. Each object might include any other object. + +SW uses multipass approach if it needs to build more than one solution. +(Unlike CMake that is telled which options go to what configuration during single pass.) + +It is possible to use different frontends to describe build. +Main frontend is called `sw` as well as the program and uses C++ code directly. +Current secondary frontend is `cppan` YAML frontend used in first version of the program. + +Build process + +\subsection{Frontends} + +\subsubsection{C++ frontend (sw)} + +HINT: run `sw create project` to force sw to create first config and generate an IDE project for you._ + +To start your first build configuration, create a file called `sw.cpp`. + +\begin{swcpp} +// this is our 'main' build function signature +// function accepts current Solution +void build(Solution &s) +{ + // add non copyable target to Solution of type Executable with name 'mytarget' + auto &t = s.addTarget("mytarget"); + t += "src/main.cpp"; // add our first source file + // t += "dependency.path"_dep; // add needed dependency +} +\end{swcpp} + +SW uses the latest current standard available - C++17. + +To control your build (add definitions, dependencies, link libraries) sw uses user-defined literals. For more help on this, see https://github.com/SoftwareNetwork/sw/blob/master/src/sw/driver/suffix.h +Examples: + +\begin{swcpp} +t += "MY_DEFINITION"_def; +t += "ws2_32.lib"_slib; +t += "src"_idir; +\end{swcpp} + +Now create `src/main.cpp` file with contents you want. + +Run `sw build` to perform build or `sw generate` to generate IDE project. + + + +Visibility + +To provide control on properies visibility, one might use following target members: + +\begin{swcpp} +t.Private += ...; // equals to t += ...; +t.Protected += ...; // available only for this target and current project members +t.Public += ...; // available for this target and all downstream users +t.Inheritance += ...; // available only for all downstream users +\end{swcpp} + +Underlying implementation uses three bits to describe inheritance. + +\begin{enumerate} +\item This target T +\item This project P (excluding T) +\item All other projects A (excluding P and T) +\end{enumerate} + +This gives 7 different inheritance modes (excluding 000) and you could use them all! + + + + + +More than one configuration + +To create additional configs you might add them on command line or write into configuration. +Add following code to your `sw.cpp`: + +\begin{swcpp} +// configure signature +// Note that it accepts whole build, not a single solution! +void configure(Build &b) +{ + auto &s1 = b.addSolution(); // add first solution + s1.Settings.Native.LibrariesType = LibraryType::Static; + s1.Settings.Native.ConfigurationType = ConfigurationType::ReleaseWithDebugInformation; + + auto &s2 = b.addSolution(); // add first solution + s2.Settings.Native.LibrariesType = LibraryType::Shared; + s2.Settings.Native.ConfigurationType = ConfigurationType::Debug; + + return; + + // following code can be used for advanced toolchain configuration + if (b.isConfigSelected("cygwin2macos")) + b.loadModule("utils/cc/cygwin2macos.cpp").call("configure", b); + else if (b.isConfigSelected("win2macos")) + b.loadModule("utils/cc/win2macos.cpp").call("configure", b); +} +\end{swcpp} + +In this function you could provide full custom toolchain to use (compilers, linkers, librarians etc.). +Extended configs can be found here: \url{https://github.com/SoftwareNetwork/sw/tree/master/utils/cc} + + +\subsubsection{YAML declarative frontend (CPPAN)} + +CPPAN is a declarative frontend using YAML syntax. + +Example: \url{https://github.com/cppan/cppan/blob/v1/doc/cppan.yml} + +Quick Start + +We'll describe initial setup and usage based on this demo project \url{https://github.com/cppan/demo_project}. + +To start work with cppan install its client into the system. On all systems and work can be done without root privileges. +\begin{enumerate} +\item +Create your project's initial structure, `CMakeLists.txt` file etc. +\item +Create `cppan.yml` file in the project's root directory. +\item +Open it and write dependencies on which your project depends. +\end{enumerate} + +`cppan.yml` files use YAML syntax which is very simple. Example of this file can be: + +\begin{cppan} + dependencies: + pvt.cppan.demo.gsl: master + pvt.cppan.demo.yaml_cpp: "*" + + pvt.cppan.demo.boost.asio: 1 + pvt.cppan.demo.boost.filesystem: 1.60 + pvt.cppan.demo.boost.log: 1.60.0 +\end{cppan} + +`dependencies` directive tells the CPPAN which projects are used by your project. `*` means any latest fixed (not a branch) version. Textual name is a branch name (`master`). Versions can be `1.2.8` - exact version, `1.2` means `1.2.*` any version in 1.2 series, `1` means `1.*.*` and version in 1 series. When the new version is available it will be downloaded and replace your current one only in case if you use series versions. If you use strict fixed version, it won't be updated, so no surprises. + +Now you should run `cppan` client in project's root directory where `cppan.yml` is located. It will download necessary packages and do initial build system setup. + +After this you should include `.cppan` subdirectory in your `CMakeLists.txt` file. + +\begin{cmake} + add_subdirectory(.cppan) +\end{cmake} + +You can do this after `project()` directive. In this case all dependencies won't be re-built after any compile flags. If you need your special compile flags to have influence on deps, write `add_subdirectory(.cppan)` after compiler setup. + +For your target(s) add `cppan` to `target_link_libraries()`: + +\begin{cmake} + target_link_libraries(your_target cppan) +\end{cmake} + +CMake will try to link all deps into this target. To be more specific you can provide only necessary deps tothis target: + +\begin{cmake} + target_link_libraries(your_target org.boost.algorithm-1.60.0) # or + target_link_libraries(your_target org.boost.algorithm-1.60) # or + target_link_libraries(your_target org.boost.algorithm-1) # or + target_link_libraries(your_target org.boost.algorithm) # or +\end{cmake} + +All these names are aliases to full name. So, when you have more that 1 version of library (what is really really bad!), you can specify correct version. +For custom build steps you may use executables by their shortest name. + +Internally cppan generate a `CMakeLists.txt` file for dependency. It will use all files it found in the dependency dir. + +\begin{cmake} + file(GLOB_RECURSE src "*") +\end{cmake} + + +Syntax + +files + +In `files` directive you specify what files to include into the distributable package. It can be a regex expression or a relative file name. + +\begin{cppan} + files: + - include/.* + - src/.* +\end{cppan} + +or + +\begin{cppan} + files: + - sqlite3.h + - sqlite3ext.h + - sqlite3.c +\end{cppan} + +or just + +\begin{cppan} + files: include/.* +\end{cppan} + +or + +\begin{cppan} + files: # from google.protobuf + - src/.*\.h + - src/google/protobuf/arena.cc + - src/google/protobuf/arenastring.cc + - src/google/protobuf/extension_set.cc +\end{cppan} + +dependencies + +`dependencies` contains a list of all dependencies required by your project. Can be `private` and `public`. `public` are exported when you add you project to C++ Archive Network. `private` stays private and can be used by your project's tools and other stuff. + +For example when you develop an application, you want to add unit tests, regression tests, benchmarks etc. You can specify test frameworks as dependencies too. For example, `pvt.cppan.demo.google.googletest.gtest` or `pvt.cppan.demo.google.googletest.gmock`. + +But when you develop a library and want export it to CPPAN, you won't those libraries in the public dependency list. +You can write: + +\begin{cppan} + dependencies: + public: + org.boost.filesystem: 1 + private: + pvt.cppan.demo.google.googletest.gtest: master +\end{cppan} + +By default all deps are public. + +\begin{cppan} + dependencies: + org.boost.filesystem: 1.60 # public + pvt.cppan.demo.google.googletest.gtest: master # public now +\end{cppan} + +include_directories + +Include directories are needed by your project and project users. You must always write `private` or `public` keywords. `private` include dirs available for your lib only. `public` available for your lib and its users. + +\begin{cppan} + include_directories: # boost.math example + public: + - include + private: + - src/tr1 +\end{cppan} + +license + +Include license file if you have it in the project tree. + + license: LICENSE.txt + +root_directory + +When adding version from remote file (archive) often there is a root dir inside the archive. You can use this directive to specify a path to be added to all relative files and dirs. + +\begin{cppan} + root_directory: sqlite-amalgamation-3110000 # sqlite3 example +\end{cppan} + +exclude_from_build + +Sometimes you want to ship a source file, but do not want to include it into build. Maybe it will be conditionally included from config header or whatever. + +\begin{cppan} + exclude_from_build: # from boost.thread + - src/pthread/once_atomic.cpp +\end{cppan} + +options + +In `options` you can provide predefined macros for specific configurations. +`any`, `static` and `shared` are available. +Inside them you can use `definitions` to provide compile defines. You must write `public` or `private` near each define. `private` is only for current library. `public` define will see all users and the current lib. + +\begin{cppan} + options: # from boost.log + any: + definitions: + public: BOOST_LOG_WITHOUT_EVENT_LOG + private: BOOST_LOG_BUILDING_THE_LIB=1 + shared: + definitions: + public: BOOST_LOG_DYN_LINK + private: BOOST_LOG_DLL +\end{cppan} + +But try to minimize use of such options. + +pre_sources, post_sources, post_target, post_alias + +You can provide your custom build system insertions with these directives. + +\begin{cppan} + post_sources: | # custom step from boost.config + if (WIN32) + file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/include/boost/config/auto_link.hpp "") + endif() +\end{cppan} + +Can be used in options too near with `definitions`. + +root_project, projects + +Can be used when you're exporting more than one project from one repository. Inside `projects` you should describe all exported projects. Relative name of each should be specified after this. Inside each project, write usual command. + +\begin{cppan} + root_project: pvt.cppan.demo.google.googletest + projects: + gtest: # use relative name here - absolute will be pvt.cppan.demo.google.googletest.gtest + license: googletest/LICENSE + files: + - googletest/include/.*\.h + - googletest/src/.* + gmock: # use relative name here + # ... +\end{cppan} + +package_dir + +Can be used to choose storage of downloaded packages. Could be `system`, `user`, `local`. Default is `user`. `system` requires root right when running cppan, deps will go to `/usr/share/cppan/packages`. `user` stores deps in `\$HOME/.cppan/packages`. `local` will store deps in cppan/ in local dir. + + package_dir: local + +You can selectively choose what deps should go to one of those locations. + +\begin{cppan} + dependencies: + org.boost.filesystem: + version: "*" + package_dir: local +\end{cppan} + +It is convenient when you want to apply your patches to some dependency. + +check_function_exists, check_include_exists, check_type_size, check_symbol_exists, check_library_exists + +These use cmake facilities to provide a way of checking headers, symbols, functions etc. Cannot be under `projects` directive. Can be only under root. They will be gathered during `cppan` run, duplicates will be removed, so not duplicate work. + +\begin{cppan} + check_function_exists: # from libressl + - asprintf + - inet_pton + - reallocarray + + check_include_exists: + - err.h +\end{cppan} + + + +\subsubsection{CMake frontend} + +If you have your projects in CMake, SW is able to load and run them to extract build rules. + +CMake frontend is in initial state right now. Try it and report any issues. + + + + +\section{Command Line Reference} + + + + +\section{Build System Supported Languages} + +SW aims to build a wide specter of programming languages. + +Mature support: +\begin{enumerate} +\item ASM +\item C +\item C++ +\end{enumerate} + +Hello-world support: +\begin{enumerate} +\item C\# +\item D +\item Fortran +\item Go +\item Java +\item Kotlin +\item Rust +\end{enumerate} + + +Ported Intepreters + +- perl (partial) + +- python + +- tcl + +Work started + +- java + + +\section{Integrations} + +It is possible to use SW as package manager for your favourite build system. + +Here you can find list of completed integrations with examples. + +\subsection{CMake} + + +Full example:\\ +\url{https://github.com/SoftwareNetwork/sw/blob/master/test/integrations/CMakeLists.txt} + +Steps +\begin{enumerate} +\item +Download SW, unpack and add to PATH. +\item +Run `sw setup` to perform initial integration into system. +\item +Add necessary parts to your CMakeLists.txt (see below). +\end{enumerate} + +First, make sure CMake is able to found SW package: +\begin{cmake} +find_package(SW REQUIRED) +\end{cmake} + +Then add necessary dependencies (packages) with +\begin{cmake} +sw_add_package() +\end{cmake} + +You can omit version. In this case the latest will be used. + +Next step is to execute SW to prepare imported targets script with +\begin{cmake} +sw_execute() +\end{cmake} + +Complete example: +\begin{cmake} +find_package(SW REQUIRED) +sw_add_package( + org.sw.demo.sqlite3 + org.sw.demo.glennrp.png +) +sw_execute() +\end{cmake} + +Last thing is to add dependency to your package: +\begin{cmake} +add_executable(mytarget ${MY_SOURCES}) +target_link_libraries(mytarget + org.sw.demo.glennrp.png +) +\end{cmake} + +Configure SW deps + +Set SW_BUILD_SHARED_LIBS to 1 to build shared libs instead of static (default) +\begin{cmake} +set(SW_BUILD_SHARED_LIBS 1) +\end{cmake} + + +\subsection{Waf} + +Full example\\ +\url{https://github.com/SoftwareNetwork/sw/blob/master/test/integrations/wscript} + +\begin{enumerate} +\item +Copy-paste these lines to your file \url{https://github.com/SoftwareNetwork/sw/blob/master/test/integrations/wscript#L4-L25} + +\item +Replace these lines with your dependencies \url{https://github.com/SoftwareNetwork/sw/blob/master/test/integrations/wscript#L9-L10} + +\item +Use deps like on those lines \url{https://github.com/SoftwareNetwork/sw/blob/master/test/integrations/wscript#L35-L36} + +\end{enumerate} + +To build things call + +\begin{command} +waf sw_configure sw_build configure build +\end{command} + +sw\underline\ configure step setups SW for waf. + +sw\underline\ build step builds necessary deps. + + + + + +\section{Generators} + +SW allows you to generate projects to many different existing systems. + +\begin{center} +\begin{tabular}{lc} +Generator & Support\\ +\hline +Visual Studio (C++ projects) & Full \\ +Visual Studio (NMake projects) & Full \\ +%\item Visual Studio (Utility projects) [3/5] +%\item Visual Studio (NMake + Utility projects) [3/5] +%CMake [0/5] +Compilation Database & Full \\ +Make & Full \\ +NMake & 4/5 \\ %(why?) +Ninja & Full \\ +%QMake & 0/5 \\ +Batch (win) & Full \\ +Shell (*nix) & Full \\ +SW build description & Full \\ +SW execution plan & Full \\ +Raw bootstrap & Full \\ +\hline + +Missing generators: & \\ +Xcode & \\ +CMake & \\ +qmake & \\ + +\hline +\end{tabular} +\end{center} + + +Raw bootstrap is used to bootstrap programs without sw. + + +\section{Reproducible builds} + +SW supports reproducible builds. +Invoke your commands with `--reproducible-build` parameter. +Binaries MUST BE the same on all systems assuming you compare identical build configs. + +\begin{command} +sw --reproducible-build ... build +\end{command} + + +\section{Command Line Reference} + +\subsection{sw alias} + +Add command alias. +\begin{command} +sw alias aliasname command line args +\end{command} + +To invoke it, run: +\begin{command} +sw aliasname +\end{command} + +You cannot add alias to existing commands. + +\subsection{sw build} + +Build current project. + +To get build and dependencies graphs, run: +\begin{command} +sw -print-graph build +\end{command} + +\subsection{sw create} + +Create templated project. + +\subsection{sw generate} + +Generate IDE project. + +\subsection{sw upload} + +Upload current project to Software Network. +Project will be fetched from your version control system using specified tag/version/branch. + +\subsection{sw setup} + +Integrate or remove sw from the system. + +Integrate sw into system. + +\begin{command} +sw setup +\end{command} + +Remove sw into system. + +\begin{command} +sw setup --uninstall +\end{command} + +To control what is cleaned up, use `--level` option with comma separated list of flags. + +\begin{command} +sw setup --uninstall --level 1,4 +\end{command} + +Available levels: +\begin{itemize} +\item 1 - Remove storage. +\item 2 - Remove sw system integration settings. +\item 4 - Remove sw settings. +\item 8 - Remove sw executable (if possible). +\item 16 - All of the above. +\end{itemize} + +\subsection{sw verify} + +Verify uploaded file. + +Sw provides byte to byte verification for files uploaded to Software Network. +If you want to check that someone is not changed project files, you can run this command. +It will download original source from the internet, create the archive and compare its hash with file on the Software Network. + + +\subsection{sw -help} + +CLI help. + +\begin{verbatim} +OVERVIEW: SW: Software Network Client + + SW is a Universal Package Manager and Build System + +USAGE: sw.client.sw-0.3.1.exe [subcommand] [options] + +SUBCOMMANDS: + + abi - List package ABI, check for ABI breakages. + build - Build files, dirs or packages. + configure - Create build script. + create - Create different projects. + fetch - Fetch sources. + generate - Generate IDE projects. + install - Add package to lock. + integrate - Integrate sw into different tools. + list - List packages in database. + open - Open package directory. + override - Override packages locally. + remote - Manage remotes. + remove - Remove package. + run - Run target (if applicable). + setup - Used to do some system setup which may require administrator access. + test - Run tests. + update - Update lock file. + upload - Upload packages. + uri - Used to invoke sw application from the website. + + Type "sw.client.sw-0.3.1.exe -help" to get more help on a specific subcommand + +OPTIONS: + +General options: + + -B - Build always + -D= - Input variables + -activate= - Activate specific packages + -build-name= - Set meaningful build name instead of hash + -cc-checks-command= - Automatically execute cc checks command + -checks-st - Perform checks in one thread (for cc) + -compiler= - Set compiler + -config-name= - Set meaningful config names instead of hashes + -configuration= - Set build configuration. + Allowed values: + - debug, d + - release, r + - releasewithdebuginformation, releasewithdebinfo, rwdi + - minimalsizerelease, minsizerel, msr + Default is release. + Specify multiple using a comma: "d,r". + -curl-verbose - + -d= - Working directory + -debug-configs - Build configs in debug mode + -do-not-mangle-object-names - + -do-not-remove-bad-module - + -exclude-target= - Targets to ignore + -explain-outdated - Explain outdated commands + -explain-outdated-full - Explain outdated commands with more info + -host-cygwin - When on cygwin, allow it as host + -host-settings-file= - Read host settings from file + -ignore-source-files-errors - Useful for debugging + -ignore-ssl-checks - + -j= - Number of jobs + -k= - Skip errors + -l - Use lock file + -libc= - Set build libc + -libcpp= - Set build libcpp + -list-predefined-targets - List predefined targets + -list-programs - List available programs on the system + -log-to-file - + -os= - Set build target os + -platform= - Set build platform. + Examples: x86, x64, arm, arm64 + -print-checks - Save extended checks info to file + -r= - Select default remote + -s - Force server resolving + -save-all-commands - + -save-command-format= - Explicitly set saved command format (bat or sh) + -save-executed-commands - + -save-failed-commands - + -sd - Force server db check + -self-upgrade - Upgrade client + -settings= - Set settings directly + -settings-file= - Read settings from file + -settings-file-config= - Select settings from file + -settings-json= - Read settings from json string + -shared-build - Set shared build (default) + -show-output - + -standalone - Build standalone binaries + -static-build - Set static build + -static-dependencies - Build static dependencies of inputs + -storage-dir= - + -target= - Targets to build + -target-os= - + -time-trace - Record chrome time trace events + -toolset= - Set VS generator toolset + -trace - Trace output + -verbose - Verbose output + -wait-for-cc-checks - Do not exit on missing cc checks, wait for user input + -win-md - Set /MD build (default) + -win-mt - Set /MT build + -write-output-to-file - + +Generic Options: + + -help - Display available options (-help-hidden for more) + -help-list - Display list of available options (-help-list-hidden for more) + -version - Display the version of this program +\end{verbatim} + + +\section{Work behind proxy} + +To use sw client via proxy, add following to your SW YAML config in +\textasciitilde/.sw/sw.yml: +\begin{verbatim} +proxy: + host: hostname:port + user: user:passwd +\end{verbatim} + +\section{Bootstrapping} + +SW client is distributed in a form of precompiled binary. +This binary is built with SW tool, so we have a circular dependency. + +It is important to be able to build it without existing SW client. +Here comes bootstrapping procedure. +To make bootstrap package, use `rawbootstrap` generator: +\begin{command} +sw *needed config* generate -g rawbootstrap +\end{command} + + + + + + +\section{Internals} +\subsection{Components and directory structure} + +Components + +\begin{enumerate} +\item +Support - small helper library. +\item +Manager - does package managing: package paths, package ids, local databases, remote repository selector, package downloader etc. +\item +Builder - controls executed commands, file timestamps, timestamp databases. +\item +Driver.cpp - main program driver that implements high level build, solutions, targets representation, programs (compilers), source files, languages and generators. +\item +Client - main executable. +\end{enumerate} + +Directory structure + +\begin{enumerate} +\item +doc - documentation +\item +include - some public headers; not well set up +\item +src - source code +\item +test - tests +\item +utils - all other misc. files: crosscompilation configs etc. +\end{enumerate} diff --git a/doc/latex/docpackages.tex b/doc/latex/docpackages.tex new file mode 100644 index 00000000..4200e0d7 --- /dev/null +++ b/doc/latex/docpackages.tex @@ -0,0 +1,49 @@ +% !TEX root = sw.tex +% !TeX spellcheck = en_US + +\usepackage{polyglossia} +\usepackage{fontspec} +%\usepackage[T1]{fontenc} +\setmainlanguage{english} + +\usepackage{graphicx} +\usepackage[final] + {listings} % code listings +\usepackage{longtable} % auto-breaking tables +\usepackage{ltcaption} % fix captions for long tables +\usepackage{relsize} % provide relative font size changes +\usepackage{textcomp} % provide \text{l,r}angle +\usepackage{underscore} % remove special status of '_' in ordinary text +\usepackage{parskip} % handle non-indented paragraphs "properly" +\usepackage{array} % new column definitions for tables +\usepackage[normalem]{ulem} +\usepackage{enumitem} +\usepackage{color} % define colors for strikeouts and underlines +\usepackage{amsmath} % additional math symbols +\usepackage{mathrsfs} % mathscr font +\usepackage[final]{microtype} +\usepackage{multicol} +\usepackage{lmodern} +%\usepackage{listingsutf8} +\usepackage{xcolor} +\usepackage{xparse} +\usepackage[most]{tcolorbox} + +\usepackage[unicode, + pdftitle={Software Management}, + pdfsubject={Software Management}, + pdfcreator={Egor Pugin}, + bookmarks=true, + bookmarksnumbered=true, + pdfpagelabels=true, + pdfpagemode=UseOutlines, + pdfstartview=FitH, + linktocpage=true, + colorlinks=true, + linkcolor=blue, + plainpages=false, + pdfstartpage=2, + ]{hyperref} + +\usepackage{expl3} +\usepackage{xparse} diff --git a/doc/latex/front.tex b/doc/latex/front.tex new file mode 100644 index 00000000..bc2357a2 --- /dev/null +++ b/doc/latex/front.tex @@ -0,0 +1,53 @@ +% !TEX root = sw.tex +% !TeX spellcheck = en_US + +%%-------------------------------------------------- +%% Title page for the SW + +\pagestyle{empty} + +\vspace*{2.5cm} + +\begin{center} +\textbf{\Huge +Software Management} + +\vspace{2cm} + +Egor Pugin + +\end{center} + +\vspace{14cm} + + + + +\begin{center} +\today +\end{center} + +\vfill + + +\textbf{Note: this is an early draft. It's known to be outdated, incomplet and + incorrekt, and it has lots of + b\kern-1.2pta\kern1ptd\hspace{1.5em}for\kern-3ptmat\kern0.6ptti\raise0.15ex\hbox{n}g.} + +Please, report any issues to author. +Contributions are welcome. + +\vspace{1em} + +\begin{tabular}{ll} +Homepage & +\url{https://software-network.org/} +\\ +Git Repository (client tool) & +\url{https://github.com/SoftwareNetwork/sw} +\\ +The latest version of this document & +\url{https://software-network.org/client/sw.pdf} +\end{tabular} + +\newpage diff --git a/doc/latex/intro.tex b/doc/latex/intro.tex new file mode 100644 index 00000000..a9ec7213 --- /dev/null +++ b/doc/latex/intro.tex @@ -0,0 +1,113 @@ +% !TEX root = sw.tex +% !TeX spellcheck = en_US + +\newcommand{\sectionToc}[1]{% + \section*{#1}% + \addcontentsline{toc}{section}{#1}% +} + + +\chapter*{Introduction} +\addcontentsline{toc}{chapter}{Introduction} + +\sectionToc{This document} + +This document describes a modern approach to software management. +It consists of several chapters which include the new approach itself, documentation for client-side tools and utilities and server-side (website) functionality description. + +License for this documentation is unspecified yet. +% GNU FDL? +% CC? + +\sectionToc{Overview} + +Software Network is a project dedicated to better software management. + +Originally started as a package manager (CPPAN - \url{https://github.com/cppan/cppan}) to C/C++ languages based on CMake build system, it is evolved to independent set of tools and libraries. +CPPAN or v1 was a playground where different ideas were studied and checked. + +Main user tool is called `sw`. Whole project also may be called as SW. Pronounce it as you like: `[software]` or `[sw]` or `[sv]`. + + + +\sectionToc{History} + +\subsection*{CPPAN or SW v1} + +Idea was formed during years of work with CMake, different projects, porting things to different OSs. +Development started in the early 2016. + +YAML was choosen as configuration file format. It was mixed declarative approach with imperative CMake insertions. + +\subsection*{SW or CPPAN v2} + +Development started in the late 2017. + +Decarative approach showed weaknesses, so it was decided to switch to the most flexible thing - complete programming language. C++ was choosen over Python (Conan) and, possibly, other languages such as Lua (Premake). + + +\section*{More on CPPAN} + +CPPAN -- C++ Archive Network. +This section is not related to current status of SW and given for historical reasons. + +The idea comes from: + +\begin{enumerate} +\item +Comprehensive Perl Archive Network (CPAN), CRAN (R-language), CTAN (TeX). +\item +Java packages and build systems (Maven). +\item +C++ Modules proposals and presentations by Gabriel Dos Reis. +\end{enumerate} + +In the beginning project aimed on C++ project with Modules only. So, the project should evolve by their release. But during development, CPPAN shows great capabilities of handling current C++98/C++11/C++14 projects and even some C libraries. + +General principles of CPPAN are listed below. + +\begin{enumerate} +\item +Source code only! You do not include your other stuff like tests, benchmarks, utilities etc. Only headers and sources (if any). On exception here: project's license file. Include it if you have one in the project tree. + +\item +Semantic versioning http://semver.org. + +\item +Zero-configure (zero-conf.) projects. Projects should contain their configurations in headers (relying on toolchain macros) or rely on CPPAN utilities (macros, different checkers in configuration file) or have no config steps at all (header only projects). Still CPPAN provides inlining of user configuration steps, compiler flags etc. + +\item +All or Nothing rule for dependencies. Many projects have optional dependencies. In CPPAN they should list them and they'll be always included to the build or not included at all. So, no optional dependencies. +\end{enumerate} + +Projects' naming + +Project names are like Modules from this C++ proposal http://open-std.org/JTC1/SC22/WG21/docs/papers/2016/p0143r1.pdf. Words are delimeted by points `.`. + +Root names are: + +1. pvt - for users' projects. E.g. `pvt.cppan.some_lib`. +2. org - for organization projects with open source licenses. E.g. `org.boost.algorithm`. +3. com - for organization projects with commercial licenses. E.g. `com.some_org.some_proprietary_lib`. + +Project versions + +Each project will have its versions. Version can be a semver number `1.2.8` or a branch name `master`, `dev`. Branches always considered as unstable unless it is stated by maintainer. Branches can be updated to the latest commit. And fixed versions can not. + + + +\sectionToc{Useful links} + + +\begin{enumerate} +\item +Website - \url{https://software-network.org/} + +\item +Download client - \url{https://software-network.org/client/} +\end{enumerate} + + +\section*{Acknowledgements} + +\undef\sectionToc diff --git a/doc/latex/layout.tex b/doc/latex/layout.tex new file mode 100644 index 00000000..98a9c7fe --- /dev/null +++ b/doc/latex/layout.tex @@ -0,0 +1,72 @@ +%!TEX root = sw.tex +%% layout.tex -- set overall page appearance + +%%-------------------------------------------------- +%% set page size, type block size, type block position + +\setlrmarginsandblock{2.245cm}{2.245cm}{*} +\setulmarginsandblock{2.5cm}{2.5cm}{*} + +%%-------------------------------------------------- +%% set header and footer positions and sizes + +\setheadfoot{\onelineskip}{2\onelineskip} +\setheaderspaces{*}{2\onelineskip}{*} + +%%-------------------------------------------------- +%% make miscellaneous adjustments, then finish the layout +\setmarginnotes{7pt}{7pt}{0pt} +\checkandfixthelayout + +%%-------------------------------------------------- +%% If there is insufficient stretchable vertical space on a page, +%% TeX will not properly consider penalties for a good page break, +%% even if \raggedbottom (default) is in effect. +\addtolength{\topskip}{0pt plus 20pt} + +%%-------------------------------------------------- +%% Place footnotes at the bottom of the page, rather +%% than immediately following the main text. +\feetatbottom + +%%-------------------------------------------------- +%% Paragraph and bullet numbering + +\newcounter{Paras} +\counterwithin{Paras}{chapter} +\counterwithin{Paras}{section} +\counterwithin{Paras}{subsection} +\counterwithin{Paras}{subsubsection} +\counterwithin{Paras}{paragraph} +\counterwithin{Paras}{subparagraph} + +\newcounter{Bullets1}[Paras] +\newcounter{Bullets2}[Bullets1] +\newcounter{Bullets3}[Bullets2] +\newcounter{Bullets4}[Bullets3] + +\makeatletter +\newcommand{\parabullnum}[2]{% +\stepcounter{#1}% +\noindent\makebox[0pt][l]{\makebox[#2][r]{% +\scriptsize\raisebox{.7ex}% +{% +\ifnum \value{Paras}>0 +\ifnum \value{Bullets1}>0 (\fi% + \arabic{Paras}% +\ifnum \value{Bullets1}>0 .\arabic{Bullets1}% +\ifnum \value{Bullets2}>0 .\arabic{Bullets2}% +\ifnum \value{Bullets3}>0 .\arabic{Bullets3}% +\fi\fi\fi% +\ifnum \value{Bullets1}>0 )\fi% +\fi% +}% +\hspace{\@totalleftmargin}\quad% +}}} +\makeatother + +\def\pnum +{\parabullnum{Paras}{0pt}} + +% Leave more room for section numbers in TOC +\cftsetindents{section}{1.5em}{3.0em} diff --git a/doc/latex/macros.tex b/doc/latex/macros.tex new file mode 100644 index 00000000..3d993845 --- /dev/null +++ b/doc/latex/macros.tex @@ -0,0 +1,64 @@ +% !TEX root = sw.tex +% !TeX spellcheck = en_US + +\tcbset{common/.style={before upper = {\topskip0pt \maxdepth=0pt}, + enhanced, + listing only, + breakable = unlimited, + top = 0em, + bottom = 0em, + left = 0pt, + right = 0pt, + arc = 0em, + outer arc = 0em, + boxsep = 0em, + boxrule = 1pt, + titlerule = 0em, + colback = white, + size = fbox, + } +} + +\newtcblisting{command}[1][]{common, + title=Shell, + listing only, + listing options={ + basicstyle=\ttfamily\scriptsize, + tabsize=2, + inputencoding=utf8 + }, + #1 +} + +\newtcblisting{cmake}[1][]{common, + title=CMake, + listing only, + listing options={ + basicstyle=\ttfamily\scriptsize, + tabsize=2, + inputencoding=utf8 + }, + #1 +} + +\newtcblisting{swcpp}[1][]{common, + title=sw.cpp, + listing only, + listing options={ + basicstyle=\ttfamily\scriptsize, + tabsize=2, + inputencoding=utf8 + }, + #1 +} + +\newtcblisting{cppan}[1][]{common, + title=cppan.yml, + listing only, + listing options={ + basicstyle=\ttfamily\scriptsize, + tabsize=2, + inputencoding=utf8 + }, + #1 +} diff --git a/doc/latex/server.tex b/doc/latex/server.tex new file mode 100644 index 00000000..05993e2a --- /dev/null +++ b/doc/latex/server.tex @@ -0,0 +1,156 @@ +% !TEX root = sw.tex +% !TeX spellcheck = en_US + + +\chapter{Server tools} + +Software Network -- server frontend -- +\url{https://software-network.org/} + +Download clients -- \url{https://software-network.org/client} + +\section{Publish a project} + +Publish Instructions + +\begin{enumerate} + +\item +Prepare your project. + +\item +Prepare build script. + +\item +Set up source code repository. + +\item +Upload project on some hosting. + +\item + +Create an account on Software Network and your user token at\\ \url{https://software-network.org/u/tokens}. + +\item +Create your first publisher \url{https://software-network.org/u/publishers}. + +\item +Add user token to SW settings. Run: +` +sw remote alter origin add token PUBLISHERNAME SECRETTOKEN +` + +\item +Run locally near build script to upload the project: +` +sw upload PREFIX +` + +\end{enumerate} + + +SW will download your sources from the public hosting using Source provided in build script. + +--- + +PREFIX is your namespace (com/org/pub/pvt) + your publisher name + custom subdirectory inside it. +``` +namespace.publisher[.subdirectory] +``` + +Examples: +\begin{enumerate} +\item +org.sw.demo +\item +org.boost +\item +com.someorgname +\item +pub.egorpugin.my.fancy.subdir +\item +pvt.egorpugin.my.secret.project +\end{enumerate} + + + + +\section*{Old cppan info} + +It uses ssl for any interactions, api calls etc. It uses http to send packages (data) to users. But hashsum checks are performed on client side and hashes are trasferred securely. + +On that site you can find projects, organizations, project versions. + +To add your project to CPPAN you have to: + +1. Register (e.g. `cppan` account name). +1. Login +1. Create project. It will be created under your account in `private` - `pvt` root namespace. E.g. `pvt.cppan.my_very_useful_library`. +1. Add project version. + +Project version sources + +1. git repository +2. remote file (on some server: http, ftp) +3. local file (from your computer) + +You can add either fixed version (`1.2.8`) or a branch (`master`, `develop`). Branch is updatable. Version is not. + +When adding version from git, it tries to find a tag in form `prefixX.Y.Z` where `X.Y.Z` is version provided and `prefix` is custom prefix on your tags. For example, boost uses `boost-` prefix, some projects use `v` and some use empty prefix. You cannot change `X.Y.Z` delimiters. It's always `.`. So, if you want to add your project, consider changing your tag naming schema for future. + +When adding branch from git, it tries to find a branch with same name in the git repo. + +Types of projects: + +1. library +2. executable +3. root project - an umbrella project which can be downloaded as dependency with all its children. For example, if you write in `dependencies` `pvt.cppan.demo.boost` it will download and compile whole boost. +4. directory - an umbrella project which can not be downloaded as dependency. + +You can specify custom content of `cppan.yml` on AddProjectVersion page. It helps if you're experimenting. + +You can create a permanent `cppan.yml` file in your repository or an archive, so it will be used as input. + +Organizations + +You can add an organization if you are representing one. Then you can add admins (can create, remove projects) and users (can add versions of their projects). + +Organizations will receive two root namespaces: `org` for projects with open source licensed and `com` for proprietary code. Private repositories both for users and orgs probably will be introduced later. + + + + + + + + + + +\chapter*{F.A.Q.} +\addcontentsline{toc}{chapter}{F.A.Q.} + + +Q: What is `org.sw.demo` namespace? + +`org.sw` is a utility SW account and `org.sw.demo` contains many projects, but they're not official. You could use them as a starting point in uploading your packages. And official packages will be in `pub/org.your_name.*` namespace. Also for orgs: `org.boost.*`, `org.google.*`, `org.facebook.*`, `com.ibm.*`. + +Q: Where does sw download/generate stuff? + +By default, in your user home directory. Like `\$HOME/.sw/storage` on *nix or `\%USERPROFILE\%/.sw/storage` on Windows. + +Q: How to change that directory? + +Open `\$HOME/.sw/sw.yml`, add `storage_dir: your/favourite/dir/for/sw`. + +Q: Will be server side open sourced? When? + +Probably yes, later. + + + +\chapter*{TODO} +\addcontentsline{toc}{chapter}{TODO} + +Help is appreciated. + +frontends: lua, python, makefile, c, cmake, angelscript diff --git a/doc/latex/sm.tex b/doc/latex/sm.tex new file mode 100644 index 00000000..41b37987 --- /dev/null +++ b/doc/latex/sm.tex @@ -0,0 +1,71 @@ +% !TEX root = sw.tex +% !TeX spellcheck = en_US + + +\chapter{Software Management} + +\section{Features} + +Goals: + +\begin{enumerate} +\item +Reliability. +\item +Correctness. +\item +Repeatability. +\item +Robustness. +\item +Scalability. +\item +Performance. This one is mostly provided by language of implementation (C++). +\end{enumerate} + +Features: + +\begin{enumerate} +\item +Build System is integrated with Package Manager in one program. This allows us to have more information on both ends. User does not need any external tools except sw itself. +\item +Describe your builds directly in C++(17). +\item +Different frontends. Do not like C++? Write you build configuration in declarative YAML, JSON, Python, LUA and even on good old CMake etc. Currently only basic YAML frontend is implemented. Contributions are welcome. +SW itself is written in modern C++ (C++17). +\item +Easy crosscompilation. +\item +Generators for different IDEs (WIP, contributions are welcome). +\item +Integrations with other tools (CMake etc.). +\end{enumerate} + + + + + + +\section{Package Id} + +\subsection{Path} + +\subsection{Version} + + +\section{Drivers} + +\section{Frontends} + +Main frontend - C++. + +Second frontend - CPPAN (v1) YAML-based frontend. + + +\section{Security} + +SW security is based on GPG digital signatures. + +TBD + + diff --git a/doc/latex/styles.tex b/doc/latex/styles.tex new file mode 100644 index 00000000..b4fce10c --- /dev/null +++ b/doc/latex/styles.tex @@ -0,0 +1,10 @@ +% !TEX root = sw.tex +%% styles.tex -- set styles for: +% chapters +% pages +% footnotes + +%%-------------------------------------------------- +%% set section numbering limit, toc limit +\maxsecnumdepth{subparagraph} +\setcounter{tocdepth}{5} diff --git a/doc/latex/sw.tex b/doc/latex/sw.tex new file mode 100644 index 00000000..a7ad0043 --- /dev/null +++ b/doc/latex/sw.tex @@ -0,0 +1,26 @@ +% !TeX spellcheck = en_US + +%% main file for the SW and Software Management documentation +%% + +%%-------------------------------------------------- +%% basics +\documentclass[a4paper,10pt,oneside,openany,final]{memoir} + +\input{docpackages.tex} +\input{layout.tex} +\input{styles.tex} +\input{macros.tex} + +%%-------------------------------------------------- +\begin{document} + +\input{front.tex} +\tableofcontents + +\input{intro.tex} +\input{sm.tex} +\input{client.tex} +\input{server.tex} + +\end{document} diff --git a/doc/latex/text.tex b/doc/latex/text.tex new file mode 100644 index 00000000..e749314e --- /dev/null +++ b/doc/latex/text.tex @@ -0,0 +1,70 @@ +% !TEX root = sw.tex +% !TeX spellcheck = en_US + +\chapter*{Introduction} + +\section*{This document} + +This document describes a modern approach to software management. +It consists of several chapters which include the new approach itself, documentation for client-side tools and utilities and server-side (website) functionality description. + +License for this documentation is unspecified yet. +% GNU FDL? +% CC? + +\section*{Overview} + +Software Network is a project dedicated to better software management. + +Originally started as a package manager ([CPPAN](https://github.com/cppan/cppan)) to C/C++ languages based on CMake build system, it is evolved to independent set of tools and libraries. +CPPAN or v1 was a playground where different ideas were studied and checked. + +Main user tool is called `sw`. Whole project also may be called as SW. Pronounce it as you like: `[software]` or `[sw]` or `[sv]`. + +\section*{Useful links} + +\begin{enumerate} + +\item +* Website - \url{https://software-network.org/} + +\item +* Download client - \url{https://software-network.org/client/} + +\item +* Command Line Reference \url{https://github.com/SoftwareNetwork/sw/wiki/Command-Line-Reference} + +\item +* Publish a project](https://github.com/SoftwareNetwork/sw/wiki/Publish) + +\item +* Why SW? Check out its [Features](https://github.com/SoftwareNetwork/sw/wiki/Features) + +\item +* F.A.Q.](https://github.com/SoftwareNetwork/sw/wiki/F.A.Q.) + +\item +* History](https://github.com/SoftwareNetwork/sw/wiki/History) + +\item +* About](https://github.com/SoftwareNetwork/sw/wiki/About) + +\end{enumerate} + + + +\chapter{Software Management} + +\section{x} + +\section{x2} + +\chapter{SW client tool} + +\section{Quick Start} + +\section{Command Line Reference} + + + +\chapter{Software Network -- server frontend} diff --git a/doc/readme.md b/doc/readme.md index 1cb325b7..18876dd2 100644 --- a/doc/readme.md +++ b/doc/readme.md @@ -1,32 +1,10 @@ -# [C++ Archive Network (CPPAN)](https://cppan.org/) Documentation +# [Software Network (SW)](https://software-network.org/) Documentation ## Quick Start 1. Download the latest client application, unpack and put it to PATH. -1. (!) Run once `cppan` from any directory without any arguments to perform initial configuration. -1. In your `CMakeLists.txt` write: -``` -find_package(CPPAN REQUIRED) -cppan_add_package( - pvt.cppan.demo.sqlite3 - pvt.cppan.demo.fmt-4 - pvt.cppan.demo.madler.zlib-* - pvt.cppan.demo.boost.asio-1.66 - ... - libs you want to add -) -cppan_execute() - -# near your target -add_executable(myexe ...) -target_link_libraries(myexe - pvt.cppan.demo.sqlite3 - pvt.cppan.demo.madler.zlib - pvt.cppan.demo.boost.asio - ... -) -``` -4. Perform other usual CMake steps. +1. (optional) Run once `sw setup` from any directory to perform extended configuration. Requires administartor rights. +1. Create project config or build script named `sw.cpp`. Report if anything goes wrong with this workflow! @@ -34,35 +12,15 @@ Report if anything goes wrong with this workflow! ### Windows -Make sure you are running the latest Visual Studio (2017), CMake. +Make sure you are running the latest Visual Studio (2017/2019). -1. VS2017 - many setups. -1. VS2017 + CMake + Ninja. +1. VS2017. 2. Clang-cl (6.0+). -3. Clang-cl + Ninja. - -Cygwin poorly tested, slow builds. -Mingw is not tested. -Both in general should work fine. -WSL works fine. ### *nix -On Linux (Ubuntu and Centos) use ninja. Both of clang/gcc works fine. -Make works only with single job. - -Macos tested with different setups also gcc/clang/AppleClang/Xcode. -Xcode and ninja uses multiple jobs. -Make works only with single job. ## More links -- [Getting Started](https://github.com/cppan/cppan/blob/master/doc/getting_started.md) - Running CPPAN client. -- [Config Options](https://github.com/cppan/cppan/blob/master/doc/cppan.yml) - Tuning your dependencies, prepare your project to be added to CPPAN, available config options. -- [Website Usage](https://github.com/cppan/cppan/blob/master/doc/website.md) - Describes basic usage of CPPAN site. -- [Build Definitions](https://github.com/cppan/cppan/blob/master/doc/cpp_definitions.md) - Preprocessor variables you can rely on during CPPAN build. -- [F.A.Q.](https://github.com/cppan/cppan/blob/master/doc/faq.md) -- [Support CPPAN](https://github.com/cppan/cppan/blob/master/doc/support.md) - - +Find more info on [SW Wiki](https://github.com/SoftwareNetwork/sw/wiki) diff --git a/doc/support.md b/doc/support.md index e28d531a..ac007750 100644 --- a/doc/support.md +++ b/doc/support.md @@ -1,25 +1,19 @@ -# Support C++ Archive Network - -Currently CPPAN server exists on my own funds almost for two years already and development goes only in my spare time. - -Feel free to support the project and its development if you like it. - -## Credit card transfers - -### Paypal - -[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=37Q3U359YWRKJ) - -### Yandex - -https://money.yandex.ru/to/410015962212665 - -## Patreon - -https://www.patreon.com/egorpugin - -## Crypto - -- Bitcoin: 1GUsPwLfsjnE6mb1UVXtXkJ5HHkRp9GY2k - - +# Support Software Network + +Currently SW server exists on my own funds almost for three years already and development goes only in my spare time. + +Feel free to support the project and its development if you like it. + +## Credit card transfers + +### Paypal + +[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=37Q3U359YWRKJ) + +### Yandex + +https://money.yandex.ru/to/410015962212665 + + diff --git a/doc/website.md b/doc/website.md deleted file mode 100644 index 3481f603..00000000 --- a/doc/website.md +++ /dev/null @@ -1,41 +0,0 @@ -CPPAN project is located on the https://cppan.org/ site. - -It uses ssl for any interactions, api calls etc. It uses http to send packages (data) to users. But hashsum checks are performed on client side and hashes are trasferred securely. - -On that site you can find projects, organizations, project versions. - -To add your project to CPPAN you have to: - -1. Register (e.g. `cppan` account name). -1. Login -1. Create project. It will be created under your account in `private` - `pvt` root namespace. E.g. `pvt.cppan.my_very_useful_library`. -1. Add project version. - -Project version sources - -1. git repository -2. remote file (on some server: http, ftp) -3. local file (from your computer) - -You can add either fixed version (`1.2.8`) or a branch (`master`, `develop`). Branch is updatable. Version is not. - -When adding version from git, it tries to find a tag in form `prefixX.Y.Z` where `X.Y.Z` is version provided and `prefix` is custom prefix on your tags. For example, boost uses `boost-` prefix, some projects use `v` and some use empty prefix. You cannot change `X.Y.Z` delimiters. It's always `.`. So, if you want to add your project, consider changing your tag naming schema for future. - -When adding branch from git, it tries to find a branch with same name in the git repo. - -Types of projects: - -1. library -2. executable -3. root project - an umbrella project which can be downloaded as dependency with all its children. For example, if you write in `dependencies` `pvt.cppan.demo.boost` it will download and compile whole boost. -4. directory - an umbrella project which can not be downloaded as dependency. - -You can specify custom content of `cppan.yml` on AddProjectVersion page. It helps if you're experimenting. - -You can create a permanent `cppan.yml` file in your repository or an archive, so it will be used as input. - -## Organizations - -You can add an organization if you are representing one. Then you can add admins (can create, remove projects) and users (can add versions of their projects). - -Organizations will receive two root namespaces: `org` for projects with open source licensed and `com` for proprietary code. Private repositories both for users and orgs probably will be introduced later. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index 687384df..00000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,132 +0,0 @@ -# -# cppan -# - -################################################################################ - -if (WIN32) - add_definitions(-D_WIN32_WINNT=0x0601) -endif() - -add_definitions(-DUSE_LOGGER=1) - -# process is still in deps -include_directories(${PROJECT_SOURCE_DIR}/dep/process) - -# for dirs & stamps -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) - -######################################## -# support -######################################## - -file(GLOB common_src "support/*") -set(common_src ${common_src}) -add_library(support ${common_src}) -target_include_directories(support PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/support) - -if (UNIX AND NOT APPLE AND NOT ( - EXISTS "/etc/centos-release" OR - EXISTS "/etc/fedora-release" OR - EXISTS "/etc/arch-release" -)) -target_link_libraries(support backtrace) -endif() -target_link_libraries(support - pvt.cppan.demo.boost.property_tree - pvt.cppan.demo.boost.stacktrace - pvt.egorpugin.primitives.context - pvt.egorpugin.primitives.hash - pvt.egorpugin.primitives.http - pvt.egorpugin.primitives.log - pvt.egorpugin.primitives.lock - pvt.egorpugin.primitives.yaml -) - -######################################## -# common -######################################## - -set(gen_src - ${CMAKE_CURRENT_SOURCE_DIR}/inserts/inserts.cpp.in - ${CMAKE_CURRENT_SOURCE_DIR}/inserts/cppan.h - ${CMAKE_CURRENT_SOURCE_DIR}/inserts/build.cmake - ${CMAKE_CURRENT_SOURCE_DIR}/inserts/functions.cmake - ${CMAKE_CURRENT_SOURCE_DIR}/inserts/generate.cmake - ${CMAKE_CURRENT_SOURCE_DIR}/inserts/exports.cmake - ${CMAKE_CURRENT_SOURCE_DIR}/inserts/header.cmake - ${CMAKE_CURRENT_SOURCE_DIR}/inserts/version.rc.in - ${CMAKE_CURRENT_SOURCE_DIR}/inserts/branch.rc.in - ${CMAKE_CURRENT_SOURCE_DIR}/inserts/CPPANConfig.cmake -) - -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/inserts.cpp - COMMAND pvt.egorpugin.primitives.embedder ${CMAKE_CURRENT_SOURCE_DIR}/inserts/inserts.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/inserts.cpp - DEPENDS pvt.egorpugin.primitives.embedder ${gen_src} - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -) - -add_executable(stamp_genenerator gen/stamp_gen.cpp) -set_property(TARGET stamp_genenerator PROPERTY FOLDER gen) -set(stamp ${CMAKE_CURRENT_BINARY_DIR}/stamp.h.in) -set_source_files_properties(${stamp} PROPERTIES GENERATED True) - -if (NOT CPPAN_TEST OR NOT EXISTS ${stamp} OR 1) -add_custom_target(gen_stamp - COMMAND stamp_genenerator > ${stamp} -) -set_property(TARGET gen_stamp PROPERTY FOLDER gen) -add_dependencies(support gen_stamp) -endif() - -file(GLOB common_src "common/*" "printers/*") -set(common_src ${common_src} - ${CMAKE_CURRENT_BINARY_DIR}/inserts.cpp - ${gen_src} - - ${stamp} -) -add_library(common ${common_src}) - -target_compile_definitions(common - PUBLIC -DVERSION_MAJOR=${VERSION_MAJOR} - PUBLIC -DVERSION_MINOR=${VERSION_MINOR} - PUBLIC -DVERSION_PATCH=${VERSION_PATCH} - PUBLIC -DBUILD_NUMBER=${BUILD_NUMBER} - PUBLIC -DCPPAN_VERSION_STRING="${CPPAN_VERSION_STRING}" - PUBLIC -DCPPAN_CLIENT -) -target_include_directories(common - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/common -) -target_link_libraries(common - support - bazel_parser - extract_comments -) - -target_link_libraries(common - pvt.cppan.demo.sqlite3 - pvt.cppan.demo.fmt - pvt.cppan.demo.mpark.variant - - pvt.egorpugin.primitives.pack - pvt.egorpugin.primitives.date_time - pvt.egorpugin.primitives.executor - pvt.egorpugin.primitives.command - pvt.egorpugin.primitives.win32helpers -) -if (WIN32) -target_link_libraries(common - pvt.cppan.demo.giovannidicanio.winreg -) -endif() - -################################################################################ - -add_subdirectory(bazel) -add_subdirectory(client) -add_subdirectory(comments) - -################################################################################ diff --git a/src/bazel/CMakeLists.txt b/src/bazel/CMakeLists.txt deleted file mode 100644 index 29755161..00000000 --- a/src/bazel/CMakeLists.txt +++ /dev/null @@ -1,58 +0,0 @@ -# -# cppan -# - -################################################################################ - -######################################## -# bazel_parser -######################################## - -if (FLEX_FOUND AND BISON_FOUND) - BISON_TARGET(grammar - "${CMAKE_CURRENT_SOURCE_DIR}/grammar.yy" - "${CMAKE_CURRENT_SOURCE_DIR}/grammar.cpp" - ) - FLEX_TARGET(lexer - "${CMAKE_CURRENT_SOURCE_DIR}/lexer.ll" - "${CMAKE_CURRENT_SOURCE_DIR}/lexer.cpp" - COMPILE_FLAGS "--header-file=${CMAKE_CURRENT_SOURCE_DIR}/lexer.h -L" - ) - ADD_FLEX_BISON_DEPENDENCY(lexer grammar) - - set(parser_src - ${BISON_grammar_OUTPUTS} - ${FLEX_lexer_OUTPUTS} - ${CMAKE_CURRENT_SOURCE_DIR}/lexer.h - ) - set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/lexer.h PROPERTIES GENERATED TRUE) - - set(bazel_parser_src - bazel.cpp - bazel.h - driver.cpp - driver.h - grammar.yy - lexer.ll - ) -else() - file(GLOB parser_src "*") - list(FILTER parser_src EXCLUDE REGEX ".*CMakeLists.txt") -endif() - -add_library(bazel_parser ${parser_src} ${bazel_parser_src}) -target_link_libraries(bazel_parser - common - pvt.cppan.demo.imageworks.pystring -) -set_property(TARGET bazel_parser PROPERTY FOLDER parse) - -######################################## -# bazel_parser_test -######################################## - -add_executable(bazel_parser_test test/test.cpp) -target_link_libraries(bazel_parser_test bazel_parser) -set_property(TARGET bazel_parser_test PROPERTY FOLDER test) - -################################################################################ diff --git a/src/bazel/driver.cpp b/src/bazel/driver.cpp deleted file mode 100644 index fcfb6a0c..00000000 --- a/src/bazel/driver.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "driver.h" - -#include -#include -#include - -// Prevent using because of bug in flex. -#define YY_NO_UNISTD_H 1 -#define YY_DECL 1 -#include -extern yy_bazel::parser::symbol_type ll_bazellex(yyscan_t yyscanner, yy_bazel::location &loc); - -BazelParserDriver::BazelParserDriver() -{ -} - -yy_bazel::parser::symbol_type BazelParserDriver::lex() -{ - auto ret = ll_bazellex(scanner, location); - return ret; -} - -int BazelParserDriver::parse(const std::string &s) -{ - parseMode = Mode::String; - - ll_bazellex_init(&scanner); - ll_bazel_scan_string(s.c_str(), scanner); - auto res = parse(); - ll_bazellex_destroy(scanner); - - return res; -} - -int BazelParserDriver::parse() -{ - yy_bazel::parser parser(*this); - parser.set_debug_level(debug); - int res = parser.parse(); - return res; -} - -void BazelParserDriver::error(const yy_bazel::location &l, const std::string &m) -{ - std::ostringstream ss; - ss << l << " " << m << "\n"; - if (!can_throw) - std::cerr << ss.str(); - else - throw std::runtime_error("Error during bazel parse: " + ss.str()); -} - -void BazelParserDriver::error(const std::string& m) -{ - std::ostringstream ss; - ss << m << "\n"; - if (!can_throw) - std::cerr << ss.str(); - else - throw std::runtime_error("Error during bazel parse: " + ss.str()); -} diff --git a/src/bazel/driver.h b/src/bazel/driver.h deleted file mode 100644 index 67dbcec6..00000000 --- a/src/bazel/driver.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#include "bazel.h" - -#include - -class BazelParserDriver -{ - enum class Mode - { - String, - Tokens, - }; - -public: - bazel::File bazel_file; - bool debug = false; - bool can_throw = true; - - BazelParserDriver(); - - yy_bazel::parser::symbol_type lex(); - int parse(const std::string &s); - - void error(const yy_bazel::location &l, const std::string &m); - void error(const std::string &m); - - // lex & parse -private: - void *scanner; - yy_bazel::location location; - Mode parseMode; - - int parse(); -}; diff --git a/src/bazel/grammar.cpp b/src/bazel/grammar.cpp deleted file mode 100644 index 65438c6b..00000000 --- a/src/bazel/grammar.cpp +++ /dev/null @@ -1,1361 +0,0 @@ -// A Bison parser, made by GNU Bison 3.0.4. - -// Skeleton implementation for Bison LALR(1) parsers in C++ - -// Copyright (C) 2002-2015 Free Software Foundation, Inc. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// As a special exception, you may create a larger work that contains -// part or all of the Bison parser skeleton and distribute that work -// under terms of your choice, so long as that work isn't itself a -// parser generator using the skeleton or a modified version thereof -// as a parser skeleton. Alternatively, if you modify or redistribute -// the parser skeleton itself, you may (at your option) remove this -// special exception, which will cause the skeleton and the resulting -// Bison output files to be licensed under the GNU General Public -// License without this special exception. - -// This special exception was added by the Free Software Foundation in -// version 2.2 of Bison. - -// Take the name prefix into account. -#define yylex yy_bazellex - -// First part of user declarations. - - -#include -#include -#include - -#include "bazel/driver.h" - -#define yylex(p) p.lex() - - - -# ifndef YY_NULLPTR -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULLPTR nullptr -# else -# define YY_NULLPTR 0 -# endif -# endif - -#include "grammar.hpp" - -// User implementation prologue. - - - - -#ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS -# if ENABLE_NLS -# include // FIXME: INFRINGES ON USER NAME SPACE. -# define YY_(msgid) dgettext ("bison-runtime", msgid) -# endif -# endif -# ifndef YY_ -# define YY_(msgid) msgid -# endif -#endif - -#define YYRHSLOC(Rhs, K) ((Rhs)[K].location) -/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. - If N is 0, then set CURRENT to the empty location which ends - the previous symbol: RHS[0] (always defined). */ - -# ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - do \ - if (N) \ - { \ - (Current).begin = YYRHSLOC (Rhs, 1).begin; \ - (Current).end = YYRHSLOC (Rhs, N).end; \ - } \ - else \ - { \ - (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \ - } \ - while (/*CONSTCOND*/ false) -# endif - - -// Suppress unused-variable warnings by "using" E. -#define YYUSE(E) ((void) (E)) - -// Enable debugging if requested. -#if YY_BAZELDEBUG - -// A pseudo ostream that takes yydebug_ into account. -# define YYCDEBUG if (yydebug_) (*yycdebug_) - -# define YY_SYMBOL_PRINT(Title, Symbol) \ - do { \ - if (yydebug_) \ - { \ - *yycdebug_ << Title << ' '; \ - yy_print_ (*yycdebug_, Symbol); \ - *yycdebug_ << std::endl; \ - } \ - } while (false) - -# define YY_REDUCE_PRINT(Rule) \ - do { \ - if (yydebug_) \ - yy_reduce_print_ (Rule); \ - } while (false) - -# define YY_STACK_PRINT() \ - do { \ - if (yydebug_) \ - yystack_print_ (); \ - } while (false) - -#else // !YY_BAZELDEBUG - -# define YYCDEBUG if (false) std::cerr -# define YY_SYMBOL_PRINT(Title, Symbol) YYUSE(Symbol) -# define YY_REDUCE_PRINT(Rule) static_cast(0) -# define YY_STACK_PRINT() static_cast(0) - -#endif // !YY_BAZELDEBUG - -#define yyerrok (yyerrstatus_ = 0) -#define yyclearin (yyla.clear ()) - -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab -#define YYRECOVERING() (!!yyerrstatus_) - - -namespace yy_bazel { - - - /* Return YYSTR after stripping away unnecessary quotes and - backslashes, so that it's suitable for yyerror. The heuristic is - that double-quoting is unnecessary unless the string contains an - apostrophe, a comma, or backslash (other than backslash-backslash). - YYSTR is taken from yytname. */ - std::string - parser::yytnamerr_ (const char *yystr) - { - if (*yystr == '"') - { - std::string yyr = ""; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - // Fall through. - default: - yyr += *yyp; - break; - - case '"': - return yyr; - } - do_not_strip_quotes: ; - } - - return yystr; - } - - - /// Build a parser object. - parser::parser (BazelParserDriver &driver_yyarg) - : -#if YY_BAZELDEBUG - yydebug_ (false), - yycdebug_ (&std::cerr), -#endif - driver (driver_yyarg) - {} - - parser::~parser () - {} - - - /*---------------. - | Symbol types. | - `---------------*/ - - - - // by_state. - inline - parser::by_state::by_state () - : state (empty_state) - {} - - inline - parser::by_state::by_state (const by_state& other) - : state (other.state) - {} - - inline - void - parser::by_state::clear () - { - state = empty_state; - } - - inline - void - parser::by_state::move (by_state& that) - { - state = that.state; - that.clear (); - } - - inline - parser::by_state::by_state (state_type s) - : state (s) - {} - - inline - parser::symbol_number_type - parser::by_state::type_get () const - { - if (state == empty_state) - return empty_symbol; - else - return yystos_[state]; - } - - inline - parser::stack_symbol_type::stack_symbol_type () - {} - - - inline - parser::stack_symbol_type::stack_symbol_type (state_type s, symbol_type& that) - : super_type (s, that.location) - { - switch (that.type_get ()) - { - case 28: // statements - value.move< bazel::File > (that.value); - break; - - case 29: // statement - case 31: // function_call - value.move< bazel::Function > (that.value); - break; - - case 33: // parameter - case 34: // variable_decl - value.move< bazel::Parameter > (that.value); - break; - - case 32: // parameters - value.move< bazel::Parameters > (that.value); - break; - - case 36: // expr - case 37: // tuple - case 42: // array - case 43: // array_contents - case 44: // array_content - value.move< bazel::Values > (that.value); - break; - - case 25: // INTEGER - value.move< int > (that.value); - break; - - case 22: // STRING - case 23: // KEYWORD - case 24: // ID - case 48: // identifier - case 49: // string - case 50: // keyword - value.move< std::string > (that.value); - break; - - default: - break; - } - - // that is emptied. - that.type = empty_symbol; - } - - inline - parser::stack_symbol_type& - parser::stack_symbol_type::operator= (const stack_symbol_type& that) - { - state = that.state; - switch (that.type_get ()) - { - case 28: // statements - value.copy< bazel::File > (that.value); - break; - - case 29: // statement - case 31: // function_call - value.copy< bazel::Function > (that.value); - break; - - case 33: // parameter - case 34: // variable_decl - value.copy< bazel::Parameter > (that.value); - break; - - case 32: // parameters - value.copy< bazel::Parameters > (that.value); - break; - - case 36: // expr - case 37: // tuple - case 42: // array - case 43: // array_contents - case 44: // array_content - value.copy< bazel::Values > (that.value); - break; - - case 25: // INTEGER - value.copy< int > (that.value); - break; - - case 22: // STRING - case 23: // KEYWORD - case 24: // ID - case 48: // identifier - case 49: // string - case 50: // keyword - value.copy< std::string > (that.value); - break; - - default: - break; - } - - location = that.location; - return *this; - } - - - template - inline - void - parser::yy_destroy_ (const char* yymsg, basic_symbol& yysym) const - { - if (yymsg) - YY_SYMBOL_PRINT (yymsg, yysym); - } - -#if YY_BAZELDEBUG - template - void - parser::yy_print_ (std::ostream& yyo, - const basic_symbol& yysym) const - { - std::ostream& yyoutput = yyo; - YYUSE (yyoutput); - symbol_number_type yytype = yysym.type_get (); - // Avoid a (spurious) G++ 4.8 warning about "array subscript is - // below array bounds". - if (yysym.empty ()) - std::abort (); - yyo << (yytype < yyntokens_ ? "token" : "nterm") - << ' ' << yytname_[yytype] << " (" - << yysym.location << ": "; - YYUSE (yytype); - yyo << ')'; - } -#endif - - inline - void - parser::yypush_ (const char* m, state_type s, symbol_type& sym) - { - stack_symbol_type t (s, sym); - yypush_ (m, t); - } - - inline - void - parser::yypush_ (const char* m, stack_symbol_type& s) - { - if (m) - YY_SYMBOL_PRINT (m, s); - yystack_.push (s); - } - - inline - void - parser::yypop_ (unsigned int n) - { - yystack_.pop (n); - } - -#if YY_BAZELDEBUG - std::ostream& - parser::debug_stream () const - { - return *yycdebug_; - } - - void - parser::set_debug_stream (std::ostream& o) - { - yycdebug_ = &o; - } - - - parser::debug_level_type - parser::debug_level () const - { - return yydebug_; - } - - void - parser::set_debug_level (debug_level_type l) - { - yydebug_ = l; - } -#endif // YY_BAZELDEBUG - - inline parser::state_type - parser::yy_lr_goto_state_ (state_type yystate, int yysym) - { - int yyr = yypgoto_[yysym - yyntokens_] + yystate; - if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate) - return yytable_[yyr]; - else - return yydefgoto_[yysym - yyntokens_]; - } - - inline bool - parser::yy_pact_value_is_default_ (int yyvalue) - { - return yyvalue == yypact_ninf_; - } - - inline bool - parser::yy_table_value_is_error_ (int yyvalue) - { - return yyvalue == yytable_ninf_; - } - - int - parser::parse () - { - // State. - int yyn; - /// Length of the RHS of the rule being reduced. - int yylen = 0; - - // Error handling. - int yynerrs_ = 0; - int yyerrstatus_ = 0; - - /// The lookahead symbol. - symbol_type yyla; - - /// The locations where the error started and ended. - stack_symbol_type yyerror_range[3]; - - /// The return value of parse (). - int yyresult; - - // FIXME: This shoud be completely indented. It is not yet to - // avoid gratuitous conflicts when merging into the master branch. - try - { - YYCDEBUG << "Starting parse" << std::endl; - - - /* Initialize the stack. The initial state will be set in - yynewstate, since the latter expects the semantical and the - location values to have been already stored, initialize these - stacks with a primary value. */ - yystack_.clear (); - yypush_ (YY_NULLPTR, 0, yyla); - - // A new symbol was pushed on the stack. - yynewstate: - YYCDEBUG << "Entering state " << yystack_[0].state << std::endl; - - // Accept? - if (yystack_[0].state == yyfinal_) - goto yyacceptlab; - - goto yybackup; - - // Backup. - yybackup: - - // Try to take a decision without lookahead. - yyn = yypact_[yystack_[0].state]; - if (yy_pact_value_is_default_ (yyn)) - goto yydefault; - - // Read a lookahead token. - if (yyla.empty ()) - { - YYCDEBUG << "Reading a token: "; - try - { - symbol_type yylookahead (yylex (driver)); - yyla.move (yylookahead); - } - catch (const syntax_error& yyexc) - { - error (yyexc); - goto yyerrlab1; - } - } - YY_SYMBOL_PRINT ("Next token is", yyla); - - /* If the proper action on seeing token YYLA.TYPE is to reduce or - to detect an error, take that action. */ - yyn += yyla.type_get (); - if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type_get ()) - goto yydefault; - - // Reduce or error. - yyn = yytable_[yyn]; - if (yyn <= 0) - { - if (yy_table_value_is_error_ (yyn)) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } - - // Count tokens shifted since error; after three, turn off error status. - if (yyerrstatus_) - --yyerrstatus_; - - // Shift the lookahead token. - yypush_ ("Shifting", yyn, yyla); - goto yynewstate; - - /*-----------------------------------------------------------. - | yydefault -- do the default action for the current state. | - `-----------------------------------------------------------*/ - yydefault: - yyn = yydefact_[yystack_[0].state]; - if (yyn == 0) - goto yyerrlab; - goto yyreduce; - - /*-----------------------------. - | yyreduce -- Do a reduction. | - `-----------------------------*/ - yyreduce: - yylen = yyr2_[yyn]; - { - stack_symbol_type yylhs; - yylhs.state = yy_lr_goto_state_(yystack_[yylen].state, yyr1_[yyn]); - /* Variants are always initialized to an empty instance of the - correct type. The default '$$ = $1' action is NOT applied - when using variants. */ - switch (yyr1_[yyn]) - { - case 28: // statements - yylhs.value.build< bazel::File > (); - break; - - case 29: // statement - case 31: // function_call - yylhs.value.build< bazel::Function > (); - break; - - case 33: // parameter - case 34: // variable_decl - yylhs.value.build< bazel::Parameter > (); - break; - - case 32: // parameters - yylhs.value.build< bazel::Parameters > (); - break; - - case 36: // expr - case 37: // tuple - case 42: // array - case 43: // array_contents - case 44: // array_content - yylhs.value.build< bazel::Values > (); - break; - - case 25: // INTEGER - yylhs.value.build< int > (); - break; - - case 22: // STRING - case 23: // KEYWORD - case 24: // ID - case 48: // identifier - case 49: // string - case 50: // keyword - yylhs.value.build< std::string > (); - break; - - default: - break; - } - - - // Compute the default @$. - { - slice slice (yystack_, yylen); - YYLLOC_DEFAULT (yylhs.location, slice, yylen); - } - - // Perform the reduction. - YY_REDUCE_PRINT (yyn); - try - { - switch (yyn) - { - case 2: - - { /*driver.bazel_file = $1;*/ } - - break; - - case 3: - - { /*$$.functions.push_back($1);*/ } - - break; - - case 4: - - { - /*$1.functions.push_back($2);*/ - yylhs.value.as< bazel::File > () = std::move(yystack_[1].value.as< bazel::File > ()); - } - - break; - - case 5: - - { - // ? - yylhs.value.as< bazel::Function > ().name = yystack_[0].value.as< bazel::Parameter > ().name; - yylhs.value.as< bazel::Function > ().parameters.push_back(yystack_[0].value.as< bazel::Parameter > ()); - // global vars - driver.bazel_file.parameters[yystack_[0].value.as< bazel::Parameter > ().name] = yystack_[0].value.as< bazel::Parameter > (); - } - - break; - - case 6: - - { /*$$ = $1;*/ } - - break; - - case 7: - - { /*$$ = $1;*/ } - - break; - - case 9: - - { - bazel::Function f; - f.name = yystack_[3].value.as< std::string > (); - f.parameters = yystack_[1].value.as< bazel::Parameters > (); - yylhs.value.as< bazel::Function > () = f; - driver.bazel_file.functions.push_back(f); - } - - break; - - case 10: - - { yylhs.value.as< bazel::Parameters > ().push_back(yystack_[0].value.as< bazel::Parameter > ()); } - - break; - - case 11: - - { yylhs.value.as< bazel::Parameters > ().push_back(yystack_[1].value.as< bazel::Parameter > ()); } - - break; - - case 12: - - { - yystack_[0].value.as< bazel::Parameters > ().push_back(yystack_[2].value.as< bazel::Parameter > ()); - yylhs.value.as< bazel::Parameters > () = std::move(yystack_[0].value.as< bazel::Parameters > ()); - } - - break; - - case 13: - - {} - - break; - - case 14: - - { yylhs.value.as< bazel::Parameter > () = yystack_[0].value.as< bazel::Parameter > (); } - - break; - - case 15: - - { - bazel::Parameter p; - p.values = yystack_[0].value.as< bazel::Values > (); - yylhs.value.as< bazel::Parameter > () = p; - } - - break; - - case 16: - - { - bazel::Parameter p; - p.name = "kv_map"; - yylhs.value.as< bazel::Parameter > () = p; - } - - break; - - case 17: - - { yylhs.value.as< bazel::Parameter > () = bazel::Parameter{ yystack_[2].value.as< std::string > (), yystack_[0].value.as< bazel::Values > () }; } - - break; - - case 18: - - { yylhs.value.as< bazel::Parameter > () = bazel::Parameter{ yystack_[2].value.as< std::string > () }; } - - break; - - case 19: - - {} - - break; - - case 20: - - {} - - break; - - case 21: - - { - bazel::Values v; - v.insert(yystack_[0].value.as< std::string > ()); - yylhs.value.as< bazel::Values > () = v; - } - - break; - - case 22: - - { - bazel::Values v; - v.insert(yystack_[2].value.as< std::string > ()); - yylhs.value.as< bazel::Values > () = v; - } - - break; - - case 23: - - { - bazel::Values v; - v.insert(yystack_[0].value.as< std::string > ()); - yylhs.value.as< bazel::Values > () = v; - } - - break; - - case 24: - - { yylhs.value.as< bazel::Values > () = std::move(yystack_[0].value.as< bazel::Values > ()); } - - break; - - case 25: - - { - yystack_[2].value.as< bazel::Values > ().clear(); - yystack_[2].value.as< bazel::Values > ().insert(yystack_[0].value.as< bazel::Values > ().begin(), yystack_[0].value.as< bazel::Values > ().end()); - yylhs.value.as< bazel::Values > () = std::move(yystack_[2].value.as< bazel::Values > ()); - } - - break; - - case 26: - - { - yystack_[2].value.as< bazel::Values > ().insert(yystack_[0].value.as< bazel::Values > ().begin(), yystack_[0].value.as< bazel::Values > ().end()); - yylhs.value.as< bazel::Values > () = std::move(yystack_[2].value.as< bazel::Values > ()); - } - - break; - - case 27: - - { - bazel::Values v; - //v.insert("fcall"); - yylhs.value.as< bazel::Values > () = v; - //$$ = $1; - } - - break; - - case 29: - - { /*$$ = $1;*/ } - - break; - - case 30: - - { /*$$ = $1;*/ } - - break; - - case 31: - - {} - - break; - - case 40: - - { yylhs.value.as< bazel::Values > () = std::move(yystack_[1].value.as< bazel::Values > ()); } - - break; - - case 42: - - {} - - break; - - case 43: - - { yylhs.value.as< bazel::Values > () = std::move(yystack_[0].value.as< bazel::Values > ()); } - - break; - - case 44: - - { - yystack_[0].value.as< bazel::Values > ().insert(yystack_[2].value.as< bazel::Values > ().begin(), yystack_[2].value.as< bazel::Values > ().end()); - yylhs.value.as< bazel::Values > () = std::move(yystack_[0].value.as< bazel::Values > ()); - } - - break; - - case 45: - - { yylhs.value.as< bazel::Values > () = std::move(yystack_[0].value.as< bazel::Values > ()); } - - break; - - case 50: - - { yylhs.value.as< std::string > () = yystack_[0].value.as< std::string > (); } - - break; - - case 51: - - { yylhs.value.as< std::string > () = yystack_[1].value.as< std::string > (); } - - break; - - case 52: - - { yylhs.value.as< std::string > () = yystack_[0].value.as< std::string > (); } - - break; - - case 53: - - { yylhs.value.as< std::string > () = yystack_[0].value.as< std::string > (); } - - break; - - - - default: - break; - } - } - catch (const syntax_error& yyexc) - { - error (yyexc); - YYERROR; - } - YY_SYMBOL_PRINT ("-> $$ =", yylhs); - yypop_ (yylen); - yylen = 0; - YY_STACK_PRINT (); - - // Shift the result of the reduction. - yypush_ (YY_NULLPTR, yylhs); - } - goto yynewstate; - - /*--------------------------------------. - | yyerrlab -- here on detecting error. | - `--------------------------------------*/ - yyerrlab: - // If not already recovering from an error, report this error. - if (!yyerrstatus_) - { - ++yynerrs_; - error (yyla.location, yysyntax_error_ (yystack_[0].state, yyla)); - } - - - yyerror_range[1].location = yyla.location; - if (yyerrstatus_ == 3) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - // Return failure if at end of input. - if (yyla.type_get () == yyeof_) - YYABORT; - else if (!yyla.empty ()) - { - yy_destroy_ ("Error: discarding", yyla); - yyla.clear (); - } - } - - // Else will try to reuse lookahead token after shifting the error token. - goto yyerrlab1; - - - /*---------------------------------------------------. - | yyerrorlab -- error raised explicitly by YYERROR. | - `---------------------------------------------------*/ - yyerrorlab: - - /* Pacify compilers like GCC when the user code never invokes - YYERROR and the label yyerrorlab therefore never appears in user - code. */ - if (false) - goto yyerrorlab; - yyerror_range[1].location = yystack_[yylen - 1].location; - /* Do not reclaim the symbols of the rule whose action triggered - this YYERROR. */ - yypop_ (yylen); - yylen = 0; - goto yyerrlab1; - - /*-------------------------------------------------------------. - | yyerrlab1 -- common code for both syntax error and YYERROR. | - `-------------------------------------------------------------*/ - yyerrlab1: - yyerrstatus_ = 3; // Each real token shifted decrements this. - { - stack_symbol_type error_token; - for (;;) - { - yyn = yypact_[yystack_[0].state]; - if (!yy_pact_value_is_default_ (yyn)) - { - yyn += yyterror_; - if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_) - { - yyn = yytable_[yyn]; - if (0 < yyn) - break; - } - } - - // Pop the current state because it cannot handle the error token. - if (yystack_.size () == 1) - YYABORT; - - yyerror_range[1].location = yystack_[0].location; - yy_destroy_ ("Error: popping", yystack_[0]); - yypop_ (); - YY_STACK_PRINT (); - } - - yyerror_range[2].location = yyla.location; - YYLLOC_DEFAULT (error_token.location, yyerror_range, 2); - - // Shift the error token. - error_token.state = yyn; - yypush_ ("Shifting", error_token); - } - goto yynewstate; - - // Accept. - yyacceptlab: - yyresult = 0; - goto yyreturn; - - // Abort. - yyabortlab: - yyresult = 1; - goto yyreturn; - - yyreturn: - if (!yyla.empty ()) - yy_destroy_ ("Cleanup: discarding lookahead", yyla); - - /* Do not reclaim the symbols of the rule whose action triggered - this YYABORT or YYACCEPT. */ - yypop_ (yylen); - while (1 < yystack_.size ()) - { - yy_destroy_ ("Cleanup: popping", yystack_[0]); - yypop_ (); - } - - return yyresult; - } - catch (...) - { - YYCDEBUG << "Exception caught: cleaning lookahead and stack" - << std::endl; - // Do not try to display the values of the reclaimed symbols, - // as their printer might throw an exception. - if (!yyla.empty ()) - yy_destroy_ (YY_NULLPTR, yyla); - - while (1 < yystack_.size ()) - { - yy_destroy_ (YY_NULLPTR, yystack_[0]); - yypop_ (); - } - throw; - } - } - - void - parser::error (const syntax_error& yyexc) - { - error (yyexc.location, yyexc.what()); - } - - // Generate an error message. - std::string - parser::yysyntax_error_ (state_type yystate, const symbol_type& yyla) const - { - // Number of reported tokens (one for the "unexpected", one per - // "expected"). - size_t yycount = 0; - // Its maximum. - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - // Arguments of yyformat. - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - - /* There are many possibilities here to consider: - - If this state is a consistent state with a default action, then - the only way this function was invoked is if the default action - is an error action. In that case, don't check for expected - tokens because there are none. - - The only way there can be no lookahead present (in yyla) is - if this state is a consistent state with a default action. - Thus, detecting the absence of a lookahead is sufficient to - determine that there is no unexpected or expected token to - report. In that case, just report a simple "syntax error". - - Don't assume there isn't a lookahead just because this state is - a consistent state with a default action. There might have - been a previous inconsistent state, consistent state with a - non-default action, or user semantic action that manipulated - yyla. (However, yyla is currently not documented for users.) - - Of course, the expected token list depends on states to have - correct lookahead information, and it depends on the parser not - to perform extra reductions after fetching a lookahead from the - scanner and before detecting a syntax error. Thus, state - merging (from LALR or IELR) and default reductions corrupt the - expected token list. However, the list is correct for - canonical LR with one exception: it will still contain any - token that will not be accepted due to an error action in a - later state. - */ - if (!yyla.empty ()) - { - int yytoken = yyla.type_get (); - yyarg[yycount++] = yytname_[yytoken]; - int yyn = yypact_[yystate]; - if (!yy_pact_value_is_default_ (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - // Stay within bounds of both yycheck and yytname. - int yychecklim = yylast_ - yyn + 1; - int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; - for (int yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_ - && !yy_table_value_is_error_ (yytable_[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - break; - } - else - yyarg[yycount++] = yytname_[yyx]; - } - } - } - - char const* yyformat = YY_NULLPTR; - switch (yycount) - { -#define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -#undef YYCASE_ - } - - std::string yyres; - // Argument number. - size_t yyi = 0; - for (char const* yyp = yyformat; *yyp; ++yyp) - if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) - { - yyres += yytnamerr_ (yyarg[yyi++]); - ++yyp; - } - else - yyres += *yyp; - return yyres; - } - - - const signed char parser::yypact_ninf_ = -50; - - const signed char parser::yytable_ninf_ = -14; - - const signed char - parser::yypact_[] = - { - 89, 117, 117, -18, -50, -50, -9, 8, 56, -50, - -50, -50, -50, 27, -50, -50, 5, -50, 117, 6, - 11, 31, 27, 13, 17, 16, 30, 117, -50, -9, - -50, -50, -50, 117, 117, -50, -18, 103, -18, 103, - -4, 117, -50, -50, 117, 117, 51, -50, 27, 27, - 28, 32, 47, 55, -50, 27, -50, -50, 27, -50, - -50, -50, -50, 112, 27, -50, 117, 41, 57, 62, - -50, 80, -50, 27, 27, -50, 32, 117, -50, -50, - 27 - }; - - const unsigned char - parser::yydefact_[] = - { - 0, 32, 42, 0, 52, 53, 50, 0, 0, 3, - 7, 27, 5, 6, 28, 24, 21, 23, 0, 33, - 0, 21, 45, 0, 43, 0, 0, 0, 51, 46, - 1, 2, 4, 0, 0, 41, 0, 13, 0, 0, - 29, 32, 31, 40, 42, 0, 0, 47, 25, 26, - 0, 36, 0, 10, 14, 15, 16, 22, 17, 18, - 30, 34, 44, 0, 19, 48, 0, 0, 37, 0, - 9, 11, 8, 20, 49, 35, 36, 0, 12, 38, - 39 - }; - - const signed char - parser::yypgoto_[] = - { - -50, -50, -50, 69, -50, 1, 14, -50, -34, -50, - -1, -50, 46, 49, 18, -50, -50, 48, -50, 61, - -50, -50, 10, -49, 9 - }; - - const signed char - parser::yydefgoto_[] = - { - -1, 7, 8, 9, 10, 11, 52, 53, 12, 63, - 13, 14, 20, 56, 67, 68, 15, 23, 24, 28, - 29, 35, 21, 17, 18 - }; - - const signed char - parser::yytable_[] = - { - 19, 22, 69, 54, 25, 60, 6, 27, 30, 37, - 16, 33, 41, 26, 34, 38, 42, 40, 16, 5, - 39, 33, 36, 44, 34, 45, 46, 69, 36, 5, - 43, 36, 48, 49, 37, 37, 55, 54, 58, 57, - 19, 38, 33, 22, 64, 34, 50, 16, 26, 36, - 5, 5, 70, 75, 4, 36, 31, 36, 36, 66, - 1, 71, 73, 76, 36, 74, 33, 36, 65, 34, - 55, 77, 2, 36, 5, 3, 80, 32, 4, 5, - 6, 16, 36, 36, 1, 78, -13, 61, 59, 36, - 47, 51, 62, 1, 79, 0, 2, 0, 0, 0, - 0, 0, 4, 5, 6, 2, 0, 1, 3, 0, - 0, 4, 5, 6, 51, 0, 1, 0, 0, 2, - 0, 1, 0, 0, 0, 4, 5, 6, 2, 0, - 0, 0, 72, 2, 4, 5, 6, 0, 0, 4, - 5, 6 - }; - - const signed char - parser::yycheck_[] = - { - 1, 2, 51, 37, 3, 9, 24, 16, 0, 4, - 0, 15, 6, 3, 18, 10, 5, 18, 8, 23, - 15, 15, 13, 6, 18, 9, 27, 76, 19, 23, - 17, 22, 33, 34, 4, 4, 37, 71, 39, 38, - 41, 10, 15, 44, 45, 18, 36, 37, 38, 40, - 23, 23, 5, 12, 22, 46, 0, 48, 49, 50, - 4, 6, 63, 6, 55, 66, 15, 58, 17, 18, - 71, 9, 16, 64, 23, 19, 77, 8, 22, 23, - 24, 71, 73, 74, 4, 71, 6, 41, 39, 80, - 29, 11, 44, 4, 76, -1, 16, -1, -1, -1, - -1, -1, 22, 23, 24, 16, -1, 4, 19, -1, - -1, 22, 23, 24, 11, -1, 4, -1, -1, 16, - -1, 4, -1, -1, -1, 22, 23, 24, 16, -1, - -1, -1, 20, 16, 22, 23, 24, -1, -1, 22, - 23, 24 - }; - - const unsigned char - parser::yystos_[] = - { - 0, 4, 16, 19, 22, 23, 24, 27, 28, 29, - 30, 31, 34, 36, 37, 42, 48, 49, 50, 36, - 38, 48, 36, 43, 44, 31, 48, 16, 45, 46, - 0, 0, 29, 15, 18, 47, 50, 4, 10, 15, - 36, 6, 5, 17, 6, 9, 36, 45, 36, 36, - 48, 11, 32, 33, 34, 36, 39, 31, 36, 39, - 9, 38, 43, 35, 36, 17, 50, 40, 41, 49, - 5, 6, 20, 36, 36, 12, 6, 9, 32, 40, - 36 - }; - - const unsigned char - parser::yyr1_[] = - { - 0, 26, 27, 28, 28, 29, 29, 29, 30, 31, - 32, 32, 32, 33, 33, 33, 33, 34, 34, 35, - 35, 36, 36, 36, 36, 36, 36, 36, 36, 36, - 36, 37, 38, 38, 38, 39, 40, 40, 40, 41, - 42, 42, 43, 43, 43, 44, 45, 45, 46, 47, - 48, 48, 49, 50 - }; - - const unsigned char - parser::yyr2_[] = - { - 0, 2, 2, 1, 2, 1, 1, 1, 5, 4, - 1, 2, 3, 0, 1, 1, 1, 3, 3, 1, - 2, 1, 3, 1, 1, 3, 3, 1, 1, 2, - 3, 3, 0, 1, 3, 3, 0, 1, 3, 3, - 3, 2, 0, 1, 3, 1, 1, 2, 3, 4, - 1, 2, 1, 1 - }; - - - - // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. - // First, the terminals, then, starting at \a yyntokens_, nonterminals. - const char* - const parser::yytname_[] = - { - "\"end of file\"", "error", "$undefined", "ERROR_SYMBOL", "L_BRACKET", - "R_BRACKET", "COMMA", "QUOTE", "SEMICOLON", "COLON", "POINT", - "L_CURLY_BRACKET", "R_CURLY_BRACKET", "SHARP", "R_ARROW", "EQUAL", - "L_SQUARE_BRACKET", "R_SQUARE_BRACKET", "PLUS", "DEF", "END_OF_DEF", - "CLASS", "STRING", "KEYWORD", "ID", "INTEGER", "$accept", "file", - "statements", "statement", "function_def", "function_call", "parameters", - "parameter", "variable_decl", "exprs", "expr", "tuple", "tuple_values", - "kv_map", "kv_map_values", "kv_map_value", "array", "array_contents", - "array_content", "array_subscripts", "array_subscript", "for_op", - "identifier", "string", "keyword", YY_NULLPTR - }; - -#if YY_BAZELDEBUG - const unsigned short int - parser::yyrline_[] = - { - 0, 69, 69, 73, 75, 84, 92, 94, 98, 100, - 110, 112, 114, 122, 123, 125, 131, 139, 141, 145, - 147, 151, 157, 163, 169, 171, 177, 188, 195, 202, - 204, 208, 212, 213, 214, 217, 220, 221, 222, 225, - 228, 230, 234, 235, 237, 244, 248, 249, 252, 255, - 258, 260, 263, 266 - }; - - // Print the state stack on the debug stream. - void - parser::yystack_print_ () - { - *yycdebug_ << "Stack now"; - for (stack_type::const_iterator - i = yystack_.begin (), - i_end = yystack_.end (); - i != i_end; ++i) - *yycdebug_ << ' ' << i->state; - *yycdebug_ << std::endl; - } - - // Report on the debug stream that the rule \a yyrule is going to be reduced. - void - parser::yy_reduce_print_ (int yyrule) - { - unsigned int yylno = yyrline_[yyrule]; - int yynrhs = yyr2_[yyrule]; - // Print the symbols being reduced, and their result. - *yycdebug_ << "Reducing stack by rule " << yyrule - 1 - << " (line " << yylno << "):" << std::endl; - // The symbols being reduced. - for (int yyi = 0; yyi < yynrhs; yyi++) - YY_SYMBOL_PRINT (" $" << yyi + 1 << " =", - yystack_[(yynrhs) - (yyi + 1)]); - } -#endif // YY_BAZELDEBUG - - - -} // yy_bazel - - - - -void yy_bazel::parser::error(const location_type& l, const std::string& m) -{ - driver.error(l, m); -} diff --git a/src/bazel/grammar.hpp b/src/bazel/grammar.hpp deleted file mode 100644 index 771603fe..00000000 --- a/src/bazel/grammar.hpp +++ /dev/null @@ -1,1382 +0,0 @@ -// A Bison parser, made by GNU Bison 3.0.4. - -// Skeleton interface for Bison LALR(1) parsers in C++ - -// Copyright (C) 2002-2015 Free Software Foundation, Inc. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// As a special exception, you may create a larger work that contains -// part or all of the Bison parser skeleton and distribute that work -// under terms of your choice, so long as that work isn't itself a -// parser generator using the skeleton or a modified version thereof -// as a parser skeleton. Alternatively, if you modify or redistribute -// the parser skeleton itself, you may (at your option) remove this -// special exception, which will cause the skeleton and the resulting -// Bison output files to be licensed under the GNU General Public -// License without this special exception. - -// This special exception was added by the Free Software Foundation in -// version 2.2 of Bison. - -/** - ** \file D:/dev/cppan_client/src/bazel/grammar.hpp - ** Define the yy_bazel::parser class. - */ - -// C++ LALR(1) parser skeleton written by Akim Demaille. - -#ifndef YY_YY_BAZEL_D_DEV_CPPAN_CLIENT_SRC_BAZEL_GRAMMAR_HPP_INCLUDED -# define YY_YY_BAZEL_D_DEV_CPPAN_CLIENT_SRC_BAZEL_GRAMMAR_HPP_INCLUDED -// // "%code requires" blocks. - - -#include "bazel/bazel.h" - -class BazelParserDriver; - - - -# include -# include // std::abort -# include -# include -# include -# include -# include "stack.hh" -# include "location.hh" -#include -#ifndef YYASSERT -# include -# define YYASSERT assert -#endif - - -#ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) -# else -# define YY_ATTRIBUTE(Spec) /* empty */ -# endif -#endif - -#ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) -#endif - -#ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) -#endif - -#if !defined _Noreturn \ - && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) -# if defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) -# else -# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) -# endif -#endif - -/* Suppress unused-variable warnings by "using" E. */ -#if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) -#else -# define YYUSE(E) /* empty */ -#endif - -#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ -/* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ - _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ - _Pragma ("GCC diagnostic pop") -#else -# define YY_INITIAL_VALUE(Value) Value -#endif -#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_END -#endif -#ifndef YY_INITIAL_VALUE -# define YY_INITIAL_VALUE(Value) /* Nothing. */ -#endif - -/* Debug traces. */ -#ifndef YY_BAZELDEBUG -# if defined YYDEBUG -#if YYDEBUG -# define YY_BAZELDEBUG 1 -# else -# define YY_BAZELDEBUG 0 -# endif -# else /* ! defined YYDEBUG */ -# define YY_BAZELDEBUG 1 -# endif /* ! defined YYDEBUG */ -#endif /* ! defined YY_BAZELDEBUG */ - - -namespace yy_bazel { - - - - - /// A char[S] buffer to store and retrieve objects. - /// - /// Sort of a variant, but does not keep track of the nature - /// of the stored data, since that knowledge is available - /// via the current state. - template - struct variant - { - /// Type of *this. - typedef variant self_type; - - /// Empty construction. - variant () - : yytypeid_ (YY_NULLPTR) - {} - - /// Construct and fill. - template - variant (const T& t) - : yytypeid_ (&typeid (T)) - { - YYASSERT (sizeof (T) <= S); - new (yyas_ ()) T (t); - } - - /// Destruction, allowed only if empty. - ~variant () - { - YYASSERT (!yytypeid_); - } - - /// Instantiate an empty \a T in here. - template - T& - build () - { - YYASSERT (!yytypeid_); - YYASSERT (sizeof (T) <= S); - yytypeid_ = & typeid (T); - return *new (yyas_ ()) T; - } - - /// Instantiate a \a T in here from \a t. - template - T& - build (const T& t) - { - YYASSERT (!yytypeid_); - YYASSERT (sizeof (T) <= S); - yytypeid_ = & typeid (T); - return *new (yyas_ ()) T (t); - } - - /// Accessor to a built \a T. - template - T& - as () - { - YYASSERT (*yytypeid_ == typeid (T)); - YYASSERT (sizeof (T) <= S); - return *yyas_ (); - } - - /// Const accessor to a built \a T (for %printer). - template - const T& - as () const - { - YYASSERT (*yytypeid_ == typeid (T)); - YYASSERT (sizeof (T) <= S); - return *yyas_ (); - } - - /// Swap the content with \a other, of same type. - /// - /// Both variants must be built beforehand, because swapping the actual - /// data requires reading it (with as()), and this is not possible on - /// unconstructed variants: it would require some dynamic testing, which - /// should not be the variant's responsability. - /// Swapping between built and (possibly) non-built is done with - /// variant::move (). - template - void - swap (self_type& other) - { - YYASSERT (yytypeid_); - YYASSERT (*yytypeid_ == *other.yytypeid_); - std::swap (as (), other.as ()); - } - - /// Move the content of \a other to this. - /// - /// Destroys \a other. - template - void - move (self_type& other) - { - build (); - swap (other); - other.destroy (); - } - - /// Copy the content of \a other to this. - template - void - copy (const self_type& other) - { - build (other.as ()); - } - - /// Destroy the stored \a T. - template - void - destroy () - { - as ().~T (); - yytypeid_ = YY_NULLPTR; - } - - private: - /// Prohibit blind copies. - self_type& operator=(const self_type&); - variant (const self_type&); - - /// Accessor to raw memory as \a T. - template - T* - yyas_ () - { - void *yyp = yybuffer_.yyraw; - return static_cast (yyp); - } - - /// Const accessor to raw memory as \a T. - template - const T* - yyas_ () const - { - const void *yyp = yybuffer_.yyraw; - return static_cast (yyp); - } - - union - { - /// Strongest alignment constraints. - long double yyalign_me; - /// A buffer large enough to store any of the semantic values. - char yyraw[S]; - } yybuffer_; - - /// Whether the content is built: if defined, the name of the stored type. - const std::type_info *yytypeid_; - }; - - - /// A Bison parser. - class parser - { - public: -#ifndef YY_BAZELSTYPE - /// An auxiliary type to compute the largest semantic type. - union union_type - { - // statements - char dummy1[sizeof(bazel::File)]; - - // statement - // function_call - char dummy2[sizeof(bazel::Function)]; - - // parameter - // variable_decl - char dummy3[sizeof(bazel::Parameter)]; - - // parameters - char dummy4[sizeof(bazel::Parameters)]; - - // expr - // tuple - // array - // array_contents - // array_content - char dummy5[sizeof(bazel::Values)]; - - // INTEGER - char dummy6[sizeof(int)]; - - // STRING - // KEYWORD - // ID - // identifier - // string - // keyword - char dummy7[sizeof(std::string)]; -}; - - /// Symbol semantic values. - typedef variant semantic_type; -#else - typedef YY_BAZELSTYPE semantic_type; -#endif - /// Symbol locations. - typedef location location_type; - - /// Syntax errors thrown from user actions. - struct syntax_error : std::runtime_error - { - syntax_error (const location_type& l, const std::string& m); - location_type location; - }; - - /// Tokens. - struct token - { - enum yytokentype - { - EOQ = 0, - ERROR_SYMBOL = 258, - L_BRACKET = 259, - R_BRACKET = 260, - COMMA = 261, - QUOTE = 262, - SEMICOLON = 263, - COLON = 264, - POINT = 265, - L_CURLY_BRACKET = 266, - R_CURLY_BRACKET = 267, - SHARP = 268, - R_ARROW = 269, - EQUAL = 270, - L_SQUARE_BRACKET = 271, - R_SQUARE_BRACKET = 272, - PLUS = 273, - DEF = 274, - END_OF_DEF = 275, - CLASS = 276, - STRING = 277, - KEYWORD = 278, - ID = 279, - INTEGER = 280 - }; - }; - - /// (External) token type, as returned by yylex. - typedef token::yytokentype token_type; - - /// Symbol type: an internal symbol number. - typedef int symbol_number_type; - - /// The symbol type number to denote an empty symbol. - enum { empty_symbol = -2 }; - - /// Internal symbol number for tokens (subsumed by symbol_number_type). - typedef unsigned char token_number_type; - - /// A complete symbol. - /// - /// Expects its Base type to provide access to the symbol type - /// via type_get(). - /// - /// Provide access to semantic value and location. - template - struct basic_symbol : Base - { - /// Alias to Base. - typedef Base super_type; - - /// Default constructor. - basic_symbol (); - - /// Copy constructor. - basic_symbol (const basic_symbol& other); - - /// Constructor for valueless symbols, and symbols from each type. - - basic_symbol (typename Base::kind_type t, const location_type& l); - - basic_symbol (typename Base::kind_type t, const bazel::File v, const location_type& l); - - basic_symbol (typename Base::kind_type t, const bazel::Function v, const location_type& l); - - basic_symbol (typename Base::kind_type t, const bazel::Parameter v, const location_type& l); - - basic_symbol (typename Base::kind_type t, const bazel::Parameters v, const location_type& l); - - basic_symbol (typename Base::kind_type t, const bazel::Values v, const location_type& l); - - basic_symbol (typename Base::kind_type t, const int v, const location_type& l); - - basic_symbol (typename Base::kind_type t, const std::string v, const location_type& l); - - - /// Constructor for symbols with semantic value. - basic_symbol (typename Base::kind_type t, - const semantic_type& v, - const location_type& l); - - /// Destroy the symbol. - ~basic_symbol (); - - /// Destroy contents, and record that is empty. - void clear (); - - /// Whether empty. - bool empty () const; - - /// Destructive move, \a s is emptied into this. - void move (basic_symbol& s); - - /// The semantic value. - semantic_type value; - - /// The location. - location_type location; - - private: - /// Assignment operator. - basic_symbol& operator= (const basic_symbol& other); - }; - - /// Type access provider for token (enum) based symbols. - struct by_type - { - /// Default constructor. - by_type (); - - /// Copy constructor. - by_type (const by_type& other); - - /// The symbol type as needed by the constructor. - typedef token_type kind_type; - - /// Constructor from (external) token numbers. - by_type (kind_type t); - - /// Record that this symbol is empty. - void clear (); - - /// Steal the symbol type from \a that. - void move (by_type& that); - - /// The (internal) type number (corresponding to \a type). - /// \a empty when empty. - symbol_number_type type_get () const; - - /// The token. - token_type token () const; - - /// The symbol type. - /// \a empty_symbol when empty. - /// An int, not token_number_type, to be able to store empty_symbol. - int type; - }; - - /// "External" symbols: returned by the scanner. - typedef basic_symbol symbol_type; - - // Symbol constructors declarations. - static inline - symbol_type - make_EOQ (const location_type& l); - - static inline - symbol_type - make_ERROR_SYMBOL (const location_type& l); - - static inline - symbol_type - make_L_BRACKET (const location_type& l); - - static inline - symbol_type - make_R_BRACKET (const location_type& l); - - static inline - symbol_type - make_COMMA (const location_type& l); - - static inline - symbol_type - make_QUOTE (const location_type& l); - - static inline - symbol_type - make_SEMICOLON (const location_type& l); - - static inline - symbol_type - make_COLON (const location_type& l); - - static inline - symbol_type - make_POINT (const location_type& l); - - static inline - symbol_type - make_L_CURLY_BRACKET (const location_type& l); - - static inline - symbol_type - make_R_CURLY_BRACKET (const location_type& l); - - static inline - symbol_type - make_SHARP (const location_type& l); - - static inline - symbol_type - make_R_ARROW (const location_type& l); - - static inline - symbol_type - make_EQUAL (const location_type& l); - - static inline - symbol_type - make_L_SQUARE_BRACKET (const location_type& l); - - static inline - symbol_type - make_R_SQUARE_BRACKET (const location_type& l); - - static inline - symbol_type - make_PLUS (const location_type& l); - - static inline - symbol_type - make_DEF (const location_type& l); - - static inline - symbol_type - make_END_OF_DEF (const location_type& l); - - static inline - symbol_type - make_CLASS (const location_type& l); - - static inline - symbol_type - make_STRING (const std::string& v, const location_type& l); - - static inline - symbol_type - make_KEYWORD (const std::string& v, const location_type& l); - - static inline - symbol_type - make_ID (const std::string& v, const location_type& l); - - static inline - symbol_type - make_INTEGER (const int& v, const location_type& l); - - - /// Build a parser object. - parser (BazelParserDriver &driver_yyarg); - virtual ~parser (); - - /// Parse. - /// \returns 0 iff parsing succeeded. - virtual int parse (); - -#if YY_BAZELDEBUG - /// The current debugging stream. - std::ostream& debug_stream () const YY_ATTRIBUTE_PURE; - /// Set the current debugging stream. - void set_debug_stream (std::ostream &); - - /// Type for debugging levels. - typedef int debug_level_type; - /// The current debugging level. - debug_level_type debug_level () const YY_ATTRIBUTE_PURE; - /// Set the current debugging level. - void set_debug_level (debug_level_type l); -#endif - - /// Report a syntax error. - /// \param loc where the syntax error is found. - /// \param msg a description of the syntax error. - virtual void error (const location_type& loc, const std::string& msg); - - /// Report a syntax error. - void error (const syntax_error& err); - - private: - /// This class is not copyable. - parser (const parser&); - parser& operator= (const parser&); - - /// State numbers. - typedef int state_type; - - /// Generate an error message. - /// \param yystate the state where the error occurred. - /// \param yyla the lookahead token. - virtual std::string yysyntax_error_ (state_type yystate, - const symbol_type& yyla) const; - - /// Compute post-reduction state. - /// \param yystate the current state - /// \param yysym the nonterminal to push on the stack - state_type yy_lr_goto_state_ (state_type yystate, int yysym); - - /// Whether the given \c yypact_ value indicates a defaulted state. - /// \param yyvalue the value to check - static bool yy_pact_value_is_default_ (int yyvalue); - - /// Whether the given \c yytable_ value indicates a syntax error. - /// \param yyvalue the value to check - static bool yy_table_value_is_error_ (int yyvalue); - - static const signed char yypact_ninf_; - static const signed char yytable_ninf_; - - /// Convert a scanner token number \a t to a symbol number. - static token_number_type yytranslate_ (token_type t); - - // Tables. - // YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - // STATE-NUM. - static const signed char yypact_[]; - - // YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. - // Performed when YYTABLE does not specify something else to do. Zero - // means the default is an error. - static const unsigned char yydefact_[]; - - // YYPGOTO[NTERM-NUM]. - static const signed char yypgoto_[]; - - // YYDEFGOTO[NTERM-NUM]. - static const signed char yydefgoto_[]; - - // YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If - // positive, shift that token. If negative, reduce the rule whose - // number is the opposite. If YYTABLE_NINF, syntax error. - static const signed char yytable_[]; - - static const signed char yycheck_[]; - - // YYSTOS[STATE-NUM] -- The (internal number of the) accessing - // symbol of state STATE-NUM. - static const unsigned char yystos_[]; - - // YYR1[YYN] -- Symbol number of symbol that rule YYN derives. - static const unsigned char yyr1_[]; - - // YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. - static const unsigned char yyr2_[]; - - - /// Convert the symbol name \a n to a form suitable for a diagnostic. - static std::string yytnamerr_ (const char *n); - - - /// For a symbol, its name in clear. - static const char* const yytname_[]; -#if YY_BAZELDEBUG - // YYRLINE[YYN] -- Source line where rule number YYN was defined. - static const unsigned short int yyrline_[]; - /// Report on the debug stream that the rule \a r is going to be reduced. - virtual void yy_reduce_print_ (int r); - /// Print the state stack on the debug stream. - virtual void yystack_print_ (); - - // Debugging. - int yydebug_; - std::ostream* yycdebug_; - - /// \brief Display a symbol type, value and location. - /// \param yyo The output stream. - /// \param yysym The symbol. - template - void yy_print_ (std::ostream& yyo, const basic_symbol& yysym) const; -#endif - - /// \brief Reclaim the memory associated to a symbol. - /// \param yymsg Why this token is reclaimed. - /// If null, print nothing. - /// \param yysym The symbol. - template - void yy_destroy_ (const char* yymsg, basic_symbol& yysym) const; - - private: - /// Type access provider for state based symbols. - struct by_state - { - /// Default constructor. - by_state (); - - /// The symbol type as needed by the constructor. - typedef state_type kind_type; - - /// Constructor. - by_state (kind_type s); - - /// Copy constructor. - by_state (const by_state& other); - - /// Record that this symbol is empty. - void clear (); - - /// Steal the symbol type from \a that. - void move (by_state& that); - - /// The (internal) type number (corresponding to \a state). - /// \a empty_symbol when empty. - symbol_number_type type_get () const; - - /// The state number used to denote an empty symbol. - enum { empty_state = -1 }; - - /// The state. - /// \a empty when empty. - state_type state; - }; - - /// "Internal" symbol: element of the stack. - struct stack_symbol_type : basic_symbol - { - /// Superclass. - typedef basic_symbol super_type; - /// Construct an empty symbol. - stack_symbol_type (); - /// Steal the contents from \a sym to build this. - stack_symbol_type (state_type s, symbol_type& sym); - /// Assignment, needed by push_back. - stack_symbol_type& operator= (const stack_symbol_type& that); - }; - - /// Stack type. - typedef stack stack_type; - - /// The stack. - stack_type yystack_; - - /// Push a new state on the stack. - /// \param m a debug message to display - /// if null, no trace is output. - /// \param s the symbol - /// \warning the contents of \a s.value is stolen. - void yypush_ (const char* m, stack_symbol_type& s); - - /// Push a new look ahead token on the state on the stack. - /// \param m a debug message to display - /// if null, no trace is output. - /// \param s the state - /// \param sym the symbol (for its value and location). - /// \warning the contents of \a s.value is stolen. - void yypush_ (const char* m, state_type s, symbol_type& sym); - - /// Pop \a n symbols the three stacks. - void yypop_ (unsigned int n = 1); - - /// Constants. - enum - { - yyeof_ = 0, - yylast_ = 141, ///< Last index in yytable_. - yynnts_ = 25, ///< Number of nonterminal symbols. - yyfinal_ = 30, ///< Termination state number. - yyterror_ = 1, - yyerrcode_ = 256, - yyntokens_ = 26 ///< Number of tokens. - }; - - - // User arguments. - BazelParserDriver &driver; - }; - - // Symbol number corresponding to token number t. - inline - parser::token_number_type - parser::yytranslate_ (token_type t) - { - static - const token_number_type - translate_table[] = - { - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, - 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, - 25 - }; - const unsigned int user_token_number_max_ = 280; - const token_number_type undef_token_ = 2; - - if (static_cast(t) <= yyeof_) - return yyeof_; - else if (static_cast (t) <= user_token_number_max_) - return translate_table[t]; - else - return undef_token_; - } - - inline - parser::syntax_error::syntax_error (const location_type& l, const std::string& m) - : std::runtime_error (m) - , location (l) - {} - - // basic_symbol. - template - inline - parser::basic_symbol::basic_symbol () - : value () - {} - - template - inline - parser::basic_symbol::basic_symbol (const basic_symbol& other) - : Base (other) - , value () - , location (other.location) - { - switch (other.type_get ()) - { - case 28: // statements - value.copy< bazel::File > (other.value); - break; - - case 29: // statement - case 31: // function_call - value.copy< bazel::Function > (other.value); - break; - - case 33: // parameter - case 34: // variable_decl - value.copy< bazel::Parameter > (other.value); - break; - - case 32: // parameters - value.copy< bazel::Parameters > (other.value); - break; - - case 36: // expr - case 37: // tuple - case 42: // array - case 43: // array_contents - case 44: // array_content - value.copy< bazel::Values > (other.value); - break; - - case 25: // INTEGER - value.copy< int > (other.value); - break; - - case 22: // STRING - case 23: // KEYWORD - case 24: // ID - case 48: // identifier - case 49: // string - case 50: // keyword - value.copy< std::string > (other.value); - break; - - default: - break; - } - - } - - - template - inline - parser::basic_symbol::basic_symbol (typename Base::kind_type t, const semantic_type& v, const location_type& l) - : Base (t) - , value () - , location (l) - { - (void) v; - switch (this->type_get ()) - { - case 28: // statements - value.copy< bazel::File > (v); - break; - - case 29: // statement - case 31: // function_call - value.copy< bazel::Function > (v); - break; - - case 33: // parameter - case 34: // variable_decl - value.copy< bazel::Parameter > (v); - break; - - case 32: // parameters - value.copy< bazel::Parameters > (v); - break; - - case 36: // expr - case 37: // tuple - case 42: // array - case 43: // array_contents - case 44: // array_content - value.copy< bazel::Values > (v); - break; - - case 25: // INTEGER - value.copy< int > (v); - break; - - case 22: // STRING - case 23: // KEYWORD - case 24: // ID - case 48: // identifier - case 49: // string - case 50: // keyword - value.copy< std::string > (v); - break; - - default: - break; - } -} - - - // Implementation of basic_symbol constructor for each type. - - template - parser::basic_symbol::basic_symbol (typename Base::kind_type t, const location_type& l) - : Base (t) - , value () - , location (l) - {} - - template - parser::basic_symbol::basic_symbol (typename Base::kind_type t, const bazel::File v, const location_type& l) - : Base (t) - , value (v) - , location (l) - {} - - template - parser::basic_symbol::basic_symbol (typename Base::kind_type t, const bazel::Function v, const location_type& l) - : Base (t) - , value (v) - , location (l) - {} - - template - parser::basic_symbol::basic_symbol (typename Base::kind_type t, const bazel::Parameter v, const location_type& l) - : Base (t) - , value (v) - , location (l) - {} - - template - parser::basic_symbol::basic_symbol (typename Base::kind_type t, const bazel::Parameters v, const location_type& l) - : Base (t) - , value (v) - , location (l) - {} - - template - parser::basic_symbol::basic_symbol (typename Base::kind_type t, const bazel::Values v, const location_type& l) - : Base (t) - , value (v) - , location (l) - {} - - template - parser::basic_symbol::basic_symbol (typename Base::kind_type t, const int v, const location_type& l) - : Base (t) - , value (v) - , location (l) - {} - - template - parser::basic_symbol::basic_symbol (typename Base::kind_type t, const std::string v, const location_type& l) - : Base (t) - , value (v) - , location (l) - {} - - - template - inline - parser::basic_symbol::~basic_symbol () - { - clear (); - } - - template - inline - void - parser::basic_symbol::clear () - { - // User destructor. - symbol_number_type yytype = this->type_get (); - basic_symbol& yysym = *this; - (void) yysym; - switch (yytype) - { - default: - break; - } - - // Type destructor. - switch (yytype) - { - case 28: // statements - value.template destroy< bazel::File > (); - break; - - case 29: // statement - case 31: // function_call - value.template destroy< bazel::Function > (); - break; - - case 33: // parameter - case 34: // variable_decl - value.template destroy< bazel::Parameter > (); - break; - - case 32: // parameters - value.template destroy< bazel::Parameters > (); - break; - - case 36: // expr - case 37: // tuple - case 42: // array - case 43: // array_contents - case 44: // array_content - value.template destroy< bazel::Values > (); - break; - - case 25: // INTEGER - value.template destroy< int > (); - break; - - case 22: // STRING - case 23: // KEYWORD - case 24: // ID - case 48: // identifier - case 49: // string - case 50: // keyword - value.template destroy< std::string > (); - break; - - default: - break; - } - - Base::clear (); - } - - template - inline - bool - parser::basic_symbol::empty () const - { - return Base::type_get () == empty_symbol; - } - - template - inline - void - parser::basic_symbol::move (basic_symbol& s) - { - super_type::move(s); - switch (this->type_get ()) - { - case 28: // statements - value.move< bazel::File > (s.value); - break; - - case 29: // statement - case 31: // function_call - value.move< bazel::Function > (s.value); - break; - - case 33: // parameter - case 34: // variable_decl - value.move< bazel::Parameter > (s.value); - break; - - case 32: // parameters - value.move< bazel::Parameters > (s.value); - break; - - case 36: // expr - case 37: // tuple - case 42: // array - case 43: // array_contents - case 44: // array_content - value.move< bazel::Values > (s.value); - break; - - case 25: // INTEGER - value.move< int > (s.value); - break; - - case 22: // STRING - case 23: // KEYWORD - case 24: // ID - case 48: // identifier - case 49: // string - case 50: // keyword - value.move< std::string > (s.value); - break; - - default: - break; - } - - location = s.location; - } - - // by_type. - inline - parser::by_type::by_type () - : type (empty_symbol) - {} - - inline - parser::by_type::by_type (const by_type& other) - : type (other.type) - {} - - inline - parser::by_type::by_type (token_type t) - : type (yytranslate_ (t)) - {} - - inline - void - parser::by_type::clear () - { - type = empty_symbol; - } - - inline - void - parser::by_type::move (by_type& that) - { - type = that.type; - that.clear (); - } - - inline - int - parser::by_type::type_get () const - { - return type; - } - - inline - parser::token_type - parser::by_type::token () const - { - // YYTOKNUM[NUM] -- (External) token number corresponding to the - // (internal) symbol number NUM (which must be that of a token). */ - static - const unsigned short int - yytoken_number_[] = - { - 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 279, 280 - }; - return static_cast (yytoken_number_[type]); - } - // Implementation of make_symbol for each symbol type. - parser::symbol_type - parser::make_EOQ (const location_type& l) - { - return symbol_type (token::EOQ, l); - } - - parser::symbol_type - parser::make_ERROR_SYMBOL (const location_type& l) - { - return symbol_type (token::ERROR_SYMBOL, l); - } - - parser::symbol_type - parser::make_L_BRACKET (const location_type& l) - { - return symbol_type (token::L_BRACKET, l); - } - - parser::symbol_type - parser::make_R_BRACKET (const location_type& l) - { - return symbol_type (token::R_BRACKET, l); - } - - parser::symbol_type - parser::make_COMMA (const location_type& l) - { - return symbol_type (token::COMMA, l); - } - - parser::symbol_type - parser::make_QUOTE (const location_type& l) - { - return symbol_type (token::QUOTE, l); - } - - parser::symbol_type - parser::make_SEMICOLON (const location_type& l) - { - return symbol_type (token::SEMICOLON, l); - } - - parser::symbol_type - parser::make_COLON (const location_type& l) - { - return symbol_type (token::COLON, l); - } - - parser::symbol_type - parser::make_POINT (const location_type& l) - { - return symbol_type (token::POINT, l); - } - - parser::symbol_type - parser::make_L_CURLY_BRACKET (const location_type& l) - { - return symbol_type (token::L_CURLY_BRACKET, l); - } - - parser::symbol_type - parser::make_R_CURLY_BRACKET (const location_type& l) - { - return symbol_type (token::R_CURLY_BRACKET, l); - } - - parser::symbol_type - parser::make_SHARP (const location_type& l) - { - return symbol_type (token::SHARP, l); - } - - parser::symbol_type - parser::make_R_ARROW (const location_type& l) - { - return symbol_type (token::R_ARROW, l); - } - - parser::symbol_type - parser::make_EQUAL (const location_type& l) - { - return symbol_type (token::EQUAL, l); - } - - parser::symbol_type - parser::make_L_SQUARE_BRACKET (const location_type& l) - { - return symbol_type (token::L_SQUARE_BRACKET, l); - } - - parser::symbol_type - parser::make_R_SQUARE_BRACKET (const location_type& l) - { - return symbol_type (token::R_SQUARE_BRACKET, l); - } - - parser::symbol_type - parser::make_PLUS (const location_type& l) - { - return symbol_type (token::PLUS, l); - } - - parser::symbol_type - parser::make_DEF (const location_type& l) - { - return symbol_type (token::DEF, l); - } - - parser::symbol_type - parser::make_END_OF_DEF (const location_type& l) - { - return symbol_type (token::END_OF_DEF, l); - } - - parser::symbol_type - parser::make_CLASS (const location_type& l) - { - return symbol_type (token::CLASS, l); - } - - parser::symbol_type - parser::make_STRING (const std::string& v, const location_type& l) - { - return symbol_type (token::STRING, v, l); - } - - parser::symbol_type - parser::make_KEYWORD (const std::string& v, const location_type& l) - { - return symbol_type (token::KEYWORD, v, l); - } - - parser::symbol_type - parser::make_ID (const std::string& v, const location_type& l) - { - return symbol_type (token::ID, v, l); - } - - parser::symbol_type - parser::make_INTEGER (const int& v, const location_type& l) - { - return symbol_type (token::INTEGER, v, l); - } - - - -} // yy_bazel - - - - - -#endif // !YY_YY_BAZEL_D_DEV_CPPAN_CLIENT_SRC_BAZEL_GRAMMAR_HPP_INCLUDED diff --git a/src/bazel/lexer.cpp b/src/bazel/lexer.cpp deleted file mode 100644 index 37435eb7..00000000 --- a/src/bazel/lexer.cpp +++ /dev/null @@ -1,2169 +0,0 @@ -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 3 -#define YY_FLEX_MINOR_VERSION 0 -#define YY_FLEX_SUBMINOR_VERSION 0 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; - -#else - -#if defined(__cplusplus) && __cplusplus >= 199711L -#include -#endif - -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767 - 1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647 - 1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -/* TODO: this is always defined, so inline it */ -#define yyconst const - -#if defined(__GNUC__) && __GNUC__ >= 3 -#define yynoreturn __attribute__((__noreturn__)) -#else -#define yynoreturn -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an - * integer in range [0..255] for use as an array index. - */ -#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) - -/* An opaque pointer. */ -#ifndef YY_TYPEDEF_YY_SCANNER_T -#define YY_TYPEDEF_YY_SCANNER_T -typedef void* yyscan_t; -#endif - -/* For convenience, these vars (plus the bison vars far below) - are macros in the reentrant scanner. */ -#define yyin yyg->yyin_r -#define yyout yyg->yyout_r -#define yyextra yyg->yyextra_r -#define yyleng yyg->yyleng_r -#define yytext yyg->yytext_r -#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) -#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) -#define yy_flex_debug yyg->yy_flex_debug_r - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN yyg->yy_start = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START ((yyg->yy_start - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE ll_bazelrestart(yyin , yyscanner ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires - * access to the local variable yy_act. Since yyless() is a macro, it would break - * existing scanners that call yyless() from OUTSIDE ll_bazellex. - * One obvious solution it to make yy_act a global. I tried that, and saw - * a 5% performance hit in a non-yylineno scanner, because yy_act is - * normally declared as a register variable-- so it is not worth it. - */ - #define YY_LESS_LINENO(n) \ - do { \ - int yyl;\ - for ( yyl = n; yyl < yyleng; ++yyl )\ - if ( yytext[yyl] == '\n' )\ - --yylineno;\ - }while(0) - #define YY_LINENO_REWIND_TO(dst) \ - do {\ - const char *p;\ - for ( p = yy_cp-1; p >= (dst); --p)\ - if ( *p == '\n' )\ - --yylineno;\ - }while(0) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = yyg->yy_hold_char; \ - YY_RESTORE_YY_MORE_OFFSET \ - yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - int yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via ll_bazelrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \ - ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] - -void ll_bazelrestart (FILE *input_file , yyscan_t yyscanner ); -void ll_bazel_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); -YY_BUFFER_STATE ll_bazel_create_buffer (FILE *file,int size , yyscan_t yyscanner ); -void ll_bazel_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner ); -void ll_bazel_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner ); -void ll_bazelpush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); -void ll_bazelpop_buffer_state (yyscan_t yyscanner ); - -static void ll_bazelensure_buffer_stack (yyscan_t yyscanner ); -static void ll_bazel_load_buffer_state (yyscan_t yyscanner ); -static void ll_bazel_init_buffer (YY_BUFFER_STATE b,FILE *file , yyscan_t yyscanner ); - -#define YY_FLUSH_BUFFER ll_bazel_flush_buffer(YY_CURRENT_BUFFER , yyscanner) - -YY_BUFFER_STATE ll_bazel_scan_buffer (char *base,yy_size_t size , yyscan_t yyscanner ); -YY_BUFFER_STATE ll_bazel_scan_string (yyconst char *yy_str , yyscan_t yyscanner ); -YY_BUFFER_STATE ll_bazel_scan_bytes (yyconst char *bytes,int len , yyscan_t yyscanner ); - -void *ll_bazelalloc (yy_size_t , yyscan_t yyscanner ); -void *ll_bazelrealloc (void *,yy_size_t , yyscan_t yyscanner ); -void ll_bazelfree (void * , yyscan_t yyscanner ); - -#define yy_new_buffer ll_bazel_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - ll_bazelensure_buffer_stack (yyscanner); \ - YY_CURRENT_BUFFER_LVALUE = \ - ll_bazel_create_buffer(yyin,YY_BUF_SIZE , yyscanner); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - ll_bazelensure_buffer_stack (yyscanner); \ - YY_CURRENT_BUFFER_LVALUE = \ - ll_bazel_create_buffer(yyin,YY_BUF_SIZE , yyscanner); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ - -#define ll_bazelwrap(yyscanner) (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP - -typedef flex_uint8_t YY_CHAR; - -typedef int yy_state_type; - -#define yytext_ptr yytext_r - -static yy_state_type yy_get_previous_state (yyscan_t yyscanner ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state , yyscan_t yyscanner); -static int yy_get_next_buffer (yyscan_t yyscanner ); -static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - yyg->yytext_ptr = yy_bp; \ -yyleng = (size_t) (yy_cp - yy_bp); \ - yyg->yy_hold_char = *yy_cp; \ - *yy_cp = '\0'; \ - yyg->yy_c_buf_p = yy_cp; - -#define YY_NUM_RULES 26 -#define YY_END_OF_BUFFER 27 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info -{ -flex_int32_t yy_verify; -flex_int32_t yy_nxt; -}; -static yyconst flex_int16_t yy_accept[120] = - { 0, - 0, 0, 0, 0, 27, 25, 3, 5, 4, 25, - 25, 25, 8, 9, 16, 14, 25, 15, 22, 7, - 6, 18, 12, 13, 22, 22, 22, 22, 22, 22, - 22, 22, 22, 22, 22, 22, 22, 22, 22, 10, - 11, 5, 3, 0, 24, 0, 1, 0, 23, 17, - 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, - 22, 22, 22, 20, 22, 22, 22, 22, 22, 22, - 22, 22, 22, 2, 22, 22, 22, 22, 19, 22, - 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, - 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, - - 22, 22, 22, 22, 22, 22, 22, 21, 22, 22, - 22, 22, 22, 22, 22, 22, 22, 22, 0 - } ; - -static yyconst YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 1, 5, 6, 1, 1, 1, 7, 8, - 9, 1, 10, 11, 12, 13, 1, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 15, 16, 1, - 17, 18, 1, 1, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, - 19, 20, 21, 1, 14, 1, 22, 23, 24, 25, - - 26, 27, 28, 29, 30, 14, 31, 32, 33, 34, - 35, 36, 14, 37, 38, 39, 40, 14, 41, 42, - 43, 14, 44, 1, 45, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst YY_CHAR yy_meta[46] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 2, 1, 1, 1, 1, 1, 3, - 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 1, 1 - } ; - -static yyconst flex_int16_t yy_base[124] = - { 0, - 0, 0, 154, 153, 155, 158, 152, 158, 158, 148, - 149, 144, 158, 158, 158, 158, 132, 158, 0, 158, - 158, 158, 158, 158, 12, 112, 16, 122, 15, 19, - 115, 25, 124, 110, 107, 31, 38, 106, 113, 158, - 158, 138, 138, 134, 158, 135, 158, 130, 158, 158, - 0, 111, 97, 108, 111, 98, 34, 32, 41, 97, - 93, 94, 93, 0, 91, 93, 86, 86, 93, 92, - 82, 77, 89, 158, 92, 95, 78, 76, 0, 87, - 87, 86, 87, 88, 76, 85, 72, 83, 67, 70, - 65, 62, 69, 63, 68, 60, 67, 60, 63, 72, - - 56, 67, 52, 64, 52, 62, 48, 0, 52, 46, - 52, 51, 43, 59, 46, 39, 35, 43, 158, 70, - 72, 75, 53 - } ; - -static yyconst flex_int16_t yy_def[124] = - { 0, - 119, 1, 1, 1, 119, 119, 119, 119, 119, 120, - 121, 122, 119, 119, 119, 119, 119, 119, 123, 119, - 119, 119, 119, 119, 123, 123, 123, 123, 123, 123, - 123, 123, 123, 123, 123, 123, 123, 123, 123, 119, - 119, 119, 119, 120, 119, 121, 119, 122, 119, 119, - 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, - 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, - 123, 123, 123, 119, 123, 123, 123, 123, 123, 123, - 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, - 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, - - 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, - 123, 123, 123, 123, 123, 123, 123, 123, 0, 119, - 119, 119, 119 - } ; - -static yyconst flex_int16_t yy_nxt[204] = - { 0, - 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 6, 23, 6, - 24, 25, 26, 27, 28, 29, 30, 31, 19, 32, - 19, 33, 19, 34, 35, 36, 37, 19, 38, 19, - 39, 19, 19, 40, 41, 52, 58, 55, 60, 53, - 56, 64, 68, 61, 51, 62, 59, 65, 64, 70, - 79, 80, 64, 71, 82, 64, 83, 69, 64, 81, - 44, 44, 46, 46, 46, 48, 48, 64, 118, 64, - 64, 64, 64, 117, 64, 116, 64, 64, 115, 64, - 64, 114, 113, 112, 111, 110, 109, 108, 64, 107, - - 106, 105, 104, 103, 64, 102, 101, 100, 64, 99, - 64, 98, 64, 64, 97, 96, 95, 94, 93, 64, - 92, 91, 90, 89, 64, 88, 87, 86, 85, 64, - 84, 78, 77, 76, 75, 64, 49, 47, 45, 43, - 74, 73, 72, 64, 67, 66, 63, 57, 54, 50, - 49, 47, 45, 43, 119, 42, 42, 5, 119, 119, - 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, - 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, - 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, - 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, - - 119, 119, 119 - } ; - -static yyconst flex_int16_t yy_chk[204] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 25, 29, 27, 30, 25, - 27, 32, 36, 30, 123, 30, 29, 32, 32, 37, - 57, 58, 32, 37, 59, 57, 59, 36, 118, 58, - 120, 120, 121, 121, 121, 122, 122, 117, 116, 115, - 114, 113, 112, 111, 110, 109, 107, 106, 105, 104, - 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, - - 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, - 83, 82, 81, 80, 78, 77, 76, 75, 73, 72, - 71, 70, 69, 68, 67, 66, 65, 63, 62, 61, - 60, 56, 55, 54, 53, 52, 48, 46, 44, 43, - 42, 39, 38, 35, 34, 33, 31, 28, 26, 17, - 12, 11, 10, 7, 5, 4, 3, 119, 119, 119, - 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, - 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, - 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, - 119, 119, 119, 119, 119, 119, 119, 119, 119, 119, - - 119, 119, 119 - } ; - -/* Table of booleans, true if rule could match eol. */ -static yyconst flex_int32_t yy_rule_can_match_eol[27] = - { 0, -1, -1, -0, -0, -1, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, - - 0, -0, -0, -1, -1, -0, -0, - }; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -#pragma warning(disable: 4005) -#include - -#include "bazel/grammar.hpp" - -#define YY_USER_ACTION loc.columns(yyleng); - -#define YY_DECL yy_bazel::parser::symbol_type ll_bazellex(yyscan_t yyscanner,yy_bazel::location &loc) - -#define MAKE(x) yy_bazel::parser::make_ ## x(loc) -#define MAKE_VALUE(x, v) yy_bazel::parser::make_ ## x((v), loc) -#define YY_NO_UNISTD_H 1 - -#define INITIAL 0 -#define IN_FUNCTION 1 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#ifndef WIN32 -#include -#endif -#endif - -#ifdef WIN32 -#include -#define fileno _fileno -#define isatty _isatty -#define read _read -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -/* Holds the entire state of the reentrant scanner. */ -struct yyguts_t - { - - /* User-defined. Not touched by flex. */ - YY_EXTRA_TYPE yyextra_r; - - /* The rest are the same as the globals declared in the non-reentrant scanner. */ - FILE *yyin_r, *yyout_r; - size_t yy_buffer_stack_top; /**< index of top of stack. */ - size_t yy_buffer_stack_max; /**< capacity of stack. */ - YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ - char yy_hold_char; - int yy_n_chars; - int yyleng_r; - char *yy_c_buf_p; - int yy_init; - int yy_start; - int yy_did_buffer_switch_on_eof; - int yy_start_stack_ptr; - int yy_start_stack_depth; - int *yy_start_stack; - yy_state_type yy_last_accepting_state; - char* yy_last_accepting_cpos; - - int yylineno_r; - int yy_flex_debug_r; - - char *yytext_r; - int yy_more_flag; - int yy_more_len; - - }; /* end struct yyguts_t */ - -static int yy_init_globals (yyscan_t yyscanner ); - -int ll_bazellex_init (yyscan_t* scanner); - -int ll_bazellex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int ll_bazellex_destroy (yyscan_t yyscanner ); - -int ll_bazelget_debug (yyscan_t yyscanner ); - -void ll_bazelset_debug (int debug_flag , yyscan_t yyscanner ); - -YY_EXTRA_TYPE ll_bazelget_extra (yyscan_t yyscanner ); - -void ll_bazelset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner ); - -FILE *ll_bazelget_in (yyscan_t yyscanner ); - -void ll_bazelset_in (FILE * _in_str , yyscan_t yyscanner ); - -FILE *ll_bazelget_out (yyscan_t yyscanner ); - -void ll_bazelset_out (FILE * _out_str , yyscan_t yyscanner ); - - int ll_bazelget_leng (yyscan_t yyscanner ); - -char *ll_bazelget_text (yyscan_t yyscanner ); - -int ll_bazelget_lineno (yyscan_t yyscanner ); - -void ll_bazelset_lineno (int _line_number , yyscan_t yyscanner ); - -int ll_bazelget_column (yyscan_t yyscanner ); - -void ll_bazelset_column (int _column_no , yyscan_t yyscanner ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int ll_bazelwrap (yyscan_t yyscanner ); -#else -extern int ll_bazelwrap (yyscan_t yyscanner ); -#endif -#endif - -#ifndef YY_NO_UNPUT - -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int , yyscan_t yyscanner); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * , yyscan_t yyscanner); -#endif - -#ifndef YY_NO_INPUT - -#ifdef __cplusplus -static int yyinput (yyscan_t yyscanner ); -#else -static int input (yyscan_t yyscanner ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - int n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int ll_bazellex (yyscan_t yyscanner); - -#define YY_DECL int ll_bazellex (yyscan_t yyscanner) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; -#endif - -#define YY_RULE_SETUP \ -YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if ( !yyg->yy_init ) - { - yyg->yy_init = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! yyg->yy_start ) - yyg->yy_start = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - ll_bazelensure_buffer_stack (yyscanner); - YY_CURRENT_BUFFER_LVALUE = - ll_bazel_create_buffer(yyin,YY_BUF_SIZE , yyscanner); - } - - ll_bazel_load_buffer_state(yyscanner ); - } - - { - - // Code run each time ll_bazellex is called. - loc.step(); - - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ - { - yy_cp = yyg->yy_c_buf_p; - - /* Support of yytext. */ - *yy_cp = yyg->yy_hold_char; - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - -yy_current_state = yyg->yy_start; -yy_match: -do -{ -YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; -if ( yy_accept[yy_current_state] ) -{ -yyg->yy_last_accepting_state = yy_current_state; -yyg->yy_last_accepting_cpos = yy_cp; -} -while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) -{ -yy_current_state = (int) yy_def[yy_current_state]; -if ( yy_current_state >= 120 ) -yy_c = yy_meta[yy_c]; -} -yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; -++yy_cp; -} -while ( yy_current_state != 119 ); -yy_cp = yyg->yy_last_accepting_cpos; -yy_current_state = yyg->yy_last_accepting_state; - -yy_find_action: -yy_act = yy_accept[yy_current_state]; - - YY_DO_BEFORE_ACTION; - -if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) -{ -int yyl; -for ( yyl = 0; yyl < yyleng; ++yyl ) -if ( yytext[yyl] == '\n' ) - - do{ yylineno++; - yycolumn=0; - }while(0) -; -} - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ -case 0: /* must back up */ -/* undo the effects of YY_DO_BEFORE_ACTION */ -*yy_cp = yyg->yy_hold_char; -yy_cp = yyg->yy_last_accepting_cpos; -yy_current_state = yyg->yy_last_accepting_state; -goto yy_find_action; - -case 1: -/* rule 1 can match eol */ -*yy_cp = yyg->yy_hold_char; /* undo effects of setting up yytext */ -YY_LINENO_REWIND_TO(yy_cp - 1); -yyg->yy_c_buf_p = yy_cp -= 1; -YY_DO_BEFORE_ACTION; /* set up yytext again */ -YY_RULE_SETUP -// ignore comments - YY_BREAK -case 2: -/* rule 2 can match eol */ -YY_RULE_SETUP -{ - loc.lines(yyleng); - loc.step(); - BEGIN(0); - return MAKE(END_OF_DEF); - } - YY_BREAK -case 3: -YY_RULE_SETUP -loc.step(); - YY_BREAK -case 4: -YY_RULE_SETUP -loc.step(); - YY_BREAK -case 5: -/* rule 5 can match eol */ -YY_RULE_SETUP -{ - loc.lines(yyleng); - loc.step(); - } - YY_BREAK -case 6: -YY_RULE_SETUP -return MAKE(SEMICOLON); - YY_BREAK -case 7: -YY_RULE_SETUP -return MAKE(COLON); - YY_BREAK -case 8: -YY_RULE_SETUP -return MAKE(L_BRACKET); - YY_BREAK -case 9: -YY_RULE_SETUP -return MAKE(R_BRACKET); - YY_BREAK -case 10: -YY_RULE_SETUP -return MAKE(L_CURLY_BRACKET); - YY_BREAK -case 11: -YY_RULE_SETUP -return MAKE(R_CURLY_BRACKET); - YY_BREAK -case 12: -YY_RULE_SETUP -return MAKE(L_SQUARE_BRACKET); - YY_BREAK -case 13: -YY_RULE_SETUP -return MAKE(R_SQUARE_BRACKET); - YY_BREAK -case 14: -YY_RULE_SETUP -return MAKE(COMMA); - YY_BREAK -case 15: -YY_RULE_SETUP -return MAKE(POINT); - YY_BREAK -case 16: -YY_RULE_SETUP -return MAKE(PLUS); - YY_BREAK -case 17: -YY_RULE_SETUP -return MAKE(R_ARROW); - YY_BREAK -case 18: -YY_RULE_SETUP -return MAKE(EQUAL); - YY_BREAK -case 19: -YY_RULE_SETUP -BEGIN(IN_FUNCTION); return MAKE(DEF); - YY_BREAK -case 20: -YY_RULE_SETUP -return MAKE_VALUE(KEYWORD, yytext); - YY_BREAK -case 21: -YY_RULE_SETUP -return MAKE(CLASS); - YY_BREAK -case 22: -YY_RULE_SETUP -return MAKE_VALUE(ID, yytext); - YY_BREAK -case 23: -/* rule 23 can match eol */ -case 24: -/* rule 24 can match eol */ -YY_RULE_SETUP -return MAKE_VALUE(STRING, yytext); - YY_BREAK -case 25: -YY_RULE_SETUP -{ /*driver.error(loc, "invalid character");*/ return MAKE(ERROR_SYMBOL); } - YY_BREAK -case YY_STATE_EOF(INITIAL): -case YY_STATE_EOF(IN_FUNCTION): -return MAKE(EOQ); - YY_BREAK -case 26: -YY_RULE_SETUP -ECHO; - YY_BREAK - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = yyg->yy_hold_char; - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * ll_bazellex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( yyscanner ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner); - - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++yyg->yy_c_buf_p; - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { -yy_cp = yyg->yy_last_accepting_cpos; -yy_current_state = yyg->yy_last_accepting_state; - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( yyscanner ) ) - { - case EOB_ACT_END_OF_FILE: - { - yyg->yy_did_buffer_switch_on_eof = 0; - - if ( ll_bazelwrap(yyscanner ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! yyg->yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - yyg->yy_c_buf_p = - yyg->yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( yyscanner ); - - yy_cp = yyg->yy_c_buf_p; - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - yyg->yy_c_buf_p = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; - - yy_current_state = yy_get_previous_state( yyscanner ); - - yy_cp = yyg->yy_c_buf_p; - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ -} /* end of ll_bazellex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = yyg->yytext_ptr; - int number_to_move, i; - int ret_val; - - if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1); - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; - - else - { - int num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) (yyg->yy_c_buf_p - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - int new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - ll_bazelrealloc((void *) b->yy_ch_buf,(yy_size_t) (b->yy_buf_size + 2) , yyscanner ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = NULL; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - yyg->yy_n_chars, num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - if ( yyg->yy_n_chars == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - ll_bazelrestart(yyin , yyscanner); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) ll_bazelrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,(yy_size_t) new_size , yyscanner ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } - - yyg->yy_n_chars += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - - yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (yyscan_t yyscanner) -{ - yy_state_type yy_current_state; - char *yy_cp; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - -yy_current_state = yyg->yy_start; - - for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) - { -YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); -if ( yy_accept[yy_current_state] ) -{ -yyg->yy_last_accepting_state = yy_current_state; -yyg->yy_last_accepting_cpos = yy_cp; -} -while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) -{ -yy_current_state = (int) yy_def[yy_current_state]; -if ( yy_current_state >= 120 ) -yy_c = yy_meta[yy_c]; -} -yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) -{ - int yy_is_jam; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ -char *yy_cp = yyg->yy_c_buf_p; - -YY_CHAR yy_c = 1; -if ( yy_accept[yy_current_state] ) -{ -yyg->yy_last_accepting_state = yy_current_state; -yyg->yy_last_accepting_cpos = yy_cp; -} -while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) -{ -yy_current_state = (int) yy_def[yy_current_state]; -if ( yy_current_state >= 120 ) -yy_c = yy_meta[yy_c]; -} -yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; -yy_is_jam = (yy_current_state == 119); - - (void)yyg; - return yy_is_jam ? 0 : yy_current_state; -} - -#ifndef YY_NO_UNPUT - -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (yyscan_t yyscanner) -#else - static int input (yyscan_t yyscanner) -#endif - -{ - int c; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - *yyg->yy_c_buf_p = yyg->yy_hold_char; - - if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) - /* This was really a NUL. */ - *yyg->yy_c_buf_p = '\0'; - - else - { /* need more input */ - int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr); - ++yyg->yy_c_buf_p; - - switch ( yy_get_next_buffer( yyscanner ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - ll_bazelrestart(yyin , yyscanner); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( ll_bazelwrap(yyscanner ) ) - return 0; - - if ( ! yyg->yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(yyscanner); -#else - return input(yyscanner); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - yyg->yy_c_buf_p = yyg->yytext_ptr + offset; - break; - } - } - } - - c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ - *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ - yyg->yy_hold_char = *++yyg->yy_c_buf_p; - -if ( c == '\n' ) - - do{ yylineno++; - yycolumn=0; - }while(0) -; - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * @param yyscanner The scanner object. - * @note This function does not reset the start condition to @c INITIAL . - */ - void ll_bazelrestart (FILE * input_file , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if ( ! YY_CURRENT_BUFFER ){ - ll_bazelensure_buffer_stack (yyscanner); - YY_CURRENT_BUFFER_LVALUE = - ll_bazel_create_buffer(yyin,YY_BUF_SIZE , yyscanner); - } - - ll_bazel_init_buffer(YY_CURRENT_BUFFER,input_file , yyscanner); - ll_bazel_load_buffer_state(yyscanner ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * @param yyscanner The scanner object. - */ - void ll_bazel_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* TODO. We should be able to replace this entire function body - * with - * ll_bazelpop_buffer_state(); - * ll_bazelpush_buffer_state(new_buffer); - */ - ll_bazelensure_buffer_stack (yyscanner); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *yyg->yy_c_buf_p = yyg->yy_hold_char; - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - ll_bazel_load_buffer_state(yyscanner ); - - /* We don't actually know whether we did this switch during - * EOF (ll_bazelwrap()) processing, but the only time this flag - * is looked at is after ll_bazelwrap() is called, so it's safe - * to go ahead and always set it. - */ - yyg->yy_did_buffer_switch_on_eof = 1; -} - -static void ll_bazel_load_buffer_state (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - yyg->yy_hold_char = *yyg->yy_c_buf_p; -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * @param yyscanner The scanner object. - * @return the allocated buffer state. - */ - YY_BUFFER_STATE ll_bazel_create_buffer (FILE * file, int size , yyscan_t yyscanner) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) ll_bazelalloc(sizeof( struct yy_buffer_state ) , yyscanner ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in ll_bazel_create_buffer()" ); - - b->yy_buf_size = size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) ll_bazelalloc((yy_size_t) (b->yy_buf_size + 2) , yyscanner ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in ll_bazel_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - ll_bazel_init_buffer(b,file , yyscanner); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with ll_bazel_create_buffer() - * @param yyscanner The scanner object. - */ - void ll_bazel_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - ll_bazelfree((void *) b->yy_ch_buf , yyscanner ); - - ll_bazelfree((void *) b , yyscanner ); -} - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a ll_bazelrestart() or at EOF. - */ - static void ll_bazel_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) - -{ - int oerrno = errno; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - ll_bazel_flush_buffer(b , yyscanner); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then ll_bazel_init_buffer was _probably_ - * called from ll_bazelrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = 0; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * @param yyscanner The scanner object. - */ - void ll_bazel_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - ll_bazel_load_buffer_state(yyscanner ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * @param yyscanner The scanner object. - */ -void ll_bazelpush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if (new_buffer == NULL) - return; - - ll_bazelensure_buffer_stack(yyscanner); - - /* This block is copied from ll_bazel_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *yyg->yy_c_buf_p = yyg->yy_hold_char; - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - yyg->yy_buffer_stack_top++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from ll_bazel_switch_to_buffer. */ - ll_bazel_load_buffer_state(yyscanner ); - yyg->yy_did_buffer_switch_on_eof = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * @param yyscanner The scanner object. - */ -void ll_bazelpop_buffer_state (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if (!YY_CURRENT_BUFFER) - return; - - ll_bazel_delete_buffer(YY_CURRENT_BUFFER , yyscanner); - YY_CURRENT_BUFFER_LVALUE = NULL; - if (yyg->yy_buffer_stack_top > 0) - --yyg->yy_buffer_stack_top; - - if (YY_CURRENT_BUFFER) { - ll_bazel_load_buffer_state(yyscanner ); - yyg->yy_did_buffer_switch_on_eof = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void ll_bazelensure_buffer_stack (yyscan_t yyscanner) -{ - yy_size_t num_to_alloc; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if (!yyg->yy_buffer_stack) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - yyg->yy_buffer_stack = (struct yy_buffer_state**)ll_bazelalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - , yyscanner); - if ( ! yyg->yy_buffer_stack ) - YY_FATAL_ERROR( "out of dynamic memory in ll_bazelensure_buffer_stack()" ); - - memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - yyg->yy_buffer_stack_max = num_to_alloc; - yyg->yy_buffer_stack_top = 0; - return; - } - - if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = yyg->yy_buffer_stack_max + grow_size; - yyg->yy_buffer_stack = (struct yy_buffer_state**)ll_bazelrealloc - (yyg->yy_buffer_stack, - num_to_alloc * sizeof(struct yy_buffer_state*) - , yyscanner); - if ( ! yyg->yy_buffer_stack ) - YY_FATAL_ERROR( "out of dynamic memory in ll_bazelensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); - yyg->yy_buffer_stack_max = num_to_alloc; - } -} - -/** Setup the input buffer state to scan directly from a user-specified character buffer. - * @param base the character buffer - * @param size the size in bytes of the character buffer - * @param yyscanner The scanner object. - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE ll_bazel_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return NULL; - - b = (YY_BUFFER_STATE) ll_bazelalloc(sizeof( struct yy_buffer_state ) , yyscanner ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in ll_bazel_scan_buffer()" ); - - b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = NULL; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - ll_bazel_switch_to_buffer(b , yyscanner ); - - return b; -} - -/** Setup the input buffer state to scan a string. The next call to ll_bazellex() will - * scan from a @e copy of @a str. - * @param yystr a NUL-terminated string to scan - * @param yyscanner The scanner object. - * @return the newly allocated buffer state object. - * @note If you want to scan bytes that may contain NUL values, then use - * ll_bazel_scan_bytes() instead. - */ -YY_BUFFER_STATE ll_bazel_scan_string (yyconst char * yystr , yyscan_t yyscanner) -{ - - return ll_bazel_scan_bytes(yystr,(int) strlen(yystr) , yyscanner); -} - -/** Setup the input buffer state to scan the given bytes. The next call to ll_bazellex() will - * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * @param yyscanner The scanner object. - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE ll_bazel_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = (yy_size_t) (_yybytes_len + 2); - buf = (char *) ll_bazelalloc(n , yyscanner ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in ll_bazel_scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = ll_bazel_scan_buffer(buf,n , yyscanner); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in ll_bazel_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = yyg->yy_hold_char; \ - yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ - yyg->yy_hold_char = *yyg->yy_c_buf_p; \ - *yyg->yy_c_buf_p = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the user-defined data for this scanner. - * @param yyscanner The scanner object. - */ -YY_EXTRA_TYPE ll_bazelget_extra (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyextra; -} - -/** Get the current line number. - * @param yyscanner The scanner object. - */ -int ll_bazelget_lineno (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if (! YY_CURRENT_BUFFER) - return 0; - - return yylineno; -} - -/** Get the current column number. - * @param yyscanner The scanner object. - */ -int ll_bazelget_column (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if (! YY_CURRENT_BUFFER) - return 0; - - return yycolumn; -} - -/** Get the input stream. - * @param yyscanner The scanner object. - */ -FILE *ll_bazelget_in (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyin; -} - -/** Get the output stream. - * @param yyscanner The scanner object. - */ -FILE *ll_bazelget_out (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyout; -} - -/** Get the length of the current token. - * @param yyscanner The scanner object. - */ -int ll_bazelget_leng (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyleng; -} - -/** Get the current token. - * @param yyscanner The scanner object. - */ - -char *ll_bazelget_text (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yytext; -} - -/** Set the user-defined data. This data is never touched by the scanner. - * @param user_defined The data to be associated with this scanner. - * @param yyscanner The scanner object. - */ -void ll_bazelset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyextra = user_defined ; -} - -/** Set the current line number. - * @param _line_number line number - * @param yyscanner The scanner object. - */ -void ll_bazelset_lineno (int _line_number , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* lineno is only valid if an input buffer exists. */ - if (! YY_CURRENT_BUFFER ) - YY_FATAL_ERROR( "ll_bazelset_lineno called with no buffer" ); - - yylineno = _line_number; -} - -/** Set the current column. - * @param _column_no column number - * @param yyscanner The scanner object. - */ -void ll_bazelset_column (int _column_no , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* column is only valid if an input buffer exists. */ - if (! YY_CURRENT_BUFFER ) - YY_FATAL_ERROR( "ll_bazelset_column called with no buffer" ); - - yycolumn = _column_no; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param _in_str A readable stream. - * @param yyscanner The scanner object. - * @see ll_bazel_switch_to_buffer - */ -void ll_bazelset_in (FILE * _in_str , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyin = _in_str ; -} - -void ll_bazelset_out (FILE * _out_str , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyout = _out_str ; -} - -int ll_bazelget_debug (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yy_flex_debug; -} - -void ll_bazelset_debug (int _bdebug , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yy_flex_debug = _bdebug ; -} - -/* Accessor methods for yylval and yylloc */ - -/* User-visible API */ - -/* ll_bazellex_init is special because it creates the scanner itself, so it is - * the ONLY reentrant function that doesn't take the scanner as the last argument. - * That's why we explicitly handle the declaration, instead of using our macros. - */ - -int ll_bazellex_init(yyscan_t* ptr_yy_globals) - -{ - if (ptr_yy_globals == NULL){ - errno = EINVAL; - return 1; - } - - *ptr_yy_globals = (yyscan_t) ll_bazelalloc ( sizeof( struct yyguts_t ), NULL ); - - if (*ptr_yy_globals == NULL){ - errno = ENOMEM; - return 1; - } - - /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ - memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); - - return yy_init_globals ( *ptr_yy_globals ); -} - -/* ll_bazellex_init_extra has the same functionality as ll_bazellex_init, but follows the - * convention of taking the scanner as the last argument. Note however, that - * this is a *pointer* to a scanner, as it will be allocated by this call (and - * is the reason, too, why this function also must handle its own declaration). - * The user defined value in the first argument will be available to ll_bazelalloc in - * the yyextra field. - */ - -int ll_bazellex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals ) - -{ - struct yyguts_t dummy_yyguts; - - ll_bazelset_extra (yy_user_defined, &dummy_yyguts); - - if (ptr_yy_globals == NULL){ - errno = EINVAL; - return 1; - } - - *ptr_yy_globals = (yyscan_t) ll_bazelalloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); - - if (*ptr_yy_globals == NULL){ - errno = ENOMEM; - return 1; - } - - /* By setting to 0xAA, we expose bugs in - yy_init_globals. Leave at 0x00 for releases. */ - memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); - - ll_bazelset_extra (yy_user_defined, *ptr_yy_globals); - - return yy_init_globals ( *ptr_yy_globals ); -} - -static int yy_init_globals (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from ll_bazellex_destroy(), so don't allocate here. - */ - - yyg->yy_buffer_stack = NULL; - yyg->yy_buffer_stack_top = 0; - yyg->yy_buffer_stack_max = 0; - yyg->yy_c_buf_p = NULL; - yyg->yy_init = 0; - yyg->yy_start = 0; - - yyg->yy_start_stack_ptr = 0; - yyg->yy_start_stack_depth = 0; - yyg->yy_start_stack = NULL; - -/* Defined in main.c */ -#ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; -#else - yyin = NULL; - yyout = NULL; -#endif - - /* For future reference: Set errno on error, since we are called by - * ll_bazellex_init() - */ - return 0; -} - -/* ll_bazellex_destroy is for both reentrant and non-reentrant scanners. */ -int ll_bazellex_destroy (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - ll_bazel_delete_buffer(YY_CURRENT_BUFFER , yyscanner ); - YY_CURRENT_BUFFER_LVALUE = NULL; - ll_bazelpop_buffer_state(yyscanner); - } - - /* Destroy the stack itself. */ - ll_bazelfree(yyg->yy_buffer_stack , yyscanner); - yyg->yy_buffer_stack = NULL; - - /* Destroy the start condition stack. */ - ll_bazelfree(yyg->yy_start_stack , yyscanner ); - yyg->yy_start_stack = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * ll_bazellex() is called, initialization will occur. */ - yy_init_globals( yyscanner); - - /* Destroy the main struct (reentrant only). */ - ll_bazelfree ( yyscanner , yyscanner ); - yyscanner = NULL; - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - - int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner) -{ - int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *ll_bazelalloc (yy_size_t size , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - return malloc(size); -} - -void *ll_bazelrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return realloc(ptr, size); -} - -void ll_bazelfree (void * ptr , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - free( (char *) ptr ); /* see ll_bazelrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - diff --git a/src/bazel/lexer.h b/src/bazel/lexer.h deleted file mode 100644 index b3baa3f0..00000000 --- a/src/bazel/lexer.h +++ /dev/null @@ -1,344 +0,0 @@ -#ifndef ll_bazelHEADER_H -#define ll_bazelHEADER_H 1 -#define ll_bazelIN_HEADER 1 - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 3 -#define YY_FLEX_MINOR_VERSION 0 -#define YY_FLEX_SUBMINOR_VERSION 0 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; - -#else - -#if defined(__cplusplus) && __cplusplus >= 199711L -#include -#endif - -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767 - 1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647 - 1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -/* TODO: this is always defined, so inline it */ -#define yyconst const - -#if defined(__GNUC__) && __GNUC__ >= 3 -#define yynoreturn __attribute__((__noreturn__)) -#else -#define yynoreturn -#endif - -/* An opaque pointer. */ -#ifndef YY_TYPEDEF_YY_SCANNER_T -#define YY_TYPEDEF_YY_SCANNER_T -typedef void* yyscan_t; -#endif - -/* For convenience, these vars (plus the bison vars far below) - are macros in the reentrant scanner. */ -#define yyin yyg->yyin_r -#define yyout yyg->yyout_r -#define yyextra yyg->yyextra_r -#define yyleng yyg->yyleng_r -#define yytext yyg->yytext_r -#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) -#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) -#define yy_flex_debug yyg->yy_flex_debug_r - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - int yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -void ll_bazelrestart (FILE *input_file , yyscan_t yyscanner ); -void ll_bazel_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); -YY_BUFFER_STATE ll_bazel_create_buffer (FILE *file,int size , yyscan_t yyscanner ); -void ll_bazel_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner ); -void ll_bazel_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner ); -void ll_bazelpush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); -void ll_bazelpop_buffer_state (yyscan_t yyscanner ); - -YY_BUFFER_STATE ll_bazel_scan_buffer (char *base,yy_size_t size , yyscan_t yyscanner ); -YY_BUFFER_STATE ll_bazel_scan_string (yyconst char *yy_str , yyscan_t yyscanner ); -YY_BUFFER_STATE ll_bazel_scan_bytes (yyconst char *bytes,int len , yyscan_t yyscanner ); - -void *ll_bazelalloc (yy_size_t , yyscan_t yyscanner ); -void *ll_bazelrealloc (void *,yy_size_t , yyscan_t yyscanner ); -void ll_bazelfree (void * , yyscan_t yyscanner ); - -/* Begin user sect3 */ - -#define ll_bazelwrap(yyscanner) (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP - -#define yytext_ptr yytext_r - -#ifdef YY_HEADER_EXPORT_START_CONDITIONS -#define INITIAL 0 -#define IN_FUNCTION 1 - -#endif - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#ifndef WIN32 -#include -#endif -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -int ll_bazellex_init (yyscan_t* scanner); - -int ll_bazellex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int ll_bazellex_destroy (yyscan_t yyscanner ); - -int ll_bazelget_debug (yyscan_t yyscanner ); - -void ll_bazelset_debug (int debug_flag , yyscan_t yyscanner ); - -YY_EXTRA_TYPE ll_bazelget_extra (yyscan_t yyscanner ); - -void ll_bazelset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner ); - -FILE *ll_bazelget_in (yyscan_t yyscanner ); - -void ll_bazelset_in (FILE * _in_str , yyscan_t yyscanner ); - -FILE *ll_bazelget_out (yyscan_t yyscanner ); - -void ll_bazelset_out (FILE * _out_str , yyscan_t yyscanner ); - - int ll_bazelget_leng (yyscan_t yyscanner ); - -char *ll_bazelget_text (yyscan_t yyscanner ); - -int ll_bazelget_lineno (yyscan_t yyscanner ); - -void ll_bazelset_lineno (int _line_number , yyscan_t yyscanner ); - -int ll_bazelget_column (yyscan_t yyscanner ); - -void ll_bazelset_column (int _column_no , yyscan_t yyscanner ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int ll_bazelwrap (yyscan_t yyscanner ); -#else -extern int ll_bazelwrap (yyscan_t yyscanner ); -#endif -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int , yyscan_t yyscanner); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * , yyscan_t yyscanner); -#endif - -#ifndef YY_NO_INPUT - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int ll_bazellex (yyscan_t yyscanner); - -#define YY_DECL int ll_bazellex (yyscan_t yyscanner) -#endif /* !YY_DECL */ - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - -#undef YY_NEW_FILE -#undef YY_FLUSH_BUFFER -#undef yy_set_bol -#undef yy_new_buffer -#undef yy_set_interactive -#undef YY_DO_BEFORE_ACTION - -#ifdef YY_DECL_IS_OURS -#undef YY_DECL_IS_OURS -#undef YY_DECL -#endif - -#undef ll_bazelIN_HEADER - -#endif /* ll_bazelHEADER_H */ - diff --git a/src/bazel/location.hh b/src/bazel/location.hh deleted file mode 100644 index cc358a35..00000000 --- a/src/bazel/location.hh +++ /dev/null @@ -1,192 +0,0 @@ -// A Bison parser, made by GNU Bison 3.0.4. - -// Locations for Bison parsers in C++ - -// Copyright (C) 2002-2015 Free Software Foundation, Inc. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// As a special exception, you may create a larger work that contains -// part or all of the Bison parser skeleton and distribute that work -// under terms of your choice, so long as that work isn't itself a -// parser generator using the skeleton or a modified version thereof -// as a parser skeleton. Alternatively, if you modify or redistribute -// the parser skeleton itself, you may (at your option) remove this -// special exception, which will cause the skeleton and the resulting -// Bison output files to be licensed under the GNU General Public -// License without this special exception. - -// This special exception was added by the Free Software Foundation in -// version 2.2 of Bison. - -/** - ** \file D:/dev/cppan_client/src/bazel/location.hh - ** Define the yy_bazel::location class. - */ - -#ifndef YY_YY_BAZEL_D_DEV_CPPAN_CLIENT_SRC_BAZEL_LOCATION_HH_INCLUDED -# define YY_YY_BAZEL_D_DEV_CPPAN_CLIENT_SRC_BAZEL_LOCATION_HH_INCLUDED - -# include "position.hh" - - -namespace yy_bazel { - - /// Abstract a location. - class location - { - public: - - /// Construct a location from \a b to \a e. - location (const position& b, const position& e) - : begin (b) - , end (e) - { - } - - /// Construct a 0-width location in \a p. - explicit location (const position& p = position ()) - : begin (p) - , end (p) - { - } - - /// Construct a 0-width location in \a f, \a l, \a c. - explicit location (std::string* f, - unsigned int l = 1u, - unsigned int c = 1u) - : begin (f, l, c) - , end (f, l, c) - { - } - - - /// Initialization. - void initialize (std::string* f = YY_NULLPTR, - unsigned int l = 1u, - unsigned int c = 1u) - { - begin.initialize (f, l, c); - end = begin; - } - - /** \name Line and Column related manipulators - ** \{ */ - public: - /// Reset initial location to final location. - void step () - { - begin = end; - } - - /// Extend the current location to the COUNT next columns. - void columns (int count = 1) - { - end += count; - } - - /// Extend the current location to the COUNT next lines. - void lines (int count = 1) - { - end.lines (count); - } - /** \} */ - - - public: - /// Beginning of the located region. - position begin; - /// End of the located region. - position end; - }; - - /// Join two locations, in place. - inline location& operator+= (location& res, const location& end) - { - res.end = end.end; - return res; - } - - /// Join two locations. - inline location operator+ (location res, const location& end) - { - return res += end; - } - - /// Add \a width columns to the end position, in place. - inline location& operator+= (location& res, int width) - { - res.columns (width); - return res; - } - - /// Add \a width columns to the end position. - inline location operator+ (location res, int width) - { - return res += width; - } - - /// Subtract \a width columns to the end position, in place. - inline location& operator-= (location& res, int width) - { - return res += -width; - } - - /// Subtract \a width columns to the end position. - inline location operator- (location res, int width) - { - return res -= width; - } - - /// Compare two location objects. - inline bool - operator== (const location& loc1, const location& loc2) - { - return loc1.begin == loc2.begin && loc1.end == loc2.end; - } - - /// Compare two location objects. - inline bool - operator!= (const location& loc1, const location& loc2) - { - return !(loc1 == loc2); - } - - /** \brief Intercept output stream redirection. - ** \param ostr the destination output stream - ** \param loc a reference to the location to redirect - ** - ** Avoid duplicate information. - */ - template - inline std::basic_ostream& - operator<< (std::basic_ostream& ostr, const location& loc) - { - unsigned int end_col = 0 < loc.end.column ? loc.end.column - 1 : 0; - ostr << loc.begin; - if (loc.end.filename - && (!loc.begin.filename - || *loc.begin.filename != *loc.end.filename)) - ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col; - else if (loc.begin.line < loc.end.line) - ostr << '-' << loc.end.line << '.' << end_col; - else if (loc.begin.column < end_col) - ostr << '-' << end_col; - return ostr; - } - - -} // yy_bazel - -#endif // !YY_YY_BAZEL_D_DEV_CPPAN_CLIENT_SRC_BAZEL_LOCATION_HH_INCLUDED diff --git a/src/bazel/position.hh b/src/bazel/position.hh deleted file mode 100644 index 6ecac7ef..00000000 --- a/src/bazel/position.hh +++ /dev/null @@ -1,180 +0,0 @@ -// A Bison parser, made by GNU Bison 3.0.4. - -// Positions for Bison parsers in C++ - -// Copyright (C) 2002-2015 Free Software Foundation, Inc. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// As a special exception, you may create a larger work that contains -// part or all of the Bison parser skeleton and distribute that work -// under terms of your choice, so long as that work isn't itself a -// parser generator using the skeleton or a modified version thereof -// as a parser skeleton. Alternatively, if you modify or redistribute -// the parser skeleton itself, you may (at your option) remove this -// special exception, which will cause the skeleton and the resulting -// Bison output files to be licensed under the GNU General Public -// License without this special exception. - -// This special exception was added by the Free Software Foundation in -// version 2.2 of Bison. - -/** - ** \file D:/dev/cppan_client/src/bazel/position.hh - ** Define the yy_bazel::position class. - */ - -#ifndef YY_YY_BAZEL_D_DEV_CPPAN_CLIENT_SRC_BAZEL_POSITION_HH_INCLUDED -# define YY_YY_BAZEL_D_DEV_CPPAN_CLIENT_SRC_BAZEL_POSITION_HH_INCLUDED - -# include // std::max -# include -# include - -# ifndef YY_NULLPTR -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULLPTR nullptr -# else -# define YY_NULLPTR 0 -# endif -# endif - - -namespace yy_bazel { - - /// Abstract a position. - class position - { - public: - /// Construct a position. - explicit position (std::string* f = YY_NULLPTR, - unsigned int l = 1u, - unsigned int c = 1u) - : filename (f) - , line (l) - , column (c) - { - } - - - /// Initialization. - void initialize (std::string* fn = YY_NULLPTR, - unsigned int l = 1u, - unsigned int c = 1u) - { - filename = fn; - line = l; - column = c; - } - - /** \name Line and Column related manipulators - ** \{ */ - /// (line related) Advance to the COUNT next lines. - void lines (int count = 1) - { - if (count) - { - column = 1u; - line = add_ (line, count, 1); - } - } - - /// (column related) Advance to the COUNT next columns. - void columns (int count = 1) - { - column = add_ (column, count, 1); - } - /** \} */ - - /// File name to which this position refers. - std::string* filename; - /// Current line number. - unsigned int line; - /// Current column number. - unsigned int column; - - private: - /// Compute max(min, lhs+rhs) (provided min <= lhs). - static unsigned int add_ (unsigned int lhs, int rhs, unsigned int min) - { - return (0 < rhs || -static_cast(rhs) < lhs - ? rhs + lhs - : min); - } - }; - - /// Add \a width columns, in place. - inline position& - operator+= (position& res, int width) - { - res.columns (width); - return res; - } - - /// Add \a width columns. - inline position - operator+ (position res, int width) - { - return res += width; - } - - /// Subtract \a width columns, in place. - inline position& - operator-= (position& res, int width) - { - return res += -width; - } - - /// Subtract \a width columns. - inline position - operator- (position res, int width) - { - return res -= width; - } - - /// Compare two position objects. - inline bool - operator== (const position& pos1, const position& pos2) - { - return (pos1.line == pos2.line - && pos1.column == pos2.column - && (pos1.filename == pos2.filename - || (pos1.filename && pos2.filename - && *pos1.filename == *pos2.filename))); - } - - /// Compare two position objects. - inline bool - operator!= (const position& pos1, const position& pos2) - { - return !(pos1 == pos2); - } - - /** \brief Intercept output stream redirection. - ** \param ostr the destination output stream - ** \param pos a reference to the position to redirect - */ - template - inline std::basic_ostream& - operator<< (std::basic_ostream& ostr, const position& pos) - { - if (pos.filename) - ostr << *pos.filename << ':'; - return ostr << pos.line << '.' << pos.column; - } - - -} // yy_bazel - -#endif // !YY_YY_BAZEL_D_DEV_CPPAN_CLIENT_SRC_BAZEL_POSITION_HH_INCLUDED diff --git a/src/bazel/stack.hh b/src/bazel/stack.hh deleted file mode 100644 index 3ed65d01..00000000 --- a/src/bazel/stack.hh +++ /dev/null @@ -1,157 +0,0 @@ -// A Bison parser, made by GNU Bison 3.0.4. - -// Stack handling for Bison parsers in C++ - -// Copyright (C) 2002-2015 Free Software Foundation, Inc. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// As a special exception, you may create a larger work that contains -// part or all of the Bison parser skeleton and distribute that work -// under terms of your choice, so long as that work isn't itself a -// parser generator using the skeleton or a modified version thereof -// as a parser skeleton. Alternatively, if you modify or redistribute -// the parser skeleton itself, you may (at your option) remove this -// special exception, which will cause the skeleton and the resulting -// Bison output files to be licensed under the GNU General Public -// License without this special exception. - -// This special exception was added by the Free Software Foundation in -// version 2.2 of Bison. - -/** - ** \file D:/dev/cppan_client/src/bazel/stack.hh - ** Define the yy_bazel::stack class. - */ - -#ifndef YY_YY_BAZEL_D_DEV_CPPAN_CLIENT_SRC_BAZEL_STACK_HH_INCLUDED -# define YY_YY_BAZEL_D_DEV_CPPAN_CLIENT_SRC_BAZEL_STACK_HH_INCLUDED - -# include - - -namespace yy_bazel { - - template > - class stack - { - public: - // Hide our reversed order. - typedef typename S::reverse_iterator iterator; - typedef typename S::const_reverse_iterator const_iterator; - - stack () - : seq_ () - { - seq_.reserve (200); - } - - stack (unsigned int n) - : seq_ (n) - {} - - inline - T& - operator[] (unsigned int i) - { - return seq_[seq_.size () - 1 - i]; - } - - inline - const T& - operator[] (unsigned int i) const - { - return seq_[seq_.size () - 1 - i]; - } - - /// Steal the contents of \a t. - /// - /// Close to move-semantics. - inline - void - push (T& t) - { - seq_.push_back (T()); - operator[](0).move (t); - } - - inline - void - pop (unsigned int n = 1) - { - for (; n; --n) - seq_.pop_back (); - } - - void - clear () - { - seq_.clear (); - } - - inline - typename S::size_type - size () const - { - return seq_.size (); - } - - inline - const_iterator - begin () const - { - return seq_.rbegin (); - } - - inline - const_iterator - end () const - { - return seq_.rend (); - } - - private: - stack (const stack&); - stack& operator= (const stack&); - /// The wrapped container. - S seq_; - }; - - /// Present a slice of the top of a stack. - template > - class slice - { - public: - slice (const S& stack, unsigned int range) - : stack_ (stack) - , range_ (range) - {} - - inline - const T& - operator [] (unsigned int i) const - { - return stack_[range_ - i]; - } - - private: - const S& stack_; - unsigned int range_; - }; - - -} // yy_bazel - - -#endif // !YY_YY_BAZEL_D_DEV_CPPAN_CLIENT_SRC_BAZEL_STACK_HH_INCLUDED diff --git a/src/bazel/test/test.cpp b/src/bazel/test/test.cpp deleted file mode 100644 index 1be7aa3d..00000000 --- a/src/bazel/test/test.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include -#include - -#include "../driver.h" - -int main(int argc, char *argv[]) -{ - if (argc != 2) - return 1; - - std::string f, s; - std::ifstream ifile(argv[1]); - while (std::getline(ifile, s)) - f += s + "\n"; - - BazelParserDriver driver; - driver.can_throw = false; - //driver.debug = true; - auto ret = driver.parse(f); - - if (ret) - return ret; - - auto bf = driver.bazel_file; - bf.trimQuotes(); - auto files = bf.getFiles("protobuf"); - - bf = bazel::parse(f); - files = bf.getFiles("protobuf"); - files = bf.getFiles("protoc_lib"); - files = bf.getFiles("protobuf_lite"); - files = bf.getFiles("protoc"); - files = bf.getFiles(""); - - return 0; -} diff --git a/src/client/CMakeLists.txt b/src/client/CMakeLists.txt deleted file mode 100644 index 936acc50..00000000 --- a/src/client/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -# -# cppan -# - -######################################## -# cppan -######################################## - -file(GLOB cppan_src "*.cpp" "*.h" "*.rc") - -add_executable(client ${cppan_src}) -target_link_libraries(client common - pvt.cppan.demo.boost.program_options - pvt.cppan.demo.yhirose.cpp_linenoise -) -if (UNIX AND NOT APPLE) -target_link_libraries(client -static-libstdc++ -static-libgcc) -endif() - -if (CPPAN_TEST) -add_custom_command(TARGET client POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $/cppanx${CMAKE_EXECUTABLE_SUFFIX} -) -endif() - -set_target_properties(client PROPERTIES OUTPUT_NAME cppan) -if (WIN32) -set_target_properties(client PROPERTIES OUTPUT_NAME_DEBUG cppand) -endif() - -if (WIN32) -install(TARGETS client RUNTIME - DESTINATION . - COMPONENT client -) -else() -install(TARGETS client RUNTIME - DESTINATION /usr/local/bin - COMPONENT client -) -endif() - -################################################################################ diff --git a/src/client/autotools.h b/src/client/autotools.h deleted file mode 100644 index 686d3adc..00000000 --- a/src/client/autotools.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "filesystem.h" - -void process_configure_ac(const path &p); diff --git a/src/client/fix_imports.cpp b/src/client/fix_imports.cpp deleted file mode 100644 index 7c219bb6..00000000 --- a/src/client/fix_imports.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "fix_imports.h" - -#include -#include -#include - -#include - -#include -#include - -#include -#include -#include -#include - -String fix_imports(const Strings &lines_old, const String &old_target, const String &new_target) -{ - CMakeContext ctx; - ctx.increaseIndent(); - for (auto &line1 : lines_old) - { - auto line = line1; - boost::algorithm::trim(line); - line = line.substr(0, line.find(old_target)) + new_target + line.substr(line.find(old_target) + old_target.size()); - if (line.find("add_library") == 0 || line.find("add_executable") == 0) - boost::algorithm::replace_all(line, "IMPORTED", "IMPORTED GLOBAL"); - ctx.addLine(line); - } - ctx.decreaseIndent(); - ctx.before().addLine("if (NOT TARGET " + new_target + ")"); - ctx.after().addLine("endif()"); - ctx.after().emptyLines(3); - ctx.splitLines(); - return ctx.getText(); -} - -void fix_imports(const String &target, const path &aliases_file, const path &old_file, const path &new_file) -{ - auto s = read_file(old_file); - auto aliases_s = read_file(aliases_file); - auto dep = extractFromString(target); - - if (!new_file.parent_path().empty()) - fs::create_directories(new_file.parent_path()); - boost::nowide::ofstream ofile(new_file.string()); - if (!ofile) - throw std::runtime_error("Cannot open the output file for writing"); - - // finds all inside round brackets () - // also checks that closing bracket ) is not in quotes - String add_library = "(add_library|add_executable|set_property|set_target_properties)\\("; - - Strings lines; - std::regex r(add_library); - std::smatch m; - bool exe = false; - while (std::regex_search(s, m, r)) - { - exe |= m[1].str() == "add_executable"; - - auto b = m[1].first - s.begin(); - auto e = get_end_of_string_block(s, (int)(m.suffix().first - s.begin())); - - lines.push_back(s.substr(b, e - b)); - s = m.suffix(); - } - - // set exe imports only to release binary - // maybe add an option for this behavior later - auto lines_not_exe = lines; - if (exe) - { - String rel_conf = "IMPORTED_LOCATION_RELEASE"; - String confs = "(IMPORTED_LOCATION_DEBUG|IMPORTED_LOCATION_MINSIZEREL|IMPORTED_LOCATION_RELWITHDEBINFO)"; - String rpath = "\\s*(\".*?\")"; - String iloc = confs + rpath; - String release_path; - for (auto &line : lines) - { - if (line.find(rel_conf) != line.npos) - { - r = rel_conf + rpath; - if (std::regex_search(line, m, r)) - { - release_path = m[1].str(); - r = iloc; - for (auto &line2 : lines) - { - if (std::regex_search(line2, m, r)) - { - String t; - t = m.prefix().str(); - t += m[1].str(); - t += " "; - t += release_path; - t += m.suffix().str(); - line2 = t; - } - } - } - else - std::cerr << "Cannot extract file path from IMPORTED_LOCATION_RELEASE\n"; // cannot find std? - break; - } - } - } - - auto fix = [&aliases_s](const auto &lines, const auto &dep) - { - const auto &tgt = dep.target_name_hash; - CMakeContext ctx; - - StringSet aliases; - { - Strings aliasesv; - boost::algorithm::trim(aliases_s); - boost::algorithm::split(aliasesv, aliases_s, boost::is_any_of(";")); - for (auto &a : aliasesv) - boost::algorithm::trim(a); - aliases.insert(aliasesv.begin(), aliasesv.end()); - } - - add_aliases(ctx, dep, true, aliases, [&lines, &tgt](const auto &s, const auto &v) - { - return fix_imports(lines, tgt, s); - }); - - ctx.emptyLines(1); - ctx.splitLines(); - return ctx.getText(); - }; - - CMakeContext ctx; - file_header(ctx, dep); - if (exe) - { - ctx.addLine("if (CPPAN_BUILD_EXECUTABLES_WITH_SAME_CONFIGURATION)"); - ctx.increaseIndent(); - ctx.addLine(fix(lines_not_exe, dep)); - ctx.decreaseIndent(); - ctx.addLine("else()"); - ctx.increaseIndent(); - ctx.addLine(fix(lines, dep)); - ctx.decreaseIndent(); - ctx.addLine("endif()"); - } - else - { - ctx.addLine(fix(lines, dep)); - } - file_footer(ctx, dep); - - ctx.splitLines(); - auto t = ctx.getText(); - boost::replace_all(t, "\r", ""); - ofile << t; -} diff --git a/src/client/fix_imports.h b/src/client/fix_imports.h deleted file mode 100644 index 97393169..00000000 --- a/src/client/fix_imports.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -void fix_imports(const String &target, const path &aliases_file, const path &old_file, const path &new_file); diff --git a/src/client/init.cpp b/src/client/init.cpp deleted file mode 100644 index 1f49cebb..00000000 --- a/src/client/init.cpp +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "build.h" - -#include -#include - -#include - -#include - -using void_f = std::function; - -const String invitation = "> "; - -void completion_callback(const char *s, Strings &completions); - -bool is_y(const String &s) -{ - if (s.empty()) - return false; - return s[0] == 'y' || s[0] == 'Y'; -} - -void readline(String &d) -{ - String s; - std::getline(std::cin, s); - if (!s.empty()) - d = s; -} - -auto read_packages(const String &s) -{ - auto &pdb = getPackagesDatabase(); - auto pkgs = pdb.getMatchingPackages(s); - std::vector spkgs; - spkgs.reserve(pkgs.size()); - for (auto &pkg : pkgs) - spkgs.push_back(pkg.toString()); - return spkgs; -} - -auto read_versions(const String &pkg) -{ - auto &pdb = getPackagesDatabase(); - auto versions = pdb.getVersionsForPackage(pkg); - std::vector spkgs; - spkgs.reserve(versions.size()); - bool has_versions = false; - for (auto &v : versions) - { - spkgs.push_back(pkg + "-" + v.toString()); - if (v.isVersion()) - { - has_versions = true; - v.patch = -1; - spkgs.push_back(pkg + "-" + v.toAnyVersion()); - v.minor = -1; - spkgs.push_back(pkg + "-" + v.toAnyVersion()); - } - } - if (has_versions) - spkgs.push_back(pkg + "-*"); // self, * version - return spkgs; -} - -bool y_n_branch(const String &s, const void_f &yf = void_f(), const void_f &nf = void_f()) -{ - std::cout << s << " (yes/no) [no]: "; - String t; - readline(t); - bool y = is_y(t); - if (y && yf) - yf(); - else if (nf) - nf(); - return y; -} - -void command_init(const Strings &args) -{ - bool script = false; - bool build_project = true; - bool header_only = false; - String project_type = "e"; - String idir; - Project p; - p.name = current_thread_path().filename().string(); - - // interactive mode - if (args.empty()) - { - script = y_n_branch("Create script?"); - std::cout << "Enter project name [" << p.name << "]: "; - readline(p.name); - idir = p.name; - - std::cout << "Enter project type (e - executable, l - library) [" << project_type << "]: "; - readline(project_type); - - if (project_type[0] == 'l') - { - p.type = ProjectType::Library; - - y_n_branch("Header only?", [&] { header_only = true; }); - - std::cout << "Enter include directory name [" << idir << "]: "; - readline(idir); - } - - y_n_branch("Add some dependencies?", [&] - { - std::cout << "Start entering dependency names. Press TAB to list matching packages, ESC to stop.\n"; - - linenoise::SetCompletionCallback(completion_callback); - std::string line; - while (!linenoise::Readline(invitation.c_str(), line)) - { - linenoise::AddHistory(line.c_str()); - try - { - auto d = extractFromString(line); - - // check pkg - if (read_packages(d.ppath.toString()).empty()) - { - std::cout << "No such package.\n"; - continue; - } - - // check version - auto &pdb = getPackagesDatabase(); - auto v = pdb.getExactVersionForPackage(d); - - p.dependencies[d.ppath.toString()] = d; - } - catch (const std::exception &e) - { - if (read_packages(line).size() == 1) - { - std::cout << "Please, enter version after '-' symbol.\n"; - continue; - } - std::cout << e.what() << "\n"; - } - } - linenoise::disableRawMode(0); - }); - } - else - { - // TODO: use program options? - - int i = 0; - - script = args[i++] == "script"; - p.name = args[i++]; - idir = p.name; - project_type = args[i++]; - - if (project_type[0] == 'l' || project_type[0] == 'h') - { - p.type = ProjectType::Library; - idir = args[i++]; - if (project_type[0] == 'h') - header_only = true; - } - - for (; i < (int)args.size(); i++) - { - const auto &line = args[i]; - try - { - auto d = extractFromString(line); - - // check pkg - if (read_packages(d.ppath.toString()).empty()) - { - std::cout << "No such package:" << line << "\n"; - continue; - } - - // check version - auto &pdb = getPackagesDatabase(); - auto v = pdb.getExactVersionForPackage(d); - - p.dependencies[d.ppath.toString()] = d; - } - catch (const std::exception &e) - { - if (read_packages(line).size() == 1) - { - std::cout << "Please, enter version after '-' symbol:" << line << "\n"; - continue; - } - std::cout << e.what() << "\n"; - } - } - - build_project = false; - } - - error_code ec; - auto root = current_thread_path(); - - static const auto err_exist = "File or dir with such name already exist"; - static const auto int_main = "int main(int argc, char **argv)\n{\n return 0;\n}\n"s; - - if (script) - { - auto n = p.name + ".cpp"; - if (fs::exists(root / n)) - throw std::runtime_error(err_exist); - write_file(root / n, "/*\n" + dump_yaml_config(p.save()) + "*/\n\n" + - int_main); - - if (build_project && y_n_branch("Build the project?")) - build(root / n); - } - else - { - Config c; - c.allow_relative_project_names = true; - //c.allow_local_dependencies = true; - - yaml orig; - if (fs::is_regular_file(CPPAN_FILENAME)) - { - orig = load_yaml_config(path(CPPAN_FILENAME)); - c.load(orig); - } - - // checks first - auto &projects = c.getProjects(); - if (projects.find(p.name) != projects.end()) - throw std::runtime_error("Project " + p.name + " already exists in the config"); - - if (fs::exists(root / p.name) || - fs::exists(root / p.name / "src") || - fs::exists(root / p.name / "include") || - fs::exists(root / p.name / "include" / idir) || - fs::exists(root / p.name / "include" / idir / (p.name + ".h")) || - fs::exists(root / p.name / "src" / (p.name + ".cpp")) || - 0) - throw std::runtime_error(err_exist); - - // TODO: add deps includes from hints - // into header? cpp? <- cpp! to hide from users - - // create, no checks - fs::create_directories(root / p.name / "src"); - if (p.type == ProjectType::Library) - { - fs::create_directories(root / p.name / "include" / idir); - write_file(root / p.name / "include" / idir / (p.name + ".h"), "//#include \n\n"); - if (header_only) - write_file(root / p.name / "src" / (p.name + ".cpp"), "#include <" + idir + "/" + p.name + ".h>\n\n"); - } - else - { - write_file(root / p.name / "src" / (p.name + ".cpp"), "//#include \n\n" - + int_main); - } - - p.root_directory = p.name; - - yaml y; - if (!fs::exists(CPPAN_FILENAME)) - { - y = p.save(); - } - else - { - projects[p.name] = p; - y = c.save(); - orig["projects"] = y["projects"]; - y = orig; - } - dump_yaml_config(CPPAN_FILENAME, y); - - if (build_project && y_n_branch("Build the project?")) - build(); - } -} - -void completion_callback(const char *in, Strings &completions) -{ - String s = in; - completions = read_packages(s); - if (completions.empty() && !s.empty()) - { - s.resize(s.size() - 1); - completions = read_packages(s); - } - if (completions.size() == 1) - completions = read_versions(completions[0]); - - std::sort(completions.begin(), completions.end()); - completions.erase(std::unique(completions.begin(), completions.end()), completions.end()); - - std::cout << "\n"; - bool show = true; - if (completions.size() > 50) - { - show = false; - std::cout << "Display all " << completions.size() << " possibilities? (y or n)" << " "; - int c = 0; -#ifdef _WIN32 - linenoise::win32read(&c); -#else - read(0, &c, 1); -#endif - std::cout << "\n"; - show = is_y(s = c); - if (!show) - completions.clear(); - } - if (show) - { - std::ios_base::sync_with_stdio(false); - for (auto &c : completions) - std::cout << c << "\n"; - std::ios_base::sync_with_stdio(true); - } - std::cout << invitation; -} diff --git a/src/client/main.cpp b/src/client/main.cpp deleted file mode 100644 index 3e3ed2bd..00000000 --- a/src/client/main.cpp +++ /dev/null @@ -1,1110 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "build.h" -#include "fix_imports.h" -#include "options.h" -#include "autotools.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -//DECLARE_STATIC_LOGGER(logger, "main"); - -enum class ApiResult -{ - Handled, - NotHandled, - Error, -}; - -ApiResult api_call(const String &cmd, const Strings &args); -void check_spec_file(); -void default_run(); -void init(const Strings &args, const String &log_level); -void load_current_config(); -void self_upgrade(); -void self_upgrade_copy(const path &dst); -optional internal(const Strings &args); -void command_init(const Strings &args); - -int main1(int argc, char *argv[]) -try -{ - // library initializations - setup_utf8_filesystem(); - - // fix arguments - make them UTF-8 - boost::nowide::args wargs(argc, argv); - - // - Strings args; - for (auto i = 0; i < argc; i++) - args.push_back(argv[i]); - - String log_level = "info"; - - // set correct working directory to look for config file - std::unique_ptr cp; - - // do manual checks of critical arguments - { - Strings args_copy = args; - for (size_t i = 1; i < args.size(); i++) - { - // working dir - if (args[i] == "-d"s || args[i] == "--dir"s) - { - if (i + 1 < args.size()) - cp = std::make_unique(args[i + 1], CurrentPathScope::All); - else - throw std::runtime_error("Missing necessary argument for "s + args[i] + " option"); - args_copy.erase(args_copy.begin() + i, args_copy.begin() + i + 2); - } - - // verbosity - if (args[i] == "-v"s || args[i] == "--verbose"s) - { - log_level = "debug"; - args_copy.erase(args_copy.begin() + i, args_copy.begin() + i + 1); - } - if (args[i] == "--trace"s) - { - log_level = "trace"; - args_copy.erase(args_copy.begin() + i, args_copy.begin() + i + 1); - } - - // additional build args - if (args[i] == "--"s) - { - auto &s = Settings::get_user_settings(); - s.additional_build_args.assign(args_copy.begin() + i + 1, args_copy.end()); - args_copy.erase(args_copy.begin() + i, args_copy.end()); - } - - if (args[i] == "--self-upgrade") - { - Settings::get_user_settings().disable_update_checks = true; - } - } - args = args_copy; - } - - // main cppan client init routine - init(args, log_level); - - // default run - if (args.size() == 1) - { - default_run(); - return 0; - } - - // handle internal args - if (auto r = internal(args)) - return r.value(); - - if (args.size() > 1) - { - const auto cmd = args[1]; - - // command selector, always exit inside this if() - if (cmd[0] != '-') - { - if (cmd == "parse-configure-ac") - { - if (args.size() != 3) - { - if (fs::exists("configure.ac")) - { - process_configure_ac("configure.ac"); - return 0; - } - std::cout << "invalid number of arguments\n"; - std::cout << "usage: cppan parse-configure-ac configure.ac\n"; - return 1; - } - process_configure_ac(args[2]); - return 0; - } - - if (cmd == "parse-bazel") - { - void process_bazel(const path &p, const std::string &libname = "cc_library", const std::string &binname = "cc_binary"); - - if (args.size() == 2) - { - for (auto &f : bazel_filenames) - { - if (fs::exists(f)) - { - process_bazel(f); - return 0; - } - } - std::cout << "invalid number of arguments\n"; - std::cout << "usage: cppan parse-bazel BUILD.bazel\n"; - return 1; - } - switch (args.size()) - { - case 3: - process_bazel(args[2]); - break; - case 4: - process_bazel(args[2], args[3]); - break; - case 5: - process_bazel(args[2], args[3], args[4]); - break; - } - return 0; - } - - if (cmd == "list") - { - auto &db = getPackagesDatabase(); - db.listPackages(args.size() > 2 ? args[2] : ""); - return 0; - } - - if (cmd == "init") - { - // this prevents db updating (but not initial dl) during dependency helper - Settings::get_system_settings().can_update_packages_db = false; - getPackagesDatabase(); - - command_init(Strings(args.begin() + 2, args.end())); - return 0; - } - - // api - switch (api_call(cmd, args)) - { - case ApiResult::Handled: - return 0; - case ApiResult::Error: - return 1; - default: - break; - } - - // file/url arg - if (isUrl(cmd)) - return build(cmd); - if (fs::exists(cmd)) - { - if (fs::is_directory(cmd)) - { - ScopedCurrentPath cp(cmd, CurrentPathScope::All); - default_run(); - return 0; - } - if (fs::is_regular_file(cmd)) - return build(cmd); - } - - // maybe we entered a package? - try - { - extractFromString(cmd); - LOG_WARN(logger, "Trying to build as package"); - try - { - return build_package(cmd); - } - catch (const std::exception &e) - { - LOG_ERROR(logger, e.what()); - } - return 1; - } - catch (const std::exception &) - { - } - - std::cout << "unknown command: " << cmd << "\n"; - return 1; - } -#ifdef _WIN32 - else if (args[1] == "--self-upgrade-copy") // remove this very very later (at 0.3.0 - 0.5.0) - { - self_upgrade_copy(args[2]); - return 0; - } -#endif - } - - // pay attention to the priority of arguments - - ProgramOptions options; - bool r = options.parseArgs(args); - - httpSettings.verbose = options["curl-verbose"].as(); - httpSettings.ignore_ssl_checks = options["ignore-ssl-checks"].as(); - - // always first - if (!r || options().count("help")) - { - std::cout << options.printHelp() << "\n"; - return !r; - } - if (options["version"].as()) - { - std::cout << get_program_version_string("cppan") << "\n"; - return 0; - } - - // self-upgrade? - if (options()["self-upgrade"].as()) - { - self_upgrade(); - return 0; - } - - if (options["clear-cache"].as()) - { - CMakePrinter c; - // TODO: provide better way of opening passed storage in args[2] - c.clear_cache(); - return 0; - } - if (options["clear-vars-cache"].as()) - { - Config c; - // TODO: provide better way of opening passed storage in args[2] - c.clear_vars_cache(); - return 0; - } - if (options().count(CLEAN_PACKAGES)) - { - auto fs = CleanTarget::getStrings(); - int flags = 0; - auto opts = options[CLEAN_PACKAGES].as(); - auto pkg = opts[0]; - decltype(opts) opts2; - opts2.assign(opts.begin() + 1, opts.end()); - for (auto &o : opts2) - { - auto i = fs.find(o); - if (i != fs.end()) - flags |= i->second; - else - throw std::runtime_error("No such flag: " + o); - } - if (flags == 0) - flags = CleanTarget::All; - cleanPackages(pkg, flags); - return 0; - } - if (options().count(CLEAN_CONFIGS)) - { - cleanConfigs(options[CLEAN_CONFIGS].as()); - return 0; - } - if (options().count("beautify")) - { - path p = options["beautify"].as(); - auto y = load_yaml_config(p); - dump_yaml_config(p, y); - return 0; - } - if (options().count("beautify-strict")) - { - path p = options["beautify-strict"].as(); - Config c(p); - c.save(p.parent_path()); - return 0; - } - if (options().count("print-cpp")) - { - auto pkg = extractFromString(options["print-cpp"].as()); - Config c(pkg.getDirSrc()); - c.getDefaultProject().pkg = pkg; - std::cout << c.getDefaultProject().print_cpp(); - return 0; - } - if (options().count("print-cpp2")) - { - auto pkg = extractFromString(options["print-cpp2"].as()); - Config c(pkg.getDirSrc()); - c.getDefaultProject().pkg = pkg; - std::cout << c.getDefaultProject().print_cpp2(); - return 0; - } - - Settings::get_user_settings().force_server_query = options()[SERVER_QUERY].as(); - - if (options().count("verify")) - { - verify(options["verify"].as()); - LOG_INFO(logger, "Verified... Ok. Packages are the same."); - return 0; - } - - if (options()["fetch"].as()) - { - Config c; - c.allow_relative_project_names = true; - c.reload("."); - applyVersionToUrl(c.getDefaultProject().source, c.getDefaultProject().pkg.version); - download(c.getDefaultProject().source); - LOG_INFO(logger, "Fetched... Ok."); - return 0; - } - - auto generate = options().count("generate"); - if (options().count("build") || generate) - { - if (generate) - Settings::get_local_settings().generate_only = true; - - auto build_arg = options[generate ? "generate" : "build"].as(); - - if (fs::exists(build_arg) || isUrl(build_arg)) - return build(build_arg, options["config"].as()); - else - { - LOG_WARN(logger, "No such file or directory, trying to build as package"); - try - { - build_package(build_arg, options["settings"].as(), options["config"].as()); - return 0; - } - catch (const std::exception &e) - { - LOG_ERROR(logger, e.what()); - } - return 1; - } - } - if (options().count("build-only")) - { - return build_only(options["build-only"].as(), options["config"].as()); - } - if (options().count(BUILD_PACKAGES)) - { - auto pkgs = options[BUILD_PACKAGES].as(); - for (auto &pkg : pkgs) - { - auto r = build_package(pkg, options["settings"].as(), options["config"].as()); - if (r) - return r; - } - return 0; - } - - auto par = options()["prepare-archive-remote"].as(); - if (options()["prepare-archive"].as() || par) - { - path t = ".cppan/temp"; - Config c; - c.load_current_config(); - Projects &projects = c.getProjects(); - const auto cwd = current_thread_path(); - for (auto &ps : projects) - { - auto &project = ps.second; - - auto p = cwd; - if (par) - { - p = t / unique_path(); - fs::create_directories(p); - current_thread_path(p); - - if (!isValidSourceUrl(project.source)) - throw std::runtime_error("Source is empty"); - - applyVersionToUrl(project.source, project.pkg.version); - download(project.source); - fs::copy_file(cwd / CPPAN_FILENAME, CPPAN_FILENAME, fs::copy_options::overwrite_existing); - } - SCOPE_EXIT - { - if (par) - { - current_thread_path(cwd); - remove_all_from_dir(p); - } - }; - project.findSources(); - String archive_name = make_archive_name(project.pkg.ppath.toString()); - if (!project.writeArchive(fs::absolute(cwd / archive_name))) - throw std::runtime_error("Archive write failed"); - } - return 0; - } - - default_run(); - - return 0; -} -catch (const std::exception &e) -{ - std::cerr << e.what() << "\n"; - //if (auto st = boost::get_error_info(e)) - //std::cerr << *st << '\n'; - return 1; -} -catch (...) -{ - std::cerr << "Unhandled unknown exception" << "\n"; - return 1; -} - -int main(int argc, char *argv[]) -{ -#ifndef _WIN32 - auto r = main1(argc, argv); - return r; -#else - primitives::minidump::dir = L"cppan\\dump"; - primitives::minidump::v_major = VERSION_MAJOR; - primitives::minidump::v_minor = VERSION_MINOR; - primitives::minidump::v_patch = VERSION_PATCH; - primitives::executor::bExecutorUseSEH = true; - - __try - { - auto r = main1(argc, argv); - return r; - } - __except (PRIMITIVES_GENERATE_DUMP) - { - return 1; - } -#endif -} - -void check_spec_file() -{ - // no config - cannot do anything more - if (!fs::exists(current_thread_path() / CPPAN_FILENAME)) - throw std::runtime_error("No spec file found"); -} - -void default_run() -{ - check_spec_file(); - - Config c; - c.allow_relative_project_names = true; - c.allow_local_dependencies = true; - auto &deps = Settings::get_local_settings().dependencies; - if (deps.empty()) - { - c.load_current_config(); - - // if we have several projects, gather deps in a new config - const auto &projects = c.getProjects(); - if (projects.size() > 1) - { - Config c2; - for (auto &p : projects) - { - c2.getDefaultProject().dependencies.insert( - p.second.dependencies.begin(), p.second.dependencies.end()); - } - c = c2; - } - } - c.getDefaultProject().dependencies.insert(deps.begin(), deps.end()); - c.process(); -} - -void init(const Strings &args, const String &log_level) -{ - // initial sequence - - LoggerSettings log_settings; - log_settings.log_level = log_level; - //log_settings.log_file = (get_root_directory() / "cppan").string(); - log_settings.simple_logger = true; - log_settings.print_trace = true; - initLogger(log_settings); - - // first trace message - LOG_TRACE(logger, "----------------------------------------"); - LOG_TRACE(logger, "Starting cppan..."); - - // initialize CPPAN structures (settings), do not remove - auto &us = Settings::get_user_settings(); - - // disable update checks for internal commands - bool init = !(args.size() > 1 && args[1].find("internal-") == 0); - if (!init) - us.disable_update_checks = true; - - load_current_config(); - getServiceDatabase(init); -} - -void load_current_config() -{ - try - { - // load local settings for storage dir - Config c; - //c.allow_relative_project_names = true; - //c.allow_local_dependencies = true; - c.load_current_config_settings(); - } - catch (...) - { - // ignore everything - } - - // load proxy settings early - httpSettings.proxy = Settings::get_local_settings().proxy; -} - -void self_upgrade() -{ -#ifdef _WIN32 - String client = "/client/cppan-master-Windows-client.zip"; -#elif __APPLE__ - String client = "/client/cppan-master-macOS-client.zip"; -#else - String client = "/client/.service/cppan-master-Linux-client.zip"; -#endif - - auto &s = Settings::get_user_settings(); - - auto fn = fs::temp_directory_path() / unique_path(); - std::cout << "Downloading checksum file" << "\n"; - download_file(s.remotes[0].url + client + ".md5", fn, 50_MB); - auto md5sum = boost::algorithm::trim_copy(read_file(fn)); - - fn = fs::temp_directory_path() / unique_path(); - std::cout << "Downloading the latest client" << "\n"; - download_file(s.remotes[0].url + client, fn, 50_MB); - if (md5sum != md5(fn)) - throw std::runtime_error("Downloaded bad file (md5 check failed)"); - - std::cout << "Unpacking" << "\n"; - auto tmp_dir = fs::temp_directory_path() / "cppan.bak"; - unpack_file(fn, tmp_dir); - - // self update - auto program = get_program(); -#ifdef _WIN32 - auto exe = (tmp_dir / "cppan.exe").wstring(); - auto arg0 = L"\"" + exe + L"\""; - auto dst = L"\"" + program.wstring() + L"\""; - std::cout << "Replacing client" << "\n"; - auto cmd_line = arg0 + L" internal-self-upgrade-copy " + dst; - STARTUPINFO si = { 0 }; - PROCESS_INFORMATION pi = { 0 }; - if (!CreateProcess(exe.c_str(), &cmd_line[0], 0, 0, 0, 0, 0, 0, &si, &pi)) - { - throw std::runtime_error("errno = "s + std::to_string(errno) + "\n" + - "Cannot do a self upgrade. Replace this file with newer CPPAN client manually."); - } -#else - auto cppan = tmp_dir / "cppan"; - fs::permissions(cppan, fs::perms::owner_all | fs::perms::group_exec | fs::perms::others_exec); - fs::remove(program); - fs::copy_file(cppan, program); - fs::remove(cppan); -#endif -} - -void self_upgrade_copy(const path &dst) -{ - int n = 3; - while (n--) - { - std::cout << "Waiting old program to exit...\n"; - std::this_thread::sleep_for(std::chrono::seconds(2)); - try - { - fs::copy_file(get_program(), dst, fs::copy_options::overwrite_existing); - break; - } - catch (std::exception &e) - { - std::cerr << "Cannot replace program with new executable: " << e.what() << "\n"; - if (n == 0) - throw; - std::cerr << "Retrying... (" << n << ")\n"; - } - } - std::cout << "Success!\n"; -} - -optional internal(const Strings &args) -{ - // internal stuff - if (args[1] == "internal-fix-imports") - { - if (args.size() != 6) - { - std::cout << "invalid number of arguments\n"; - std::cout << "usage: cppan internal-fix-imports target aliases.file old.file new.file\n"; - return 1; - } - fix_imports(args[2], args[3], args[4], args[5]); - return 0; - } - - if (args[1] == "internal-create-link-to-solution") - { -#ifndef _WIN32 - return 0; -#endif - if (args.size() != 4) - { - std::cout << "invalid number of arguments: " << args.size() << "\n"; - std::cout << "usage: cppan internal-create-link-to-solution solution.sln link.lnk\n"; - return 1; - } - if (!create_link(args[2], args[3], "Link to CPPAN Solution")) - return 1; - return 0; - } - - if (args[1] == "internal-parallel-vars-check") - { - if (args.size() < 7) - { - std::cout << "invalid number of arguments: " << args.size() << "\n"; - std::cout << "usage: cppan internal-parallel-vars-check cmake_binary vars_dir vars_file checks_file generator system_version toolset toolchain\n"; - return 1; - } - - size_t a = 2; - -#define ASSIGN_ARG(x) if (a < args.size()) o.x = trim_double_quotes(args[a++]) - ParallelCheckOptions o; - ASSIGN_ARG(cmake_binary); - ASSIGN_ARG(dir); - ASSIGN_ARG(vars_file); - ASSIGN_ARG(checks_file); - ASSIGN_ARG(generator); - ASSIGN_ARG(system_version); - ASSIGN_ARG(toolset); - ASSIGN_ARG(toolchain); -#undef ASSIGN_ARG - - CMakePrinter c; - c.parallel_vars_check(o); - return 0; - } - - if (args[1] == "internal-parallel-moc") - { - if (args.size() != 3) - { - std::cout << "invalid number of arguments: " << args.size() << "\n"; - std::cout << "usage: cppan internal-parallel-moc moc.list\n"; - return 1; - } - - path file = trim_double_quotes(args[2]); - std::istringstream f(read_file(file)); - auto &e = getExecutor(); - while (1) - { - std::string wd, prog, arg; - f >> std::quoted(wd); - if (!f) - break; - f >> std::quoted(prog) >> std::quoted(arg); - primitives::Command c; - c.working_directory = wd; - c.program = prog; - c.args.push_back(arg); - e.push([c]() mutable { c.execute(); }); - } - e.wait(); - - return 0; - } - - if (args[1] == "internal-self-upgrade-copy") - { - self_upgrade_copy(args[2]); - return 0; - } - - if (args[1].find("internal-") == 0) - throw std::runtime_error("Unknown internal command: " + args[1]); - - return optional(); -} - -ApiResult api_call(const String &cmd, const Strings &args) -{ - auto us = Settings::get_user_settings(); - - auto get_remote = [&us](const String &remote) - { - auto i = std::find_if(us.remotes.begin(), us.remotes.end(), - [&remote](auto &v) { return v.name == remote; }); - return i; - }; - auto find_remote = [&get_remote, &us](const String &remote) - { - auto i = get_remote(remote); - if (i == us.remotes.end()) - throw std::runtime_error("unknown remote: " + remote); - return *i; - }; - auto has_remote = [&get_remote, &us](const String &remote) - { - return get_remote(remote) != us.remotes.end(); - }; - - if (cmd == "add" || cmd == "create") - { - if (args.size() < 3) - { - std::cout << "invalid number of arguments\n"; - std::cout << "usage: cppan add project|version [remote] name ...\n"; - return ApiResult::Error; - } - - size_t arg = 2; - String what = args[arg++]; - if (what == "project" || what == "package") - { - auto proj_usage = [] - { - std::cout << "invalid number of arguments\n"; - std::cout << "usage: cppan add project [remote] name [type]\n"; - }; - - if (args.size() < arg + 1) - { - proj_usage(); - return ApiResult::Error; - } - - String remote = DEFAULT_REMOTE_NAME; - ProjectPath p(args[arg++]); - if (has_remote(remote) && p.is_relative() && p.size() == 1) - { - remote = args[arg - 1]; - - if (args.size() < arg + 1) - { - proj_usage(); - return ApiResult::Error; - } - - p = ProjectPath(args[arg++]); - } - - // type - ProjectType type = ProjectType::Library; - if (args.size() > arg) - { - String t = args[arg++]; - if (t == "l" || t == "lib" || t == "library") - type = ProjectType::Library; - else if (t == "e" || t == "exe" || t == "executable") - type = ProjectType::Executable; - else if (t == "r" || t == "root" || t == "root_project") - type = ProjectType::RootProject; - else if (t == "d" || t == "dir" || t == "directory") - type = ProjectType::Directory; - } - - Api().add_project(find_remote(remote), p, type); - return ApiResult::Handled; - } - - if (what == "version") - { - auto proj_usage = [] - { - std::cout << "invalid number of arguments\n"; - std::cout << "usage: cppan add version [remote] name cppan.yml\n"; - }; - - if (args.size() < arg + 1) - { - proj_usage(); - return ApiResult::Error; - } - - String remote = DEFAULT_REMOTE_NAME; - ProjectPath p(args[arg++]); - if (has_remote(remote) && p.is_relative() && p.size() == 1) - { - remote = args[arg - 1]; - - if (args.size() < arg + 1) - { - proj_usage(); - return ApiResult::Error; - } - - p = ProjectPath(args[arg++]); - } - - if (args.size() < arg + 1) - { - proj_usage(); - return ApiResult::Error; - } - - auto f = args[arg++]; - if (fs::exists(f) && fs::is_regular_file(f)) - { - Api().add_version(find_remote(remote), p, read_file(f)); - return ApiResult::Handled; - } - - if (args.size() < arg + 1) - { - Api().add_version(find_remote(remote), p, Version(f)); - return ApiResult::Handled; - } - - auto vold = args[arg++]; - Api().add_version(find_remote(remote), p, Version(f), vold); - - return ApiResult::Handled; - } - - return ApiResult::Handled; - } - - if (cmd == "update") - { - if (args.size() < 3) - { - std::cout << "invalid number of arguments\n"; - std::cout << "usage: cppan update version [remote] name version\n"; - return ApiResult::Error; - } - - size_t arg = 2; - String what = args[arg++]; - - if (what == "version") - { - auto proj_usage = [] - { - std::cout << "invalid number of arguments\n"; - std::cout << "usage: cppan update version [remote] name version\n"; - }; - - if (args.size() < arg + 1) - { - proj_usage(); - return ApiResult::Error; - } - - String remote = DEFAULT_REMOTE_NAME; - ProjectPath p(args[arg++]); - if (has_remote(remote) && p.is_relative() && p.size() == 1) - { - remote = args[arg - 1]; - - if (args.size() < arg + 1) - { - proj_usage(); - return ApiResult::Error; - } - - p = ProjectPath(args[arg++]); - } - - if (args.size() < arg + 1) - { - proj_usage(); - return ApiResult::Error; - } - - Api().update_version(find_remote(remote), p, String(args[arg++])); - return ApiResult::Handled; - } - - return ApiResult::NotHandled; - } - - if (cmd == "remove") - { - if (args.size() < 3) - { - std::cout << "invalid number of arguments\n"; - std::cout << "usage: cppan remove project|version [remote] name ...\n"; - return ApiResult::Error; - } - - size_t arg = 2; - String what = args[arg++]; - if (what == "project" || what == "package") - { - auto proj_usage = [] - { - std::cout << "invalid number of arguments\n"; - std::cout << "usage: cppan remove project [remote] name\n"; - }; - - if (args.size() < arg + 1) - { - proj_usage(); - return ApiResult::Error; - } - - String remote = DEFAULT_REMOTE_NAME; - ProjectPath p(args[arg++]); - if (has_remote(remote) && p.is_relative() && p.size() == 1) - { - remote = args[arg - 1]; - - if (args.size() < arg + 1) - { - proj_usage(); - return ApiResult::Error; - } - - p = ProjectPath(args[arg++]); - } - - Api().remove_project(find_remote(remote), p); - return ApiResult::Handled; - } - - if (what == "version") - { - auto proj_usage = [] - { - std::cout << "invalid number of arguments\n"; - std::cout << "usage: cppan remove version [remote] name version\n"; - }; - - if (args.size() < arg + 1) - { - proj_usage(); - return ApiResult::Error; - } - - String remote = DEFAULT_REMOTE_NAME; - ProjectPath p(args[arg++]); - if (has_remote(remote) && p.is_relative() && p.size() == 1) - { - remote = args[arg - 1]; - - if (args.size() < arg + 1) - { - proj_usage(); - return ApiResult::Error; - } - - p = ProjectPath(args[arg++]); - } - - if (args.size() < arg + 1) - { - proj_usage(); - return ApiResult::Error; - } - - Api().remove_version(find_remote(remote), p, String(args[arg++])); - return ApiResult::Handled; - } - - return ApiResult::Handled; - } - - if (cmd == "notifications") - { - /*auto proj_usage = [] - { - std::cout << "invalid number of arguments\n"; - std::cout << "usage: cppan notifications [origin] [clear] [N]\n"; - };*/ - - size_t arg = 2; - - String remote = DEFAULT_REMOTE_NAME; - if (args.size() < arg + 1) - { - Api().get_notifications(find_remote(remote)); - return ApiResult::Handled; - } - - String arg2 = args[arg++]; - if (args.size() < arg + 1) - { - if (arg2 == "clear") - { - Api().clear_notifications(find_remote(remote)); - return ApiResult::Handled; - } - - int n = 10; - try - { - n = std::stoi(arg2); - } - catch (const std::exception&) - { - Api().get_notifications(find_remote(arg2)); - return ApiResult::Handled; - } - - Api().get_notifications(find_remote(remote), n); - return ApiResult::Handled; - } - - String arg3 = args[arg++]; - if (args.size() < arg + 1) - { - if (arg3 == "clear") - { - Api().clear_notifications(find_remote(arg2)); - return ApiResult::Handled; - } - - Api().get_notifications(find_remote(arg2), std::stoi(arg3)); - return ApiResult::Handled; - } - - return ApiResult::Error; - } - - return ApiResult::NotHandled; -} diff --git a/src/client/options.cpp b/src/client/options.cpp deleted file mode 100644 index 430a137c..00000000 --- a/src/client/options.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "options.h" - -#include -#include - -ProgramOptions::ProgramOptions() - : - visible("Allowed options"), - hidden("Hidden options") -{ - visible.add_options() - ("help,h", "produce this message") - ("dir,d", po::value(), "working directory") - ("version,V", po::bool_switch(), "version") - ("prepare-archive", po::bool_switch(), "prepare archive locally") - ("prepare-archive-remote", po::bool_switch(), "prepare archive from remote source") - ("curl-verbose", po::bool_switch(), "set curl to verbose mode") - ("self-upgrade", po::bool_switch(), "upgrade CPPAN client to the latest version") - ("ignore-ssl-checks,k", po::bool_switch(), "ignore ssl checks and errors") - - (SERVER_QUERY ",s", po::bool_switch(), "force query server") - - ("fetch", po::bool_switch(), "fetch current source") - ("verify", po::value(), "verify package") - - ("config", po::value()->default_value(""), "config name for building") - ("generate", po::value(), "file or dir: generate project files for inline building") - ("build", po::value(), "file or dir: inline building") - ("build-only", po::value(), "file or dir: inline building without touching any configs") - (BUILD_PACKAGES, po::value()->multitoken(), "build existing cppan package") - - ("settings", po::value()->default_value(""), "file to take settings from") - - ("verbose,v", po::bool_switch(), "verbose output") - ("trace", po::bool_switch(), "trace output") - - ("clear-cache", po::bool_switch(), "clear CMakeCache.txt files") - ("clear-vars-cache", po::bool_switch(), "clear checked symbols, types, includes etc.") - (CLEAN_PACKAGES, po::value()->multitoken(), "completely clean package files for matched regex") - (CLEAN_CONFIGS, po::value()->multitoken(), "clean config dirs and files") - - ("beautify", po::value(), "beautify yaml script") - ("beautify-strict", po::value(), "convert to strict cppan config") - ("print-cpp", po::value(), "print config's values in cpp style") - ("print-cpp2", po::value(), "print config's values in cpp style 2") - ; - - // i - internal options - hidden.add_options() - ; -} - -bool ProgramOptions::parseArgs(int argc, const char * const * argv) -{ - try - { - po::options_description all("Allowed options"); - all.add(visible).add(hidden); - - po::store(po::parse_command_line(argc, argv, all), vm); - po::notify(vm); - } - catch (const po::error &e) - { - std::cerr << e.what() << "\n\n"; - return false; - } - return true; -} - -bool ProgramOptions::parseArgs(const Strings &args) -{ - std::vector argv; - for (const auto &a : args) - argv.push_back(&a[0]); - return parseArgs((int)argv.size(), &argv[0]); -} - -std::string ProgramOptions::printHelp() const -{ - std::ostringstream oss; - oss << visible; - return oss.str(); -} diff --git a/src/client/options.h b/src/client/options.h deleted file mode 100644 index 6bba9203..00000000 --- a/src/client/options.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -#include - -namespace po = boost::program_options; - -class ProgramOptions -{ -public: - ProgramOptions(); - - bool parseArgs(int argc, const char * const *argv); - bool parseArgs(const Strings &args); - std::string printHelp() const; - - const po::variable_value& operator[](const std::string& name) const { return vm[name]; } - const po::variables_map &operator()() const { return vm; } - -private: - po::variables_map vm; - po::options_description visible; - po::options_description hidden; -}; - -#define BUILD_PACKAGES "build-packages" -#define CLEAN_PACKAGES "clean-packages" -#define CLEAN_CONFIGS "clean-configs" -#define SERVER_QUERY "server-query" diff --git a/src/client/resource.rc b/src/client/resource.rc deleted file mode 100644 index acc46b8c..00000000 --- a/src/client/resource.rc +++ /dev/null @@ -1,22 +0,0 @@ -//MAINICON ICON "client.ico" - -1 VERSIONINFO - FILEVERSION VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, BUILD_NUMBER - PRODUCTVERSION VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, BUILD_NUMBER -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "FileDescription", "C++ Archive Network Client Tool" - VALUE "LegalCopyright", "Egor Pugin" - VALUE "OriginalFilename", "cppan.exe" - VALUE "ProductName", "C++ Archive Network" - VALUE "ProductVersion", CPPAN_VERSION_STRING - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END diff --git a/src/comments/CMakeLists.txt b/src/comments/CMakeLists.txt deleted file mode 100644 index 86bef7e6..00000000 --- a/src/comments/CMakeLists.txt +++ /dev/null @@ -1,44 +0,0 @@ -# -# cppan -# - -######################################## -# extract_comments -######################################## - -if (FLEX_FOUND AND BISON_FOUND) - BISON_TARGET(grammar - "${CMAKE_CURRENT_SOURCE_DIR}/grammar.yy" - "${CMAKE_CURRENT_SOURCE_DIR}/grammar.cpp" - ) - FLEX_TARGET(lexer - "${CMAKE_CURRENT_SOURCE_DIR}/lexer.ll" - "${CMAKE_CURRENT_SOURCE_DIR}/lexer.cpp" - COMPILE_FLAGS "--header-file=${CMAKE_CURRENT_SOURCE_DIR}/lexer.h -L" - ) - ADD_FLEX_BISON_DEPENDENCY(lexer grammar) - - set(parser_src - ${BISON_grammar_OUTPUTS} - ${FLEX_lexer_OUTPUTS} - ${CMAKE_CURRENT_SOURCE_DIR}/lexer.h - ) - set_source_files_properties(${CMAKE_CURRENT_SOURCE_DIR}/lexer.h PROPERTIES GENERATED TRUE) - - set(builder_src - driver.cpp - driver.h - grammar.yy - lexer.ll - - ${parser_src} - ) -else() - file(GLOB builder_src "*") - list(FILTER builder_src EXCLUDE REGEX ".*CMakeLists.txt") -endif() - -add_library(extract_comments ${builder_src}) -set_property(TARGET extract_comments PROPERTY FOLDER parse) - -################################################################################ diff --git a/src/comments/driver.cpp b/src/comments/driver.cpp deleted file mode 100644 index af70f6e7..00000000 --- a/src/comments/driver.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "driver.h" - -#include -#include -#include - -// Prevent using because of bug in flex. -#define YY_NO_UNISTD_H 1 -#define YY_DECL 1 -#include -extern yy_comments::parser::symbol_type ll_commentslex(yyscan_t yyscanner, yy_comments::location &loc); - -std::vector extract_comments(const std::string &s) -{ - CommentsParserDriver driver; - driver.parse(s); - return driver.comments; -} - -CommentsParserDriver::CommentsParserDriver() -{ -} - -yy_comments::parser::symbol_type CommentsParserDriver::lex() -{ - auto ret = ll_commentslex(scanner, location); - return ret; -} - -int CommentsParserDriver::parse(const std::string &s) -{ - ll_commentslex_init(&scanner); - ll_comments_scan_string(s.c_str(), scanner); - auto res = parse(); - ll_commentslex_destroy(scanner); - - return res; -} - -int CommentsParserDriver::parse() -{ - yy_comments::parser parser(*this); - parser.set_debug_level(debug); - int res = parser.parse(); - return res; -} - -void CommentsParserDriver::error(const yy_comments::location &l, const std::string &m) -{ - if (silent) - return; - std::ostringstream ss; - ss << l << " " << m << "\n"; - if (!can_throw) - std::cerr << ss.str(); - else - throw std::runtime_error("Error during parse: " + ss.str()); -} - -void CommentsParserDriver::error(const std::string& m) -{ - if (silent) - return; - std::ostringstream ss; - ss << m << "\n"; - if (!can_throw) - std::cerr << ss.str(); - else - throw std::runtime_error("Error during parse: " + ss.str()); -} diff --git a/src/comments/driver.h b/src/comments/driver.h deleted file mode 100644 index 3eaf8532..00000000 --- a/src/comments/driver.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#include - -class CommentsParserDriver -{ -public: - std::vector comments; - bool debug = false; - bool can_throw = true; - bool silent = true; - - CommentsParserDriver(); - - yy_comments::parser::symbol_type lex(); - int parse(const std::string &s); - - void error(const yy_comments::location &l, const std::string &m); - void error(const std::string &m); - - // lex & parse -private: - void *scanner; - yy_comments::location location; - - int parse(); -}; diff --git a/src/comments/grammar.cpp b/src/comments/grammar.cpp deleted file mode 100644 index 9b9ac47f..00000000 --- a/src/comments/grammar.cpp +++ /dev/null @@ -1,932 +0,0 @@ -// A Bison parser, made by GNU Bison 3.0.4. - -// Skeleton implementation for Bison LALR(1) parsers in C++ - -// Copyright (C) 2002-2015 Free Software Foundation, Inc. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// As a special exception, you may create a larger work that contains -// part or all of the Bison parser skeleton and distribute that work -// under terms of your choice, so long as that work isn't itself a -// parser generator using the skeleton or a modified version thereof -// as a parser skeleton. Alternatively, if you modify or redistribute -// the parser skeleton itself, you may (at your option) remove this -// special exception, which will cause the skeleton and the resulting -// Bison output files to be licensed under the GNU General Public -// License without this special exception. - -// This special exception was added by the Free Software Foundation in -// version 2.2 of Bison. - -// Take the name prefix into account. -#define yylex yy_commentslex - -// First part of user declarations. - - -#include -#include -#include - -#include "comments/driver.h" - -#define yylex(p) p.lex() - - - -# ifndef YY_NULLPTR -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULLPTR nullptr -# else -# define YY_NULLPTR 0 -# endif -# endif - -#include "grammar.hpp" - -// User implementation prologue. - - - - -#ifndef YY_ -# if defined YYENABLE_NLS && YYENABLE_NLS -# if ENABLE_NLS -# include // FIXME: INFRINGES ON USER NAME SPACE. -# define YY_(msgid) dgettext ("bison-runtime", msgid) -# endif -# endif -# ifndef YY_ -# define YY_(msgid) msgid -# endif -#endif - -#define YYRHSLOC(Rhs, K) ((Rhs)[K].location) -/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. - If N is 0, then set CURRENT to the empty location which ends - the previous symbol: RHS[0] (always defined). */ - -# ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - do \ - if (N) \ - { \ - (Current).begin = YYRHSLOC (Rhs, 1).begin; \ - (Current).end = YYRHSLOC (Rhs, N).end; \ - } \ - else \ - { \ - (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \ - } \ - while (/*CONSTCOND*/ false) -# endif - - -// Suppress unused-variable warnings by "using" E. -#define YYUSE(E) ((void) (E)) - -// Enable debugging if requested. -#if YY_COMMENTSDEBUG - -// A pseudo ostream that takes yydebug_ into account. -# define YYCDEBUG if (yydebug_) (*yycdebug_) - -# define YY_SYMBOL_PRINT(Title, Symbol) \ - do { \ - if (yydebug_) \ - { \ - *yycdebug_ << Title << ' '; \ - yy_print_ (*yycdebug_, Symbol); \ - *yycdebug_ << std::endl; \ - } \ - } while (false) - -# define YY_REDUCE_PRINT(Rule) \ - do { \ - if (yydebug_) \ - yy_reduce_print_ (Rule); \ - } while (false) - -# define YY_STACK_PRINT() \ - do { \ - if (yydebug_) \ - yystack_print_ (); \ - } while (false) - -#else // !YY_COMMENTSDEBUG - -# define YYCDEBUG if (false) std::cerr -# define YY_SYMBOL_PRINT(Title, Symbol) YYUSE(Symbol) -# define YY_REDUCE_PRINT(Rule) static_cast(0) -# define YY_STACK_PRINT() static_cast(0) - -#endif // !YY_COMMENTSDEBUG - -#define yyerrok (yyerrstatus_ = 0) -#define yyclearin (yyla.clear ()) - -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrorlab -#define YYRECOVERING() (!!yyerrstatus_) - - -namespace yy_comments { - - - /* Return YYSTR after stripping away unnecessary quotes and - backslashes, so that it's suitable for yyerror. The heuristic is - that double-quoting is unnecessary unless the string contains an - apostrophe, a comma, or backslash (other than backslash-backslash). - YYSTR is taken from yytname. */ - std::string - parser::yytnamerr_ (const char *yystr) - { - if (*yystr == '"') - { - std::string yyr = ""; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - // Fall through. - default: - yyr += *yyp; - break; - - case '"': - return yyr; - } - do_not_strip_quotes: ; - } - - return yystr; - } - - - /// Build a parser object. - parser::parser (CommentsParserDriver &driver_yyarg) - : -#if YY_COMMENTSDEBUG - yydebug_ (false), - yycdebug_ (&std::cerr), -#endif - driver (driver_yyarg) - {} - - parser::~parser () - {} - - - /*---------------. - | Symbol types. | - `---------------*/ - - - - // by_state. - inline - parser::by_state::by_state () - : state (empty_state) - {} - - inline - parser::by_state::by_state (const by_state& other) - : state (other.state) - {} - - inline - void - parser::by_state::clear () - { - state = empty_state; - } - - inline - void - parser::by_state::move (by_state& that) - { - state = that.state; - that.clear (); - } - - inline - parser::by_state::by_state (state_type s) - : state (s) - {} - - inline - parser::symbol_number_type - parser::by_state::type_get () const - { - if (state == empty_state) - return empty_symbol; - else - return yystos_[state]; - } - - inline - parser::stack_symbol_type::stack_symbol_type () - {} - - - inline - parser::stack_symbol_type::stack_symbol_type (state_type s, symbol_type& that) - : super_type (s, that.location) - { - switch (that.type_get ()) - { - case 4: // STRING - case 8: // comment - case 9: // err - value.move< std::string > (that.value); - break; - - default: - break; - } - - // that is emptied. - that.type = empty_symbol; - } - - inline - parser::stack_symbol_type& - parser::stack_symbol_type::operator= (const stack_symbol_type& that) - { - state = that.state; - switch (that.type_get ()) - { - case 4: // STRING - case 8: // comment - case 9: // err - value.copy< std::string > (that.value); - break; - - default: - break; - } - - location = that.location; - return *this; - } - - - template - inline - void - parser::yy_destroy_ (const char* yymsg, basic_symbol& yysym) const - { - if (yymsg) - YY_SYMBOL_PRINT (yymsg, yysym); - } - -#if YY_COMMENTSDEBUG - template - void - parser::yy_print_ (std::ostream& yyo, - const basic_symbol& yysym) const - { - std::ostream& yyoutput = yyo; - YYUSE (yyoutput); - symbol_number_type yytype = yysym.type_get (); - // Avoid a (spurious) G++ 4.8 warning about "array subscript is - // below array bounds". - if (yysym.empty ()) - std::abort (); - yyo << (yytype < yyntokens_ ? "token" : "nterm") - << ' ' << yytname_[yytype] << " (" - << yysym.location << ": "; - YYUSE (yytype); - yyo << ')'; - } -#endif - - inline - void - parser::yypush_ (const char* m, state_type s, symbol_type& sym) - { - stack_symbol_type t (s, sym); - yypush_ (m, t); - } - - inline - void - parser::yypush_ (const char* m, stack_symbol_type& s) - { - if (m) - YY_SYMBOL_PRINT (m, s); - yystack_.push (s); - } - - inline - void - parser::yypop_ (unsigned int n) - { - yystack_.pop (n); - } - -#if YY_COMMENTSDEBUG - std::ostream& - parser::debug_stream () const - { - return *yycdebug_; - } - - void - parser::set_debug_stream (std::ostream& o) - { - yycdebug_ = &o; - } - - - parser::debug_level_type - parser::debug_level () const - { - return yydebug_; - } - - void - parser::set_debug_level (debug_level_type l) - { - yydebug_ = l; - } -#endif // YY_COMMENTSDEBUG - - inline parser::state_type - parser::yy_lr_goto_state_ (state_type yystate, int yysym) - { - int yyr = yypgoto_[yysym - yyntokens_] + yystate; - if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate) - return yytable_[yyr]; - else - return yydefgoto_[yysym - yyntokens_]; - } - - inline bool - parser::yy_pact_value_is_default_ (int yyvalue) - { - return yyvalue == yypact_ninf_; - } - - inline bool - parser::yy_table_value_is_error_ (int yyvalue) - { - return yyvalue == yytable_ninf_; - } - - int - parser::parse () - { - // State. - int yyn; - /// Length of the RHS of the rule being reduced. - int yylen = 0; - - // Error handling. - int yynerrs_ = 0; - int yyerrstatus_ = 0; - - /// The lookahead symbol. - symbol_type yyla; - - /// The locations where the error started and ended. - stack_symbol_type yyerror_range[3]; - - /// The return value of parse (). - int yyresult; - - // FIXME: This shoud be completely indented. It is not yet to - // avoid gratuitous conflicts when merging into the master branch. - try - { - YYCDEBUG << "Starting parse" << std::endl; - - - /* Initialize the stack. The initial state will be set in - yynewstate, since the latter expects the semantical and the - location values to have been already stored, initialize these - stacks with a primary value. */ - yystack_.clear (); - yypush_ (YY_NULLPTR, 0, yyla); - - // A new symbol was pushed on the stack. - yynewstate: - YYCDEBUG << "Entering state " << yystack_[0].state << std::endl; - - // Accept? - if (yystack_[0].state == yyfinal_) - goto yyacceptlab; - - goto yybackup; - - // Backup. - yybackup: - - // Try to take a decision without lookahead. - yyn = yypact_[yystack_[0].state]; - if (yy_pact_value_is_default_ (yyn)) - goto yydefault; - - // Read a lookahead token. - if (yyla.empty ()) - { - YYCDEBUG << "Reading a token: "; - try - { - symbol_type yylookahead (yylex (driver)); - yyla.move (yylookahead); - } - catch (const syntax_error& yyexc) - { - error (yyexc); - goto yyerrlab1; - } - } - YY_SYMBOL_PRINT ("Next token is", yyla); - - /* If the proper action on seeing token YYLA.TYPE is to reduce or - to detect an error, take that action. */ - yyn += yyla.type_get (); - if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type_get ()) - goto yydefault; - - // Reduce or error. - yyn = yytable_[yyn]; - if (yyn <= 0) - { - if (yy_table_value_is_error_ (yyn)) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } - - // Count tokens shifted since error; after three, turn off error status. - if (yyerrstatus_) - --yyerrstatus_; - - // Shift the lookahead token. - yypush_ ("Shifting", yyn, yyla); - goto yynewstate; - - /*-----------------------------------------------------------. - | yydefault -- do the default action for the current state. | - `-----------------------------------------------------------*/ - yydefault: - yyn = yydefact_[yystack_[0].state]; - if (yyn == 0) - goto yyerrlab; - goto yyreduce; - - /*-----------------------------. - | yyreduce -- Do a reduction. | - `-----------------------------*/ - yyreduce: - yylen = yyr2_[yyn]; - { - stack_symbol_type yylhs; - yylhs.state = yy_lr_goto_state_(yystack_[yylen].state, yyr1_[yyn]); - /* Variants are always initialized to an empty instance of the - correct type. The default '$$ = $1' action is NOT applied - when using variants. */ - switch (yyr1_[yyn]) - { - case 4: // STRING - case 8: // comment - case 9: // err - yylhs.value.build< std::string > (); - break; - - default: - break; - } - - - // Compute the default @$. - { - slice slice (yystack_, yylen); - YYLLOC_DEFAULT (yylhs.location, slice, yylen); - } - - // Perform the reduction. - YY_REDUCE_PRINT (yyn); - try - { - switch (yyn) - { - case 3: - - { driver.comments.push_back(yystack_[0].value.as< std::string > ()); } - - break; - - case 4: - - { driver.comments.push_back(yystack_[0].value.as< std::string > ()); } - - break; - - case 5: - - { yylhs.value.as< std::string > () = yystack_[0].value.as< std::string > (); } - - break; - - case 7: - - { return 0; } - - break; - - - - default: - break; - } - } - catch (const syntax_error& yyexc) - { - error (yyexc); - YYERROR; - } - YY_SYMBOL_PRINT ("-> $$ =", yylhs); - yypop_ (yylen); - yylen = 0; - YY_STACK_PRINT (); - - // Shift the result of the reduction. - yypush_ (YY_NULLPTR, yylhs); - } - goto yynewstate; - - /*--------------------------------------. - | yyerrlab -- here on detecting error. | - `--------------------------------------*/ - yyerrlab: - // If not already recovering from an error, report this error. - if (!yyerrstatus_) - { - ++yynerrs_; - error (yyla.location, yysyntax_error_ (yystack_[0].state, yyla)); - } - - - yyerror_range[1].location = yyla.location; - if (yyerrstatus_ == 3) - { - /* If just tried and failed to reuse lookahead token after an - error, discard it. */ - - // Return failure if at end of input. - if (yyla.type_get () == yyeof_) - YYABORT; - else if (!yyla.empty ()) - { - yy_destroy_ ("Error: discarding", yyla); - yyla.clear (); - } - } - - // Else will try to reuse lookahead token after shifting the error token. - goto yyerrlab1; - - - /*---------------------------------------------------. - | yyerrorlab -- error raised explicitly by YYERROR. | - `---------------------------------------------------*/ - yyerrorlab: - - /* Pacify compilers like GCC when the user code never invokes - YYERROR and the label yyerrorlab therefore never appears in user - code. */ - if (false) - goto yyerrorlab; - yyerror_range[1].location = yystack_[yylen - 1].location; - /* Do not reclaim the symbols of the rule whose action triggered - this YYERROR. */ - yypop_ (yylen); - yylen = 0; - goto yyerrlab1; - - /*-------------------------------------------------------------. - | yyerrlab1 -- common code for both syntax error and YYERROR. | - `-------------------------------------------------------------*/ - yyerrlab1: - yyerrstatus_ = 3; // Each real token shifted decrements this. - { - stack_symbol_type error_token; - for (;;) - { - yyn = yypact_[yystack_[0].state]; - if (!yy_pact_value_is_default_ (yyn)) - { - yyn += yyterror_; - if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_) - { - yyn = yytable_[yyn]; - if (0 < yyn) - break; - } - } - - // Pop the current state because it cannot handle the error token. - if (yystack_.size () == 1) - YYABORT; - - yyerror_range[1].location = yystack_[0].location; - yy_destroy_ ("Error: popping", yystack_[0]); - yypop_ (); - YY_STACK_PRINT (); - } - - yyerror_range[2].location = yyla.location; - YYLLOC_DEFAULT (error_token.location, yyerror_range, 2); - - // Shift the error token. - error_token.state = yyn; - yypush_ ("Shifting", error_token); - } - goto yynewstate; - - // Accept. - yyacceptlab: - yyresult = 0; - goto yyreturn; - - // Abort. - yyabortlab: - yyresult = 1; - goto yyreturn; - - yyreturn: - if (!yyla.empty ()) - yy_destroy_ ("Cleanup: discarding lookahead", yyla); - - /* Do not reclaim the symbols of the rule whose action triggered - this YYABORT or YYACCEPT. */ - yypop_ (yylen); - while (1 < yystack_.size ()) - { - yy_destroy_ ("Cleanup: popping", yystack_[0]); - yypop_ (); - } - - return yyresult; - } - catch (...) - { - YYCDEBUG << "Exception caught: cleaning lookahead and stack" - << std::endl; - // Do not try to display the values of the reclaimed symbols, - // as their printer might throw an exception. - if (!yyla.empty ()) - yy_destroy_ (YY_NULLPTR, yyla); - - while (1 < yystack_.size ()) - { - yy_destroy_ (YY_NULLPTR, yystack_[0]); - yypop_ (); - } - throw; - } - } - - void - parser::error (const syntax_error& yyexc) - { - error (yyexc.location, yyexc.what()); - } - - // Generate an error message. - std::string - parser::yysyntax_error_ (state_type yystate, const symbol_type& yyla) const - { - // Number of reported tokens (one for the "unexpected", one per - // "expected"). - size_t yycount = 0; - // Its maximum. - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - // Arguments of yyformat. - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - - /* There are many possibilities here to consider: - - If this state is a consistent state with a default action, then - the only way this function was invoked is if the default action - is an error action. In that case, don't check for expected - tokens because there are none. - - The only way there can be no lookahead present (in yyla) is - if this state is a consistent state with a default action. - Thus, detecting the absence of a lookahead is sufficient to - determine that there is no unexpected or expected token to - report. In that case, just report a simple "syntax error". - - Don't assume there isn't a lookahead just because this state is - a consistent state with a default action. There might have - been a previous inconsistent state, consistent state with a - non-default action, or user semantic action that manipulated - yyla. (However, yyla is currently not documented for users.) - - Of course, the expected token list depends on states to have - correct lookahead information, and it depends on the parser not - to perform extra reductions after fetching a lookahead from the - scanner and before detecting a syntax error. Thus, state - merging (from LALR or IELR) and default reductions corrupt the - expected token list. However, the list is correct for - canonical LR with one exception: it will still contain any - token that will not be accepted due to an error action in a - later state. - */ - if (!yyla.empty ()) - { - int yytoken = yyla.type_get (); - yyarg[yycount++] = yytname_[yytoken]; - int yyn = yypact_[yystate]; - if (!yy_pact_value_is_default_ (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - // Stay within bounds of both yycheck and yytname. - int yychecklim = yylast_ - yyn + 1; - int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; - for (int yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_ - && !yy_table_value_is_error_ (yytable_[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - break; - } - else - yyarg[yycount++] = yytname_[yyx]; - } - } - } - - char const* yyformat = YY_NULLPTR; - switch (yycount) - { -#define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -#undef YYCASE_ - } - - std::string yyres; - // Argument number. - size_t yyi = 0; - for (char const* yyp = yyformat; *yyp; ++yyp) - if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) - { - yyres += yytnamerr_ (yyarg[yyi++]); - ++yyp; - } - else - yyres += *yyp; - return yyres; - } - - - const signed char parser::yypact_ninf_ = -3; - - const signed char parser::yytable_ninf_ = -1; - - const signed char - parser::yypact_[] = - { - -2, -3, -3, 5, 0, -3, -3, -3, -3, -3 - }; - - const unsigned char - parser::yydefact_[] = - { - 0, 7, 5, 0, 0, 3, 6, 1, 2, 4 - }; - - const signed char - parser::yypgoto_[] = - { - -3, -3, -3, 2, -3 - }; - - const signed char - parser::yydefgoto_[] = - { - -1, 3, 4, 5, 6 - }; - - const unsigned char - parser::yytable_[] = - { - 8, 1, 2, 1, 2, 7, 9 - }; - - const unsigned char - parser::yycheck_[] = - { - 0, 3, 4, 3, 4, 0, 4 - }; - - const unsigned char - parser::yystos_[] = - { - 0, 3, 4, 6, 7, 8, 9, 0, 0, 8 - }; - - const unsigned char - parser::yyr1_[] = - { - 0, 5, 6, 7, 7, 8, 8, 9 - }; - - const unsigned char - parser::yyr2_[] = - { - 0, 2, 2, 1, 2, 1, 1, 1 - }; - - - - // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. - // First, the terminals, then, starting at \a yyntokens_, nonterminals. - const char* - const parser::yytname_[] = - { - "\"end of file\"", "error", "$undefined", "ERROR_SYMBOL", "STRING", - "$accept", "file", "comments", "comment", "err", YY_NULLPTR - }; - -#if YY_COMMENTSDEBUG - const unsigned char - parser::yyrline_[] = - { - 0, 54, 54, 57, 59, 63, 65, 67 - }; - - // Print the state stack on the debug stream. - void - parser::yystack_print_ () - { - *yycdebug_ << "Stack now"; - for (stack_type::const_iterator - i = yystack_.begin (), - i_end = yystack_.end (); - i != i_end; ++i) - *yycdebug_ << ' ' << i->state; - *yycdebug_ << std::endl; - } - - // Report on the debug stream that the rule \a yyrule is going to be reduced. - void - parser::yy_reduce_print_ (int yyrule) - { - unsigned int yylno = yyrline_[yyrule]; - int yynrhs = yyr2_[yyrule]; - // Print the symbols being reduced, and their result. - *yycdebug_ << "Reducing stack by rule " << yyrule - 1 - << " (line " << yylno << "):" << std::endl; - // The symbols being reduced. - for (int yyi = 0; yyi < yynrhs; yyi++) - YY_SYMBOL_PRINT (" $" << yyi + 1 << " =", - yystack_[(yynrhs) - (yyi + 1)]); - } -#endif // YY_COMMENTSDEBUG - - - -} // yy_comments - - - - -void yy_comments::parser::error(const location_type& l, const std::string& m) -{ - driver.error(l, m); -} diff --git a/src/comments/grammar.hpp b/src/comments/grammar.hpp deleted file mode 100644 index df49a2b1..00000000 --- a/src/comments/grammar.hpp +++ /dev/null @@ -1,931 +0,0 @@ -// A Bison parser, made by GNU Bison 3.0.4. - -// Skeleton interface for Bison LALR(1) parsers in C++ - -// Copyright (C) 2002-2015 Free Software Foundation, Inc. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// As a special exception, you may create a larger work that contains -// part or all of the Bison parser skeleton and distribute that work -// under terms of your choice, so long as that work isn't itself a -// parser generator using the skeleton or a modified version thereof -// as a parser skeleton. Alternatively, if you modify or redistribute -// the parser skeleton itself, you may (at your option) remove this -// special exception, which will cause the skeleton and the resulting -// Bison output files to be licensed under the GNU General Public -// License without this special exception. - -// This special exception was added by the Free Software Foundation in -// version 2.2 of Bison. - -/** - ** \file D:/dev/cppan_client/src/comments/grammar.hpp - ** Define the yy_comments::parser class. - */ - -// C++ LALR(1) parser skeleton written by Akim Demaille. - -#ifndef YY_YY_COMMENTS_D_DEV_CPPAN_CLIENT_SRC_COMMENTS_GRAMMAR_HPP_INCLUDED -# define YY_YY_COMMENTS_D_DEV_CPPAN_CLIENT_SRC_COMMENTS_GRAMMAR_HPP_INCLUDED -// // "%code requires" blocks. - - -class CommentsParserDriver; - - - -# include -# include // std::abort -# include -# include -# include -# include -# include "stack.hh" -# include "location.hh" -#include -#ifndef YYASSERT -# include -# define YYASSERT assert -#endif - - -#ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) -# else -# define YY_ATTRIBUTE(Spec) /* empty */ -# endif -#endif - -#ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) -#endif - -#ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) -#endif - -#if !defined _Noreturn \ - && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) -# if defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) -# else -# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) -# endif -#endif - -/* Suppress unused-variable warnings by "using" E. */ -#if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) -#else -# define YYUSE(E) /* empty */ -#endif - -#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ -/* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ - _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ - _Pragma ("GCC diagnostic pop") -#else -# define YY_INITIAL_VALUE(Value) Value -#endif -#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN -# define YY_IGNORE_MAYBE_UNINITIALIZED_END -#endif -#ifndef YY_INITIAL_VALUE -# define YY_INITIAL_VALUE(Value) /* Nothing. */ -#endif - -/* Debug traces. */ -#ifndef YY_COMMENTSDEBUG -# if defined YYDEBUG -#if YYDEBUG -# define YY_COMMENTSDEBUG 1 -# else -# define YY_COMMENTSDEBUG 0 -# endif -# else /* ! defined YYDEBUG */ -# define YY_COMMENTSDEBUG 1 -# endif /* ! defined YYDEBUG */ -#endif /* ! defined YY_COMMENTSDEBUG */ - - -namespace yy_comments { - - - - - /// A char[S] buffer to store and retrieve objects. - /// - /// Sort of a variant, but does not keep track of the nature - /// of the stored data, since that knowledge is available - /// via the current state. - template - struct variant - { - /// Type of *this. - typedef variant self_type; - - /// Empty construction. - variant () - : yytypeid_ (YY_NULLPTR) - {} - - /// Construct and fill. - template - variant (const T& t) - : yytypeid_ (&typeid (T)) - { - YYASSERT (sizeof (T) <= S); - new (yyas_ ()) T (t); - } - - /// Destruction, allowed only if empty. - ~variant () - { - YYASSERT (!yytypeid_); - } - - /// Instantiate an empty \a T in here. - template - T& - build () - { - YYASSERT (!yytypeid_); - YYASSERT (sizeof (T) <= S); - yytypeid_ = & typeid (T); - return *new (yyas_ ()) T; - } - - /// Instantiate a \a T in here from \a t. - template - T& - build (const T& t) - { - YYASSERT (!yytypeid_); - YYASSERT (sizeof (T) <= S); - yytypeid_ = & typeid (T); - return *new (yyas_ ()) T (t); - } - - /// Accessor to a built \a T. - template - T& - as () - { - YYASSERT (*yytypeid_ == typeid (T)); - YYASSERT (sizeof (T) <= S); - return *yyas_ (); - } - - /// Const accessor to a built \a T (for %printer). - template - const T& - as () const - { - YYASSERT (*yytypeid_ == typeid (T)); - YYASSERT (sizeof (T) <= S); - return *yyas_ (); - } - - /// Swap the content with \a other, of same type. - /// - /// Both variants must be built beforehand, because swapping the actual - /// data requires reading it (with as()), and this is not possible on - /// unconstructed variants: it would require some dynamic testing, which - /// should not be the variant's responsability. - /// Swapping between built and (possibly) non-built is done with - /// variant::move (). - template - void - swap (self_type& other) - { - YYASSERT (yytypeid_); - YYASSERT (*yytypeid_ == *other.yytypeid_); - std::swap (as (), other.as ()); - } - - /// Move the content of \a other to this. - /// - /// Destroys \a other. - template - void - move (self_type& other) - { - build (); - swap (other); - other.destroy (); - } - - /// Copy the content of \a other to this. - template - void - copy (const self_type& other) - { - build (other.as ()); - } - - /// Destroy the stored \a T. - template - void - destroy () - { - as ().~T (); - yytypeid_ = YY_NULLPTR; - } - - private: - /// Prohibit blind copies. - self_type& operator=(const self_type&); - variant (const self_type&); - - /// Accessor to raw memory as \a T. - template - T* - yyas_ () - { - void *yyp = yybuffer_.yyraw; - return static_cast (yyp); - } - - /// Const accessor to raw memory as \a T. - template - const T* - yyas_ () const - { - const void *yyp = yybuffer_.yyraw; - return static_cast (yyp); - } - - union - { - /// Strongest alignment constraints. - long double yyalign_me; - /// A buffer large enough to store any of the semantic values. - char yyraw[S]; - } yybuffer_; - - /// Whether the content is built: if defined, the name of the stored type. - const std::type_info *yytypeid_; - }; - - - /// A Bison parser. - class parser - { - public: -#ifndef YY_COMMENTSSTYPE - /// An auxiliary type to compute the largest semantic type. - union union_type - { - // STRING - // comment - // err - char dummy1[sizeof(std::string)]; -}; - - /// Symbol semantic values. - typedef variant semantic_type; -#else - typedef YY_COMMENTSSTYPE semantic_type; -#endif - /// Symbol locations. - typedef location location_type; - - /// Syntax errors thrown from user actions. - struct syntax_error : std::runtime_error - { - syntax_error (const location_type& l, const std::string& m); - location_type location; - }; - - /// Tokens. - struct token - { - enum yytokentype - { - EOQ = 0, - ERROR_SYMBOL = 258, - STRING = 259 - }; - }; - - /// (External) token type, as returned by yylex. - typedef token::yytokentype token_type; - - /// Symbol type: an internal symbol number. - typedef int symbol_number_type; - - /// The symbol type number to denote an empty symbol. - enum { empty_symbol = -2 }; - - /// Internal symbol number for tokens (subsumed by symbol_number_type). - typedef unsigned char token_number_type; - - /// A complete symbol. - /// - /// Expects its Base type to provide access to the symbol type - /// via type_get(). - /// - /// Provide access to semantic value and location. - template - struct basic_symbol : Base - { - /// Alias to Base. - typedef Base super_type; - - /// Default constructor. - basic_symbol (); - - /// Copy constructor. - basic_symbol (const basic_symbol& other); - - /// Constructor for valueless symbols, and symbols from each type. - - basic_symbol (typename Base::kind_type t, const location_type& l); - - basic_symbol (typename Base::kind_type t, const std::string v, const location_type& l); - - - /// Constructor for symbols with semantic value. - basic_symbol (typename Base::kind_type t, - const semantic_type& v, - const location_type& l); - - /// Destroy the symbol. - ~basic_symbol (); - - /// Destroy contents, and record that is empty. - void clear (); - - /// Whether empty. - bool empty () const; - - /// Destructive move, \a s is emptied into this. - void move (basic_symbol& s); - - /// The semantic value. - semantic_type value; - - /// The location. - location_type location; - - private: - /// Assignment operator. - basic_symbol& operator= (const basic_symbol& other); - }; - - /// Type access provider for token (enum) based symbols. - struct by_type - { - /// Default constructor. - by_type (); - - /// Copy constructor. - by_type (const by_type& other); - - /// The symbol type as needed by the constructor. - typedef token_type kind_type; - - /// Constructor from (external) token numbers. - by_type (kind_type t); - - /// Record that this symbol is empty. - void clear (); - - /// Steal the symbol type from \a that. - void move (by_type& that); - - /// The (internal) type number (corresponding to \a type). - /// \a empty when empty. - symbol_number_type type_get () const; - - /// The token. - token_type token () const; - - /// The symbol type. - /// \a empty_symbol when empty. - /// An int, not token_number_type, to be able to store empty_symbol. - int type; - }; - - /// "External" symbols: returned by the scanner. - typedef basic_symbol symbol_type; - - // Symbol constructors declarations. - static inline - symbol_type - make_EOQ (const location_type& l); - - static inline - symbol_type - make_ERROR_SYMBOL (const location_type& l); - - static inline - symbol_type - make_STRING (const std::string& v, const location_type& l); - - - /// Build a parser object. - parser (CommentsParserDriver &driver_yyarg); - virtual ~parser (); - - /// Parse. - /// \returns 0 iff parsing succeeded. - virtual int parse (); - -#if YY_COMMENTSDEBUG - /// The current debugging stream. - std::ostream& debug_stream () const YY_ATTRIBUTE_PURE; - /// Set the current debugging stream. - void set_debug_stream (std::ostream &); - - /// Type for debugging levels. - typedef int debug_level_type; - /// The current debugging level. - debug_level_type debug_level () const YY_ATTRIBUTE_PURE; - /// Set the current debugging level. - void set_debug_level (debug_level_type l); -#endif - - /// Report a syntax error. - /// \param loc where the syntax error is found. - /// \param msg a description of the syntax error. - virtual void error (const location_type& loc, const std::string& msg); - - /// Report a syntax error. - void error (const syntax_error& err); - - private: - /// This class is not copyable. - parser (const parser&); - parser& operator= (const parser&); - - /// State numbers. - typedef int state_type; - - /// Generate an error message. - /// \param yystate the state where the error occurred. - /// \param yyla the lookahead token. - virtual std::string yysyntax_error_ (state_type yystate, - const symbol_type& yyla) const; - - /// Compute post-reduction state. - /// \param yystate the current state - /// \param yysym the nonterminal to push on the stack - state_type yy_lr_goto_state_ (state_type yystate, int yysym); - - /// Whether the given \c yypact_ value indicates a defaulted state. - /// \param yyvalue the value to check - static bool yy_pact_value_is_default_ (int yyvalue); - - /// Whether the given \c yytable_ value indicates a syntax error. - /// \param yyvalue the value to check - static bool yy_table_value_is_error_ (int yyvalue); - - static const signed char yypact_ninf_; - static const signed char yytable_ninf_; - - /// Convert a scanner token number \a t to a symbol number. - static token_number_type yytranslate_ (token_type t); - - // Tables. - // YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - // STATE-NUM. - static const signed char yypact_[]; - - // YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. - // Performed when YYTABLE does not specify something else to do. Zero - // means the default is an error. - static const unsigned char yydefact_[]; - - // YYPGOTO[NTERM-NUM]. - static const signed char yypgoto_[]; - - // YYDEFGOTO[NTERM-NUM]. - static const signed char yydefgoto_[]; - - // YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If - // positive, shift that token. If negative, reduce the rule whose - // number is the opposite. If YYTABLE_NINF, syntax error. - static const unsigned char yytable_[]; - - static const unsigned char yycheck_[]; - - // YYSTOS[STATE-NUM] -- The (internal number of the) accessing - // symbol of state STATE-NUM. - static const unsigned char yystos_[]; - - // YYR1[YYN] -- Symbol number of symbol that rule YYN derives. - static const unsigned char yyr1_[]; - - // YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. - static const unsigned char yyr2_[]; - - - /// Convert the symbol name \a n to a form suitable for a diagnostic. - static std::string yytnamerr_ (const char *n); - - - /// For a symbol, its name in clear. - static const char* const yytname_[]; -#if YY_COMMENTSDEBUG - // YYRLINE[YYN] -- Source line where rule number YYN was defined. - static const unsigned char yyrline_[]; - /// Report on the debug stream that the rule \a r is going to be reduced. - virtual void yy_reduce_print_ (int r); - /// Print the state stack on the debug stream. - virtual void yystack_print_ (); - - // Debugging. - int yydebug_; - std::ostream* yycdebug_; - - /// \brief Display a symbol type, value and location. - /// \param yyo The output stream. - /// \param yysym The symbol. - template - void yy_print_ (std::ostream& yyo, const basic_symbol& yysym) const; -#endif - - /// \brief Reclaim the memory associated to a symbol. - /// \param yymsg Why this token is reclaimed. - /// If null, print nothing. - /// \param yysym The symbol. - template - void yy_destroy_ (const char* yymsg, basic_symbol& yysym) const; - - private: - /// Type access provider for state based symbols. - struct by_state - { - /// Default constructor. - by_state (); - - /// The symbol type as needed by the constructor. - typedef state_type kind_type; - - /// Constructor. - by_state (kind_type s); - - /// Copy constructor. - by_state (const by_state& other); - - /// Record that this symbol is empty. - void clear (); - - /// Steal the symbol type from \a that. - void move (by_state& that); - - /// The (internal) type number (corresponding to \a state). - /// \a empty_symbol when empty. - symbol_number_type type_get () const; - - /// The state number used to denote an empty symbol. - enum { empty_state = -1 }; - - /// The state. - /// \a empty when empty. - state_type state; - }; - - /// "Internal" symbol: element of the stack. - struct stack_symbol_type : basic_symbol - { - /// Superclass. - typedef basic_symbol super_type; - /// Construct an empty symbol. - stack_symbol_type (); - /// Steal the contents from \a sym to build this. - stack_symbol_type (state_type s, symbol_type& sym); - /// Assignment, needed by push_back. - stack_symbol_type& operator= (const stack_symbol_type& that); - }; - - /// Stack type. - typedef stack stack_type; - - /// The stack. - stack_type yystack_; - - /// Push a new state on the stack. - /// \param m a debug message to display - /// if null, no trace is output. - /// \param s the symbol - /// \warning the contents of \a s.value is stolen. - void yypush_ (const char* m, stack_symbol_type& s); - - /// Push a new look ahead token on the state on the stack. - /// \param m a debug message to display - /// if null, no trace is output. - /// \param s the state - /// \param sym the symbol (for its value and location). - /// \warning the contents of \a s.value is stolen. - void yypush_ (const char* m, state_type s, symbol_type& sym); - - /// Pop \a n symbols the three stacks. - void yypop_ (unsigned int n = 1); - - /// Constants. - enum - { - yyeof_ = 0, - yylast_ = 6, ///< Last index in yytable_. - yynnts_ = 5, ///< Number of nonterminal symbols. - yyfinal_ = 7, ///< Termination state number. - yyterror_ = 1, - yyerrcode_ = 256, - yyntokens_ = 5 ///< Number of tokens. - }; - - - // User arguments. - CommentsParserDriver &driver; - }; - - // Symbol number corresponding to token number t. - inline - parser::token_number_type - parser::yytranslate_ (token_type t) - { - static - const token_number_type - translate_table[] = - { - 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 1, 2, 3, 4 - }; - const unsigned int user_token_number_max_ = 259; - const token_number_type undef_token_ = 2; - - if (static_cast(t) <= yyeof_) - return yyeof_; - else if (static_cast (t) <= user_token_number_max_) - return translate_table[t]; - else - return undef_token_; - } - - inline - parser::syntax_error::syntax_error (const location_type& l, const std::string& m) - : std::runtime_error (m) - , location (l) - {} - - // basic_symbol. - template - inline - parser::basic_symbol::basic_symbol () - : value () - {} - - template - inline - parser::basic_symbol::basic_symbol (const basic_symbol& other) - : Base (other) - , value () - , location (other.location) - { - switch (other.type_get ()) - { - case 4: // STRING - case 8: // comment - case 9: // err - value.copy< std::string > (other.value); - break; - - default: - break; - } - - } - - - template - inline - parser::basic_symbol::basic_symbol (typename Base::kind_type t, const semantic_type& v, const location_type& l) - : Base (t) - , value () - , location (l) - { - (void) v; - switch (this->type_get ()) - { - case 4: // STRING - case 8: // comment - case 9: // err - value.copy< std::string > (v); - break; - - default: - break; - } -} - - - // Implementation of basic_symbol constructor for each type. - - template - parser::basic_symbol::basic_symbol (typename Base::kind_type t, const location_type& l) - : Base (t) - , value () - , location (l) - {} - - template - parser::basic_symbol::basic_symbol (typename Base::kind_type t, const std::string v, const location_type& l) - : Base (t) - , value (v) - , location (l) - {} - - - template - inline - parser::basic_symbol::~basic_symbol () - { - clear (); - } - - template - inline - void - parser::basic_symbol::clear () - { - // User destructor. - symbol_number_type yytype = this->type_get (); - basic_symbol& yysym = *this; - (void) yysym; - switch (yytype) - { - default: - break; - } - - // Type destructor. - switch (yytype) - { - case 4: // STRING - case 8: // comment - case 9: // err - value.template destroy< std::string > (); - break; - - default: - break; - } - - Base::clear (); - } - - template - inline - bool - parser::basic_symbol::empty () const - { - return Base::type_get () == empty_symbol; - } - - template - inline - void - parser::basic_symbol::move (basic_symbol& s) - { - super_type::move(s); - switch (this->type_get ()) - { - case 4: // STRING - case 8: // comment - case 9: // err - value.move< std::string > (s.value); - break; - - default: - break; - } - - location = s.location; - } - - // by_type. - inline - parser::by_type::by_type () - : type (empty_symbol) - {} - - inline - parser::by_type::by_type (const by_type& other) - : type (other.type) - {} - - inline - parser::by_type::by_type (token_type t) - : type (yytranslate_ (t)) - {} - - inline - void - parser::by_type::clear () - { - type = empty_symbol; - } - - inline - void - parser::by_type::move (by_type& that) - { - type = that.type; - that.clear (); - } - - inline - int - parser::by_type::type_get () const - { - return type; - } - - inline - parser::token_type - parser::by_type::token () const - { - // YYTOKNUM[NUM] -- (External) token number corresponding to the - // (internal) symbol number NUM (which must be that of a token). */ - static - const unsigned short int - yytoken_number_[] = - { - 0, 256, 257, 258, 259 - }; - return static_cast (yytoken_number_[type]); - } - // Implementation of make_symbol for each symbol type. - parser::symbol_type - parser::make_EOQ (const location_type& l) - { - return symbol_type (token::EOQ, l); - } - - parser::symbol_type - parser::make_ERROR_SYMBOL (const location_type& l) - { - return symbol_type (token::ERROR_SYMBOL, l); - } - - parser::symbol_type - parser::make_STRING (const std::string& v, const location_type& l) - { - return symbol_type (token::STRING, v, l); - } - - - -} // yy_comments - - - - - -#endif // !YY_YY_COMMENTS_D_DEV_CPPAN_CLIENT_SRC_COMMENTS_GRAMMAR_HPP_INCLUDED diff --git a/src/comments/grammar.yy b/src/comments/grammar.yy deleted file mode 100644 index b0b06a70..00000000 --- a/src/comments/grammar.yy +++ /dev/null @@ -1,76 +0,0 @@ -%{ -#include -#include -#include - -#include "comments/driver.h" - -#define yylex(p) p.lex() -%} - -//////////////////////////////////////// - -// general settings -%require "3.0" -%debug -%start file -%locations -%verbose -%no-lines -%error-verbose - -//////////////////////////////////////// - -// c++ skeleton and options -%skeleton "lalr1.cc" - -%define api.prefix {yy_comments} -%define api.value.type variant -%define api.token.constructor // C++ style of handling variants -%define parse.assert // check C++ variant types - -%code requires // forward decl of C++ driver (our parser) in HPP -{ -class CommentsParserDriver; -} - -// param to yy_comments::parser() constructor -// the parsing context -%param { CommentsParserDriver &driver } - -//////////////////////////////////////// - -// tokens and types -%token EOQ 0 "end of file" -%token ERROR_SYMBOL - -%token STRING -%type comment err - -//////////////////////////////////////// - -%% - -file: comments EOQ - ; - -comments: comment - { driver.comments.push_back($1); } - | comments comment - { driver.comments.push_back($2); } - ; - -comment: STRING - { $$ = $1; } - | err - ; -err: ERROR_SYMBOL - { return 0; } - ; - -%% - -void yy_comments::parser::error(const location_type& l, const std::string& m) -{ - driver.error(l, m); -} diff --git a/src/comments/lexer.cpp b/src/comments/lexer.cpp deleted file mode 100644 index d5807d6c..00000000 --- a/src/comments/lexer.cpp +++ /dev/null @@ -1,2018 +0,0 @@ -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 3 -#define YY_FLEX_MINOR_VERSION 0 -#define YY_FLEX_SUBMINOR_VERSION 0 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; - -#else - -#if defined(__cplusplus) && __cplusplus >= 199711L -#include -#endif - -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767 - 1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647 - 1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -/* TODO: this is always defined, so inline it */ -#define yyconst const - -#if defined(__GNUC__) && __GNUC__ >= 3 -#define yynoreturn __attribute__((__noreturn__)) -#else -#define yynoreturn -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an - * integer in range [0..255] for use as an array index. - */ -#define YY_SC_TO_UI(c) ((YY_CHAR) (c)) - -/* An opaque pointer. */ -#ifndef YY_TYPEDEF_YY_SCANNER_T -#define YY_TYPEDEF_YY_SCANNER_T -typedef void* yyscan_t; -#endif - -/* For convenience, these vars (plus the bison vars far below) - are macros in the reentrant scanner. */ -#define yyin yyg->yyin_r -#define yyout yyg->yyout_r -#define yyextra yyg->yyextra_r -#define yyleng yyg->yyleng_r -#define yytext yyg->yytext_r -#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) -#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) -#define yy_flex_debug yyg->yy_flex_debug_r - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN yyg->yy_start = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START ((yyg->yy_start - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE ll_commentsrestart(yyin , yyscanner ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -/* The state buf must be large enough to hold one state per character in the main buffer. - */ -#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires - * access to the local variable yy_act. Since yyless() is a macro, it would break - * existing scanners that call yyless() from OUTSIDE ll_commentslex. - * One obvious solution it to make yy_act a global. I tried that, and saw - * a 5% performance hit in a non-yylineno scanner, because yy_act is - * normally declared as a register variable-- so it is not worth it. - */ - #define YY_LESS_LINENO(n) \ - do { \ - int yyl;\ - for ( yyl = n; yyl < yyleng; ++yyl )\ - if ( yytext[yyl] == '\n' )\ - --yylineno;\ - }while(0) - #define YY_LINENO_REWIND_TO(dst) \ - do {\ - const char *p;\ - for ( p = yy_cp-1; p >= (dst); --p)\ - if ( *p == '\n' )\ - --yylineno;\ - }while(0) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = yyg->yy_hold_char; \ - YY_RESTORE_YY_MORE_OFFSET \ - yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner ) - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - int yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via ll_commentsrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \ - ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] - -void ll_commentsrestart (FILE *input_file , yyscan_t yyscanner ); -void ll_comments_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); -YY_BUFFER_STATE ll_comments_create_buffer (FILE *file,int size , yyscan_t yyscanner ); -void ll_comments_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner ); -void ll_comments_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner ); -void ll_commentspush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); -void ll_commentspop_buffer_state (yyscan_t yyscanner ); - -static void ll_commentsensure_buffer_stack (yyscan_t yyscanner ); -static void ll_comments_load_buffer_state (yyscan_t yyscanner ); -static void ll_comments_init_buffer (YY_BUFFER_STATE b,FILE *file , yyscan_t yyscanner ); - -#define YY_FLUSH_BUFFER ll_comments_flush_buffer(YY_CURRENT_BUFFER , yyscanner) - -YY_BUFFER_STATE ll_comments_scan_buffer (char *base,yy_size_t size , yyscan_t yyscanner ); -YY_BUFFER_STATE ll_comments_scan_string (yyconst char *yy_str , yyscan_t yyscanner ); -YY_BUFFER_STATE ll_comments_scan_bytes (yyconst char *bytes,int len , yyscan_t yyscanner ); - -void *ll_commentsalloc (yy_size_t , yyscan_t yyscanner ); -void *ll_commentsrealloc (void *,yy_size_t , yyscan_t yyscanner ); -void ll_commentsfree (void * , yyscan_t yyscanner ); - -#define yy_new_buffer ll_comments_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - ll_commentsensure_buffer_stack (yyscanner); \ - YY_CURRENT_BUFFER_LVALUE = \ - ll_comments_create_buffer(yyin,YY_BUF_SIZE , yyscanner); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - ll_commentsensure_buffer_stack (yyscanner); \ - YY_CURRENT_BUFFER_LVALUE = \ - ll_comments_create_buffer(yyin,YY_BUF_SIZE , yyscanner); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ - -#define ll_commentswrap(yyscanner) (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP - -typedef flex_uint8_t YY_CHAR; - -typedef int yy_state_type; - -#define yytext_ptr yytext_r - -static yy_state_type yy_get_previous_state (yyscan_t yyscanner ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state , yyscan_t yyscanner); -static int yy_get_next_buffer (yyscan_t yyscanner ); -static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - yyg->yytext_ptr = yy_bp; \ -yyleng = (size_t) (yy_cp - yy_bp); \ - yyg->yy_hold_char = *yy_cp; \ - *yy_cp = '\0'; \ - yyg->yy_c_buf_p = yy_cp; - -#define YY_NUM_RULES 12 -#define YY_END_OF_BUFFER 13 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info -{ -flex_int32_t yy_verify; -flex_int32_t yy_nxt; -}; -static yyconst flex_int16_t yy_accept[26] = - { 0, - 0, 0, 7, 7, 13, 11, 2, 4, 3, 11, - 11, 7, 9, 8, 2, 0, 1, 6, 5, 7, - 8, 8, 10, 5, 0 - } ; - -static yyconst YY_CHAR yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 1, 1, 5, 1, 1, 1, 1, 1, - 1, 6, 1, 1, 1, 1, 7, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst YY_CHAR yy_meta[8] = - { 0, - 1, 1, 2, 1, 1, 3, 1 - } ; - -static yyconst flex_int16_t yy_base[31] = - { 0, - 0, 0, 5, 9, 34, 36, 29, 36, 36, 11, - 10, 0, 36, 12, 11, 7, 36, 36, 0, 0, - 14, 16, 36, 0, 36, 23, 26, 8, 29, 32 - } ; - -static yyconst flex_int16_t yy_def[31] = - { 0, - 25, 1, 26, 26, 25, 25, 25, 25, 25, 27, - 25, 28, 25, 29, 25, 27, 25, 25, 30, 28, - 29, 29, 25, 30, 0, 25, 25, 25, 25, 25 - } ; - -static yyconst flex_int16_t yy_nxt[44] = - { 0, - 6, 7, 8, 9, 10, 6, 11, 13, 20, 17, - 14, 13, 15, 17, 14, 18, 19, 22, 23, 25, - 25, 22, 23, 12, 12, 12, 16, 16, 16, 21, - 15, 21, 24, 25, 24, 5, 25, 25, 25, 25, - 25, 25, 25 - } ; - -static yyconst flex_int16_t yy_chk[44] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 3, 28, 16, - 3, 4, 15, 10, 4, 11, 11, 14, 14, 21, - 21, 22, 22, 26, 26, 26, 27, 27, 27, 29, - 7, 29, 30, 5, 30, 25, 25, 25, 25, 25, - 25, 25, 25 - } ; - -/* Table of booleans, true if rule could match eol. */ -static yyconst flex_int32_t yy_rule_can_match_eol[13] = - { 0, -1, -0, -0, -1, -0, -0, -0, -0, -1, -0, -0, -0, - }; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -#pragma warning(disable: 4005) -#include - -#include "comments/grammar.hpp" - -#define YY_USER_ACTION loc.columns(yyleng); - -#define YY_DECL yy_comments::parser::symbol_type ll_commentslex(yyscan_t yyscanner,yy_comments::location &loc) - -#define MAKE(x) yy_comments::parser::make_ ## x(loc) -#define MAKE_VALUE(x, v) yy_comments::parser::make_ ## x((v), loc) - -std::string comment; -#define YY_NO_UNISTD_H 1 - -#define INITIAL 0 -#define COMMENT 1 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#ifndef WIN32 -#include -#endif -#endif - -#ifdef WIN32 -#include -#define fileno _fileno -#define isatty _isatty -#define read _read -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -/* Holds the entire state of the reentrant scanner. */ -struct yyguts_t - { - - /* User-defined. Not touched by flex. */ - YY_EXTRA_TYPE yyextra_r; - - /* The rest are the same as the globals declared in the non-reentrant scanner. */ - FILE *yyin_r, *yyout_r; - size_t yy_buffer_stack_top; /**< index of top of stack. */ - size_t yy_buffer_stack_max; /**< capacity of stack. */ - YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */ - char yy_hold_char; - int yy_n_chars; - int yyleng_r; - char *yy_c_buf_p; - int yy_init; - int yy_start; - int yy_did_buffer_switch_on_eof; - int yy_start_stack_ptr; - int yy_start_stack_depth; - int *yy_start_stack; - yy_state_type yy_last_accepting_state; - char* yy_last_accepting_cpos; - - int yylineno_r; - int yy_flex_debug_r; - - char *yytext_r; - int yy_more_flag; - int yy_more_len; - - }; /* end struct yyguts_t */ - -static int yy_init_globals (yyscan_t yyscanner ); - -int ll_commentslex_init (yyscan_t* scanner); - -int ll_commentslex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int ll_commentslex_destroy (yyscan_t yyscanner ); - -int ll_commentsget_debug (yyscan_t yyscanner ); - -void ll_commentsset_debug (int debug_flag , yyscan_t yyscanner ); - -YY_EXTRA_TYPE ll_commentsget_extra (yyscan_t yyscanner ); - -void ll_commentsset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner ); - -FILE *ll_commentsget_in (yyscan_t yyscanner ); - -void ll_commentsset_in (FILE * _in_str , yyscan_t yyscanner ); - -FILE *ll_commentsget_out (yyscan_t yyscanner ); - -void ll_commentsset_out (FILE * _out_str , yyscan_t yyscanner ); - - int ll_commentsget_leng (yyscan_t yyscanner ); - -char *ll_commentsget_text (yyscan_t yyscanner ); - -int ll_commentsget_lineno (yyscan_t yyscanner ); - -void ll_commentsset_lineno (int _line_number , yyscan_t yyscanner ); - -int ll_commentsget_column (yyscan_t yyscanner ); - -void ll_commentsset_column (int _column_no , yyscan_t yyscanner ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int ll_commentswrap (yyscan_t yyscanner ); -#else -extern int ll_commentswrap (yyscan_t yyscanner ); -#endif -#endif - -#ifndef YY_NO_UNPUT - -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int , yyscan_t yyscanner); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * , yyscan_t yyscanner); -#endif - -#ifndef YY_NO_INPUT - -#ifdef __cplusplus -static int yyinput (yyscan_t yyscanner ); -#else -static int input (yyscan_t yyscanner ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - int n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int ll_commentslex (yyscan_t yyscanner); - -#define YY_DECL int ll_commentslex (yyscan_t yyscanner) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; -#endif - -#define YY_RULE_SETUP \ -YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if ( !yyg->yy_init ) - { - yyg->yy_init = 1; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! yyg->yy_start ) - yyg->yy_start = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - ll_commentsensure_buffer_stack (yyscanner); - YY_CURRENT_BUFFER_LVALUE = - ll_comments_create_buffer(yyin,YY_BUF_SIZE , yyscanner); - } - - ll_comments_load_buffer_state(yyscanner ); - } - - { - - // Code run each time ll_commentslex is called. - loc.step(); - - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ - { - yy_cp = yyg->yy_c_buf_p; - - /* Support of yytext. */ - *yy_cp = yyg->yy_hold_char; - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - -yy_current_state = yyg->yy_start; -yy_match: -do -{ -YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; -if ( yy_accept[yy_current_state] ) -{ -yyg->yy_last_accepting_state = yy_current_state; -yyg->yy_last_accepting_cpos = yy_cp; -} -while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) -{ -yy_current_state = (int) yy_def[yy_current_state]; -if ( yy_current_state >= 26 ) -yy_c = yy_meta[yy_c]; -} -yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; -++yy_cp; -} -while ( yy_current_state != 25 ); -yy_cp = yyg->yy_last_accepting_cpos; -yy_current_state = yyg->yy_last_accepting_state; - -yy_find_action: -yy_act = yy_accept[yy_current_state]; - - YY_DO_BEFORE_ACTION; - -if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) -{ -int yyl; -for ( yyl = 0; yyl < yyleng; ++yyl ) -if ( yytext[yyl] == '\n' ) - - do{ yylineno++; - yycolumn=0; - }while(0) -; -} - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ -case 0: /* must back up */ -/* undo the effects of YY_DO_BEFORE_ACTION */ -*yy_cp = yyg->yy_hold_char; -yy_cp = yyg->yy_last_accepting_cpos; -yy_current_state = yyg->yy_last_accepting_state; -goto yy_find_action; - -case 1: -/* rule 1 can match eol */ -*yy_cp = yyg->yy_hold_char; /* undo effects of setting up yytext */ -YY_LINENO_REWIND_TO(yy_cp - 1); -yyg->yy_c_buf_p = yy_cp -= 1; -YY_DO_BEFORE_ACTION; /* set up yytext again */ -YY_RULE_SETUP -; // ignore comments - YY_BREAK -case 2: -YY_RULE_SETUP -loc.step(); - YY_BREAK -case 3: -YY_RULE_SETUP -loc.step(); - YY_BREAK -case 4: -/* rule 4 can match eol */ -YY_RULE_SETUP -{ - loc.lines(yyleng); - loc.step(); - } - YY_BREAK -case 5: -YY_RULE_SETUP -; - YY_BREAK -case 6: -YY_RULE_SETUP -{ BEGIN(COMMENT); comment.clear(); } - YY_BREAK -case 7: -case 8: -case 9: -/* rule 9 can match eol */ -YY_RULE_SETUP -comment += yytext; - YY_BREAK -case 10: -YY_RULE_SETUP -{ BEGIN(INITIAL); return MAKE_VALUE(STRING, comment);} - YY_BREAK -case 11: -YY_RULE_SETUP -{ /*driver.error(loc, "invalid character");*/ return MAKE(ERROR_SYMBOL); } - YY_BREAK -case YY_STATE_EOF(INITIAL): -case YY_STATE_EOF(COMMENT): -return MAKE(EOQ); - YY_BREAK -case 12: -YY_RULE_SETUP -ECHO; - YY_BREAK - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = yyg->yy_hold_char; - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * ll_commentslex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( yyscanner ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner); - - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++yyg->yy_c_buf_p; - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { -yy_cp = yyg->yy_last_accepting_cpos; -yy_current_state = yyg->yy_last_accepting_state; - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( yyscanner ) ) - { - case EOB_ACT_END_OF_FILE: - { - yyg->yy_did_buffer_switch_on_eof = 0; - - if ( ll_commentswrap(yyscanner ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! yyg->yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - yyg->yy_c_buf_p = - yyg->yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( yyscanner ); - - yy_cp = yyg->yy_c_buf_p; - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - yyg->yy_c_buf_p = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars]; - - yy_current_state = yy_get_previous_state( yyscanner ); - - yy_cp = yyg->yy_c_buf_p; - yy_bp = yyg->yytext_ptr + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of user's declarations */ -} /* end of ll_commentslex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = yyg->yytext_ptr; - int number_to_move, i; - int ret_val; - - if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1); - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0; - - else - { - int num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; - - int yy_c_buf_p_offset = - (int) (yyg->yy_c_buf_p - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - int new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - ll_commentsrealloc((void *) b->yy_ch_buf,(yy_size_t) (b->yy_buf_size + 2) , yyscanner ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = NULL; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - yyg->yy_n_chars, num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - if ( yyg->yy_n_chars == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - ll_commentsrestart(yyin , yyscanner); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { - /* Extend the array by 50%, plus the number we really need. */ - int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1); - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) ll_commentsrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,(yy_size_t) new_size , yyscanner ); - if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); - } - - yyg->yy_n_chars += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - - yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (yyscan_t yyscanner) -{ - yy_state_type yy_current_state; - char *yy_cp; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - -yy_current_state = yyg->yy_start; - - for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp ) - { -YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); -if ( yy_accept[yy_current_state] ) -{ -yyg->yy_last_accepting_state = yy_current_state; -yyg->yy_last_accepting_cpos = yy_cp; -} -while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) -{ -yy_current_state = (int) yy_def[yy_current_state]; -if ( yy_current_state >= 26 ) -yy_c = yy_meta[yy_c]; -} -yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state , yyscan_t yyscanner) -{ - int yy_is_jam; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */ -char *yy_cp = yyg->yy_c_buf_p; - -YY_CHAR yy_c = 1; -if ( yy_accept[yy_current_state] ) -{ -yyg->yy_last_accepting_state = yy_current_state; -yyg->yy_last_accepting_cpos = yy_cp; -} -while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) -{ -yy_current_state = (int) yy_def[yy_current_state]; -if ( yy_current_state >= 26 ) -yy_c = yy_meta[yy_c]; -} -yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c]; -yy_is_jam = (yy_current_state == 25); - - (void)yyg; - return yy_is_jam ? 0 : yy_current_state; -} - -#ifndef YY_NO_UNPUT - -#endif - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (yyscan_t yyscanner) -#else - static int input (yyscan_t yyscanner) -#endif - -{ - int c; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - *yyg->yy_c_buf_p = yyg->yy_hold_char; - - if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] ) - /* This was really a NUL. */ - *yyg->yy_c_buf_p = '\0'; - - else - { /* need more input */ - int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr); - ++yyg->yy_c_buf_p; - - switch ( yy_get_next_buffer( yyscanner ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - ll_commentsrestart(yyin , yyscanner); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( ll_commentswrap(yyscanner ) ) - return 0; - - if ( ! yyg->yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(yyscanner); -#else - return input(yyscanner); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - yyg->yy_c_buf_p = yyg->yytext_ptr + offset; - break; - } - } - } - - c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */ - *yyg->yy_c_buf_p = '\0'; /* preserve yytext */ - yyg->yy_hold_char = *++yyg->yy_c_buf_p; - -if ( c == '\n' ) - - do{ yylineno++; - yycolumn=0; - }while(0) -; - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * @param yyscanner The scanner object. - * @note This function does not reset the start condition to @c INITIAL . - */ - void ll_commentsrestart (FILE * input_file , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if ( ! YY_CURRENT_BUFFER ){ - ll_commentsensure_buffer_stack (yyscanner); - YY_CURRENT_BUFFER_LVALUE = - ll_comments_create_buffer(yyin,YY_BUF_SIZE , yyscanner); - } - - ll_comments_init_buffer(YY_CURRENT_BUFFER,input_file , yyscanner); - ll_comments_load_buffer_state(yyscanner ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * @param yyscanner The scanner object. - */ - void ll_comments_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* TODO. We should be able to replace this entire function body - * with - * ll_commentspop_buffer_state(); - * ll_commentspush_buffer_state(new_buffer); - */ - ll_commentsensure_buffer_stack (yyscanner); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *yyg->yy_c_buf_p = yyg->yy_hold_char; - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - ll_comments_load_buffer_state(yyscanner ); - - /* We don't actually know whether we did this switch during - * EOF (ll_commentswrap()) processing, but the only time this flag - * is looked at is after ll_commentswrap() is called, so it's safe - * to go ahead and always set it. - */ - yyg->yy_did_buffer_switch_on_eof = 1; -} - -static void ll_comments_load_buffer_state (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - yyg->yy_hold_char = *yyg->yy_c_buf_p; -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * @param yyscanner The scanner object. - * @return the allocated buffer state. - */ - YY_BUFFER_STATE ll_comments_create_buffer (FILE * file, int size , yyscan_t yyscanner) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) ll_commentsalloc(sizeof( struct yy_buffer_state ) , yyscanner ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in ll_comments_create_buffer()" ); - - b->yy_buf_size = size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) ll_commentsalloc((yy_size_t) (b->yy_buf_size + 2) , yyscanner ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in ll_comments_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - ll_comments_init_buffer(b,file , yyscanner); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with ll_comments_create_buffer() - * @param yyscanner The scanner object. - */ - void ll_comments_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - ll_commentsfree((void *) b->yy_ch_buf , yyscanner ); - - ll_commentsfree((void *) b , yyscanner ); -} - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a ll_commentsrestart() or at EOF. - */ - static void ll_comments_init_buffer (YY_BUFFER_STATE b, FILE * file , yyscan_t yyscanner) - -{ - int oerrno = errno; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - ll_comments_flush_buffer(b , yyscanner); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then ll_comments_init_buffer was _probably_ - * called from ll_commentsrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = 0; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * @param yyscanner The scanner object. - */ - void ll_comments_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - ll_comments_load_buffer_state(yyscanner ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * @param yyscanner The scanner object. - */ -void ll_commentspush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if (new_buffer == NULL) - return; - - ll_commentsensure_buffer_stack(yyscanner); - - /* This block is copied from ll_comments_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *yyg->yy_c_buf_p = yyg->yy_hold_char; - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p; - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars; - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - yyg->yy_buffer_stack_top++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from ll_comments_switch_to_buffer. */ - ll_comments_load_buffer_state(yyscanner ); - yyg->yy_did_buffer_switch_on_eof = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * @param yyscanner The scanner object. - */ -void ll_commentspop_buffer_state (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - if (!YY_CURRENT_BUFFER) - return; - - ll_comments_delete_buffer(YY_CURRENT_BUFFER , yyscanner); - YY_CURRENT_BUFFER_LVALUE = NULL; - if (yyg->yy_buffer_stack_top > 0) - --yyg->yy_buffer_stack_top; - - if (YY_CURRENT_BUFFER) { - ll_comments_load_buffer_state(yyscanner ); - yyg->yy_did_buffer_switch_on_eof = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void ll_commentsensure_buffer_stack (yyscan_t yyscanner) -{ - yy_size_t num_to_alloc; - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if (!yyg->yy_buffer_stack) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ - yyg->yy_buffer_stack = (struct yy_buffer_state**)ll_commentsalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - , yyscanner); - if ( ! yyg->yy_buffer_stack ) - YY_FATAL_ERROR( "out of dynamic memory in ll_commentsensure_buffer_stack()" ); - - memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - yyg->yy_buffer_stack_max = num_to_alloc; - yyg->yy_buffer_stack_top = 0; - return; - } - - if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = yyg->yy_buffer_stack_max + grow_size; - yyg->yy_buffer_stack = (struct yy_buffer_state**)ll_commentsrealloc - (yyg->yy_buffer_stack, - num_to_alloc * sizeof(struct yy_buffer_state*) - , yyscanner); - if ( ! yyg->yy_buffer_stack ) - YY_FATAL_ERROR( "out of dynamic memory in ll_commentsensure_buffer_stack()" ); - - /* zero only the new slots.*/ - memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*)); - yyg->yy_buffer_stack_max = num_to_alloc; - } -} - -/** Setup the input buffer state to scan directly from a user-specified character buffer. - * @param base the character buffer - * @param size the size in bytes of the character buffer - * @param yyscanner The scanner object. - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE ll_comments_scan_buffer (char * base, yy_size_t size , yyscan_t yyscanner) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return NULL; - - b = (YY_BUFFER_STATE) ll_commentsalloc(sizeof( struct yy_buffer_state ) , yyscanner ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in ll_comments_scan_buffer()" ); - - b->yy_buf_size = (int) (size - 2); /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = NULL; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - ll_comments_switch_to_buffer(b , yyscanner ); - - return b; -} - -/** Setup the input buffer state to scan a string. The next call to ll_commentslex() will - * scan from a @e copy of @a str. - * @param yystr a NUL-terminated string to scan - * @param yyscanner The scanner object. - * @return the newly allocated buffer state object. - * @note If you want to scan bytes that may contain NUL values, then use - * ll_comments_scan_bytes() instead. - */ -YY_BUFFER_STATE ll_comments_scan_string (yyconst char * yystr , yyscan_t yyscanner) -{ - - return ll_comments_scan_bytes(yystr,(int) strlen(yystr) , yyscanner); -} - -/** Setup the input buffer state to scan the given bytes. The next call to ll_commentslex() will - * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. - * @param yyscanner The scanner object. - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE ll_comments_scan_bytes (yyconst char * yybytes, int _yybytes_len , yyscan_t yyscanner) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = (yy_size_t) (_yybytes_len + 2); - buf = (char *) ll_commentsalloc(n , yyscanner ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in ll_comments_scan_bytes()" ); - - for ( i = 0; i < _yybytes_len; ++i ) - buf[i] = yybytes[i]; - - buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; - - b = ll_comments_scan_buffer(buf,n , yyscanner); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in ll_comments_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yynoreturn yy_fatal_error (yyconst char* msg , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = yyg->yy_hold_char; \ - yyg->yy_c_buf_p = yytext + yyless_macro_arg; \ - yyg->yy_hold_char = *yyg->yy_c_buf_p; \ - *yyg->yy_c_buf_p = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the user-defined data for this scanner. - * @param yyscanner The scanner object. - */ -YY_EXTRA_TYPE ll_commentsget_extra (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyextra; -} - -/** Get the current line number. - * @param yyscanner The scanner object. - */ -int ll_commentsget_lineno (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if (! YY_CURRENT_BUFFER) - return 0; - - return yylineno; -} - -/** Get the current column number. - * @param yyscanner The scanner object. - */ -int ll_commentsget_column (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - if (! YY_CURRENT_BUFFER) - return 0; - - return yycolumn; -} - -/** Get the input stream. - * @param yyscanner The scanner object. - */ -FILE *ll_commentsget_in (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyin; -} - -/** Get the output stream. - * @param yyscanner The scanner object. - */ -FILE *ll_commentsget_out (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyout; -} - -/** Get the length of the current token. - * @param yyscanner The scanner object. - */ -int ll_commentsget_leng (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yyleng; -} - -/** Get the current token. - * @param yyscanner The scanner object. - */ - -char *ll_commentsget_text (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yytext; -} - -/** Set the user-defined data. This data is never touched by the scanner. - * @param user_defined The data to be associated with this scanner. - * @param yyscanner The scanner object. - */ -void ll_commentsset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyextra = user_defined ; -} - -/** Set the current line number. - * @param _line_number line number - * @param yyscanner The scanner object. - */ -void ll_commentsset_lineno (int _line_number , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* lineno is only valid if an input buffer exists. */ - if (! YY_CURRENT_BUFFER ) - YY_FATAL_ERROR( "ll_commentsset_lineno called with no buffer" ); - - yylineno = _line_number; -} - -/** Set the current column. - * @param _column_no column number - * @param yyscanner The scanner object. - */ -void ll_commentsset_column (int _column_no , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* column is only valid if an input buffer exists. */ - if (! YY_CURRENT_BUFFER ) - YY_FATAL_ERROR( "ll_commentsset_column called with no buffer" ); - - yycolumn = _column_no; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param _in_str A readable stream. - * @param yyscanner The scanner object. - * @see ll_comments_switch_to_buffer - */ -void ll_commentsset_in (FILE * _in_str , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyin = _in_str ; -} - -void ll_commentsset_out (FILE * _out_str , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yyout = _out_str ; -} - -int ll_commentsget_debug (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - return yy_flex_debug; -} - -void ll_commentsset_debug (int _bdebug , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - yy_flex_debug = _bdebug ; -} - -/* Accessor methods for yylval and yylloc */ - -/* User-visible API */ - -/* ll_commentslex_init is special because it creates the scanner itself, so it is - * the ONLY reentrant function that doesn't take the scanner as the last argument. - * That's why we explicitly handle the declaration, instead of using our macros. - */ - -int ll_commentslex_init(yyscan_t* ptr_yy_globals) - -{ - if (ptr_yy_globals == NULL){ - errno = EINVAL; - return 1; - } - - *ptr_yy_globals = (yyscan_t) ll_commentsalloc ( sizeof( struct yyguts_t ), NULL ); - - if (*ptr_yy_globals == NULL){ - errno = ENOMEM; - return 1; - } - - /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */ - memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); - - return yy_init_globals ( *ptr_yy_globals ); -} - -/* ll_commentslex_init_extra has the same functionality as ll_commentslex_init, but follows the - * convention of taking the scanner as the last argument. Note however, that - * this is a *pointer* to a scanner, as it will be allocated by this call (and - * is the reason, too, why this function also must handle its own declaration). - * The user defined value in the first argument will be available to ll_commentsalloc in - * the yyextra field. - */ - -int ll_commentslex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals ) - -{ - struct yyguts_t dummy_yyguts; - - ll_commentsset_extra (yy_user_defined, &dummy_yyguts); - - if (ptr_yy_globals == NULL){ - errno = EINVAL; - return 1; - } - - *ptr_yy_globals = (yyscan_t) ll_commentsalloc ( sizeof( struct yyguts_t ), &dummy_yyguts ); - - if (*ptr_yy_globals == NULL){ - errno = ENOMEM; - return 1; - } - - /* By setting to 0xAA, we expose bugs in - yy_init_globals. Leave at 0x00 for releases. */ - memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t)); - - ll_commentsset_extra (yy_user_defined, *ptr_yy_globals); - - return yy_init_globals ( *ptr_yy_globals ); -} - -static int yy_init_globals (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - /* Initialization is the same as for the non-reentrant scanner. - * This function is called from ll_commentslex_destroy(), so don't allocate here. - */ - - yyg->yy_buffer_stack = NULL; - yyg->yy_buffer_stack_top = 0; - yyg->yy_buffer_stack_max = 0; - yyg->yy_c_buf_p = NULL; - yyg->yy_init = 0; - yyg->yy_start = 0; - - yyg->yy_start_stack_ptr = 0; - yyg->yy_start_stack_depth = 0; - yyg->yy_start_stack = NULL; - -/* Defined in main.c */ -#ifdef YY_STDINIT - yyin = stdin; - yyout = stdout; -#else - yyin = NULL; - yyout = NULL; -#endif - - /* For future reference: Set errno on error, since we are called by - * ll_commentslex_init() - */ - return 0; -} - -/* ll_commentslex_destroy is for both reentrant and non-reentrant scanners. */ -int ll_commentslex_destroy (yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - ll_comments_delete_buffer(YY_CURRENT_BUFFER , yyscanner ); - YY_CURRENT_BUFFER_LVALUE = NULL; - ll_commentspop_buffer_state(yyscanner); - } - - /* Destroy the stack itself. */ - ll_commentsfree(yyg->yy_buffer_stack , yyscanner); - yyg->yy_buffer_stack = NULL; - - /* Destroy the start condition stack. */ - ll_commentsfree(yyg->yy_start_stack , yyscanner ); - yyg->yy_start_stack = NULL; - - /* Reset the globals. This is important in a non-reentrant scanner so the next time - * ll_commentslex() is called, initialization will occur. */ - yy_init_globals( yyscanner); - - /* Destroy the main struct (reentrant only). */ - ll_commentsfree ( yyscanner , yyscanner ); - yyscanner = NULL; - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - - int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s , yyscan_t yyscanner) -{ - int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *ll_commentsalloc (yy_size_t size , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - return malloc(size); -} - -void *ll_commentsrealloc (void * ptr, yy_size_t size , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return realloc(ptr, size); -} - -void ll_commentsfree (void * ptr , yyscan_t yyscanner) -{ - struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; - (void)yyg; - free( (char *) ptr ); /* see ll_commentsrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - diff --git a/src/comments/lexer.h b/src/comments/lexer.h deleted file mode 100644 index 1cc69d93..00000000 --- a/src/comments/lexer.h +++ /dev/null @@ -1,344 +0,0 @@ -#ifndef ll_commentsHEADER_H -#define ll_commentsHEADER_H 1 -#define ll_commentsIN_HEADER 1 - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 3 -#define YY_FLEX_MINOR_VERSION 0 -#define YY_FLEX_SUBMINOR_VERSION 0 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L - -/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, - * if you want the limit (max/min) macros for int types. - */ -#ifndef __STDC_LIMIT_MACROS -#define __STDC_LIMIT_MACROS 1 -#endif - -#include -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; - -#else - -#if defined(__cplusplus) && __cplusplus >= 199711L -#include -#endif - -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767 - 1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647 - 1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! C99 */ - -#endif /* ! FLEXINT_H */ - -/* TODO: this is always defined, so inline it */ -#define yyconst const - -#if defined(__GNUC__) && __GNUC__ >= 3 -#define yynoreturn __attribute__((__noreturn__)) -#else -#define yynoreturn -#endif - -/* An opaque pointer. */ -#ifndef YY_TYPEDEF_YY_SCANNER_T -#define YY_TYPEDEF_YY_SCANNER_T -typedef void* yyscan_t; -#endif - -/* For convenience, these vars (plus the bison vars far below) - are macros in the reentrant scanner. */ -#define yyin yyg->yyin_r -#define yyout yyg->yyout_r -#define yyextra yyg->yyextra_r -#define yyleng yyg->yyleng_r -#define yytext yyg->yytext_r -#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno) -#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column) -#define yy_flex_debug yyg->yy_flex_debug_r - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else -#define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ -#endif - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef size_t yy_size_t; -#endif - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - int yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -void ll_commentsrestart (FILE *input_file , yyscan_t yyscanner ); -void ll_comments_switch_to_buffer (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); -YY_BUFFER_STATE ll_comments_create_buffer (FILE *file,int size , yyscan_t yyscanner ); -void ll_comments_delete_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner ); -void ll_comments_flush_buffer (YY_BUFFER_STATE b , yyscan_t yyscanner ); -void ll_commentspush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner ); -void ll_commentspop_buffer_state (yyscan_t yyscanner ); - -YY_BUFFER_STATE ll_comments_scan_buffer (char *base,yy_size_t size , yyscan_t yyscanner ); -YY_BUFFER_STATE ll_comments_scan_string (yyconst char *yy_str , yyscan_t yyscanner ); -YY_BUFFER_STATE ll_comments_scan_bytes (yyconst char *bytes,int len , yyscan_t yyscanner ); - -void *ll_commentsalloc (yy_size_t , yyscan_t yyscanner ); -void *ll_commentsrealloc (void *,yy_size_t , yyscan_t yyscanner ); -void ll_commentsfree (void * , yyscan_t yyscanner ); - -/* Begin user sect3 */ - -#define ll_commentswrap(yyscanner) (/*CONSTCOND*/1) -#define YY_SKIP_YYWRAP - -#define yytext_ptr yytext_r - -#ifdef YY_HEADER_EXPORT_START_CONDITIONS -#define INITIAL 0 -#define COMMENT 1 - -#endif - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#ifndef WIN32 -#include -#endif -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -int ll_commentslex_init (yyscan_t* scanner); - -int ll_commentslex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner); - -/* Accessor methods to globals. - These are made visible to non-reentrant scanners for convenience. */ - -int ll_commentslex_destroy (yyscan_t yyscanner ); - -int ll_commentsget_debug (yyscan_t yyscanner ); - -void ll_commentsset_debug (int debug_flag , yyscan_t yyscanner ); - -YY_EXTRA_TYPE ll_commentsget_extra (yyscan_t yyscanner ); - -void ll_commentsset_extra (YY_EXTRA_TYPE user_defined , yyscan_t yyscanner ); - -FILE *ll_commentsget_in (yyscan_t yyscanner ); - -void ll_commentsset_in (FILE * _in_str , yyscan_t yyscanner ); - -FILE *ll_commentsget_out (yyscan_t yyscanner ); - -void ll_commentsset_out (FILE * _out_str , yyscan_t yyscanner ); - - int ll_commentsget_leng (yyscan_t yyscanner ); - -char *ll_commentsget_text (yyscan_t yyscanner ); - -int ll_commentsget_lineno (yyscan_t yyscanner ); - -void ll_commentsset_lineno (int _line_number , yyscan_t yyscanner ); - -int ll_commentsget_column (yyscan_t yyscanner ); - -void ll_commentsset_column (int _column_no , yyscan_t yyscanner ); - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int ll_commentswrap (yyscan_t yyscanner ); -#else -extern int ll_commentswrap (yyscan_t yyscanner ); -#endif -#endif - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int , yyscan_t yyscanner); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * , yyscan_t yyscanner); -#endif - -#ifndef YY_NO_INPUT - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else -#define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int ll_commentslex (yyscan_t yyscanner); - -#define YY_DECL int ll_commentslex (yyscan_t yyscanner) -#endif /* !YY_DECL */ - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - -#undef YY_NEW_FILE -#undef YY_FLUSH_BUFFER -#undef yy_set_bol -#undef yy_new_buffer -#undef yy_set_interactive -#undef YY_DO_BEFORE_ACTION - -#ifdef YY_DECL_IS_OURS -#undef YY_DECL_IS_OURS -#undef YY_DECL -#endif - -#undef ll_commentsIN_HEADER - -#endif /* ll_commentsHEADER_H */ - diff --git a/src/comments/lexer.ll b/src/comments/lexer.ll deleted file mode 100644 index 59f21905..00000000 --- a/src/comments/lexer.ll +++ /dev/null @@ -1,55 +0,0 @@ -%{ -#pragma warning(disable: 4005) -#include - -#include "comments/grammar.hpp" - -#define YY_USER_ACTION loc.columns(yyleng); - -#define YY_DECL yy_comments::parser::symbol_type yylex(yyscan_t yyscanner, yy_comments::location &loc) - -#define MAKE(x) yy_comments::parser::make_ ## x(loc) -#define MAKE_VALUE(x, v) yy_comments::parser::make_ ## x((v), loc) - -std::string comment; -%} - -%option nounistd -%option yylineno -%option nounput -%option batch -%option never-interactive -%option reentrant -%option noyywrap -%option prefix="ll_comments" - -%x COMMENT - -%% - -%{ - // Code run each time yylex is called. - loc.step(); -%} - -#.*/\n ; // ignore comments - -[ \t]+ loc.step(); -\r loc.step(); -\n { - loc.lines(yyleng); - loc.step(); - } - -\/\/.* ; - -"/*" { BEGIN(COMMENT); comment.clear(); } -[^*\n]* | -"*"+[^*/\n]* | -\n comment += yytext; -"*"+"/" { BEGIN(INITIAL); return MAKE_VALUE(STRING, comment);} - -. { /*driver.error(loc, "invalid character");*/ return MAKE(ERROR_SYMBOL); } -<> return MAKE(EOQ); - -%% diff --git a/src/comments/location.hh b/src/comments/location.hh deleted file mode 100644 index 8f4fac9d..00000000 --- a/src/comments/location.hh +++ /dev/null @@ -1,192 +0,0 @@ -// A Bison parser, made by GNU Bison 3.0.4. - -// Locations for Bison parsers in C++ - -// Copyright (C) 2002-2015 Free Software Foundation, Inc. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// As a special exception, you may create a larger work that contains -// part or all of the Bison parser skeleton and distribute that work -// under terms of your choice, so long as that work isn't itself a -// parser generator using the skeleton or a modified version thereof -// as a parser skeleton. Alternatively, if you modify or redistribute -// the parser skeleton itself, you may (at your option) remove this -// special exception, which will cause the skeleton and the resulting -// Bison output files to be licensed under the GNU General Public -// License without this special exception. - -// This special exception was added by the Free Software Foundation in -// version 2.2 of Bison. - -/** - ** \file D:/dev/cppan_client/src/comments/location.hh - ** Define the yy_comments::location class. - */ - -#ifndef YY_YY_COMMENTS_D_DEV_CPPAN_CLIENT_SRC_COMMENTS_LOCATION_HH_INCLUDED -# define YY_YY_COMMENTS_D_DEV_CPPAN_CLIENT_SRC_COMMENTS_LOCATION_HH_INCLUDED - -# include "position.hh" - - -namespace yy_comments { - - /// Abstract a location. - class location - { - public: - - /// Construct a location from \a b to \a e. - location (const position& b, const position& e) - : begin (b) - , end (e) - { - } - - /// Construct a 0-width location in \a p. - explicit location (const position& p = position ()) - : begin (p) - , end (p) - { - } - - /// Construct a 0-width location in \a f, \a l, \a c. - explicit location (std::string* f, - unsigned int l = 1u, - unsigned int c = 1u) - : begin (f, l, c) - , end (f, l, c) - { - } - - - /// Initialization. - void initialize (std::string* f = YY_NULLPTR, - unsigned int l = 1u, - unsigned int c = 1u) - { - begin.initialize (f, l, c); - end = begin; - } - - /** \name Line and Column related manipulators - ** \{ */ - public: - /// Reset initial location to final location. - void step () - { - begin = end; - } - - /// Extend the current location to the COUNT next columns. - void columns (int count = 1) - { - end += count; - } - - /// Extend the current location to the COUNT next lines. - void lines (int count = 1) - { - end.lines (count); - } - /** \} */ - - - public: - /// Beginning of the located region. - position begin; - /// End of the located region. - position end; - }; - - /// Join two locations, in place. - inline location& operator+= (location& res, const location& end) - { - res.end = end.end; - return res; - } - - /// Join two locations. - inline location operator+ (location res, const location& end) - { - return res += end; - } - - /// Add \a width columns to the end position, in place. - inline location& operator+= (location& res, int width) - { - res.columns (width); - return res; - } - - /// Add \a width columns to the end position. - inline location operator+ (location res, int width) - { - return res += width; - } - - /// Subtract \a width columns to the end position, in place. - inline location& operator-= (location& res, int width) - { - return res += -width; - } - - /// Subtract \a width columns to the end position. - inline location operator- (location res, int width) - { - return res -= width; - } - - /// Compare two location objects. - inline bool - operator== (const location& loc1, const location& loc2) - { - return loc1.begin == loc2.begin && loc1.end == loc2.end; - } - - /// Compare two location objects. - inline bool - operator!= (const location& loc1, const location& loc2) - { - return !(loc1 == loc2); - } - - /** \brief Intercept output stream redirection. - ** \param ostr the destination output stream - ** \param loc a reference to the location to redirect - ** - ** Avoid duplicate information. - */ - template - inline std::basic_ostream& - operator<< (std::basic_ostream& ostr, const location& loc) - { - unsigned int end_col = 0 < loc.end.column ? loc.end.column - 1 : 0; - ostr << loc.begin; - if (loc.end.filename - && (!loc.begin.filename - || *loc.begin.filename != *loc.end.filename)) - ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col; - else if (loc.begin.line < loc.end.line) - ostr << '-' << loc.end.line << '.' << end_col; - else if (loc.begin.column < end_col) - ostr << '-' << end_col; - return ostr; - } - - -} // yy_comments - -#endif // !YY_YY_COMMENTS_D_DEV_CPPAN_CLIENT_SRC_COMMENTS_LOCATION_HH_INCLUDED diff --git a/src/comments/position.hh b/src/comments/position.hh deleted file mode 100644 index 9fa7f002..00000000 --- a/src/comments/position.hh +++ /dev/null @@ -1,180 +0,0 @@ -// A Bison parser, made by GNU Bison 3.0.4. - -// Positions for Bison parsers in C++ - -// Copyright (C) 2002-2015 Free Software Foundation, Inc. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// As a special exception, you may create a larger work that contains -// part or all of the Bison parser skeleton and distribute that work -// under terms of your choice, so long as that work isn't itself a -// parser generator using the skeleton or a modified version thereof -// as a parser skeleton. Alternatively, if you modify or redistribute -// the parser skeleton itself, you may (at your option) remove this -// special exception, which will cause the skeleton and the resulting -// Bison output files to be licensed under the GNU General Public -// License without this special exception. - -// This special exception was added by the Free Software Foundation in -// version 2.2 of Bison. - -/** - ** \file D:/dev/cppan_client/src/comments/position.hh - ** Define the yy_comments::position class. - */ - -#ifndef YY_YY_COMMENTS_D_DEV_CPPAN_CLIENT_SRC_COMMENTS_POSITION_HH_INCLUDED -# define YY_YY_COMMENTS_D_DEV_CPPAN_CLIENT_SRC_COMMENTS_POSITION_HH_INCLUDED - -# include // std::max -# include -# include - -# ifndef YY_NULLPTR -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULLPTR nullptr -# else -# define YY_NULLPTR 0 -# endif -# endif - - -namespace yy_comments { - - /// Abstract a position. - class position - { - public: - /// Construct a position. - explicit position (std::string* f = YY_NULLPTR, - unsigned int l = 1u, - unsigned int c = 1u) - : filename (f) - , line (l) - , column (c) - { - } - - - /// Initialization. - void initialize (std::string* fn = YY_NULLPTR, - unsigned int l = 1u, - unsigned int c = 1u) - { - filename = fn; - line = l; - column = c; - } - - /** \name Line and Column related manipulators - ** \{ */ - /// (line related) Advance to the COUNT next lines. - void lines (int count = 1) - { - if (count) - { - column = 1u; - line = add_ (line, count, 1); - } - } - - /// (column related) Advance to the COUNT next columns. - void columns (int count = 1) - { - column = add_ (column, count, 1); - } - /** \} */ - - /// File name to which this position refers. - std::string* filename; - /// Current line number. - unsigned int line; - /// Current column number. - unsigned int column; - - private: - /// Compute max(min, lhs+rhs) (provided min <= lhs). - static unsigned int add_ (unsigned int lhs, int rhs, unsigned int min) - { - return (0 < rhs || -static_cast(rhs) < lhs - ? rhs + lhs - : min); - } - }; - - /// Add \a width columns, in place. - inline position& - operator+= (position& res, int width) - { - res.columns (width); - return res; - } - - /// Add \a width columns. - inline position - operator+ (position res, int width) - { - return res += width; - } - - /// Subtract \a width columns, in place. - inline position& - operator-= (position& res, int width) - { - return res += -width; - } - - /// Subtract \a width columns. - inline position - operator- (position res, int width) - { - return res -= width; - } - - /// Compare two position objects. - inline bool - operator== (const position& pos1, const position& pos2) - { - return (pos1.line == pos2.line - && pos1.column == pos2.column - && (pos1.filename == pos2.filename - || (pos1.filename && pos2.filename - && *pos1.filename == *pos2.filename))); - } - - /// Compare two position objects. - inline bool - operator!= (const position& pos1, const position& pos2) - { - return !(pos1 == pos2); - } - - /** \brief Intercept output stream redirection. - ** \param ostr the destination output stream - ** \param pos a reference to the position to redirect - */ - template - inline std::basic_ostream& - operator<< (std::basic_ostream& ostr, const position& pos) - { - if (pos.filename) - ostr << *pos.filename << ':'; - return ostr << pos.line << '.' << pos.column; - } - - -} // yy_comments - -#endif // !YY_YY_COMMENTS_D_DEV_CPPAN_CLIENT_SRC_COMMENTS_POSITION_HH_INCLUDED diff --git a/src/comments/stack.hh b/src/comments/stack.hh deleted file mode 100644 index 8846b25d..00000000 --- a/src/comments/stack.hh +++ /dev/null @@ -1,157 +0,0 @@ -// A Bison parser, made by GNU Bison 3.0.4. - -// Stack handling for Bison parsers in C++ - -// Copyright (C) 2002-2015 Free Software Foundation, Inc. - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -// As a special exception, you may create a larger work that contains -// part or all of the Bison parser skeleton and distribute that work -// under terms of your choice, so long as that work isn't itself a -// parser generator using the skeleton or a modified version thereof -// as a parser skeleton. Alternatively, if you modify or redistribute -// the parser skeleton itself, you may (at your option) remove this -// special exception, which will cause the skeleton and the resulting -// Bison output files to be licensed under the GNU General Public -// License without this special exception. - -// This special exception was added by the Free Software Foundation in -// version 2.2 of Bison. - -/** - ** \file D:/dev/cppan_client/src/comments/stack.hh - ** Define the yy_comments::stack class. - */ - -#ifndef YY_YY_COMMENTS_D_DEV_CPPAN_CLIENT_SRC_COMMENTS_STACK_HH_INCLUDED -# define YY_YY_COMMENTS_D_DEV_CPPAN_CLIENT_SRC_COMMENTS_STACK_HH_INCLUDED - -# include - - -namespace yy_comments { - - template > - class stack - { - public: - // Hide our reversed order. - typedef typename S::reverse_iterator iterator; - typedef typename S::const_reverse_iterator const_iterator; - - stack () - : seq_ () - { - seq_.reserve (200); - } - - stack (unsigned int n) - : seq_ (n) - {} - - inline - T& - operator[] (unsigned int i) - { - return seq_[seq_.size () - 1 - i]; - } - - inline - const T& - operator[] (unsigned int i) const - { - return seq_[seq_.size () - 1 - i]; - } - - /// Steal the contents of \a t. - /// - /// Close to move-semantics. - inline - void - push (T& t) - { - seq_.push_back (T()); - operator[](0).move (t); - } - - inline - void - pop (unsigned int n = 1) - { - for (; n; --n) - seq_.pop_back (); - } - - void - clear () - { - seq_.clear (); - } - - inline - typename S::size_type - size () const - { - return seq_.size (); - } - - inline - const_iterator - begin () const - { - return seq_.rbegin (); - } - - inline - const_iterator - end () const - { - return seq_.rend (); - } - - private: - stack (const stack&); - stack& operator= (const stack&); - /// The wrapped container. - S seq_; - }; - - /// Present a slice of the top of a stack. - template > - class slice - { - public: - slice (const S& stack, unsigned int range) - : stack_ (stack) - , range_ (range) - {} - - inline - const T& - operator [] (unsigned int i) const - { - return stack_[range_ - i]; - } - - private: - const S& stack_; - unsigned int range_; - }; - - -} // yy_comments - - -#endif // !YY_YY_COMMENTS_D_DEV_CPPAN_CLIENT_SRC_COMMENTS_STACK_HH_INCLUDED diff --git a/src/common/access_table.cpp b/src/common/access_table.cpp deleted file mode 100644 index 8f5b8f33..00000000 --- a/src/common/access_table.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "access_table.h" - -#include "cppan_string.h" -#include "database.h" -#include "directories.h" -#include "lock.h" -#include "stamp.h" - -#include - -struct AccessData -{ - Stamps stamps; - bool do_not_update = false; - int refs = 0; - - void load() - { - if (refs++ > 0) - return; - - stamps = getServiceDatabase().getFileStamps(); - } - - void save() - { - if (--refs > 0) - return; - - getServiceDatabase().setFileStamps(stamps); - } - - void clear() - { - stamps.clear(); - getServiceDatabase().clearFileStamps(); - } -}; - -static AccessData data; - -AccessTable::AccessTable() -{ - data.load(); -} - -AccessTable::~AccessTable() -{ - data.save(); -} - -bool AccessTable::must_update_contents(const path &p) const -{ - if (!fs::exists(p)) - return true; - if (data.do_not_update) - return false; - if (!is_under_root(p, directories.storage_dir_etc)) - return true; - return fs::last_write_time(p) != data.stamps[p]; -} - -bool AccessTable::updates_disabled() const -{ - return data.do_not_update; -} - -void AccessTable::update_contents(const path &p, const String &s) const -{ - write_file_if_different(p, s); - data.stamps[p] = fs::last_write_time(p); -} - -void AccessTable::write_if_older(const path &p, const String &s) const -{ - if (!is_under_root(p, directories.storage_dir_etc)) - { - write_file_if_different(p, s); - return; - } - if (must_update_contents(p)) - update_contents(p, s); -} - -void AccessTable::clear() const -{ - data.clear(); -} - -void AccessTable::remove(const path &p) const -{ - std::set rm; - for (auto &s : data.stamps) - { - if (is_under_root(s.first, p)) - rm.insert(s.first); - } - for (auto &s : rm) - data.stamps.erase(s); -} - -void AccessTable::do_not_update_files(bool v) -{ - data.do_not_update = v; -} diff --git a/src/common/access_table.h b/src/common/access_table.h deleted file mode 100644 index 56750754..00000000 --- a/src/common/access_table.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "cppan_string.h" -#include "filesystem.h" - -class AccessTable -{ -public: - AccessTable(); - ~AccessTable(); - - bool updates_disabled() const; - bool must_update_contents(const path &p) const; - void update_contents(const path &p, const String &s) const; - void write_if_older(const path &p, const String &s) const; - void clear() const; - void remove(const path &p) const; - - static void do_not_update_files(bool v); -}; diff --git a/src/common/api.cpp b/src/common/api.cpp deleted file mode 100644 index 96fa37cb..00000000 --- a/src/common/api.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "api.h" - -#include "http.h" -#include "project.h" -#include "settings.h" - -#include -//DECLARE_STATIC_LOGGER(logger, "api"); - -ptree api_call(const Remote &r, const String &api, ptree request) -{ - if (r.user.empty()) - throw std::runtime_error("Remote user is empty"); - if (r.token.empty()) - throw std::runtime_error("Remote token is empty"); - - request.put("auth.user", r.user); - request.put("auth.token", r.token); - - HttpRequest req = httpSettings; - req.type = HttpRequest::Post; - req.url = r.url + "/api/" + api; - req.data = ptree2string(request); - auto resp = url_request(req); - auto ret = string2ptree(resp.response); - if (resp.http_code != 200) - { - auto e = ret.get("error", ""); - throw std::runtime_error(e); - } - - return string2ptree(resp.response); -} - -void check_relative(const Remote &r, ProjectPath &p) -{ - if (p.is_relative(r.user)) - p = "pvt." + r.user + "." + p.toString(); -} - -void Api::add_project(const Remote &r, ProjectPath p, ProjectType t) -{ - check_relative(r, p); - ptree request; - request.put("project", p.toString()); - request.put("type", toIndex(t)); - api_call(r, "add_project", request); -} - -void Api::remove_project(const Remote &r, ProjectPath p) -{ - check_relative(r, p); - ptree request; - request.put("project", p.toString()); - api_call(r, "remove_project", request); -} - -void Api::add_version(const Remote &r, ProjectPath p, const String &cppan) -{ - check_relative(r, p); - ptree request; - request.put("project", p.toString()); - request.put("cppan", cppan); - api_call(r, "add_version", request); -} - -void Api::add_version(const Remote &r, ProjectPath p, const Version &vnew) -{ - add_version(r, p, vnew, String()); -} - -void Api::add_version(const Remote &r, ProjectPath p, const Version &vnew, const String &vold) -{ - check_relative(r, p); - ptree request; - request.put("project", p.toString()); - request.put("new", vnew.toString()); - if (!vold.empty()) - request.put("old", vold); - api_call(r, "add_version", request); -} - -void Api::update_version(const Remote &r, ProjectPath p, const Version &v) -{ - if (!v.isBranch()) - throw std::runtime_error("Only branches can be updated"); - check_relative(r, p); - ptree request; - request.put("project", p.toString()); - request.put("version", v.toString()); - api_call(r, "update_version", request); -} - -void Api::remove_version(const Remote &r, ProjectPath p, const Version &v) -{ - check_relative(r, p); - ptree request; - request.put("project", p.toString()); - request.put("version", v.toString()); - api_call(r, "remove_version", request); -} - -void Api::get_notifications(const Remote &r, int n) -{ - if (n < 0) - return; - - ptree request; - request.put("n", n); - auto response = api_call(r, "get_notifications", request); - auto notifications = response.get_child("notifications"); - int i = 1; - for (auto &n : notifications) - { - auto nt = (NotificationType)n.second.get("type", 0); - auto t = n.second.get("text", ""); - auto ts = n.second.get("timestamp", ""); - - std::ostringstream ss; - ss << i++ << " "; - switch (nt) - { - case NotificationType::Error: - ss << "E"; - break; - case NotificationType::Warning: - ss << "W"; - break; - case NotificationType::Message: - ss << "I"; - break; - case NotificationType::Success: - ss << "OK"; - break; - default: - break; - } - LOG_INFO(logger, ss.str() << " " << ts << " " << t); - } -} - -void Api::clear_notifications(const Remote &r) -{ - ptree request; - api_call(r, "clear_notifications", request); -} diff --git a/src/common/api.h b/src/common/api.h deleted file mode 100644 index cf3b217f..00000000 --- a/src/common/api.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "cppan_string.h" -#include "enums.h" - -class ProjectPath; -struct Remote; -struct Version; - -struct Api -{ - void add_project(const Remote &r, ProjectPath p, ProjectType t); - void remove_project(const Remote &r, ProjectPath p); - void add_version(const Remote &r, ProjectPath p, const String &cppan); - void add_version(const Remote &r, ProjectPath p, const Version &vnew); - void add_version(const Remote &r, ProjectPath p, const Version &vnew, const String &vold); - void update_version(const Remote &r, ProjectPath p, const Version &v); - void remove_version(const Remote &r, ProjectPath p, const Version &v); - void get_notifications(const Remote &r, int n = 10); - void clear_notifications(const Remote &r); -}; diff --git a/src/common/bsi.inl b/src/common/bsi.inl deleted file mode 100644 index 1cfb171c..00000000 --- a/src/common/bsi.inl +++ /dev/null @@ -1,6 +0,0 @@ -BSI(pre_project) -BSI(post_project) -BSI(pre_sources) -BSI(post_sources) -BSI(post_target) -BSI(post_alias) diff --git a/src/common/build.cpp b/src/common/build.cpp deleted file mode 100644 index 007e01b0..00000000 --- a/src/common/build.cpp +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "build.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include - -#include -//DECLARE_STATIC_LOGGER(logger, "build"); - -int build_packages(const String &name, const PackagesSet &pkgs, const path &settings_fn, const String &config); -int build_packages(const String &name, const PackagesSet &pkgs); -int build_packages(const Config &c, const String &name); - -String test_run() -{ - // do a test build to extract config string - auto src_dir = temp_directory_path() / "temp" / unique_path(); - auto bin_dir = src_dir / "build"; - - fs::create_directories(src_dir); - write_file(src_dir / CPPAN_FILENAME, ""); - SCOPE_EXIT - { - // remove test dir - error_code ec; - fs::remove_all(src_dir, ec); - }; - - // invoke cppan - Config conf(src_dir); - conf.process(src_dir); - - BuildSettings s; - s.allow_links = false; - s.disable_checks = true; - s.source_directory = src_dir; - s.binary_directory = bin_dir; - s.test_run = true; - - auto printer = Printer::create(Settings::get_local_settings().printerType); - printer->prepare_build(s); - - LOG_INFO(logger, "--"); - LOG_INFO(logger, "-- Performing test run"); - LOG_INFO(logger, "--"); - - auto ret = printer->generate(s); - - if (ret) - throw std::runtime_error("There are errors during test run"); - - // read cfg - auto c = read_file(bin_dir / CPPAN_CONFIG_FILENAME); - if (c.empty()) - throw std::logic_error("Test config is empty"); - - auto cmake_version = get_cmake_version(); - - // move this to printer some time - // copy cached cmake config to storage - copy_dir( - bin_dir / "CMakeFiles" / cmake_version, - directories.storage_dir_cfg / hash_config(c) / "CMakeFiles" / cmake_version); - - return c; -} - -String get_config() -{ - // add original config to db - // but return hashed - - auto &db = getServiceDatabase(); - auto h = Settings::get_local_settings().get_hash(); - auto c = db.getConfigByHash(h); - - if (!c.empty()) - return hash_config(c); - - c = test_run(); - auto ch = hash_config(c); - db.addConfigHash(h, c, ch); - - return ch; -} - -int build_packages(const Config &c, const String &name) -{ - auto &sdb = getServiceDatabase(); - - // install all pkgs first - for (auto &p : c.getProjects()) - for (auto &d : p.second.dependencies) - sdb.addInstalledPackage(d.second); - - BuildSettings bs; - - path src; - String cmake_version; - - auto set_config = [&](const String &config) - { - bs.config = config; - bs.set_build_dirs(name); - bs.append_build_dirs(bs.config); - - cmake_version = get_cmake_version(); - src = directories.storage_dir_cfg / bs.config / "CMakeFiles" / cmake_version; - }; - - set_config(get_config()); - - // if dir does not exist it means probably we have new cmake version - // we have config value but there was not a test run with copying cmake prepared files - // so start unconditional test run - bool new_config = false; - if (!fs::exists(src)) - { - auto config = test_run(); - auto ch = hash_config(config); - if (bs.config != ch) - { - // the original config was detected incorrectly, re-apply - set_config(ch); - new_config = true; - - // also register in db - auto h = Settings::get_local_settings().get_hash(); - sdb.addConfigHash(h, config, ch); - - // do we need to addConfigHash() here? like in get_config() - // or config must be very unique? - } - - if (!fs::exists(src)) - throw std::runtime_error("src dir does not exist"); - } - - // move this to printer some time - // copy cached cmake config to bin dir - auto dst = bs.binary_directory / "CMakeFiles" / cmake_version; - if (new_config) - fs::remove_all(dst); - if (!fs::exists(dst)) - { - copy_dir(src, dst); - // since cmake 3.8 - write_file(bs.binary_directory / "CMakeCache.txt", "CMAKE_PLATFORM_INFO_INITIALIZED:INTERNAL=1\n"); - } - - auto &ls = Settings::get_local_settings(); - - // setup printer config - c.process(bs.source_directory); - auto printer = Printer::create(ls.printerType); - printer->prepare_build(bs); - - auto ret = printer->generate(bs); - if (ret || ls.generate_only) - return ret; - return printer->build(bs); -} - -int build(path fn, const String &config) -{ - PackagesSet pkgs; - Config c; - String name; - std::tie(pkgs, c, name) = rd.read_packages_from_file(fn, config, true); - return build_packages(name, pkgs); -} - -int build_only(path fn, const String &config) -{ - AccessTable::do_not_update_files(true); - return build(fn, config); -} - -int build_packages(const String &name, const PackagesSet &pkgs) -{ - Config c; - for (auto &p : pkgs) - c.getDefaultProject().addDependency(p); - return build_packages(c, name); -} - -int build_packages(const String &name, const PackagesSet &pkgs, const path &settings_fn, const String &config) -{ - Config c; - if (!config.empty() && (fs::exists(settings_fn) || fs::exists(CPPAN_FILENAME))) - { - auto root = load_yaml_config(settings_fn.empty() ? CPPAN_FILENAME : settings_fn); - root["local_settings"]["current_build"] = config; - Settings::get_local_settings().load(root["local_settings"], SettingsType::Local); - } - - for (auto &p : pkgs) - c.getDefaultProject().addDependency(p); - return build_packages(c, name); -} - -int build_package(const String &target_name, const path &settings_fn, const String &config) -{ - Settings::get_local_settings().copy_all_libraries_to_output = true; - - Package p; - PackagesSet pkgs; - std::tie(p, pkgs) = resolve_dependency(target_name); - if (std::all_of(pkgs.begin(), pkgs.end(), [](const auto &p) { return p.flags[pfHeaderOnly]; })) - throw std::runtime_error("You are trying to build header only project. This is not supported."); - return build_packages(p.ppath.back(), pkgs, settings_fn, config); -} diff --git a/src/common/build.h b/src/common/build.h deleted file mode 100644 index 16941318..00000000 --- a/src/common/build.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -int build(path fn = current_thread_path(), const String &config = String()); -int build_only(path fn, const String &config = String()); -int build_package(const String &target_name, const path &settings_fn = path(), const String &config = String()); diff --git a/src/common/checks.cpp b/src/common/checks.cpp deleted file mode 100644 index f9f17938..00000000 --- a/src/common/checks.cpp +++ /dev/null @@ -1,1103 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "checks.h" -#include "checks_detail.h" - -#include "hash.h" -#include "printers/printer.h" - -#include - -#include -#include - -#include -//DECLARE_STATIC_LOGGER(logger, "checks"); - -const std::map check_information{ - { Check::Function, - { - Check::Function, - "check_function_exists", - "check_function_exists", - "function", - "functions" } }, - - { Check::Include, - { - Check::Include, - "check_include_exists", - "check_include_files", - "include", - "includes" } }, - - { Check::Type, - { - Check::Type, - "check_type_size", - "check_type_size", - "type", - "types" } }, - - { Check::Library, - { - Check::Library, - "check_library_exists", - "find_library", - "library", - "libraries" } }, - - { Check::LibraryFunction, - { - Check::LibraryFunction, - "check_library_function", - "check_library_exists", - "library function", - "functions" } }, - - { Check::Symbol, - { - Check::Symbol, - "check_symbol_exists", - "check_symbol_exists", - "symbol", - "symbols" } }, - - { Check::StructMember, - { - Check::StructMember, - "check_struct_member", - "check_struct_has_member", - "member", - "members" } }, - - { Check::Alignment, - { - Check::Alignment, - "check_type_alignment", - "check_type_alignment", - "alignment", - "alignments" } }, - - { Check::Decl, - { - Check::Decl, - "check_decl_exists", - "check_c_source_compiles", - "declaration", - "declarations" } }, - - { Check::CSourceCompiles, - { - Check::CSourceCompiles, - "check_c_source_compiles", - "check_c_source_compiles", - "c_source_compiles", - "c_source_compiles" } }, - - { Check::CSourceRuns, - { - Check::CSourceRuns, - "check_c_source_runs", - "check_c_source_runs", - "c_source_runs", - "c_source_runs" } }, - - { Check::CXXSourceCompiles, - { - Check::CXXSourceCompiles, - "check_cxx_source_compiles", - "check_cxx_source_compiles", - "cxx_source_compiles", - "cxx_source_compiles" } }, - - { Check::CXXSourceRuns, - { - Check::CXXSourceRuns, - "check_cxx_source_runs", - "check_cxx_source_runs", - "cxx_source_runs", - "cxx_source_runs" } }, - - { Check::Custom, - { - Check::Custom, - "checks", - "", - "custom", - "custom" } }, -}; - -Check::Information getCheckInformation(int type) -{ - auto i = check_information.find(type); - if (i == check_information.end()) - return Check::Information(); - return i->second; -} - -Check::Check(const Information &i, const CheckParameters ¶meters) - : information(i), parameters(parameters) -{ -} - -String Check::getDataEscaped() const -{ - auto d = getData(); - boost::replace_all(d, "\\", "\\\\\\\\"); - boost::replace_all(d, "\"", "\\\""); - return d; -} - -void Checks::load(const path &fn) -{ - load(YAML::Load(read_file(fn))); -} - -void Checks::load(const yaml &root) -{ - // functions - get_sequence_and_iterate(root, getCheckInformation(Check::Function).cppan_key, [this](const auto &n) - { - if (n.IsScalar()) - this->addCheck(n.template as()); - else if (n.IsMap()) - { - String f; - if (n["name"].IsDefined()) - f = n["name"].template as(); - else if (n["function"].IsDefined()) - f = n["function"].template as(); - CheckParameters p; - p.load(n); - auto ptr = this->addCheck(f, p); - if (n["cpp"].IsDefined()) - ptr->set_cpp(n["cpp"].template as()); - } - }); - - // types - get_sequence_and_iterate(root, getCheckInformation(Check::Type).cppan_key, [this](const auto &n) - { - if (n.IsScalar()) - this->addCheck(n.template as()); - else if (n.IsMap()) - { - if (n.size() == 1) - { - auto i = n.begin(); - auto t = i->first.template as(); - auto h = i->second.template as(); - CheckParameters p; - // if we see onliner 'type: struct tm' interpret it as - // type 'struct tm', not type 'type' and header 'struct tm' - if (t == "type") - t = h; - else - p.headers.push_back(h); - this->addCheck(t, p); - return; - } - String t; - if (n["name"].IsDefined()) - t = n["name"].template as(); - else if (n["type"].IsDefined()) - t = n["type"].template as(); - CheckParameters p; - p.load(n); - auto ptr = this->addCheck(t, p); - if (n["cpp"].IsDefined()) - ptr->set_cpp(n["cpp"].template as()); - } - }); - - // struct members - get_sequence_and_iterate(root, getCheckInformation(Check::StructMember).cppan_key, [this](const auto &n) - { - if (n.IsMap()) - { - if (n.size() == 1) - { - auto i = n.begin(); - auto m = i->first.template as(); - auto s = i->second.template as(); - this->addCheck(m, s); - return; - } - String m; - if (n["name"].IsDefined()) - m = n["name"].template as(); - else if (n["member"].IsDefined()) - m = n["member"].template as(); - auto s = n["struct"].template as(); - CheckParameters p; - p.load(n); - auto ptr = this->addCheck(m, s, p); - if (n["cpp"].IsDefined()) - ptr->set_cpp(n["cpp"].template as()); - } - else - throw std::runtime_error("struct member must be a map"); - }); - - bool has_decl = false; - -#define LOAD_SET(t) \ - do \ - { \ - auto seq = get_sequence(root, getCheckInformation(Check::t).cppan_key); \ - for (auto &v : seq) \ - { \ - auto p = addCheck(v); \ - if (p->getInformation().type == Check::Decl) \ - has_decl = true; \ - } \ - } while (0) - - LOAD_SET(Library); - LOAD_SET(Alignment); - - // decls - const auto &decl_key = getCheckInformation(Check::Decl).cppan_key; - if (root[decl_key].IsDefined()) - { - has_decl = true; - if (root[decl_key].IsMap()) - { - get_map_and_iterate(root, decl_key, [this](const auto &root) - { - auto f = root.first.template as(); - if (root.second.IsSequence() || root.second.IsScalar()) - { - CheckParameters p; - p.headers = get_sequence(root.second); - this->addCheck(f, p); - } - else - throw std::runtime_error("Decl headers should be a scalar or a set"); - }); - } - else if (root[decl_key].IsSequence()) - { - get_sequence_and_iterate(root, decl_key, [this](const auto &n) - { - if (n.IsMap()) - { - if (n.size() == 1) - { - auto i = n.begin(); - auto s = i->first.template as(); - auto h = i->second.template as(); - CheckParameters p; - p.headers = { h }; - this->addCheck(s, p); - return; - } - String s; - if (n["name"].IsDefined()) - s = n["name"].template as(); - else if (n["decl"].IsDefined()) - s = n["decl"].template as(); - CheckParameters p; - p.load(n); - /*auto ptr = */this->addCheck(s, p); - return; - } - else if (n.IsScalar()) - { - this->addCheck(n.template as()); - } - else - throw std::runtime_error("decl must be a map or seq"); - }); - } - } - - // includes - get_sequence_and_iterate(root, getCheckInformation(Check::Include).cppan_key, [this](const auto &v) - { - if (v.IsScalar()) - { - this->addCheck(v.template as()); - } - else if (v.IsMap()) - { - auto f = v["file"].template as(); - auto var = v["variable"].template as(); - auto cpp = v["cpp"].template as(); - auto p = this->addCheck(f, var); - p->set_cpp(cpp); - } - }); - - // library functions - get_sequence_and_iterate(root, getCheckInformation(Check::LibraryFunction).cppan_key, [this](const auto &v) - { - if (v.IsMap()) - { - auto f = v["function"].template as(); - auto lib = v["library"].template as(); - /*auto p = */this->addCheck(f, lib); - } - }); - - // symbols - const auto &skey = getCheckInformation(Check::Symbol).cppan_key; - if (root[skey].IsDefined()) - { - if (root[skey].IsMap()) - { - get_map_and_iterate(root, skey, [this](const auto &root) - { - auto f = root.first.template as(); - if (root.second.IsSequence() || root.second.IsScalar()) - { - CheckParameters p; - p.headers = get_sequence(root.second); - this->addCheck(f, p); - } - else - throw std::runtime_error("Symbol headers should be a scalar or a set"); - }); - } - else if (root[skey].IsSequence()) - { - get_sequence_and_iterate(root, skey, [this](const auto &n) - { - if (n.IsMap()) - { - if (n.size() == 1) - { - auto i = n.begin(); - auto s = i->first.template as(); - auto h = i->second.template as(); - CheckParameters p; - p.headers = { h }; - this->addCheck(s, p); - return; - } - String s; - if (n["name"].IsDefined()) - s = n["name"].template as(); - else if (n["symbol"].IsDefined()) - s = n["symbol"].template as(); - CheckParameters p; - p.load(n); - auto ptr = this->addCheck(s, p); - if (n["cpp"].IsDefined()) - ptr->set_cpp(n["cpp"].template as()); - return; - } - throw std::runtime_error("symbol must be a map"); - }); - } - } - -#define LOAD_MAP(t) \ - get_map_and_iterate(root, getCheckInformation(Check::t).cppan_key, [this](const auto &v) { \ - auto fi = v.first.template as(); \ - if (v.second.IsScalar()) \ - { \ - auto se = v.second.template as(); \ - this->addCheck(fi, se); \ - } \ - else if (v.second.IsMap()) \ - { \ - auto se = v.second["text"].template as(); \ - auto p = this->addCheck(fi, se); \ - if (v.second["invert"].IsDefined()) \ - p->invert = v.second["invert"].template as(); \ - } \ - else \ - { \ - throw std::runtime_error(getCheckInformation(Check::t).cppan_key + " should be a scalar or a map"); \ - } \ - }) - - LOAD_MAP(CSourceCompiles); - LOAD_MAP(CSourceRuns); - LOAD_MAP(CXXSourceCompiles); - LOAD_MAP(CXXSourceRuns); - - LOAD_MAP(Custom); - - // common (default) checks - - // add some common types - addCheck("size_t")->default_ = true; - addCheck("void *")->default_ = true; - - if (has_decl) - { - // headers - addCheck("sys/types.h")->default_ = true; - addCheck("sys/stat.h")->default_ = true; - addCheck("stdlib.h")->default_ = true; - addCheck("stddef.h")->default_ = true; - addCheck("memory.h")->default_ = true; - addCheck("string.h")->default_ = true; - addCheck("strings.h")->default_ = true; - addCheck("inttypes.h")->default_ = true; - addCheck("stdint.h")->default_ = true; - addCheck("unistd.h")->default_ = true; - - // STDC_HEADERS - addCheck("STDC_HEADERS", R"( -#include -#include -#include -#include -int main() {return 0;} -)")->default_ = true; - } -} - -void Checks::save(yaml &root) const -{ - for (auto &c : checks) - { - if (c->default_) - continue; - - auto &i = c->getInformation(); - auto t = i.type; - - switch (t) - { - case Check::Library: - case Check::Alignment: - root[i.cppan_key].push_back(c->getData()); - break; - case Check::Decl: - case Check::Type: - case Check::Function: - case Check::LibraryFunction: - case Check::Include: - case Check::Symbol: - case Check::StructMember: - case Check::CSourceCompiles: - case Check::CSourceRuns: - case Check::CXXSourceCompiles: - case Check::CXXSourceRuns: - case Check::Custom: - c->save(root); - break; - } - } -} - -bool Checks::empty() const -{ - return checks.empty(); -} - -Checks &Checks::operator+=(const Checks &rhs) -{ - checks.insert(rhs.checks.begin(), rhs.checks.end()); - return *this; -} - -String Checks::save() const -{ - yaml root; - save(root); - return dump_yaml_config(root); -} - -void invert(CMakeContext &ctx, const CheckPtr &c) -{ - ctx.addLine(); - ctx.addLine("if (" + c->getVariable() + ")"); - ctx.addLine(" set(" + c->getVariable() + " 0)"); - ctx.addLine("else()"); - ctx.addLine(" set(" + c->getVariable() + " 1)"); - ctx.addLine("endif()"); -} - -void Checks::write_checks(CMakeContext &ctx, const StringSet &prefixes) const -{ - for (auto &c : checks) - { - auto &i = c->getInformation(); - auto t = i.type; - - ctx.if_("NOT DEFINED " + c->getVariable()); - - switch (t) - { - case Check::Include: - ctx.addLine(i.function + "(\"" + c->getData() + "\" " + c->getVariable() + ")"); - break; - case Check::Alignment: - // for C language, can be opted later for C++ - ctx.addLine(i.function + "(\"" + c->getData() + "\" C " + c->getVariable() + ")"); - break; - case Check::Library: - ctx.addLine("find_library(" + c->getVariable() + " " + c->getData() + ")"); - ctx.addLine("if (\"${" + c->getVariable() + "}\" STREQUAL \"" + c->getVariable() + "-NOTFOUND\")"); - ctx.addLine(" set(" + c->getVariable() + " 0)"); - ctx.addLine("else()"); - ctx.addLine(" set(" + c->getVariable() + " 1)"); - ctx.addLine("endif()"); - break; - case Check::LibraryFunction: - { - auto p = (CheckLibraryFunction *)c.get(); - ctx.addLine(i.function + "(" + p->library +" \"" + c->getData() + "\" \"\" " + c->getVariable() + ")"); - } - break; - case Check::Function: - case Check::Symbol: - case Check::StructMember: - case Check::Type: - case Check::Decl: - c->writeCheck(ctx); - break; - case Check::CSourceCompiles: - case Check::CSourceRuns: - case Check::CXXSourceCompiles: - case Check::CXXSourceRuns: - ctx.addLine(i.function + "(\"" + c->getDataEscaped() + "\" " + c->getVariable() + ")"); - { - auto p = (CheckSource *)c.get(); - if (p->invert) - invert(ctx, c); - } - break; - case Check::Custom: - // Why not c->getDataEscaped()? - // because user can write other cmake code that does not need escaping - // user should provide escaping (in e.g. check_c_code_compiles) himself - // note that such escaping is very tricky: '\' is '\\\\' when escaped - ctx.addLine(c->getData()); - { - auto p = (CheckSource *)c.get(); - if (p->invert) - invert(ctx, c); - } - break; - default: - throw std::logic_error("Write parallel check for type " + std::to_string(t) + " not implemented"); - } - - ctx.addLine("add_check_variable(" + c->getVariable() + ")"); - ctx.endif(); - - for (const auto &p : prefixes) - { - ctx.addLine("set(" + p + c->getVariable() + " ${" + c->getVariable() + "} CACHE STRING \"\")"); - ctx.addLine("set(" + p + boost::to_lower_copy(c->getVariable()) + " ${" + c->getVariable() + "} CACHE STRING \"\")"); - } - - ctx.emptyLines(); - - if (t == Check::Symbol) - { - auto f = (CheckSymbol*)c.get(); - if (!f->parameters.headers.empty()) - { - ctx.addLine("if (" + c->getVariable() + ")"); - ctx.increaseIndent(); - for (auto &i : f->parameters.headers) - { - auto iv = Check::make_include_var(i); - ctx.addLine("set(" + iv + " 1 CACHE STRING \"\")"); - for (const auto &p : prefixes) - { - ctx.addLine("set(" + p + iv + " ${" + iv + "} CACHE STRING \"\")"); - ctx.addLine("set(" + p + boost::to_lower_copy(iv) + " ${" + iv + "} CACHE STRING \"\")"); - } - ctx.addLine("add_check_variable(" + iv + ")"); - } - ctx.decreaseIndent(); - ctx.addLine("endif()"); - ctx.addLine(); - } - } - - if (t == Check::Type) - { - CheckType ct(c->getData(), "SIZEOF_"); - CheckType ct_(c->getData(), "SIZE_OF_"); - - ctx.addLine("if (" + c->getVariable() + ")"); - ctx.increaseIndent(); - ctx.addLine("set(" + ct_.getVariable() + " ${" + c->getVariable() + "} CACHE STRING \"\")"); - ctx.addLine("set(" + ct.getVariable() + " ${" + c->getVariable() + "} CACHE STRING \"\")"); - for (const auto &p : prefixes) - { - ctx.addLine("set(" + p + ct_.getVariable() + " ${" + c->getVariable() + "} CACHE STRING \"\")"); - ctx.addLine("set(" + p + ct.getVariable() + " ${" + c->getVariable() + "} CACHE STRING \"\")"); - ctx.addLine("set(" + p + boost::to_lower_copy(ct_.getVariable()) + " ${" + c->getVariable() + "} CACHE STRING \"\")"); - ctx.addLine("set(" + p + boost::to_lower_copy(ct.getVariable()) + " ${" + c->getVariable() + "} CACHE STRING \"\")"); - } - ctx.decreaseIndent(); - ctx.addLine("endif()"); - ctx.addLine(); - } - } -} - -void Checks::write_parallel_checks_for_workers(CMakeContext &ctx) const -{ - for (auto &c : checks) - { - auto &i = c->getInformation(); - auto t = i.type; - switch (t) - { - case Check::Include: - ctx.addLine(i.function + "(\"" + c->getData() + "\" " + c->getVariable() + ")"); - break; - case Check::Alignment: - // for C language, can be opted later for C++ - ctx.addLine(i.function + "(\"" + c->getData() + "\" C " + c->getVariable() + ")"); - break; - case Check::Library: - ctx.addLine("find_library(" + c->getVariable() + " " + c->getData() + ")"); - ctx.addLine("if (\"${" + c->getVariable() + "}\" STREQUAL \"" + c->getVariable() + "-NOTFOUND\")"); - ctx.addLine(" set(" + c->getVariable() + " 0)"); - ctx.addLine("else()"); - ctx.addLine(" set(" + c->getVariable() + " 1)"); - ctx.addLine("endif()"); - break; - case Check::LibraryFunction: - { - auto p = (CheckLibraryFunction *)c.get(); - ctx.addLine(i.function + "(" + p->library + " \"" + c->getData() + "\" \"\" " + c->getVariable() + ")"); - } - break; - case Check::Decl: - continue; // do not participate in parallel - case Check::Function: - case Check::Symbol: - case Check::StructMember: - case Check::Type: - c->writeCheck(ctx); - break; - case Check::CSourceCompiles: - case Check::CSourceRuns: - case Check::CXXSourceCompiles: - case Check::CXXSourceRuns: - ctx.addLine(i.function + "(\"" + c->getDataEscaped() + "\" " + c->getVariable() + ")"); - { - auto p = (CheckSource *)c.get(); - if (p->invert) - invert(ctx, c); - } - break; - case Check::Custom: - // Why not c->getDataEscaped()? - // because user can write other cmake code that does not need escaping - // user should provide escaping (in e.g. check_c_code_compiles) himself - // note that such escaping is very tricky: '\' is '\\\\' when escaped - ctx.addLine(c->getData()); - { - auto p = (CheckSource *)c.get(); - if (p->invert) - invert(ctx, c); - } - break; - default: - throw std::logic_error("Write parallel check for type " + std::to_string(t) + " not implemented"); - } - ctx.addLine("if (NOT " + c->getVariable() + ")"); - ctx.increaseIndent(); - ctx.addLine("set(" + c->getVariable() + " 0)"); - ctx.decreaseIndent(); - ctx.addLine("else()"); - ctx.increaseIndent(); - - if (t == Check::Symbol) - { - auto f = (CheckSymbol*)c.get(); - if (!f->parameters.headers.empty()) - { - for (auto &i : f->parameters.headers) - { - auto iv = Check::make_include_var(i); - ctx.addLine("file(WRITE " + iv + " \"1\")"); - } - } - } - - ctx.decreaseIndent(); - ctx.addLine("endif()"); - ctx.addLine("file(WRITE " + c->getFileName() + " \"${" + c->getVariable() + "}\")"); - ctx.addLine(); - } -} - -void Checks::read_parallel_checks_for_workers(const path &dir) -{ - for (auto &c : checks) - { - auto fn = dir / c->getFileName(); - if (!fs::exists(fn)) - continue; - auto s = read_file(fn); - boost::trim(s); - if (s.empty()) - { - // if s empty, we do not read var - // it will be checked in normal mode - continue; - } - c->setValue(std::stoi(s)); - } -} - -void Checks::write_definitions(CMakeContext &ctx, const Package &d, const StringSet &prefixes) const -{ - const auto m = [&d] - { - if (!d.flags[pfHeaderOnly]) - return "PUBLIC"s; - if (d.flags[pfExecutable]) - return "PRIVATE"s; - return "INTERFACE"s; - }(); - - auto print_def = [&ctx, &m, &prefixes](const auto &value, const auto &s) - { - ctx.addLine(m + " " + s + "=" + value); - for (const auto &p : prefixes) - ctx.addLine(m + " " + p + s + "=" + value); - return 0; - }; - - auto add_if_definition = [&ctx, &print_def](const String &s, const String &value, const std::vector &defs = std::vector()) - { - ctx.if_(s); - ctx.addLine("target_compile_definitions(${this}"); - ctx.increaseIndent(); - print_def(value, s); - for (auto &def : defs) - print_def(value, def); - ctx.decreaseIndent(); - ctx.addLine(")"); - ctx.endif(); - ctx.addLine(); - }; - - // aliases - add_if_definition("WORDS_BIGENDIAN", "1", {"BIGENDIAN", "BIG_ENDIAN", "HOST_BIG_ENDIAN"}); - - for (auto &c : checks) - { - auto &i = c->getInformation(); - auto t = i.type; - - if (t == Check::Decl) - { - // decl will be always defined - // TODO: watch over this condition, it fails sometimes - ctx.addLine("if (NOT DEFINED " + c->getVariable() + " OR NOT " + c->getVariable() + ")"); - ctx.increaseIndent(); - ctx.addLine("set(" + c->getVariable() + " 0)"); - ctx.decreaseIndent(); - ctx.addLine("endif()"); - ctx.addLine(); - - ctx.addLine("target_compile_definitions(${this}"); - ctx.increaseIndent(); - ctx.addLine(m + " " + c->getVariable() + "=" + "${" + c->getVariable() + "}"); - for (const auto &p : prefixes) - ctx.addLine(m + " " + p + c->getVariable() + "=" + "${" + c->getVariable() + "}"); - ctx.decreaseIndent(")"); - ctx.addLine(); - continue; - } - - String value = "1"; - - if (t == Check::Alignment) - value = "${" + c->getVariable() + "}"; - - add_if_definition(c->getVariable(), value); - - if (t == Check::Type) - { - CheckType ct(c->getData(), "SIZEOF_"); - CheckType ct_(c->getData(), "SIZE_OF_"); - - add_if_definition(ct.getVariable(), "${" + ct.getVariable() + "}"); - add_if_definition(ct_.getVariable(), "${" + ct_.getVariable() + "}"); - } - } -} - -void Checks::remove_known_vars(const std::set &known_vars) -{ - auto checks_old = checks; - for (auto &c : checks_old) - { - if (known_vars.find(c->getVariable()) != known_vars.end()) - checks.erase(c); - } -} - -std::vector Checks::scatter(int N) const -{ - std::vector workers(N); - int i = 0; - for (auto &c : checks) - { - auto &inf = c->getInformation(); - auto t = inf.type; - - switch (t) - { - case Check::Decl: // do not participate in parallel - break; - default: - workers[i++ % N].checks.insert(c); - break; - } - } - return workers; -} - -void Checks::print_values() const -{ - std::map checks_to_print; - for (auto &c : checks) - { - auto &i = c->getInformation(); - auto t = i.type; - - // skip decls - if (t == Check::Decl) - continue; - - // if we have duplicate values, choose the ok one - auto &m = checks_to_print[c->getVariable()]; - if (m && m->isOk()) - continue; - m = c; - } - - // correctly sort - ChecksSet s; - for (auto &kv : checks_to_print) - s.insert(kv.second); - for (auto &v : s) - std::cout << v->printStatus() << std::endl; - //LOG_INFO(logger, v->printStatus()); -} - -void Checks::print_values(CMakeContext &ctx) const -{ - std::map checks_to_print; - for (auto &c : checks) - { - auto &i = c->getInformation(); - auto t = i.type; - - switch (t) - { - case Check::Decl: // do not participate in parallel - break; - case Check::Type: - { - auto &m = checks_to_print[c->getVariable()]; - if (m && m->isOk()) - continue; - m = c; - checks_to_print[Check::make_type_var(c->getData(), "SIZEOF_")] = c; - checks_to_print[Check::make_type_var(c->getData(), "SIZE_OF_")] = c; - break; - } - case Check::Symbol: - if (c->isOk()) - { - // add headers as found directly to ctx - auto f = (CheckSymbol*)c.get(); - for (auto &i : f->parameters.headers) - ctx.addLine("STRING;" + Check::make_include_var(i) + ";1"); - } - //[[fallthrough]]; - default: - { - // if we have duplicate values, choose the ok one - auto &m = checks_to_print[c->getVariable()]; - if (m && m->isOk()) - continue; - m = c; - break; - } - } - } - - for (auto &kv : checks_to_print) - ctx.addLine("STRING;" + kv.first + ";" + std::to_string(kv.second->getValue())); -} - -String Check::make_include_var(const String &i) -{ - auto v_def = "HAVE_" + boost::algorithm::to_upper_copy(i); - for (auto &c : v_def) - { - if (!isalnum(c)) - c = '_'; - } - return v_def; -} - -String Check::make_type_var(const String &t, const String &prefix) -{ - String v_def = prefix; - v_def += boost::algorithm::to_upper_copy(t); - for (auto &c : v_def) - { - if (c == '*') - c = 'P'; - else if (!isalnum(c)) - c = '_'; - } - return v_def; -} - -String Check::make_struct_member_var(const String &m, const String &s) -{ - return make_include_var(s + " " + m); -} - -String Check::getFileName() const -{ - if (parameters.empty()) - return getVariable(); - return getVariable() + "_" + parameters.getHash(); -} - -String CheckParameters::getHash() const -{ - String h; -#define ADD_PARAMS(x) for (auto &v : x) h += v - ADD_PARAMS(headers); - ADD_PARAMS(definitions); - ADD_PARAMS(include_directories); - ADD_PARAMS(libraries); - ADD_PARAMS(flags); - h = sha256(h); - h = h.substr(0, 4); - return h; -} - -void CheckParameters::writeHeadersBefore(CMakeContext &ctx) const -{ - if (!headers.empty()) - { - ctx.addLine("set(_oh ${CMAKE_EXTRA_INCLUDE_FILES})"); - ctx.addLine("set(CMAKE_EXTRA_INCLUDE_FILES"); - for (auto &d : headers) - ctx.addLine(d); - ctx.addLine(")"); - } -} - -void CheckParameters::writeHeadersAfter(CMakeContext &ctx) const -{ - if (!headers.empty()) - ctx.addLine("set(CMAKE_EXTRA_INCLUDE_FILES ${_oh})"); -} - -void CheckParameters::writeBefore(CMakeContext &ctx) const -{ - if (!definitions.empty()) - { - ctx.addLine("set(_od ${CMAKE_REQUIRED_DEFINITIONS})"); - ctx.addLine("set(CMAKE_REQUIRED_DEFINITIONS"); - for (auto &d : definitions) - ctx.addLine(d); - ctx.addLine(")"); - } - if (!include_directories.empty()) - { - ctx.addLine("set(_oi ${CMAKE_REQUIRED_INCLUDES})"); - ctx.addLine("set(CMAKE_REQUIRED_INCLUDES"); - for (auto &d : include_directories) - ctx.addLine(d); - ctx.addLine(")"); - } - if (!libraries.empty()) - { - ctx.addLine("set(_ol ${CMAKE_REQUIRED_LIBRARIES})"); - ctx.addLine("set(CMAKE_REQUIRED_LIBRARIES"); - for (auto &d : libraries) - ctx.addLine(d); - ctx.addLine(")"); - } - if (!flags.empty()) - { - ctx.addLine("set(_of ${CMAKE_REQUIRED_FLAGS})"); - ctx.addLine("set(CMAKE_REQUIRED_FLAGS"); - for (auto &d : flags) - ctx.addLine(d); - ctx.addLine(")"); - } -} - -void CheckParameters::writeAfter(CMakeContext &ctx) const -{ - if (!definitions.empty()) - ctx.addLine("set(CMAKE_REQUIRED_DEFINITIONS ${_od})"); - if (!include_directories.empty()) - ctx.addLine("set(CMAKE_REQUIRED_INCLUDES ${_oi})"); - if (!libraries.empty()) - ctx.addLine("set(CMAKE_REQUIRED_LIBRARIES ${_ol})"); - if (!flags.empty()) - ctx.addLine("set(CMAKE_REQUIRED_FLAGS ${_of})"); -} - -void CheckParameters::load(const yaml &n) -{ - headers = get_sequence(n["headers"]); - definitions = get_sequence_set(n["definitions"]); - include_directories = get_sequence_set(n["include_directories"]); - libraries = get_sequence_set(n["libraries"]); - flags = get_sequence_set(n["flags"]); -} - -void CheckParameters::save(yaml &n) const -{ -#define ADD_SET(x) for (auto &v : x) n[#x].push_back(v) - ADD_SET(headers); - ADD_SET(definitions); - ADD_SET(include_directories); - ADD_SET(libraries); - ADD_SET(flags); -} - -bool CheckParameters::empty() const -{ - return - headers.empty() && - definitions.empty() && - include_directories.empty() && - libraries.empty() && - flags.empty() && - 1 - ; -} - -bool CheckParameters::operator<(const CheckParameters &p) const -{ - return - std::tie(headers, definitions, include_directories, libraries, flags) < - std::tie(p.headers, p.definitions, p.include_directories, p.libraries, p.flags); -} diff --git a/src/common/checks.h b/src/common/checks.h deleted file mode 100644 index d4e38181..00000000 --- a/src/common/checks.h +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "context.h" -#include "cppan_string.h" -#include "filesystem.h" -#include "yaml.h" - -class CMakeContext; -struct Package; - -struct CheckParameters -{ - Strings headers; - StringSet definitions; - StringSet include_directories; - StringSet libraries; - StringSet flags; - - // TODO: pass all found includes to this test - // it is possible only in sequential mode - bool all_includes = false; - - void writeHeadersBefore(CMakeContext &ctx) const; - void writeHeadersAfter(CMakeContext &ctx) const; - void writeBefore(CMakeContext &ctx) const; - void writeAfter(CMakeContext &ctx) const; - void load(const yaml &n); - void save(yaml &n) const; - bool empty() const; - String getHash() const; - bool operator<(const CheckParameters &p) const; -}; - -class Check -{ -public: - enum - { - Function, - Include, - Type, - Alignment, - Library, - LibraryFunction, - Symbol, - StructMember, - CSourceCompiles, - CSourceRuns, - CXXSourceCompiles, - CXXSourceRuns, - Decl, // decl goes almost at the end!!! (sort order) - Custom, - - Max, - }; - - struct Information - { - int type; - - String cppan_key; - String function; - - // strings for printing/naming files - String singular; - String plural; - }; - -public: - // maybe variant: int, double, string? - using Value = int; - -public: - Check(const Information &i, const CheckParameters ¶meters = CheckParameters()); - virtual ~Check() = default; - - const Information &getInformation() const { return information; } - String getVariable() const { return variable; } - String getData() const { return data; } - String getDataEscaped() const; - Value getValue() const { return value; } - String getMessage() const { return message; } - - virtual void writeCheck(CMakeContext &/*ctx*/) const {} - virtual void save(yaml &/*root*/) const {} - - void setValue(const Value &v) { value = v; } - - bool get_cpp() const { return cpp; } - virtual void set_cpp(bool) {} - - String getFileName() const; - - virtual String printStatus() const - { - if (getValue()) - return "-- " + information.singular + " " + getData() + " - found (" + std::to_string(getValue()) + ")"; - else - return "-- " + information.singular + " " + getData() + " - not found"; - } - - virtual bool isOk() const - { - return !!getValue(); - } - -protected: - // self-information - Information information; - - // e.g. HAVE_STDINT_H - String variable; - - // symbol name (function, include, c/cxx source etc.) - // or source code - // or whatever - String data; - - // (cmake) value - Value value = 0; - - // message for printing - String message; - - bool cpp = false; - -public: - // default check won't be printed - bool default_ = false; - - // parameters - CheckParameters parameters; - -public: - static String make_include_var(const String &i); - static String make_type_var(const String &t, const String &prefix = "HAVE_"); - static String make_struct_member_var(const String &m, const String &s); - -private: - template - friend struct CheckPtrLess; -}; - -using CheckPtr = std::shared_ptr; - -template -struct CheckPtrLess -{ - bool operator()(const T &p1, const T &p2) const - { - if (p1 && p2) - return - std::tie(p1->information.type, p1->variable, p1->parameters) < - std::tie(p2->information.type, p2->variable, p2->parameters); - return p1 < p2; - } -}; - -using ChecksSet = std::set>; - -struct Checks -{ - ChecksSet checks; - bool valid = true; - - bool empty() const; - - void load(const yaml &root); - void load(const path &fn); - void save(yaml &root) const; - String save() const; - - void write_checks(CMakeContext &ctx, const StringSet &prefixes = StringSet()) const; - void write_definitions(CMakeContext &ctx, const Package &d, const StringSet &prefixes = StringSet()) const; - - void write_parallel_checks_for_workers(CMakeContext &ctx) const; - void read_parallel_checks_for_workers(const path &dir); - - void remove_known_vars(const std::set &known_vars); - std::vector scatter(int N) const; - void print_values() const; - void print_values(CMakeContext &ctx) const; - - Checks &operator+=(const Checks &rhs); - - template - T *addCheck(Args && ... args); -}; - -Check::Information getCheckInformation(int type); - -struct ParallelCheckOptions -{ - path cmake_binary; - path dir; - path vars_file; - path checks_file; - String generator; - String system_version; - String toolset; - String toolchain; -}; diff --git a/src/common/checks_detail.h b/src/common/checks_detail.h deleted file mode 100644 index 0cce3613..00000000 --- a/src/common/checks_detail.h +++ /dev/null @@ -1,520 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "checks.h" - -#include "printers/printer.h" - -#include -#include - -#include - -extern const std::map check_information; - -class CheckParametersScopedWriter -{ - CMakeContext &ctx; - const CheckParameters &p; - bool with_headers; -public: - CheckParametersScopedWriter(CMakeContext &ctx, const CheckParameters &p, bool with_headers = false) - : ctx(ctx), p(p), with_headers(with_headers) - { - if (with_headers) - p.writeHeadersBefore(ctx); - p.writeBefore(ctx); - } - ~CheckParametersScopedWriter() - { - p.writeAfter(ctx); - if (with_headers) - p.writeHeadersAfter(ctx); - } -}; - -class CheckFunction : public Check -{ -public: - CheckFunction(const String &f, const CheckParameters &p = CheckParameters()) - : Check(getCheckInformation(Function), p) - { - data = f; - variable = "HAVE_" + boost::algorithm::to_upper_copy(data); - } - - virtual ~CheckFunction() {} - - void save(yaml &root) const override - { - if (parameters.empty()) - { - root[information.cppan_key].push_back(getData()); - return; - } - - yaml y; - y["function"] = getData(); - parameters.save(y); - root[information.cppan_key].push_back(y); - } - - void writeCheck(CMakeContext &ctx) const override - { - CheckParametersScopedWriter p(ctx, parameters); - ctx.addLine(information.function + "(" + getData() + " " + getVariable() + ")"); - } -}; - -class CheckInclude : public Check -{ -public: - CheckInclude(const String &s) - : Check(getCheckInformation(Include)) - { - data = s; - variable = make_include_var(data); - } - - CheckInclude(const String &s, const String &var) - : Check(getCheckInformation(Include)) - { - data = s; - variable = var; - } - - void save(yaml &root) const override - { - yaml v; - v["file"] = getData(); - v["variable"] = getVariable(); - v["cpp"] = cpp; - root[information.cppan_key].push_back(v); - } - - void set_cpp(bool c) override - { - cpp = c; - if (cpp) - information.function = "CHECK_INCLUDE_FILE_CXX"; - else - information.function = getCheckInformation(Include).function; - } - - virtual ~CheckInclude() {} -}; - -class CheckType : public Check -{ -public: - CheckType(const String &t, const String &prefix = "HAVE_") - : Check(getCheckInformation(Type)) - { - data = t; - variable = make_type_var(data, prefix); - } - - CheckType(const String &t, const CheckParameters &p) - : Check(getCheckInformation(Type), p) - { - data = t; - variable = make_type_var(data); - } - - virtual ~CheckType() {} - - void writeCheck(CMakeContext &ctx) const override - { - CheckParametersScopedWriter p(ctx, parameters, true); - ctx.addLine(information.function + "(\"" + getData() + "\" " + getVariable() + ")"); - } - - void save(yaml &root) const override - { - yaml n; - n["type"] = getData(); - parameters.save(n); - root[information.cppan_key].push_back(n); - } -}; - -class CheckStructMember : public Check -{ -public: - CheckStructMember(const String &m, const String &s, const CheckParameters &p = CheckParameters()) - : Check(getCheckInformation(StructMember), p) - { - data = m; - struct_ = s; - variable = make_struct_member_var(data, struct_); - } - - virtual ~CheckStructMember() {} - - void writeCheck(CMakeContext &ctx) const override - { - CheckParametersScopedWriter p(ctx, parameters); - ctx.addLine(information.function + "(\"" + struct_ + "\" \"" + getData() + "\" \""); - for (auto &h : parameters.headers) - ctx.addText(h + ";"); - ctx.addText("\" " + getVariable()); - if (cpp) - ctx.addText(" LANGUAGE CXX"); - ctx.addText(")"); - } - - void save(yaml &root) const override - { - yaml n; - n["member"] = getData(); - n["struct"] = struct_; - parameters.save(n); - root[information.cppan_key].push_back(n); - } - - String printStatus() const override - { - if (getValue()) - return "-- " + information.singular + " " + getData() + " of " + struct_ + " - found (" + std::to_string(getValue()) + ")"; - else - return "-- " + information.singular + " " + getData() + " of " + struct_ + " - not found"; - } - -public: - String struct_; -}; - -class CheckAlignment : public Check -{ -public: - CheckAlignment(const String &s, const String &prefix = "ALIGNOF_") - : Check(getCheckInformation(Alignment)) - { - data = s; - String v_def = prefix; - v_def += boost::algorithm::to_upper_copy(s); - for (auto &c : v_def) - { - if (c == '*') - c = 'P'; - else if (!isalnum(c)) - c = '_'; - } - variable = v_def; - } - - virtual ~CheckAlignment() {} -}; - -class CheckLibrary : public Check -{ -public: - CheckLibrary(const String &s) - : Check(getCheckInformation(Library)) - { - data = s; - auto v_def = "HAVE_LIB" + boost::algorithm::to_upper_copy(data); - for (auto &c : v_def) - { - if (!isalnum(c)) - c = '_'; - } - variable = v_def; - } - - virtual ~CheckLibrary() {} -}; - -class CheckLibraryFunction : public Check -{ -public: - CheckLibraryFunction(const String &s, const String &lib) - : Check(getCheckInformation(LibraryFunction)) - { - data = s; - variable = "HAVE_" + boost::algorithm::to_upper_copy(data); - library = lib; - } - - virtual ~CheckLibraryFunction() {} - - void save(yaml &root) const override - { - yaml v; - v["function"] = getData(); - v["library"] = library; - root[information.cppan_key].push_back(v); - } - - String library; -}; - -class CheckSymbol : public Check -{ -public: - CheckSymbol(const String &s, const CheckParameters &p = CheckParameters()) - : Check(getCheckInformation(Symbol), p) - { - data = s; - variable = "HAVE_" + boost::algorithm::to_upper_copy(data); - } - - virtual ~CheckSymbol() {} - - void writeCheck(CMakeContext &ctx) const override - { - CheckParametersScopedWriter p(ctx, parameters); - ctx.addLine(information.function + "(\"" + getData() + "\" \""); - for (auto &h : parameters.headers) - ctx.addText(h + ";"); - ctx.addText("\" " + getVariable() + ")"); - } - - void save(yaml &root) const override - { - yaml n; - if (cpp) - n["cpp"] = cpp; - n["symbol"] = getData(); - parameters.save(n); - root[information.cppan_key].push_back(n); - } - - void set_cpp(bool c) override - { - cpp = c; - if (cpp) - information.function = "check_cxx_symbol_exists"; - else - information.function = getCheckInformation(Symbol).function; - } -}; - -class CheckDecl : public Check -{ -public: - CheckDecl(const String &s, const CheckParameters &p = CheckParameters()) - : Check(getCheckInformation(Decl), p) - { - data = s; - variable = "HAVE_DECL_" + boost::algorithm::to_upper_copy(data); - } - - virtual ~CheckDecl() {} - - void save(yaml &root) const override - { - yaml n; - n["decl"] = getData(); - parameters.save(n); - root[information.cppan_key].push_back(n); - } - - void writeCheck(CMakeContext &ctx) const override - { - static const Strings headers = { - "HAVE_SYS_TYPES_H", - "HAVE_SYS_STAT_H", - "STDC_HEADERS", - "HAVE_STDLIB_H", - "HAVE_STRING_H", - "HAVE_MEMORY_H", - "HAVE_STRINGS_H", - "HAVE_INTTYPES_H", - "HAVE_STDINT_H", - "HAVE_UNISTD_H", - }; - - auto print_header_def = [&ctx](const auto &h) - { - ctx.addLine("if (" + h + ")"); - ctx.addLine("set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -D" + h + "=${" + h + "})"); - ctx.addLine("endif()"); - }; - - ctx.addLine("set(CMAKE_REQUIRED_DEFINITIONS)"); - for (auto &h : headers) - print_header_def(h); - String more_headers; - for (auto &h : parameters.headers) - { - auto iv = make_include_var(h); - print_header_def(iv); - more_headers += "#ifdef " + iv + "\n"; - more_headers += "# include <" + h + ">\n"; - more_headers += "#endif\n"; - } - - ctx.addLine(information.function + "(\"" + - R"( - -#include -#ifdef HAVE_SYS_TYPES_H -# include -#endif -#ifdef HAVE_SYS_STAT_H -# include -#endif -#ifdef STDC_HEADERS -# include -# include -#else -# ifdef HAVE_STDLIB_H -# include -# endif -#endif -#ifdef HAVE_STRING_H -# if !defined STDC_HEADERS && defined HAVE_MEMORY_H -# include -# endif -# include -#endif -#ifdef HAVE_STRINGS_H -# include -#endif -#ifdef HAVE_INTTYPES_H -# include -#endif -#ifdef HAVE_STDINT_H -# include -#endif -#ifdef HAVE_UNISTD_H -# include -#endif - -)" + -more_headers + -R"( - -int main() -{ - (void) -)" + - getData() + - R"( - ; - return 0; -} -)" - "\" " + getVariable() + ")"); - - ctx.addLine("set(CMAKE_REQUIRED_DEFINITIONS)"); - } -}; - -struct CheckSource : public Check -{ - bool invert = false; - - CheckSource(const Check::Information &i) - : Check(i) - { - } - - virtual ~CheckSource() {} - - void save(yaml &root) const override - { - root[information.cppan_key][getVariable()]["text"] = getData(); - root[information.cppan_key][getVariable()]["invert"] = invert; - } - - String printStatus() const override - { - if (isOk()) - return "-- Test " + getVariable() + " - Success (" + std::to_string(getValue()) + ")"; - else - return "-- Test " + getVariable() + " - Failed"; - } - - bool isOk() const override - { - return (!invert && getValue()) || (invert && !getValue()); - } -}; - -class CheckCSourceCompiles : public CheckSource -{ -public: - CheckCSourceCompiles(const String &var, const String &d) - : CheckSource(getCheckInformation(CSourceCompiles)) - { - variable = var; - data = d; - } - - virtual ~CheckCSourceCompiles() {} -}; - -class CheckCSourceRuns : public CheckSource -{ -public: - CheckCSourceRuns(const String &var, const String &d) - : CheckSource(getCheckInformation(CSourceRuns)) - { - variable = var; - data = d; - } - - virtual ~CheckCSourceRuns() {} -}; - -class CheckCXXSourceCompiles : public CheckSource -{ -public: - CheckCXXSourceCompiles(const String &var, const String &d) - : CheckSource(getCheckInformation(CXXSourceCompiles)) - { - variable = var; - data = d; - } - - virtual ~CheckCXXSourceCompiles() {} -}; - -class CheckCXXSourceRuns : public CheckSource -{ -public: - CheckCXXSourceRuns(const String &var, const String &d) - : CheckSource(getCheckInformation(CXXSourceRuns)) - { - variable = var; - data = d; - } - - virtual ~CheckCXXSourceRuns() {} -}; - -class CheckCustom : public CheckSource -{ -public: - CheckCustom(const String &var, const String &d) - : CheckSource(getCheckInformation(Custom)) - { - variable = var; - data = d; - } - - virtual ~CheckCustom() {} -}; - -template -T *Checks::addCheck(Args && ... args) -{ - auto i = std::make_shared(std::forward(args)...); - auto r = checks.emplace(std::move(i)); - return (T*)r.first->get(); -} diff --git a/src/common/config.cpp b/src/common/config.cpp deleted file mode 100644 index 3bc33124..00000000 --- a/src/common/config.cpp +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "config.h" - -#include "access_table.h" -#include "database.h" -#include "directories.h" -#include "lock.h" -#include "resolver.h" -#include "settings.h" -#include "yaml.h" - -#include - -#include -#include - -#include -#include - -#include -//DECLARE_STATIC_LOGGER(logger, "config"); - -Config::Config() -{ - addDefaultProject(); - dir = current_thread_path(); -} - -Config::Config(const path &p, bool local) - : Config() -{ - is_local = local; - reload(p); -} - -void Config::reload(const path &p) -{ - if (fs::is_directory(p)) - { - dir = p; - ScopedCurrentPath cp(dir, CurrentPathScope::Thread); - load_current_config(); - } - else - { - dir = p.parent_path(); - ScopedCurrentPath cp(dir, CurrentPathScope::Thread); - load(p); - } -} - -void Config::addDefaultProject() -{ - Project p{ ProjectPath() }; - p.load(yaml()); - p.pkg = pkg; - projects.clear(); - projects.emplace("", p); -} - -void Config::load_current_config() -{ - if (fs::exists(dir / CPPAN_FILENAME)) - load(dir / CPPAN_FILENAME); - else - addDefaultProject(); -} - -void Config::load_current_config_settings() -{ - if (!fs::exists(dir / CPPAN_FILENAME)) - return addDefaultProject(); - auto root = load_yaml_config(dir / CPPAN_FILENAME); - load_settings(root, false); -} - -void Config::load(const path &p) -{ - auto root = load_yaml_config(p); - load(root); -} - -void Config::load(const String &s) -{ - auto root = load_yaml_config(s); - load(root); -} - -void Config::load_settings(const yaml &root, bool load_project) -{ - if (!check_config_root(root)) - return; - - auto ls = root["local_settings"]; - if (ls.IsDefined()) - { - if (!ls.IsMap()) - throw std::runtime_error("'local_settings' should be a map"); - auto &ls = Settings::get_local_settings(); - ls.load_project = load_project; - ls.load(root["local_settings"], SettingsType::Local); - ls.load_project = true; - } -} - -bool Config::check_config_root(const yaml &root) -{ - if (root.IsNull() || !root.IsMap()) - { - addDefaultProject(); - LOG_DEBUG(logger, "Spec file should be a map"); - return false; - } - return true; -} - -void Config::load(const yaml &root) -{ - if (!check_config_root(root)) - return; - - load_settings(root); - - ProjectPath root_project; - YAML_EXTRACT(root_project, String); - - auto prjs = root["projects"]; - if (prjs.IsDefined() && !prjs.IsMap()) - throw std::runtime_error("'projects' should be a map"); - - auto add_project = [this, &root_project](auto &root, auto &&name) - { - Project project(root_project); - project.defaults_allowed = defaults_allowed; - project.allow_relative_project_names = allow_relative_project_names; - project.allow_local_dependencies = allow_local_dependencies; - project.is_local = is_local; - project.load(root); - if (project.name.empty()) - project.name = name; - project.setRelativePath(name); - projects.emplace(project.pkg.ppath.toString(), project); - }; - - projects.clear(); - if (prjs.IsDefined()) - { - for (auto prj : prjs) - add_project(prj.second, prj.first.template as()); - } - else - { - add_project(root, ""); - } -} - -void Config::save(const path &dir) -{ - dump_yaml_config(dir / CPPAN_FILENAME, save()); -} - -yaml Config::save() -{ - yaml root; - int i = 0; - for (auto &p : projects) - { - auto n = p.first; - if (n.empty()) - n = p.second.name; - if (n.empty()) - n = "name" + std::to_string(i++); - root["projects"][n] = p.second.save(); - } - return root; -} - -void Config::clear_vars_cache() const -{ - for (auto &f : boost::make_iterator_range(fs::recursive_directory_iterator(directories.storage_dir_cfg), {})) - { - if (!fs::is_regular_file(f)) - continue; - remove_file(f); - } -} - -Project &Config::getProject1(const ProjectPath &ppath) -{ - if (projects.empty()) - throw std::runtime_error("Projects are empty"); - if (projects.size() == 1) - return projects.begin()->second; - auto i = projects.find(ppath.toString()); - if (i == projects.end()) - throw std::runtime_error("No such project '" + ppath.toString() + "' in config"); - return i->second; -} - -Project &Config::getProject(const ProjectPath &ppath) -{ - return getProject1(ppath); -} - -const Project &Config::getProject(const ProjectPath &ppath) const -{ - return (const Project &)((Config *)this)->getProject1(ppath); -} - -Project &Config::getDefaultProject(const ProjectPath &ppath) -{ - if (ppath.empty() && projects.size() > 1) - return projects.begin()->second; - return getProject(ppath); -} - -const Project &Config::getDefaultProject(const ProjectPath &ppath) const -{ - if (ppath.empty() && projects.size() > 1) - return projects.begin()->second; - return getProject(ppath); -} - -void Config::process(const path &p) const -{ - rd.process(p, (Config&)*this); -} - -void Config::post_download() const -{ - if (!created) - return; - - auto &p = getDefaultProject(); - p.prepareExports(); - p.patchSources(); - - // remove from table - AccessTable at; - at.remove(pkg.getDirSrc()); - at.remove(pkg.getDirObj()); - - auto printer = Printer::create(Settings::get_local_settings().printerType); - printer->d = pkg; - printer->prepare_rebuild(); -} - -Packages Config::getFileDependencies() const -{ - Packages dependencies; - for (auto &p : projects) - { - for (auto &d : p.second.dependencies) - { - // skip ill-formed deps - if (d.second.ppath.is_relative()) - continue; - dependencies.insert({ d.second.ppath.toString(), d.second }); - } - } - return dependencies; -} - -void Config::setPackage(const Package &p) -{ - pkg = p; - for (auto &project : projects) - { - // modify p - // p.ppath = project.name; - project.second.pkg = p; - } -} - -std::vector Config::split() const -{ - std::vector configs; - for (auto &p : projects) - { - Config c = *this; - c.projects.clear(); - c.projects.insert(p); - configs.push_back(c); - } - return configs; -} diff --git a/src/common/config.h b/src/common/config.h deleted file mode 100644 index fda9bf11..00000000 --- a/src/common/config.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "filesystem.h" -#include "package.h" -#include "project.h" -#include "project_path.h" -#include "yaml.h" - -#define CONFIG_ROOT "/etc/cppan/" - -struct Config -{ - Config(); - Config(const path &p, bool local = true); - - void load(const yaml &root); - void load(const path &p); - void load(const String &s); - void reload(const path &p); - - void load_current_config(); - void load_current_config_settings(); - - void save(const path &dir); - yaml save(); - - void process(const path &p = path()) const; - void post_download() const; - - void clear_vars_cache() const; - - auto &getProjects() { return projects; } - auto &getProjects() const { return projects; } - Project &getDefaultProject(const ProjectPath &ppath = ProjectPath()); - const Project &getDefaultProject(const ProjectPath &ppath = ProjectPath()) const; - Project &getProject(const ProjectPath &ppath); - const Project &getProject(const ProjectPath &ppath) const; - - void setPackage(const Package &pkg); - - // split current conf into several with only one project in it - std::vector split() const; - - Packages getFileDependencies() const; // from file - -private: - Projects projects; - path dir; // cwd - - void addDefaultProject(); - Project &getProject1(const ProjectPath &ppath); - - bool check_config_root(const yaml &root); - void load_settings(const yaml &root, bool load_project = true); - -public: - bool defaults_allowed = true; - bool allow_relative_project_names = false; - bool allow_local_dependencies = false; - bool is_local = true; - - // we create this project for the first time (downloaded, locally created etc.) - bool created = false; - - // current package - Package pkg; -}; diff --git a/src/common/cppan.natvis b/src/common/cppan.natvis deleted file mode 100644 index ad05e1d3..00000000 --- a/src/common/cppan.natvis +++ /dev/null @@ -1,71 +0,0 @@ - - - - - {pkg} - - - - {ppath}-{version} - - - - - Empty - - - {path_elements._Mypair._Myval2._Myfirst[0],sb} - - - {path_elements._Mypair._Myval2._Myfirst[0],sb}.{path_elements._Mypair._Myval2._Myfirst[1],sb} - - - {path_elements._Mypair._Myval2._Myfirst[0],sb}.{path_elements._Mypair._Myval2._Myfirst[1],sb}.{path_elements._Mypair._Myval2._Myfirst[2],sb} - - - {path_elements._Mypair._Myval2._Myfirst[0],sb}.{path_elements._Mypair._Myval2._Myfirst[1],sb}.{path_elements._Mypair._Myval2._Myfirst[2],sb}.{path_elements._Mypair._Myval2._Myfirst[3],sb} - - - {path_elements._Mypair._Myval2._Myfirst[0],sb}.{path_elements._Mypair._Myval2._Myfirst[1],sb}.{path_elements._Mypair._Myval2._Myfirst[2],sb}.{path_elements._Mypair._Myval2._Myfirst[3],sb}.{path_elements._Mypair._Myval2._Myfirst[4],sb} - - - {path_elements._Mypair._Myval2._Myfirst[0],sb}.{path_elements._Mypair._Myval2._Myfirst[1],sb}.{path_elements._Mypair._Myval2._Myfirst[2],sb}.{path_elements._Mypair._Myval2._Myfirst[3],sb}.{path_elements._Mypair._Myval2._Myfirst[4],sb}.{path_elements._Mypair._Myval2._Myfirst[5],sb} - - - {path_elements._Mypair._Myval2._Myfirst[0],sb}.{path_elements._Mypair._Myval2._Myfirst[1],sb}.{path_elements._Mypair._Myval2._Myfirst[2],sb}.{path_elements._Mypair._Myval2._Myfirst[3],sb}.{path_elements._Mypair._Myval2._Myfirst[4],sb}.{path_elements._Mypair._Myval2._Myfirst[5],sb}.{path_elements._Mypair._Myval2._Myfirst[6],sb} - - - {path_elements._Mypair._Myval2._Myfirst[0],sb}.{path_elements._Mypair._Myval2._Myfirst[1],sb}.{path_elements._Mypair._Myval2._Myfirst[2],sb}.{path_elements._Mypair._Myval2._Myfirst[3],sb}.{path_elements._Mypair._Myval2._Myfirst[4],sb}.{path_elements._Mypair._Myval2._Myfirst[5],sb}.{path_elements._Mypair._Myval2._Myfirst[6],sb}.{path_elements._Mypair._Myval2._Myfirst[7],sb} - - - {path_elements._Mypair._Myval2._Myfirst[0],sb}.{path_elements._Mypair._Myval2._Myfirst[1],sb}.{path_elements._Mypair._Myval2._Myfirst[2],sb}.{path_elements._Mypair._Myval2._Myfirst[3],sb}.{path_elements._Mypair._Myval2._Myfirst[4],sb}.{path_elements._Mypair._Myval2._Myfirst[5],sb}.{path_elements._Mypair._Myval2._Myfirst[6],sb}.{path_elements._Mypair._Myval2._Myfirst[7],sb}.{path_elements._Mypair._Myval2._Myfirst[8],sb} - - - {path_elements._Mypair._Myval2._Myfirst[0],sb}.{path_elements._Mypair._Myval2._Myfirst[1],sb}.{path_elements._Mypair._Myval2._Myfirst[2],sb}.{path_elements._Mypair._Myval2._Myfirst[3],sb}.{path_elements._Mypair._Myval2._Myfirst[4],sb}.{path_elements._Mypair._Myval2._Myfirst[5],sb}.{path_elements._Mypair._Myval2._Myfirst[6],sb}.{path_elements._Mypair._Myval2._Myfirst[7],sb}.{path_elements._Mypair._Myval2._Myfirst[8],sb}.{path_elements._Mypair._Myval2._Myfirst[9],sb} - - Empty - - - - {branch,sb} - - {major}.{minor}.{patch} - - - {major}.{minor} - - - {major} - - Empty - - diff --git a/src/common/database.cpp b/src/common/database.cpp deleted file mode 100644 index 3a82c6ae..00000000 --- a/src/common/database.cpp +++ /dev/null @@ -1,1537 +0,0 @@ -/* - * Copyright (C) 2016-2017, Egor Pugin - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "database.h" - -#include "directories.h" -#include "exceptions.h" -#include "enums.h" -#include "hash.h" -#include "http.h" -#include "lock.h" -#include "settings.h" -#include "sqlite_database.h" -#include "stamp.h" -#include "printers/cmake.h" - -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - -#include -//DECLARE_STATIC_LOGGER(logger, "db"); - -#define PACKAGES_DB_REFRESH_TIME_MINUTES 15 - -#define PACKAGES_DB_SCHEMA_VERSION 1 -#define PACKAGES_DB_SCHEMA_VERSION_FILE "schema.version" -#define PACKAGES_DB_VERSION_FILE "db.version" -#define PACKAGES_DB_DOWNLOAD_TIME_FILE "packages.time" - -const String db_repo_url = "https://github.com/cppan/database"; -const String db_master_url = db_repo_url + "/archive/master.zip"; -const String db_version_url = "https://raw.githubusercontent.com/cppan/database/master/" PACKAGES_DB_VERSION_FILE; - -const path db_dir_name = "database"; -const path db_repo_dir_name = "repository"; -const String packages_db_name = "packages.db"; -const String service_db_name = "service.db"; - -TYPED_EXCEPTION(NoSuchVersion); - -std::vector startup_actions{ - { 1, StartupAction::ClearCache }, - { 2, StartupAction::ServiceDbClearConfigHashes }, - { 4, StartupAction::CheckSchema }, - { 5, StartupAction::ClearStorageDirExp }, - { 6, StartupAction::ClearSourceGroups }, - { 7, StartupAction::ClearStorageDirExp | StartupAction::ClearStorageDirBin | StartupAction::ClearStorageDirLib }, - { 8, StartupAction::ClearCfgDirs }, - { 9, StartupAction::ClearStorageDirExp }, - { 10, StartupAction::ClearPackagesDatabase }, - { 11, StartupAction::ServiceDbClearConfigHashes }, - { 12, StartupAction::ClearStorageDirExp | StartupAction::ClearStorageDirObj }, - { 13, StartupAction::ClearStorageDirExp }, -}; - -const TableDescriptors &get_service_tables() -{ - // to prevent side effects as with global variable - // ! append new tables to the end only ! - static const TableDescriptors service_tables{ - - { "ClientStamp", - R"( - CREATE TABLE "ClientStamp" ( - "stamp" INTEGER NOT NULL - ); - )" }, - - {"ConfigHashes", - R"( - CREATE TABLE "ConfigHashes" ( - "hash" TEXT NOT NULL, -- program (settings) hash - "config" TEXT NOT NULL, -- config - "config_hash" TEXT NOT NULL, -- config hash - PRIMARY KEY ("hash") - ); - )"}, - - { "FileStamps", - R"( - CREATE TABLE "FileStamps" ( - "file" TEXT NOT NULL, - "stamp" INTEGER NOT NULL, - PRIMARY KEY ("file") - ); - )" }, - - {"InstalledPackages", - R"( - CREATE TABLE "InstalledPackages" ( - "id" INTEGER NOT NULL, - "package" TEXT NOT NULL, - "version" TEXT NOT NULL, - "hash" TEXT NOT NULL, - PRIMARY KEY ("id"), - UNIQUE ("package", "version") - ); - )"}, - - {"NextClientVersionCheck", - R"( - CREATE TABLE "NextClientVersionCheck" ( - "timestamp" INTEGER NOT NULL - ); - insert into NextClientVersionCheck values (0); - )"}, - - {"NRuns", // unneeded? - R"( - CREATE TABLE "NRuns" ( - "n_runs" INTEGER NOT NULL - ); - insert into NRuns values (0); - )"}, - - {"PackagesDbSchemaVersion", - R"( - CREATE TABLE "PackagesDbSchemaVersion" ( - "version" INTEGER NOT NULL - ); - insert into PackagesDbSchemaVersion values ()" + - std::to_string(PACKAGES_DB_SCHEMA_VERSION) + R"(); - )"}, - - {"PackageDependenciesHashes", - R"( - CREATE TABLE "PackageDependenciesHashes" ( - "package" TEXT NOT NULL, - "dependencies" TEXT NOT NULL, - PRIMARY KEY ("package") - ); - )"}, - - { "SourceGroups", - R"( - CREATE TABLE "SourceGroups" ( - "id" INTEGER NOT NULL, - "package_id" INTEGER NOT NULL, - "path" TEXT NOT NULL, - PRIMARY KEY ("id"), - FOREIGN KEY ("package_id") REFERENCES "InstalledPackages" ("id") ON DELETE CASCADE - ); - )" }, - - { "SourceGroupFiles", - R"( - CREATE TABLE "SourceGroupFiles" ( - "source_group_id" INTEGER NOT NULL, - "path" TEXT NOT NULL, - FOREIGN KEY ("source_group_id") REFERENCES "SourceGroups" ("id") ON DELETE CASCADE - ); - )" }, - - {"StartupActions", - R"( - CREATE TABLE "StartupActions" ( - "id" INTEGER NOT NULL, - "action" INTEGER NOT NULL, - PRIMARY KEY ("id", "action") - ); - )"}, - - {"TableHashes", - R"( - CREATE TABLE "TableHashes" ( - "tbl" TEXT NOT NULL, - "hash" TEXT NOT NULL, - PRIMARY KEY ("tbl") - ); - )"}, - }; - return service_tables; -} - -const TableDescriptors data_tables{ - { - "Projects", - R"( - CREATE TABLE "Projects" ( - "id" INTEGER NOT NULL, - "path" TEXT(2048) NOT NULL, - "type_id" INTEGER NOT NULL, - "flags" INTEGER NOT NULL, - PRIMARY KEY ("id") - ); - CREATE UNIQUE INDEX "ProjectPath" ON "Projects" ("path" ASC); - )" - }, - { - "ProjectVersions", - R"( - CREATE TABLE "ProjectVersions" ( - "id" INTEGER NOT NULL, - "project_id" INTEGER NOT NULL, - "major" INTEGER, - "minor" INTEGER, - "patch" INTEGER, - "branch" TEXT, - "flags" INTEGER NOT NULL, - "created" DATE NOT NULL, - "hash" TEXT NOT NULL, - PRIMARY KEY ("id"), - FOREIGN KEY ("project_id") REFERENCES "Projects" ("id") - ); - )" - }, - { - "ProjectVersionDependencies", - R"( - CREATE TABLE "ProjectVersionDependencies" ( - "project_version_id" INTEGER NOT NULL, - "project_dependency_id" INTEGER NOT NULL, - "version" TEXT NOT NULL, - "flags" INTEGER NOT NULL, - PRIMARY KEY ("project_version_id", "project_dependency_id"), - FOREIGN KEY ("project_version_id") REFERENCES "ProjectVersions" ("id"), - FOREIGN KEY ("project_dependency_id") REFERENCES "Projects" ("id") - ); - )" - }, -}; - -path getDbDirectory() -{ - // db per storage - return directories.storage_dir_etc / db_dir_name; -} - -int readPackagesDbSchemaVersion(const path &dir) -{ - auto p = dir / PACKAGES_DB_SCHEMA_VERSION_FILE; - if (!fs::exists(p)) - return 0; - return std::stoi(read_file(p)); -} - -void writePackagesDbSchemaVersion(const path &dir) -{ - write_file(dir / PACKAGES_DB_SCHEMA_VERSION_FILE, std::to_string(PACKAGES_DB_SCHEMA_VERSION)); -} - -int readPackagesDbVersion(const path &dir) -{ - auto p = dir / PACKAGES_DB_VERSION_FILE; - if (!fs::exists(p)) - return 0; - return std::stoi(read_file(p)); -} - -void writePackagesDbVersion(const path &dir, int version) -{ - write_file(dir / PACKAGES_DB_VERSION_FILE, std::to_string(version)); -} - -ServiceDatabase &getServiceDatabase(bool init) -{ - // this holder will init on-disk sdb once - // later thread local calls will just open it - static ServiceDatabase run_once_db; - if (init) - run_once_db.init(); - - thread_local - ServiceDatabase db; - return db; -} - -ServiceDatabase &getServiceDatabaseReadOnly() -{ - return getServiceDatabase(); - - RUN_ONCE - { - getServiceDatabase(); - }; - static ServiceDatabase db; - RUN_ONCE - { - db.open(true); - }; - return db; -} - -PackagesDatabase &getPackagesDatabase() -{ - // this holder will init on-disk pkgdb once - // later thread local calls will just open it - static PackagesDatabase run_once_db; - - thread_local - PackagesDatabase db; - return db; -} - -Database::Database(const String &name, const TableDescriptors &tds) - : tds(tds) -{ - db_dir = getDbDirectory(); - fn = db_dir / name; - if (!fs::exists(fn)) - { - ScopedFileLock lock(fn); - if (!fs::exists(fn)) - { - open(); - for (auto &td : tds) - db->execute(td.query); - created = true; - } - } - if (!db) - open(); -} - -void Database::open(bool read_only) -{ - db = std::make_unique(fn.string(), read_only); -} - -void Database::recreate() -{ - db.reset(); - ScopedFileLock lock(fn); - fs::remove(fn); - db = std::make_unique(fn.string()); - for (auto &td : tds) - db->execute(td.query); - created = true; -} - -ServiceDatabase::ServiceDatabase() - : Database(service_db_name, get_service_tables()) -{ -} - -void ServiceDatabase::init() -{ - RUN_ONCE - { - createTables(); - checkStamp(); - increaseNumberOfRuns(); - checkForUpdates(); - }; - - // move out of RUN_ONCE because it may try to init sdb again - performStartupActions(); -} - -void ServiceDatabase::createTables() const -{ - // add table hashes - if (created) - { - for (auto &td : tds) - setTableHash(td.name, sha256(td.query)); - } - - auto create_table = [this](const auto &td) - { - db->execute(td.query); - setTableHash(td.name, sha256(td.query)); - }; - - // TableHashes first, out of order - auto th = std::find_if(tds.begin(), tds.end(), [](const auto &td) - { - return td.name == "TableHashes"; - }); - if (!db->getNumberOfColumns(th->name)) - create_table(*th); - - // create only new tables - for (auto &td : tds) - { - if (db->getNumberOfColumns(td.name)) - continue; - create_table(td); - } -} - -void ServiceDatabase::recreateTable(const TableDescriptor &td) const -{ - db->dropTable(td.name); - db->execute(td.query); - setTableHash(td.name, sha256(td.query)); -} - -void ServiceDatabase::checkStamp() const -{ - String s; - db->execute("select * from ClientStamp", - [&s](SQLITE_CALLBACK_ARGS) - { - s = cols[0]; - return 0; - }); - - if (s == cppan_stamp) - return; - - if (s.empty()) - db->execute("replace into ClientStamp values ('" + cppan_stamp + "')"); - else - db->execute("update ClientStamp set stamp = '" + cppan_stamp + "'"); - - // if stamp is changed, we do some usual stuff between versions - - clearFileStamps(); -} - -void ServiceDatabase::performStartupActions() const -{ - registerCmakePackage(); - - // perform startup actions on client update - try - { - static bool once = false; - if (once) - return; - - std::set actions_performed; // prevent multiple execution of the same actions - for (auto &a : startup_actions) - { - if (isActionPerformed(a)) - continue; - - if (actions_performed.find(a.action) != actions_performed.end()) - { - setActionPerformed(a); - continue; - } - - if (!once) - LOG_INFO(logger, "Initializing storage"); - once = true; - - actions_performed.insert(a.action); - setActionPerformed(a); - - // do actions - if (a.action & StartupAction::ClearCache) - { - CMakePrinter().clear_cache(); - } - - if (a.action & StartupAction::ServiceDbClearConfigHashes) - { - clearConfigHashes(); - - // also cleanup temp build dir - error_code ec; - fs::remove_all(temp_directory_path(), ec); - } - - if (a.action & StartupAction::CheckSchema) - { - // create new tables - createTables(); - - // re-create changed tables - for (auto &td : tds) - { - auto h = sha256(td.query); - if (getTableHash(td.name) == h) - continue; - db->dropTable(td.name); - db->execute(td.query); - setTableHash(td.name, h); - } - } - - if (a.action & StartupAction::ClearPackagesDatabase) - { - fs::remove(getDbDirectory() / packages_db_name); - } - - if (a.action & StartupAction::ClearStorageDirExp) - { - remove_all_from_dir(directories.storage_dir_exp); - } - - if (a.action & StartupAction::ClearStorageDirObj) - { - remove_all_from_dir(directories.storage_dir_obj); - } - - if (a.action & StartupAction::ClearStorageDirBin) - { - // also remove exp to trigger cmake - remove_all_from_dir(directories.storage_dir_exp); - remove_all_from_dir(directories.storage_dir_bin); - } - - if (a.action & StartupAction::ClearStorageDirLib) - { - // also remove exp to trigger cmake - remove_all_from_dir(directories.storage_dir_exp); - remove_all_from_dir(directories.storage_dir_lib); - } - - if (a.action & StartupAction::ClearSourceGroups) - { - clearSourceGroups(); - } - - if (a.action & StartupAction::ClearCfgDirs) - { - for (auto &i : boost::make_iterator_range(fs::directory_iterator(directories.storage_dir_cfg), {})) - { - if (fs::is_directory(i)) - fs::remove_all(i); - } - } - } - } - catch (std::exception &e) - { - // do not fail - LOG_WARN(logger, "Warning: " << e.what()); - } -} - -void ServiceDatabase::checkForUpdates() const -{ - using namespace std::literals; - - auto last_check = getLastClientUpdateCheck(); - auto d = Clock::now() - last_check; - if (d < 3h) - return; - - try - { - // if there are updates, set next check (and notification) in 20 mins - // to issue a message every run - if (Settings::get_user_settings().checkForUpdates()) - setLastClientUpdateCheck(last_check + 20min); - else - setLastClientUpdateCheck(); - } - catch (...) - { - } -} - -TimePoint ServiceDatabase::getLastClientUpdateCheck() const -{ - TimePoint tp; - db->execute("select * from NextClientVersionCheck", - [&tp](SQLITE_CALLBACK_ARGS) - { - tp = Clock::from_time_t(std::stoll(cols[0])); - return 0; - }); - return tp; -} - -void ServiceDatabase::setLastClientUpdateCheck(const TimePoint &p) const -{ - db->execute("update NextClientVersionCheck set timestamp = '" + - std::to_string(Clock::to_time_t(p)) + "'"); -} - -String ServiceDatabase::getTableHash(const String &table) const -{ - String h; - db->execute("select hash from TableHashes where tbl = '" + table + "'", - [&h](SQLITE_CALLBACK_ARGS) - { - h = cols[0]; - return 0; - }); - return h; -} - -void ServiceDatabase::setTableHash(const String &table, const String &hash) const -{ - db->execute("replace into TableHashes values ('" + table + "', '" + hash + "')"); -} - -Stamps ServiceDatabase::getFileStamps() const -{ - Stamps st; - db->execute("select * from FileStamps", - [&st](SQLITE_CALLBACK_ARGS) - { - st[cols[0]] = fs::file_time_type(fs::file_time_type::duration(std::stoll(cols[1]))); - return 0; - }); - return st; -} - -void ServiceDatabase::setFileStamps(const Stamps &stamps) const -{ - if (stamps.empty()) - { - clearFileStamps(); - return; - } - String q = "replace into FileStamps values "; - for (auto &s : stamps) - q += "('" + normalize_path(s.first) + "', '" + std::to_string(s.second.time_since_epoch().count()) + "'),"; - q.resize(q.size() - 1); - q += ";"; - db->execute(q); -} - -void ServiceDatabase::clearFileStamps() const -{ - db->execute("delete from FileStamps"); -} - -bool ServiceDatabase::isActionPerformed(const StartupAction &action) const -{ - int n = 0; - try - { - db->execute("select count(*) from StartupActions where id = '" + - std::to_string(action.id) + "' and action = '" + std::to_string(action.action) + "'", - [&n](SQLITE_CALLBACK_ARGS) - { - n = std::stoi(cols[0]); - return 0; - }); - } - catch (const std::exception&) - { - // if error is in StartupActions, recreate it - auto th = std::find_if(tds.begin(), tds.end(), [](const auto &td) - { - return td.name == "StartupActions"; - }); - recreateTable(*th); - } - return n == 1; -} - -void ServiceDatabase::setActionPerformed(const StartupAction &action) const -{ - db->execute("insert into StartupActions values ('" + - std::to_string(action.id) + "', '" + std::to_string(action.action) + "')"); -} - -int ServiceDatabase::getNumberOfRuns() const -{ - int n_runs = 0; - db->execute("select n_runs from NRuns;", [&n_runs](SQLITE_CALLBACK_ARGS) - { - n_runs = std::stoi(cols[0]); - return 0; - }); - return n_runs; -} - -int ServiceDatabase::increaseNumberOfRuns() const -{ - auto prev = getNumberOfRuns(); - db->execute("update NRuns set n_runs = n_runs + 1;"); - return prev; -} - -int ServiceDatabase::getPackagesDbSchemaVersion() const -{ - int version = 0; - db->execute("select version from PackagesDbSchemaVersion;", [&version](SQLITE_CALLBACK_ARGS) - { - version = std::stoi(cols[0]); - return 0; - }); - return version; -} - -void ServiceDatabase::setPackagesDbSchemaVersion(int version) const -{ - db->execute("update PackagesDbSchemaVersion set version = " + std::to_string(version)); -} - -void ServiceDatabase::clearConfigHashes() const -{ - db->execute("delete from ConfigHashes"); -} - -String ServiceDatabase::getConfigByHash(const String &settings_hash) const -{ - String c; - db->execute("select config from ConfigHashes where hash = '" + settings_hash + "'", - [&c](SQLITE_CALLBACK_ARGS) - { - c = cols[0]; - return 0; - }); - return c; -} - -void ServiceDatabase::addConfigHash(const String &settings_hash, const String &config, const String &config_hash) const -{ - if (config.empty()) - return; - db->execute("replace into ConfigHashes values ('" + settings_hash + "', '" + config + "', '" + config_hash + "'" + ")"); -} - -void ServiceDatabase::removeConfigHashes(const String &h) const -{ - db->execute("delete from ConfigHashes where config_hash = '" + h + "'"); -} - -void ServiceDatabase::setPackageDependenciesHash(const Package &p, const String &hash) const -{ - db->execute("replace into PackageDependenciesHashes values ('" + p.target_name + "', '" + hash + "')"); -} - -bool ServiceDatabase::hasPackageDependenciesHash(const Package &p, const String &hash) const -{ - bool has = false; - db->execute("select * from PackageDependenciesHashes where package = '" + p.target_name + "' " - "and dependencies = '" + hash + "'", - [&has](SQLITE_CALLBACK_ARGS) - { - has = true; - return 0; - }); - return has; -} - -void ServiceDatabase::setSourceGroups(const Package &p, const SourceGroups &sgs) const -{ - auto id = getInstalledPackageId(p); - if (id == 0) - return; - removeSourceGroups(id); - for (auto &sg : sgs) - { - db->execute("insert into SourceGroups (package_id, path) values ('" + std::to_string(id) + "', '" + sg.first + "');"); - if (!sg.second.empty()) - { - auto sg_id = db->getLastRowId(); - String q = "insert into SourceGroupFiles values "; - for (auto &f : sg.second) - q += "('" + std::to_string(sg_id) + "', '" + f + "'),"; - q.resize(q.size() - 1); - q += ";"; - db->execute(q); - } - } -} - -SourceGroups ServiceDatabase::getSourceGroups(const Package &p) const -{ - SourceGroups sgs; - auto id = getInstalledPackageId(p); - if (id == 0) - return sgs; - std::map ids; - db->execute("select id, path from SourceGroups where package_id = '" + std::to_string(id) + "';", - [&ids](SQLITE_CALLBACK_ARGS) - { - ids[std::stoi(cols[0])] = cols[1]; - return 0; - }); - for (auto &i : ids) - { - auto &sg = sgs[i.second]; - db->execute("select path from SourceGroupFiles where source_group_id = '" + std::to_string(i.first) + "';", - [&sg](SQLITE_CALLBACK_ARGS) - { - sg.insert(cols[0]); - return 0; - }); - } - return sgs; -} - -void ServiceDatabase::removeSourceGroups(const Package &p) const -{ - auto id = getInstalledPackageId(p); - if (id == 0) - return; - removeSourceGroups(id); -} - -void ServiceDatabase::removeSourceGroups(int id) const -{ - db->execute("delete from SourceGroups where package_id = '" + std::to_string(id) + "';"); -} - -void ServiceDatabase::clearSourceGroups() const -{ - db->execute("delete from SourceGroupFiles;"); - db->execute("delete from SourceGroups;"); -} - -void ServiceDatabase::addInstalledPackage(const Package &p) const -{ - auto h = p.getFilesystemHash(); - if (getInstalledPackageHash(p) == h) - return; - db->execute("replace into InstalledPackages (package, version, hash) values ('" + p.ppath.toString() + "', '" + p.version.toString() + "', '" + p.getFilesystemHash() + "')"); -} - -void ServiceDatabase::removeInstalledPackage(const Package &p) const -{ - db->execute("delete from InstalledPackages where package = '" + p.ppath.toString() + "' and version = '" + p.version.toString() + "'"); -} - -String ServiceDatabase::getInstalledPackageHash(const Package &p) const -{ - String hash; - db->execute("select hash from InstalledPackages where package = '" + p.ppath.toString() + "' and version = '" + p.version.toString() + "'", - [&hash](SQLITE_CALLBACK_ARGS) - { - hash = cols[0]; - return 0; - }); - return hash; -} - -int ServiceDatabase::getInstalledPackageId(const Package &p) const -{ - int id = 0; - db->execute("select id from InstalledPackages where package = '" + p.ppath.toString() + "' and version = '" + p.version.toString() + "'", - [&id](SQLITE_CALLBACK_ARGS) - { - id = std::stoi(cols[0]); - return 0; - }); - return id; -} - -PackagesSet ServiceDatabase::getInstalledPackages() const -{ - std::set> pkgs_s; - db->execute("select package, version from InstalledPackages", - [&pkgs_s](SQLITE_CALLBACK_ARGS) - { - pkgs_s.insert({ cols[0], cols[1] }); - return 0; - }); - - PackagesSet pkgs; - for (auto &p : pkgs_s) - { - Package pkg; - pkg.ppath = p.first; - pkg.version = p.second; - pkg.createNames(); - pkgs.insert(pkg); - } - return pkgs; -} - -PackagesDatabase::PackagesDatabase() - : Database(packages_db_name, data_tables) -{ - db_repo_dir = db_dir / db_repo_dir_name; - - RUN_ONCE - { - init(); - }; - - // at the end we always reopen packages db as read only - open(true); -} - -void PackagesDatabase::init() -{ - if (created) - { - LOG_INFO(logger, "Packages database was not found"); - download(); - load(); - } - else if (Settings::get_system_settings().can_update_packages_db && isCurrentDbOld()) - { - LOG_DEBUG(logger, "Checking remote version"); - int version_remote = 0; - try - { - version_remote = std::stoi(download_file(db_version_url)); - } - catch (std::exception &e) - { - LOG_DEBUG(logger, "Couldn't download db version file: " << e.what()); - } - if (version_remote > readPackagesDbVersion(db_repo_dir)) - { - // multiprocess aware - single_process_job(get_lock("db_update"), [this] - { - download(); - load(true); - }); - } - } -} - -void PackagesDatabase::download() -{ - LOG_INFO(logger, "Downloading database"); - - auto download_archive = [this]() - { - fs::create_directories(db_repo_dir); - auto fn = get_temp_filename(); - download_file(db_master_url, fn, 1_GB); - auto unpack_dir = get_temp_filename(); - auto files = unpack_file(fn, unpack_dir); - for (auto &f : files) - fs::copy_file(f, db_repo_dir / f.filename(), fs::copy_options::overwrite_existing); - fs::remove_all(unpack_dir); - fs::remove(fn); - }; - - const String git = "git"; - if (!primitives::resolve_executable(git).empty()) - { - auto git_init = [this, &git]() - { - fs::create_directories(db_repo_dir); - primitives::Command::execute({ git,"-C",db_repo_dir.string(),"init","." }); - primitives::Command::execute({ git,"-C",db_repo_dir.string(),"remote","add","github",db_repo_url }); - primitives::Command::execute({ git,"-C",db_repo_dir.string(),"pull","github","master" }); - }; - - try - { - if (!fs::exists(db_repo_dir / ".git")) - { - git_init(); - } - else - { - std::error_code ec1, ec2; - primitives::Command::execute({ git,"-C",db_repo_dir.string(),"pull","github","master" }, ec1); - primitives::Command::execute({ git,"-C",db_repo_dir.string(),"reset","--hard" }, ec2); - if (ec1 || ec2) - { - // can throw - fs::remove_all(db_repo_dir); - git_init(); - } - } - } - catch (const std::exception &) - { - // cannot throw - error_code ec; - fs::remove_all(db_repo_dir, ec); - - download_archive(); - } - } - else - { - download_archive(); - } - - writeDownloadTime(); -} - -void PackagesDatabase::load(bool drop) -{ - auto &sdb = getServiceDatabase(); - auto sver_old = sdb.getPackagesDbSchemaVersion(); - int sver = readPackagesDbSchemaVersion(db_repo_dir); - if (sver && sver != PACKAGES_DB_SCHEMA_VERSION) - { - if (sver > PACKAGES_DB_SCHEMA_VERSION) - throw std::runtime_error("Client's packages db schema version is older than remote one. Please, upgrade the cppan client from site or via --self-upgrade"); - if (sver < PACKAGES_DB_SCHEMA_VERSION) - throw std::runtime_error("Client's packages db schema version is newer than remote one. Please, wait for server upgrade"); - } - if (sver > sver_old) - { - recreate(); - sdb.setPackagesDbSchemaVersion(sver); - } - - db->execute("PRAGMA foreign_keys = OFF;"); - - auto mdb = db->getDb(); - sqlite3_stmt *stmt = nullptr; - - db->execute("BEGIN;"); - - for (auto &td : data_tables) - { - if (drop) - db->execute("delete from " + td.name); - - auto n_cols = db->getNumberOfColumns(td.name); - - String query = "insert into " + td.name + " values ("; - for (int i = 0; i < n_cols; i++) - query += "?, "; - query.resize(query.size() - 2); - query += ");"; - - if (sqlite3_prepare_v2(mdb, query.c_str(), (int)query.size() + 1, &stmt, 0) != SQLITE_OK) - throw std::runtime_error(sqlite3_errmsg(mdb)); - - auto fn = db_repo_dir / (td.name + ".csv"); - boost::nowide::ifstream ifile(fn.string()); - if (!ifile) - throw std::runtime_error("Cannot open file " + fn.string() + " for reading"); - - String s; - while (std::getline(ifile, s)) - { - auto b = s.c_str(); - std::replace(s.begin(), s.end(), ';', '\0'); - - for (int i = 1; i <= n_cols; i++) - { - if (*b) - sqlite3_bind_text(stmt, i, b, -1, SQLITE_TRANSIENT); - else - sqlite3_bind_null(stmt, i); - while (*b) b++; - b++; - } - - if (sqlite3_step(stmt) != SQLITE_DONE) - throw std::runtime_error("sqlite3_step() failed"); - if (sqlite3_reset(stmt) != SQLITE_OK) - throw std::runtime_error("sqlite3_reset() failed"); - } - - if (sqlite3_finalize(stmt) != SQLITE_OK) - throw std::runtime_error("sqlite3_finalize() failed"); - } - - db->execute("COMMIT;"); - - db->execute("PRAGMA foreign_keys = ON;"); -} - -void PackagesDatabase::writeDownloadTime() const -{ - auto tp = std::chrono::system_clock::now(); - auto time = std::chrono::system_clock::to_time_t(tp); - write_file(db_dir / PACKAGES_DB_DOWNLOAD_TIME_FILE, std::to_string(time)); -} - -TimePoint PackagesDatabase::readDownloadTime() const -{ - auto fn = db_dir / PACKAGES_DB_DOWNLOAD_TIME_FILE; - String ts = "0"; - if (fs::exists(fn)) - ts = read_file(fn); - auto tp = std::chrono::system_clock::from_time_t(std::stoll(ts)); - return tp; -} - -bool PackagesDatabase::isCurrentDbOld() const -{ - auto tp_old = readDownloadTime(); - auto tp = std::chrono::system_clock::now(); - return (tp - tp_old) > std::chrono::minutes(PACKAGES_DB_REFRESH_TIME_MINUTES); -} - -IdDependencies PackagesDatabase::findDependencies(const Packages &deps) const -{ - DependenciesMap all_deps; - for (auto &dep : deps) - { - if (dep.second.flags[pfLocalProject]) - continue; - - ProjectType type; - DownloadDependency project; - project.ppath = dep.second.ppath; - project.version = dep.second.version; - - db->execute("select id, type_id, flags from Projects where path = '" + dep.second.ppath.toString() + "'", - [&project, &type](SQLITE_CALLBACK_ARGS) - { - project.id = std::stoull(cols[0]); - type = (ProjectType)std::stoi(cols[1]); - project.flags = std::stoull(cols[2]); - return 0; - }); - - if (project.id == 0) - // TODO: replace later with typed exception, so client will try to fetch same package from server - throw std::runtime_error("Package '" + project.ppath.toString() + "' not found."); - - auto find_deps = [&all_deps, this](auto &dependency) - { - dependency.flags.set(pfDirectDependency); - dependency.id = getExactProjectVersionId(dependency, dependency.version, dependency.flags, dependency.hash); - all_deps[dependency] = dependency; // assign first, deps assign second - all_deps[dependency].db_dependencies = getProjectDependencies(dependency.id, all_deps); - }; - - if (type == ProjectType::RootProject) - { - std::vector projects; - - // root projects should return all children (lib, exe) - db->execute("select id, path, flags from Projects where path like '" + project.ppath.toString() + - ".%' and type_id in ('1','2') order by path", - [&projects, &project](SQLITE_CALLBACK_ARGS) - { - DownloadDependency dep; - dep.id = std::stoull(cols[0]); - dep.ppath = String(cols[1]); - dep.version = project.version; - dep.flags = std::stoull(cols[2]); - projects.push_back(dep); - return 0; - }); - - if (projects.empty()) - // TODO: replace later with typed exception, so client will try to fetch same package from server - throw std::runtime_error("Root project '" + project.ppath.toString() + "' is empty"); - - int n = 0; - for (auto &p : projects) - { - try - { - find_deps(p); - n++; - } - catch (NoSuchVersion &) - { - } - } - if (n == 0) - { - throw NoSuchVersion("No such version/branch '" + project.version.toAnyVersion() + "' for project '" + - project.ppath.toString() + "'"); - } - } - else - { - find_deps(project); - } - } - - // make id deps - IdDependencies dds; - for (auto &ad : all_deps) - { - auto &d = ad.second; - std::unordered_set ids; - for (auto &dd2 : d.db_dependencies) - ids.insert(dd2.second.id); - d.setDependencyIds(ids); - dds[d.id] = d; - } - return dds; -} - -void check_version_age(const TimePoint &t1, const char *created) -{ - auto d = t1 - string2timepoint(created); - auto mins = std::chrono::duration_cast(d).count(); - // multiple by 2 because first time interval goes for uploading db - // and during the second one, the packet is really young - if (mins < PACKAGES_DB_REFRESH_TIME_MINUTES * 2) - throw std::runtime_error("One of the queried packages is 'young'. Young packages must be retrieved from server."); -} - -ProjectVersionId PackagesDatabase::getExactProjectVersionId(const DownloadDependency &project, Version &version, ProjectFlags &flags, String &hash) const -{ - auto err = [](const auto &v, const auto &p) - { - return NoSuchVersion("No such version/branch '" + v.toAnyVersion() + "' for project '" + p.toString() + "'"); - }; - - // save current time during first call - // it is used for detecting young packages - static auto tstart = getUtc(); - - ProjectVersionId id = 0; - static const String select = "select id, major, minor, patch, flags, hash, created from ProjectVersions where "; - - if (!version.isBranch()) - { - auto &v = version; - - db->execute( - select + " " - "project_id = '" + std::to_string(project.id) + "' and " - "major = '" + std::to_string(v.major) + "' and " - "minor = '" + std::to_string(v.minor) + "' and " - "patch = '" + std::to_string(v.patch) + "'", [&id, &flags, &hash](SQLITE_CALLBACK_ARGS) - { - id = std::stoull(cols[0]); - flags |= decltype(project.flags)(std::stoull(cols[4])); - hash = cols[5]; - check_version_age(tstart, cols[6]); - return 0; - }); - - if (id == 0) - { - if (v.patch != -1) - throw err(version, project.ppath); - - db->execute( - select + " " - "project_id = '" + std::to_string(project.id) + "' and " - "major = '" + std::to_string(v.major) + "' and " - "minor = '" + std::to_string(v.minor) + "' and " - "branch is null order by major desc, minor desc, patch desc limit 1", - [&id, &version, &flags, &hash](SQLITE_CALLBACK_ARGS) - { - id = std::stoull(cols[0]); - version.patch = std::stoi(cols[3]); - flags |= decltype(project.flags)(std::stoull(cols[4])); - hash = cols[5]; - check_version_age(tstart, cols[6]); - return 0; - }); - - if (id == 0) - { - if (v.minor != -1) - throw err(version, project.ppath); - - db->execute( - select + " " - "project_id = '" + std::to_string(project.id) + "' and " - "major = '" + std::to_string(v.major) + "' and " - "branch is null order by major desc, minor desc, patch desc limit 1", - [&id, &version, &flags, &hash](SQLITE_CALLBACK_ARGS) - { - id = std::stoull(cols[0]); - version.minor = std::stoi(cols[2]); - version.patch = std::stoi(cols[3]); - flags |= decltype(project.flags)(std::stoull(cols[4])); - hash = cols[5]; - check_version_age(tstart, cols[6]); - return 0; - }); - - if (id == 0) - { - if (v.major != -1) - throw err(version, project.ppath); - - db->execute( - select + " " - "project_id = '" + std::to_string(project.id) + "' and " - "branch is null order by major desc, minor desc, patch desc limit 1", - [&id, &version, &flags, &hash](SQLITE_CALLBACK_ARGS) - { - id = std::stoull(cols[0]); - version.major = std::stoi(cols[1]); - version.minor = std::stoi(cols[2]); - version.patch = std::stoi(cols[3]); - flags |= decltype(project.flags)(std::stoull(cols[4])); - hash = cols[5]; - check_version_age(tstart, cols[6]); - return 0; - }); - - if (id == 0) - { - // TODO: - throw err(version, project.ppath); - } - } - } - } - } - else - { - db->execute( - select + " " - "project_id = '" + std::to_string(project.id) + "' and " - "branch = '" + version.toString() + "'", [&id, &flags, &hash](SQLITE_CALLBACK_ARGS) - { - id = std::stoull(cols[0]); - flags |= decltype(project.flags)(std::stoull(cols[4])); - hash = cols[5]; - check_version_age(tstart, cols[6]); - return 0; - }); - - if (id == 0) - { - // TODO: - throw err(version, project.ppath); - } - } - - return id; -} - -PackagesDatabase::Dependencies PackagesDatabase::getProjectDependencies(ProjectVersionId project_version_id, DependenciesMap &dm) const -{ - Dependencies dependencies; - std::vector deps; - - db->execute( - "select Projects.id, path, version, Projects.flags, ProjectVersionDependencies.flags " - "from ProjectVersionDependencies join Projects on project_dependency_id = Projects.id " - "where project_version_id = '" + std::to_string(project_version_id) + "' order by path", - [&deps](SQLITE_CALLBACK_ARGS) - { - int col_id = 0; - DownloadDependency d; - d.id = std::stoull(cols[col_id++]); - d.ppath = cols[col_id++]; - d.version = String(cols[col_id++]); - d.flags = decltype(d.flags)(std::stoull(cols[col_id++])); // project's flags - d.flags |= decltype(d.flags)(std::stoull(cols[col_id++])); // merge with deps' flags - deps.push_back(d); - return 0; - }); - - for (auto &dependency : deps) - { - dependency.id = getExactProjectVersionId(dependency, dependency.version, dependency.flags, dependency.hash); - auto i = dm.find(dependency); - if (i == dm.end()) - { - dm[dependency] = dependency; // assign first, deps assign second - dm[dependency].db_dependencies = getProjectDependencies(dependency.id, dm); - } - dependencies[dependency.ppath.toString()] = dependency; - } - return dependencies; -} - -void PackagesDatabase::listPackages(const String &name) const -{ - auto pkgs = getMatchingPackages(name); - if (pkgs.empty()) - { - LOG_INFO(logger, "nothing found"); - return; - } - - for (auto &pkg : pkgs) - { - auto versions = getVersionsForPackage(pkg); - String out = pkg.toString(); - out += " ("; - for (auto &v : versions) - out += v.toString() + ", "; - out.resize(out.size() - 2); - out += ")"; - LOG_INFO(logger, out); - } -} - -Version PackagesDatabase::getExactVersionForPackage(const Package &p) const -{ - DownloadDependency d; - d.ppath = p.ppath; - d.id = getPackageId(p.ppath); - - Version v = p.version; - ProjectFlags f; - String h; - getExactProjectVersionId(d, v, f, h); - return v; -} - -template