diff options
-rw-r--r-- | README.md | 15 | ||||
-rw-r--r-- | build.gradle | 53 | ||||
-rw-r--r-- | codequality/HEADER | 13 | ||||
-rw-r--r-- | codequality/checkstyle.xml | 188 | ||||
-rw-r--r-- | gradle.properties | 1 | ||||
-rw-r--r-- | gradle/wrapper/gradle-wrapper.jar | bin | 56177 -> 0 bytes | |||
-rw-r--r-- | gradle/wrapper/gradle-wrapper.properties | 5 | ||||
-rwxr-xr-x | gradlew | 172 | ||||
-rw-r--r-- | gradlew.bat | 84 | ||||
l--------- | install | 1 | ||||
-rw-r--r-- | settings.gradle | 1 | ||||
-rw-r--r-- | src/main/ghpages/index.html | 6 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/Argument.java (renamed from src/main/java/org/anarres/cpp/Argument.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/ChrootFileSystem.java (renamed from src/main/java/org/anarres/cpp/ChrootFileSystem.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/CppReader.java (renamed from src/main/java/org/anarres/cpp/CppReader.java) | 10 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/CppTask.java (renamed from src/main/java/org/anarres/cpp/CppTask.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/DefaultPreprocessorListener.java (renamed from src/main/java/org/anarres/cpp/DefaultPreprocessorListener.java) | 22 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/Feature.java (renamed from src/main/java/org/anarres/cpp/Feature.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/FileLexerSource.java (renamed from src/main/java/org/anarres/cpp/FileLexerSource.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/FixedTokenSource.java (renamed from src/main/java/org/anarres/cpp/FixedTokenSource.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/InputLexerSource.java (renamed from src/main/java/org/anarres/cpp/InputLexerSource.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/InternalException.java (renamed from src/main/java/org/anarres/cpp/InternalException.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/JCPP.java | 193 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/JavaFileSystem.java (renamed from src/main/java/org/anarres/cpp/JavaFileSystem.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/JoinReader.java (renamed from src/main/java/org/anarres/cpp/JoinReader.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/LexerException.java (renamed from src/main/java/org/anarres/cpp/LexerException.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/LexerSource.java (renamed from src/main/java/org/anarres/cpp/LexerSource.java) | 6 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/Macro.java (renamed from src/main/java/org/anarres/cpp/Macro.java) | 65 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/MacroTokenSource.java (renamed from src/main/java/org/anarres/cpp/MacroTokenSource.java) | 8 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/NumericValue.java (renamed from src/main/java/org/anarres/cpp/NumericValue.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/Preprocessor.java (renamed from src/main/java/org/anarres/cpp/Preprocessor.java) | 291 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/PreprocessorCommand.java (renamed from src/main/java/org/anarres/cpp/PreprocessorCommand.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/PreprocessorListener.java (renamed from src/main/java/org/anarres/cpp/PreprocessorListener.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/ResourceFileSystem.java (renamed from src/main/java/org/anarres/cpp/ResourceFileSystem.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/Source.java (renamed from src/main/java/org/anarres/cpp/Source.java) | 44 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/SourceIterator.java (renamed from src/main/java/org/anarres/cpp/SourceIterator.java) | 5 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/State.java (renamed from src/main/java/org/anarres/cpp/State.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/StringLexerSource.java (renamed from src/main/java/org/anarres/cpp/StringLexerSource.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/Token.java (renamed from src/main/java/org/anarres/cpp/Token.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/TokenSnifferSource.java (renamed from src/main/java/org/anarres/cpp/TokenSnifferSource.java) | 5 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/TokenType.java (renamed from src/main/java/org/anarres/cpp/TokenType.java) | 6 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/VirtualFile.java (renamed from src/main/java/org/anarres/cpp/VirtualFile.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/VirtualFileSystem.java (renamed from src/main/java/org/anarres/cpp/VirtualFileSystem.java) | 2 | ||||
-rw-r--r-- | src/main/java/com/jogamp/gluegen/jcpp/Warning.java (renamed from src/main/java/org/anarres/cpp/Warning.java) | 2 | ||||
-rw-r--r-- | src/main/java/org/anarres/cpp/BuildMetadata.java | 72 | ||||
-rw-r--r-- | src/main/java/org/anarres/cpp/Main.java | 195 | ||||
-rw-r--r-- | src/main/velocity/org/anarres/cpp/Version.java | 83 | ||||
-rwxr-xr-x | src/scripts/jcpp | 32 | ||||
-rw-r--r-- | src/scripts/release.sh | 5 | ||||
-rw-r--r-- | src/test/java/com/jogamp/gluegen/jcpp/CppReaderTest.java (renamed from src/test/java/org/anarres/cpp/CppReaderTest.java) | 36 | ||||
-rw-r--r-- | src/test/java/com/jogamp/gluegen/jcpp/ErrorTest.java (renamed from src/test/java/org/anarres/cpp/ErrorTest.java) | 21 | ||||
-rw-r--r-- | src/test/java/com/jogamp/gluegen/jcpp/IncludeAbsoluteTest.java | 55 | ||||
-rw-r--r-- | src/test/java/com/jogamp/gluegen/jcpp/JavaFileSystemTest.java (renamed from src/test/java/org/anarres/cpp/JavaFileSystemTest.java) | 17 | ||||
-rw-r--r-- | src/test/java/com/jogamp/gluegen/jcpp/JoinReaderTest.java (renamed from src/test/java/org/anarres/cpp/JoinReaderTest.java) | 21 | ||||
-rw-r--r-- | src/test/java/com/jogamp/gluegen/jcpp/LexerSourceTest.java (renamed from src/test/java/org/anarres/cpp/LexerSourceTest.java) | 31 | ||||
-rw-r--r-- | src/test/java/com/jogamp/gluegen/jcpp/NumericValueTest.java (renamed from src/test/java/org/anarres/cpp/NumericValueTest.java) | 29 | ||||
-rw-r--r-- | src/test/java/com/jogamp/gluegen/jcpp/PreprocessorTest.java (renamed from src/test/java/org/anarres/cpp/PreprocessorTest.java) | 183 | ||||
-rw-r--r-- | src/test/java/com/jogamp/gluegen/jcpp/TokenPastingWhitespaceTest.java | 59 | ||||
-rw-r--r-- | src/test/java/org/anarres/cpp/BuildMetadataTest.java | 33 | ||||
-rw-r--r-- | src/test/java/org/anarres/cpp/IncludeAbsoluteTest.java | 35 | ||||
-rw-r--r-- | src/test/java/org/anarres/cpp/MainTest.java | 11 | ||||
-rw-r--r-- | src/test/java/org/anarres/cpp/PragmaTest.java | 39 | ||||
-rw-r--r-- | src/test/java/org/anarres/cpp/RegressionTest.java | 70 | ||||
-rw-r--r-- | src/test/java/org/anarres/cpp/TokenPastingWhitespaceTest.java | 43 | ||||
-rw-r--r-- | src/test/java/org/anarres/cpp/VaArgsPastingTest.java | 63 |
65 files changed, 870 insertions, 1499 deletions
@@ -14,7 +14,18 @@ This project has has been used to successfully preprocess much of the source code of the GNU C library. As of version 1.2.5, it can also preprocess the Apple Objective C library. +# JogAmp Branch + +This branch is modified for JogAmp +to supply [GlueGen](http://jogamp.org/gluegen/www/) with JCPP. + +This branch is only intended as a submodule for GlueGen +and hence must be [build from within GlueGen](http://jogamp.org/gluegen/doc/HowToBuild.html). + +# Original JCPP Version +* [Homepage](http://www.anarres.org/projects/jcpp/) +* [GitHub](https://github.com/shevek/jcpp.git) + # Documentation -* [JavaDoc API](http://shevek.github.io/jcpp/docs/javadoc/) -* [Coverage Report](http://shevek.github.io/jcpp/docs/cobertura/) +* [JavaDoc API](http://jogamp.org/deployment/jogamp-next/javadoc/gluegen/javadoc/) diff --git a/build.gradle b/build.gradle deleted file mode 100644 index fa3acf2..0000000 --- a/build.gradle +++ /dev/null @@ -1,53 +0,0 @@ -buildscript { - repositories { - // mavenLocal() - mavenCentral() - jcenter() - // maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' } - } - - dependencies { - classpath 'org.anarres.gradle:gradle-stdproject-plugin:1.0.9' - } -} - -apply plugin: 'org.anarres.stdproject' -stdproject { - javadocLinkSource = true; -} - - group = "org.anarres" - - apply plugin: 'org.anarres.stdmodule' - stdmodule { - description "An embeddable C Preprocessor for the JVM." - author id: 'shevek', name: 'Shevek', email: '[email protected]' - license 'Apache-2.0' - } - - sourceCompatibility = 1.5 - -dependencies { - compile 'com.google.code.findbugs:annotations:3.0.1' - compile 'org.slf4j:slf4j-api:1.7.12' - - compile 'net.sf.jopt-simple:jopt-simple:4.7' - compile 'org.apache.ant:ant:1.7.0' - compile 'com.github.zafarkhaja:java-semver:0.8.0' - - testCompile 'com.google.guava:guava:18.0' -} - -// This ensures that the info-plugin's properties file is in the -// same location for the test suite as in the JAR. -task('processTestVersionResources', type: Copy, dependsOn: processTestResources) { - into project.sourceSets.test.output.resourcesDir - from(writeManifestProperties) { - into "META-INF" - } -} -testClasses.dependsOn(processTestVersionResources) - -apply plugin: 'application' - -mainClassName = "org.anarres.cpp.Main" diff --git a/codequality/HEADER b/codequality/HEADER deleted file mode 100644 index 169c3d1..0000000 --- a/codequality/HEADER +++ /dev/null @@ -1,13 +0,0 @@ -Copyright ${year} Shevek. - -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. diff --git a/codequality/checkstyle.xml b/codequality/checkstyle.xml deleted file mode 100644 index 47c01a2..0000000 --- a/codequality/checkstyle.xml +++ /dev/null @@ -1,188 +0,0 @@ -<?xml version="1.0"?> -<!DOCTYPE module PUBLIC - "-//Puppy Crawl//DTD Check Configuration 1.2//EN" - "http://www.puppycrawl.com/dtds/configuration_1_2.dtd"> - -<module name="Checker"> - - <!-- Checks that a package-info.java file exists for each package. --> - <!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage --> - <!-- - <module name="JavadocPackage"> - <property name="allowLegacy" value="true"/> - </module> - --> - - <!-- Checks whether files end with a new line. --> - <!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile --> - <module name="NewlineAtEndOfFile"/> - - <!-- Checks that property files contain the same keys. --> - <!-- See http://checkstyle.sf.net/config_misc.html#Translation --> - <module name="Translation"/> - - <!-- Checks for Size Violations. --> - <!-- See http://checkstyle.sf.net/config_sizes.html --> - <module name="FileLength"/> - - <!-- Checks for whitespace --> - <!-- See http://checkstyle.sf.net/config_whitespace.html --> - <module name="FileTabCharacter"/> - - <!-- Miscellaneous other checks. --> - <!-- See http://checkstyle.sf.net/config_misc.html --> - <module name="RegexpSingleline"> - <property name="format" value="\s+$"/> - <property name="minimum" value="0"/> - <property name="maximum" value="0"/> - <property name="message" value="Line has trailing spaces."/> - <property name="severity" value="info"/> - </module> - - <module name="TreeWalker"> - - <!-- Checks for Javadoc comments. --> - <!-- See http://checkstyle.sf.net/config_javadoc.html --> - <module name="JavadocMethod"> - <property name="scope" value="package"/> - <property name="allowMissingParamTags" value="true"/> - <property name="allowMissingThrowsTags" value="true"/> - <property name="allowMissingReturnTag" value="true"/> - <property name="allowThrowsTagsForSubclasses" value="true"/> - <property name="allowUndeclaredRTE" value="true"/> - <property name="allowMissingPropertyJavadoc" value="true"/> - </module> - <module name="JavadocType"> - <property name="scope" value="package"/> - </module> - <module name="JavadocVariable"> - <property name="scope" value="package"/> - </module> - <module name="JavadocStyle"> - <property name="checkEmptyJavadoc" value="true"/> - </module> - - <!-- Checks for Naming Conventions. --> - <!-- See http://checkstyle.sf.net/config_naming.html --> - <module name="ConstantName"/> - <module name="LocalFinalVariableName"/> - <module name="LocalVariableName"/> - <module name="MemberName"/> - <module name="MethodName"/> - <module name="PackageName"/> - <module name="ParameterName"/> - <module name="StaticVariableName"/> - <module name="TypeName"/> - - <!-- Checks for imports --> - <!-- See http://checkstyle.sf.net/config_import.html --> - <module name="AvoidStarImport"/> - <module name="IllegalImport"/> <!-- defaults to sun.* packages --> - <module name="RedundantImport"/> - <module name="UnusedImports"/> - - - <!-- Checks for Size Violations. --> - <!-- See http://checkstyle.sf.net/config_sizes.html --> - <module name="LineLength"> - <!-- what is a good max value? --> - <property name="max" value="120"/> - <!-- ignore lines like "$File: //depot/... $" --> - <property name="ignorePattern" value="\$File.*\$"/> - <property name="severity" value="info"/> - </module> - <module name="MethodLength"/> - <module name="ParameterNumber"/> - - - <!-- Checks for whitespace --> - <!-- See http://checkstyle.sf.net/config_whitespace.html --> - <module name="EmptyForIteratorPad"/> - <module name="GenericWhitespace"/> - <module name="MethodParamPad"/> - <module name="NoWhitespaceAfter"/> - <module name="NoWhitespaceBefore"/> - <module name="OperatorWrap"/> - <module name="ParenPad"/> - <module name="TypecastParenPad"/> - <module name="WhitespaceAfter"/> - <module name="WhitespaceAround"/> - - <!-- Modifier Checks --> - <!-- See http://checkstyle.sf.net/config_modifiers.html --> - <module name="ModifierOrder"/> - <module name="RedundantModifier"/> - - - <!-- Checks for blocks. You know, those {}'s --> - <!-- See http://checkstyle.sf.net/config_blocks.html --> - <module name="AvoidNestedBlocks"/> - <module name="EmptyBlock"> - <property name="option" value="text"/> - </module> - <module name="LeftCurly"/> - <module name="NeedBraces"/> - <module name="RightCurly"/> - - - <!-- Checks for common coding problems --> - <!-- See http://checkstyle.sf.net/config_coding.html --> - <!-- <module name="AvoidInlineConditionals"/> --> - <module name="EmptyStatement"/> - <module name="EqualsHashCode"/> - <module name="HiddenField"> - <property name="ignoreConstructorParameter" value="true"/> - <property name="ignoreSetter" value="true"/> - <property name="severity" value="warning"/> - </module> - <module name="IllegalInstantiation"/> - <module name="InnerAssignment"/> - <module name="MagicNumber"> - <property name="severity" value="warning"/> - </module> - <module name="MissingSwitchDefault"/> - <!-- Problem with finding exception types... --> - <module name="RedundantThrows"> - <property name="allowUnchecked" value="true"/> - <property name="suppressLoadErrors" value="true"/> - <property name="severity" value="info"/> - </module> - <module name="SimplifyBooleanExpression"/> - <module name="SimplifyBooleanReturn"/> - - <!-- Checks for class design --> - <!-- See http://checkstyle.sf.net/config_design.html --> - <!-- <module name="DesignForExtension"/> --> - <module name="FinalClass"/> - <module name="HideUtilityClassConstructor"/> - <module name="InterfaceIsType"/> - <module name="VisibilityModifier"/> - - - <!-- Miscellaneous other checks. --> - <!-- See http://checkstyle.sf.net/config_misc.html --> - <module name="ArrayTypeStyle"/> - <!-- <module name="FinalParameters"/> --> - <module name="TodoComment"> - <property name="format" value="TODO"/> - <property name="severity" value="info"/> - </module> - <module name="UpperEll"/> - - <module name="FileContentsHolder"/> <!-- Required by comment suppression filters --> - - </module> - - <!-- Enable suppression comments --> - <module name="SuppressionCommentFilter"> - <property name="offCommentFormat" value="CHECKSTYLE IGNORE\s+(\S+)"/> - <property name="onCommentFormat" value="CHECKSTYLE END IGNORE\s+(\S+)"/> - <property name="checkFormat" value="$1"/> - </module> - <module name="SuppressWithNearbyCommentFilter"> - <!-- Syntax is "SUPPRESS CHECKSTYLE name" --> - <property name="commentFormat" value="SUPPRESS CHECKSTYLE (\w+)"/> - <property name="checkFormat" value="$1"/> - <property name="influenceFormat" value="1"/> - </module> -</module> diff --git a/gradle.properties b/gradle.properties deleted file mode 100644 index 125cdbe..0000000 --- a/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -version=1.4.15-SNAPSHOT diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar Binary files differdeleted file mode 100644 index 94336fc..0000000 --- a/gradle/wrapper/gradle-wrapper.jar +++ /dev/null diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 290541c..0000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew deleted file mode 100755 index cccdd3d..0000000 --- a/gradlew +++ /dev/null @@ -1,172 +0,0 @@ -#!/usr/bin/env sh - -############################################################################## -## -## Gradle start up script for UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" - -# Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" - -warn () { - echo "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# OS specific support (must be 'true' or 'false'). -cygwin=false -msys=false -darwin=false -nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; -esac - -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar - -# Determine the Java command to use to start the JVM. -if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - if [ ! -x "$JAVACMD" ] ; then - die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." - fi -else - JAVACMD="java" - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. - -Please set the JAVA_HOME variable in your environment to match the -location of your Java installation." -fi - -# Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=$((i+1)) - done - case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=$(save "$@") - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - -exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat deleted file mode 100644 index e95643d..0000000 --- a/gradlew.bat +++ /dev/null @@ -1,84 +0,0 @@ -@if "%DEBUG%" == "" @echo off
-@rem ##########################################################################
-@rem
-@rem Gradle startup script for Windows
-@rem
-@rem ##########################################################################
-
-@rem Set local scope for the variables with windows NT shell
-if "%OS%"=="Windows_NT" setlocal
-
-set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
-set APP_BASE_NAME=%~n0
-set APP_HOME=%DIRNAME%
-
-@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-set DEFAULT_JVM_OPTS=
-
-@rem Find java.exe
-if defined JAVA_HOME goto findJavaFromJavaHome
-
-set JAVA_EXE=java.exe
-%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto init
-
-echo.
-echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:findJavaFromJavaHome
-set JAVA_HOME=%JAVA_HOME:"=%
-set JAVA_EXE=%JAVA_HOME%/bin/java.exe
-
-if exist "%JAVA_EXE%" goto init
-
-echo.
-echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
-echo.
-echo Please set the JAVA_HOME variable in your environment to match the
-echo location of your Java installation.
-
-goto fail
-
-:init
-@rem Get command-line arguments, handling Windows variants
-
-if not "%OS%" == "Windows_NT" goto win9xME_args
-
-:win9xME_args
-@rem Slurp the command line arguments.
-set CMD_LINE_ARGS=
-set _SKIP=2
-
-:win9xME_args_slurp
-if "x%~1" == "x" goto execute
-
-set CMD_LINE_ARGS=%*
-
-:execute
-@rem Setup the command line
-
-set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
-
-@rem Execute Gradle
-"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
-
-:end
-@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
-
-:fail
-rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
-rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
-
-:mainEnd
-if "%OS%"=="Windows_NT" endlocal
-
-:omega
diff --git a/install b/install deleted file mode 120000 index a40f9f7..0000000 --- a/install +++ /dev/null @@ -1 +0,0 @@ -build/install/jcpp/
\ No newline at end of file diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index f22856c..0000000 --- a/settings.gradle +++ /dev/null @@ -1 +0,0 @@ -rootProject.name='jcpp' diff --git a/src/main/ghpages/index.html b/src/main/ghpages/index.html deleted file mode 100644 index 32292c3..0000000 --- a/src/main/ghpages/index.html +++ /dev/null @@ -1,6 +0,0 @@ -<html> -<body> -<a href="docs/javadoc/">Javadoc</a> -<a href="docs/cobertura/">Coverage</a> -</body> -</html> diff --git a/src/main/java/org/anarres/cpp/Argument.java b/src/main/java/com/jogamp/gluegen/jcpp/Argument.java index 1dd547d..da66fc3 100644 --- a/src/main/java/org/anarres/cpp/Argument.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/Argument.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.IOException; import java.util.ArrayList; diff --git a/src/main/java/org/anarres/cpp/ChrootFileSystem.java b/src/main/java/com/jogamp/gluegen/jcpp/ChrootFileSystem.java index 5abf2f8..6baefa6 100644 --- a/src/main/java/org/anarres/cpp/ChrootFileSystem.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/ChrootFileSystem.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.File; import java.io.IOException; diff --git a/src/main/java/org/anarres/cpp/CppReader.java b/src/main/java/com/jogamp/gluegen/jcpp/CppReader.java index 6ceeb8d..367194c 100644 --- a/src/main/java/org/anarres/cpp/CppReader.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/CppReader.java @@ -14,15 +14,17 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.Closeable; import java.io.IOException; import java.io.Reader; + import javax.annotation.Nonnull; -import static org.anarres.cpp.Token.CCOMMENT; -import static org.anarres.cpp.Token.CPPCOMMENT; -import static org.anarres.cpp.Token.EOF; + +import static com.jogamp.gluegen.jcpp.Token.CCOMMENT; +import static com.jogamp.gluegen.jcpp.Token.CPPCOMMENT; +import static com.jogamp.gluegen.jcpp.Token.EOF; /** * A Reader wrapper around the Preprocessor. diff --git a/src/main/java/org/anarres/cpp/CppTask.java b/src/main/java/com/jogamp/gluegen/jcpp/CppTask.java index cc9c4d3..da311f9 100644 --- a/src/main/java/org/anarres/cpp/CppTask.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/CppTask.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.File; import java.io.FileWriter; diff --git a/src/main/java/org/anarres/cpp/DefaultPreprocessorListener.java b/src/main/java/com/jogamp/gluegen/jcpp/DefaultPreprocessorListener.java index e8e850e..a3f3dd5 100644 --- a/src/main/java/org/anarres/cpp/DefaultPreprocessorListener.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/DefaultPreprocessorListener.java @@ -1,4 +1,4 @@ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; /* * Anarres C Preprocessor @@ -18,8 +18,9 @@ package org.anarres.cpp; */ import javax.annotation.Nonnegative; import javax.annotation.Nonnull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import com.jogamp.gluegen.Logging; +import com.jogamp.gluegen.Logging.LoggerIf; /** * A handler for preprocessor events, primarily errors and warnings. @@ -30,12 +31,13 @@ import org.slf4j.LoggerFactory; */ public class DefaultPreprocessorListener implements PreprocessorListener { - private static final Logger LOG = LoggerFactory.getLogger(DefaultPreprocessorListener.class); + private final LoggerIf LOG; private int errors; private int warnings; public DefaultPreprocessorListener() { + LOG = Logging.getLogger(DefaultPreprocessorListener.class); clear(); } @@ -54,7 +56,7 @@ public class DefaultPreprocessorListener implements PreprocessorListener { return warnings; } - protected void print(@Nonnull String msg) { + protected void print(@Nonnull final String msg) { LOG.info(msg); } @@ -66,8 +68,8 @@ public class DefaultPreprocessorListener implements PreprocessorListener { * it may throw an exception. */ @Override - public void handleWarning(Source source, int line, int column, - String msg) + public void handleWarning(final Source source, final int line, final int column, + final String msg) throws LexerException { warnings++; print(source.getName() + ":" + line + ":" + column @@ -82,8 +84,8 @@ public class DefaultPreprocessorListener implements PreprocessorListener { * it may throw an exception. */ @Override - public void handleError(Source source, int line, int column, - String msg) + public void handleError(final Source source, final int line, final int column, + final String msg) throws LexerException { errors++; print(source.getName() + ":" + line + ":" + column @@ -91,7 +93,7 @@ public class DefaultPreprocessorListener implements PreprocessorListener { } @Override - public void handleSourceChange(Source source, SourceChangeEvent event) { + public void handleSourceChange(final Source source, final SourceChangeEvent event) { } } diff --git a/src/main/java/org/anarres/cpp/Feature.java b/src/main/java/com/jogamp/gluegen/jcpp/Feature.java index a514269..86202fc 100644 --- a/src/main/java/org/anarres/cpp/Feature.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/Feature.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; /** * Features of the Preprocessor, which may be enabled or disabled. diff --git a/src/main/java/org/anarres/cpp/FileLexerSource.java b/src/main/java/com/jogamp/gluegen/jcpp/FileLexerSource.java index 7dc883a..01fdbd1 100644 --- a/src/main/java/org/anarres/cpp/FileLexerSource.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/FileLexerSource.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.BufferedReader; import java.io.File; diff --git a/src/main/java/org/anarres/cpp/FixedTokenSource.java b/src/main/java/com/jogamp/gluegen/jcpp/FixedTokenSource.java index fdfd328..b954bda 100644 --- a/src/main/java/org/anarres/cpp/FixedTokenSource.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/FixedTokenSource.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.IOException; import java.util.Arrays; diff --git a/src/main/java/org/anarres/cpp/InputLexerSource.java b/src/main/java/com/jogamp/gluegen/jcpp/InputLexerSource.java index 8064a9a..f4bd640 100644 --- a/src/main/java/org/anarres/cpp/InputLexerSource.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/InputLexerSource.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.InputStream; import java.io.InputStreamReader; diff --git a/src/main/java/org/anarres/cpp/InternalException.java b/src/main/java/com/jogamp/gluegen/jcpp/InternalException.java index e3a7a6e..c404a62 100644 --- a/src/main/java/org/anarres/cpp/InternalException.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/InternalException.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; /** * An internal exception. diff --git a/src/main/java/com/jogamp/gluegen/jcpp/JCPP.java b/src/main/java/com/jogamp/gluegen/jcpp/JCPP.java new file mode 100644 index 0000000..3f1e057 --- /dev/null +++ b/src/main/java/com/jogamp/gluegen/jcpp/JCPP.java @@ -0,0 +1,193 @@ +/** + * Copyright 2015 JogAmp Community. All rights reserved. + * + * 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. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of JogAmp Community. + */ +package com.jogamp.gluegen.jcpp; + +import java.io.File; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.Reader; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; + +import com.jogamp.gluegen.ASTLocusTag; +import com.jogamp.gluegen.ConstantDefinition; +import com.jogamp.gluegen.GenericCPP; +import com.jogamp.gluegen.GlueGen; +import com.jogamp.gluegen.GlueGenException; +import com.jogamp.gluegen.Logging; +import com.jogamp.gluegen.Logging.LoggerIf; + +public class JCPP implements GenericCPP { + private final LoggerIf LOG; + + public final Preprocessor cpp; + private OutputStream out; + private final List<String> includePaths; + private final boolean enableCopyOutput2Stderr; + + public JCPP(final List<String> includePaths, final boolean debug, final boolean copyOutput2Stderr, + final boolean enablePragmaOnce) { + LOG = Logging.getLogger(JCPP.class); + setOut(System.out); + this.includePaths = includePaths; + this.enableCopyOutput2Stderr = copyOutput2Stderr; + + cpp = new Preprocessor(); + cpp.addFeature(Feature.DIGRAPHS); + cpp.addFeature(Feature.TRIGRAPHS); + cpp.addFeature(Feature.LINEMARKERS); + cpp.addFeature(Feature.CSYNTAX); + cpp.addFeature(Feature.KEEPCOMMENTS); + if (enablePragmaOnce) { + cpp.addFeature(Feature.PRAGMA_ONCE); + } + cpp.addWarning(Warning.IMPORT); + cpp.setListener(new DefaultPreprocessorListener() { + @Override + public void handleError(final Source source, final int line, final int column, + final String msg) throws LexerException { + super.handleError(source, line, column, msg); + throw new GlueGenException(msg, new ASTLocusTag(source.getPath(), line, column, null)); + } + }); + if (debug) { + cpp.addFeature(Feature.DEBUG); + } + cpp.setSystemIncludePath(includePaths); + cpp.setQuoteIncludePath(includePaths); + + if (cpp.getFeature(Feature.DEBUG)) { + LOG.info("#" + "include \"...\" search starts here:"); + for (final String dir : cpp.getQuoteIncludePath()) + LOG.info(" " + dir); + LOG.info("#" + "include <...> search starts here:"); + for (final String dir : cpp.getSystemIncludePath()) + LOG.info(" " + dir); + LOG.info("End of search list."); + } + } + + @Override + public void addDefine(final String name, final String value) throws LexerException { + cpp.addMacro(name, value); + } + + @Override + public List<ConstantDefinition> getConstantDefinitions() throws GlueGenException { + final List<ConstantDefinition> constants = new ArrayList<ConstantDefinition>(); + final List<Macro> macros; + try { + macros = cpp.getMacros(true); + } catch (final Throwable t) { + throw new GlueGenException(t); + } + final int count = macros.size(); + for(int i=0; i<count; i++) { + final Macro macro = macros.get(i); + final String name = macro.getName(); + if( !GlueGen.__GLUEGEN__.equals(name) ) { + if( !macro.isFunctionLike() ) { + final String value = macro.getText(); + if ( ConstantDefinition.isConstantExpression(value) ) { + final Source source = macro.getSource(); + final ASTLocusTag locus = new ASTLocusTag( + null != source ? source.getPath() : "<programmatic>", + null != source ? source.getLine() : -1, + null != source ? source.getColumn() : -1, + macro.toString()); + final ConstantDefinition c = new ConstantDefinition(macro.getName(), value, null, locus); + constants.add(c); + } + } + } + } + return constants; + } + + @Override + public String findFile(final String filename) { + final String sep = File.separator; + for (final String inclPath : includePaths) { + final String fullPath = inclPath + sep + filename; + final File file = new File(fullPath); + if (file.exists()) { + return fullPath; + } + } + return null; + } + + @Override + public OutputStream out() { + return out; + } + @Override + public void setOut(final OutputStream out) { + this.out = out; + } + + @Override + public void run(final Reader reader, final String filename) throws GlueGenException { + final PrintWriter writer = new PrintWriter(out); + cpp.addInput(new LexerSource(reader, true) { + @Override + public String getPath() { return filename; } + @Override + public String getName() { return filename; } + @Override + public String toString() { return "file " + filename; } + } ); + try { + for (;;) { + final Token tok = cpp.token(); + if (tok == null) + break; + if (tok.getType() == Token.EOF) + break; + final String s = tok.getText(); + writer.print(s); + if (enableCopyOutput2Stderr) { + System.err.print(s); + System.err.flush(); + } + } + writer.flush(); + } catch (final Exception e) { + final StringBuilder buf = new StringBuilder("Preprocessor failed:\n"); + Source s = cpp.getSource(); + while (s != null) { + buf.append(" -> ").append(s).append("\n"); + s = s.getParent(); + } + buf.append(" : {0}\n"); + LOG.log(Level.SEVERE, buf.toString(), e); + if( e instanceof GlueGenException ) { + throw (GlueGenException)e; + } else { + throw new GlueGenException("Preprocessor failed", + new ASTLocusTag(null != s ? s.getPath() : "n/a", + null != s ? s.getLine() : -1, + null != s ? s.getColumn() : -1, null), e); + } + } + } + +} diff --git a/src/main/java/org/anarres/cpp/JavaFileSystem.java b/src/main/java/com/jogamp/gluegen/jcpp/JavaFileSystem.java index 39ae72c..a7acd36 100644 --- a/src/main/java/org/anarres/cpp/JavaFileSystem.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/JavaFileSystem.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.File; import java.io.IOException; diff --git a/src/main/java/org/anarres/cpp/JoinReader.java b/src/main/java/com/jogamp/gluegen/jcpp/JoinReader.java index 5ce08ea..e2bba26 100644 --- a/src/main/java/org/anarres/cpp/JoinReader.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/JoinReader.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.Closeable; import java.io.IOException; diff --git a/src/main/java/org/anarres/cpp/LexerException.java b/src/main/java/com/jogamp/gluegen/jcpp/LexerException.java index b5a1800..f590b92 100644 --- a/src/main/java/org/anarres/cpp/LexerException.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/LexerException.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; /** * A preprocessor exception. diff --git a/src/main/java/org/anarres/cpp/LexerSource.java b/src/main/java/com/jogamp/gluegen/jcpp/LexerSource.java index c613f96..29c231b 100644 --- a/src/main/java/org/anarres/cpp/LexerSource.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/LexerSource.java @@ -14,13 +14,15 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.BufferedReader; import java.io.IOException; import java.io.Reader; + import javax.annotation.Nonnull; -import static org.anarres.cpp.Token.*; + +import static com.jogamp.gluegen.jcpp.Token.*; /** Does not handle digraphs. */ public class LexerSource extends Source { diff --git a/src/main/java/org/anarres/cpp/Macro.java b/src/main/java/com/jogamp/gluegen/jcpp/Macro.java index 62b0532..765d37a 100644 --- a/src/main/java/org/anarres/cpp/Macro.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/Macro.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.util.ArrayList; import java.util.Iterator; @@ -29,33 +29,50 @@ import java.util.List; */ public class Macro { - private Source source; - private String name; + private final Source source; + private final String name; /* It's an explicit decision to keep these around here. We don't * need to; the argument token type is M_ARG and the value * is the index. The strings themselves are only used in * stringification of the macro, for debugging. */ private List<String> args; private boolean variadic; + private boolean hasPaste; private List<Token> tokens; - public Macro(Source source, String name) { + public Macro(final Source source, final String name) { this.source = source; this.name = name; this.args = null; this.variadic = false; + this.hasPaste = false; this.tokens = new ArrayList<Token>(); } - - public Macro(String name) { - this(null, name); + public Macro(final Macro o) { + this(o, o.tokens, true); + } + public Macro(final Macro o, final List<Token> tokens) { + this(o, tokens, false); + } + private Macro(final Macro o, final List<Token> tokens, final boolean copyTokens) { + this.source = o.source; + this.name = o.name; + if(null != o.args) { + this.args = new ArrayList<String>(o.args); + } else { + this.args = null; + } + this.variadic = o.variadic; + this.hasPaste = o.hasPaste; + if(null != tokens) { + this.tokens = copyTokens ? new ArrayList<Token>(tokens) : tokens; + } else { + this.tokens = new ArrayList<Token>(); + } } - /** - * Sets the Source from which this macro was parsed. - */ - public void setSource(Source s) { - this.source = s; + public Macro(final String name) { + this(null, name); } /** @@ -78,7 +95,7 @@ public class Macro { /** * Sets the arguments to this macro. */ - public void setArgs(List<String> args) { + /* pp */ void setArgs(final List<String> args) { this.args = args; } @@ -99,7 +116,7 @@ public class Macro { /** * Sets the variadic flag on this Macro. */ - public void setVariadic(boolean b) { + public void setVariadic(final boolean b) { this.variadic = b; } @@ -111,9 +128,16 @@ public class Macro { } /** + * Returns true if this macro contains a "paste" operator. + */ + public boolean hasPaste() { + return hasPaste; + } + + /** * Adds a token to the expansion of this macro. */ - public void addToken(Token tok) { + public void addToken(final Token tok) { this.tokens.add(tok); } @@ -124,7 +148,7 @@ public class Macro { * to the previous token when the macro is expanded. * It is an error for a macro to end with a paste token. */ - public void addPaste(Token tok) { + public void addPaste(final Token tok) { /* * Given: tok0 ## tok1 * We generate: M_PASTE, tok0, tok1 @@ -133,6 +157,7 @@ public class Macro { * M_PASTE, tok0, M_PASTE, tok1, tok2 */ this.tokens.add(tokens.size() - 1, tok); + this.hasPaste = true; } /* pp */ List<Token> getTokens() { @@ -144,9 +169,9 @@ public class Macro { * swaps them around again. We know that there will never be two * sequential paste tokens, so a boolean is sufficient. */ public String getText() { - StringBuilder buf = new StringBuilder(); + final StringBuilder buf = new StringBuilder(); boolean paste = false; - for (Token tok : tokens) { + for (final Token tok : tokens) { if (tok.getType() == Token.M_PASTE) { assert paste == false : "Two sequential pastes."; paste = true; @@ -165,10 +190,10 @@ public class Macro { @Override public String toString() { - StringBuilder buf = new StringBuilder(name); + final StringBuilder buf = new StringBuilder(name); if (args != null) { buf.append('('); - Iterator<String> it = args.iterator(); + final Iterator<String> it = args.iterator(); while (it.hasNext()) { buf.append(it.next()); if (it.hasNext()) diff --git a/src/main/java/org/anarres/cpp/MacroTokenSource.java b/src/main/java/com/jogamp/gluegen/jcpp/MacroTokenSource.java index 6423743..18839c1 100644 --- a/src/main/java/org/anarres/cpp/MacroTokenSource.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/MacroTokenSource.java @@ -14,16 +14,16 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.IOException; import java.util.Iterator; import java.util.List; + import javax.annotation.Nonnegative; import javax.annotation.Nonnull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import static org.anarres.cpp.Token.*; + +import static com.jogamp.gluegen.jcpp.Token.*; /* This source should always be active, since we don't expand macros * in any inactive context. */ diff --git a/src/main/java/org/anarres/cpp/NumericValue.java b/src/main/java/com/jogamp/gluegen/jcpp/NumericValue.java index b51ca59..7707c09 100644 --- a/src/main/java/org/anarres/cpp/NumericValue.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/NumericValue.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.math.BigDecimal; import java.math.BigInteger; diff --git a/src/main/java/org/anarres/cpp/Preprocessor.java b/src/main/java/com/jogamp/gluegen/jcpp/Preprocessor.java index 5b07824..3427467 100644 --- a/src/main/java/org/anarres/cpp/Preprocessor.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/Preprocessor.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.Closeable; import java.io.File; @@ -31,13 +31,16 @@ import java.util.Map; import java.util.Set; import java.util.Stack; import java.util.TreeMap; + import javax.annotation.CheckForNull; import javax.annotation.Nonnull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import static org.anarres.cpp.PreprocessorCommand.*; -import org.anarres.cpp.PreprocessorListener.SourceChangeEvent; -import static org.anarres.cpp.Token.*; + +import static com.jogamp.gluegen.jcpp.PreprocessorCommand.*; +import static com.jogamp.gluegen.jcpp.Token.*; + +import com.jogamp.gluegen.Logging; +import com.jogamp.gluegen.Logging.LoggerIf; +import com.jogamp.gluegen.jcpp.PreprocessorListener.SourceChangeEvent; /** * A C Preprocessor. @@ -76,7 +79,7 @@ import static org.anarres.cpp.Token.*; */ public class Preprocessor implements Closeable { - private static final Logger LOG = LoggerFactory.getLogger(Preprocessor.class); + private final LoggerIf LOG; private static final Source INTERNAL = new Source() { @Override @@ -124,6 +127,7 @@ public class Preprocessor implements Closeable { private PreprocessorListener listener; public Preprocessor() { + LOG = Logging.getLogger(Preprocessor.class); this.inputs = new ArrayList<Source>(); this.macros = new HashMap<String, Macro>(); @@ -145,7 +149,7 @@ public class Preprocessor implements Closeable { this.listener = null; } - public Preprocessor(@Nonnull Source initial) { + public Preprocessor(@Nonnull final Source initial) { this(); addInput(initial); } @@ -153,7 +157,7 @@ public class Preprocessor implements Closeable { /** Equivalent to * 'new Preprocessor(new {@link FileLexerSource}(file))' */ - public Preprocessor(@Nonnull File file) + public Preprocessor(@Nonnull final File file) throws IOException { this(new FileLexerSource(file)); } @@ -161,7 +165,7 @@ public class Preprocessor implements Closeable { /** * Sets the VirtualFileSystem used by this Preprocessor. */ - public void setFileSystem(@Nonnull VirtualFileSystem filesystem) { + public void setFileSystem(@Nonnull final VirtualFileSystem filesystem) { this.filesystem = filesystem; } @@ -180,7 +184,7 @@ public class Preprocessor implements Closeable { * The listener is notified of warnings, errors and source * changes, amongst other things. */ - public void setListener(@Nonnull PreprocessorListener listener) { + public void setListener(@Nonnull final PreprocessorListener listener) { this.listener = listener; Source s = source; while (s != null) { @@ -212,21 +216,21 @@ public class Preprocessor implements Closeable { /** * Adds a feature to the feature-set of this Preprocessor. */ - public void addFeature(@Nonnull Feature f) { + public void addFeature(@Nonnull final Feature f) { features.add(f); } /** * Adds features to the feature-set of this Preprocessor. */ - public void addFeatures(@Nonnull Collection<Feature> f) { + public void addFeatures(@Nonnull final Collection<Feature> f) { features.addAll(f); } /** * Adds features to the feature-set of this Preprocessor. */ - public void addFeatures(Feature... f) { + public void addFeatures(final Feature... f) { addFeatures(Arrays.asList(f)); } @@ -234,7 +238,7 @@ public class Preprocessor implements Closeable { * Returns true if the given feature is in * the feature-set of this Preprocessor. */ - public boolean getFeature(@Nonnull Feature f) { + public boolean getFeature(@Nonnull final Feature f) { return features.contains(f); } @@ -251,14 +255,14 @@ public class Preprocessor implements Closeable { /** * Adds a warning to the warning-set of this Preprocessor. */ - public void addWarning(@Nonnull Warning w) { + public void addWarning(@Nonnull final Warning w) { warnings.add(w); } /** * Adds warnings to the warning-set of this Preprocessor. */ - public void addWarnings(@Nonnull Collection<Warning> w) { + public void addWarnings(@Nonnull final Collection<Warning> w) { warnings.addAll(w); } @@ -266,7 +270,7 @@ public class Preprocessor implements Closeable { * Returns true if the given warning is in * the warning-set of this Preprocessor. */ - public boolean getWarning(@Nonnull Warning w) { + public boolean getWarning(@Nonnull final Warning w) { return warnings.contains(w); } @@ -275,7 +279,7 @@ public class Preprocessor implements Closeable { * * Inputs are processed in the order in which they are added. */ - public void addInput(@Nonnull Source source) { + public void addInput(@Nonnull final Source source) { source.init(this); inputs.add(source); } @@ -285,7 +289,7 @@ public class Preprocessor implements Closeable { * * @see #addInput(Source) */ - public void addInput(@Nonnull File file) + public void addInput(@Nonnull final File file) throws IOException { addInput(new FileLexerSource(file)); } @@ -296,7 +300,7 @@ public class Preprocessor implements Closeable { * If a PreprocessorListener is installed, it receives the * error. Otherwise, an exception is thrown. */ - protected void error(int line, int column, @Nonnull String msg) + protected void error(final int line, final int column, @Nonnull final String msg) throws LexerException { if (listener != null) listener.handleError(source, line, column, msg); @@ -312,7 +316,7 @@ public class Preprocessor implements Closeable { * * @see #error(int, int, String) */ - protected void error(@Nonnull Token tok, @Nonnull String msg) + protected void error(@Nonnull final Token tok, @Nonnull final String msg) throws LexerException { error(tok.getLine(), tok.getColumn(), msg); } @@ -323,7 +327,7 @@ public class Preprocessor implements Closeable { * If a PreprocessorListener is installed, it receives the * warning. Otherwise, an exception is thrown. */ - protected void warning(int line, int column, @Nonnull String msg) + protected void warning(final int line, final int column, @Nonnull final String msg) throws LexerException { if (warnings.contains(Warning.ERROR)) error(line, column, msg); @@ -341,7 +345,7 @@ public class Preprocessor implements Closeable { * * @see #warning(int, int, String) */ - protected void warning(@Nonnull Token tok, @Nonnull String msg) + protected void warning(@Nonnull final Token tok, @Nonnull final String msg) throws LexerException { warning(tok.getLine(), tok.getColumn(), msg); } @@ -354,12 +358,13 @@ public class Preprocessor implements Closeable { * * @throws LexerException if the definition fails or is otherwise illegal. */ - public void addMacro(@Nonnull Macro m) throws LexerException { + public void addMacro(@Nonnull final Macro m) throws LexerException, IOException { // System.out.println("Macro " + m); - String name = m.getName(); + final String name = m.getName(); /* Already handled as a source error in macro(). */ - if ("defined".equals(name)) + if ("defined".equals(name)) { throw new LexerException("Cannot redefine name 'defined'"); + } macros.put(m.getName(), m); } @@ -371,19 +376,23 @@ public class Preprocessor implements Closeable { * * @throws LexerException if the definition fails or is otherwise illegal. */ - public void addMacro(@Nonnull String name, @Nonnull String value) + public void addMacro(@Nonnull final String name, @Nonnull final String value) throws LexerException { try { - Macro m = new Macro(name); - StringLexerSource s = new StringLexerSource(value); - for (;;) { - Token tok = s.token(); - if (tok.getType() == EOF) - break; - m.addToken(tok); + final Macro m = new Macro(name); + final StringLexerSource s = new StringLexerSource(value); + try { + for (;;) { + final Token tok = s.token(); + if (tok.getType() == EOF) + break; + m.addToken(tok); + } + } finally { + s.close(); } addMacro(m); - } catch (IOException e) { + } catch (final IOException e) { throw new LexerException(e); } } @@ -396,7 +405,7 @@ public class Preprocessor implements Closeable { * * @throws LexerException if the definition fails or is otherwise illegal. */ - public void addMacro(@Nonnull String name) + public void addMacro(@Nonnull final String name) throws LexerException { addMacro(name, "1"); } @@ -405,7 +414,7 @@ public class Preprocessor implements Closeable { * Sets the user include path used by this Preprocessor. */ /* Note for future: Create an IncludeHandler? */ - public void setQuoteIncludePath(@Nonnull List<String> path) { + public void setQuoteIncludePath(@Nonnull final List<String> path) { this.quoteincludepath = path; } @@ -423,7 +432,7 @@ public class Preprocessor implements Closeable { * Sets the system include path used by this Preprocessor. */ /* Note for future: Create an IncludeHandler? */ - public void setSystemIncludePath(@Nonnull List<String> path) { + public void setSystemIncludePath(@Nonnull final List<String> path) { this.sysincludepath = path; } @@ -441,7 +450,7 @@ public class Preprocessor implements Closeable { * Sets the Objective-C frameworks path used by this Preprocessor. */ /* Note for future: Create an IncludeHandler? */ - public void setFrameworksPath(@Nonnull List<String> path) { + public void setFrameworksPath(@Nonnull final List<String> path) { this.frameworkspath = path; } @@ -468,6 +477,29 @@ public class Preprocessor implements Closeable { } /** + * Returns a list of {@link Macro}s. + * <p> + * Implementation returns a new list of copy-ctor {@link Macro}s. + * </p> + * @param expand if {@code true} and if macro is not {@link Macro#isFunctionLike() function-like}, + * i.e. a constant, the returned macro will be expanded. + * @throws IOException + * @throws LexerException + */ + public List<Macro> getMacros(final boolean expand) throws IOException, LexerException { + final List<Macro> res = new ArrayList<Macro>(); + final Collection<Macro> macroList = macros.values(); + for(final Macro m : macroList) { + if( expand && !m.isFunctionLike() ) { + res.add( new Macro( m, expand( m.getTokens() ) ) ); + } else { + res.add( new Macro( m ) ); + } + } + return res; + } + + /** * Returns the named macro. * * While you can modify the returned object, unexpected things @@ -494,13 +526,13 @@ public class Preprocessor implements Closeable { /* States */ private void push_state() { - State top = states.peek(); + final State top = states.peek(); states.push(new State(top)); } private void pop_state() throws LexerException { - State s = states.pop(); + final State s = states.pop(); if (states.isEmpty()) { error(0, 0, "#" + "endif without #" + "if"); states.push(s); @@ -508,7 +540,7 @@ public class Preprocessor implements Closeable { } private boolean isActive() { - State state = states.peek(); + final State state = states.peek(); return state.isParentActive() && state.isActive(); } @@ -524,7 +556,7 @@ public class Preprocessor implements Closeable { * @return the top Source on the input stack. */ // @CheckForNull - protected Source getSource() { + public Source getSource() { return source; } @@ -536,7 +568,7 @@ public class Preprocessor implements Closeable { * @see #getSource() * @see #pop_source() */ - protected void push_source(@Nonnull Source source, boolean autopop) { + protected void push_source(@Nonnull final Source source, final boolean autopop) { source.init(this); source.setParent(this.source, autopop); // source.setListener(listener); @@ -557,18 +589,18 @@ public class Preprocessor implements Closeable { * @throws IOException if an I/O error occurs. */ @CheckForNull - protected Token pop_source(boolean linemarker) + protected Token pop_source(final boolean linemarker) throws IOException { if (listener != null) listener.handleSourceChange(this.source, SourceChangeEvent.POP); - Source s = this.source; + final Source s = this.source; this.source = s.getParent(); /* Always a noop unless called externally. */ s.close(); if (listener != null && this.source != null) listener.handleSourceChange(this.source, SourceChangeEvent.RESUME); - Source t = getSource(); + final Source t = getSource(); if (getFeature(Feature.LINEMARKERS) && s.isNumbered() && t != null) { @@ -590,7 +622,7 @@ public class Preprocessor implements Closeable { private Token next_source() { if (inputs.isEmpty()) return new Token(EOF); - Source s = inputs.remove(0); + final Source s = inputs.remove(0); push_source(s, true); return line_token(s.getLine(), s.getName(), " 1"); } @@ -601,8 +633,8 @@ public class Preprocessor implements Closeable { /* XXX Make this include the NL, and make all cpp directives eat * their own NL. */ @Nonnull - private Token line_token(int line, @CheckForNull String name, @Nonnull String extra) { - StringBuilder buf = new StringBuilder(); + private Token line_token(final int line, @CheckForNull final String name, @Nonnull final String extra) { + final StringBuilder buf = new StringBuilder(); buf.append("#line ").append(line) .append(" \""); /* XXX This call to escape(name) is correct but ugly. */ @@ -619,7 +651,7 @@ public class Preprocessor implements Closeable { throws IOException, LexerException { if (source_token != null) { - Token tok = source_token; + final Token tok = source_token; source_token = null; if (getFeature(Feature.DEBUG)) LOG.debug("Returning unget token " + tok); @@ -627,18 +659,18 @@ public class Preprocessor implements Closeable { } for (;;) { - Source s = getSource(); + final Source s = getSource(); if (s == null) { - Token t = next_source(); + final Token t = next_source(); if (t.getType() == P_LINE && !getFeature(Feature.LINEMARKERS)) continue; return t; } - Token tok = s.token(); + final Token tok = s.token(); /* XXX Refactor with skipline() */ if (tok.getType() == EOF && s.isAutopop()) { // System.out.println("Autopop " + s); - Token mark = pop_source(true); + final Token mark = pop_source(true); if (mark != null) return mark; continue; @@ -649,14 +681,14 @@ public class Preprocessor implements Closeable { } } - private void source_untoken(Token tok) { + private void source_untoken(final Token tok) { if (this.source_token != null) throw new IllegalStateException("Cannot return two tokens"); this.source_token = tok; } - private boolean isWhite(Token tok) { - int type = tok.getType(); + private boolean isWhite(final Token tok) { + final int type = tok.getType(); return (type == WHITESPACE) || (type == CCOMMENT) || (type == CPPCOMMENT); @@ -680,16 +712,16 @@ public class Preprocessor implements Closeable { * * This method can, as of recent patches, return a P_LINE token. */ - private Token source_skipline(boolean white) + private Token source_skipline(final boolean white) throws IOException, LexerException { // (new Exception("skipping line")).printStackTrace(System.out); - Source s = getSource(); - Token tok = s.skipline(white); + final Source s = getSource(); + final Token tok = s.skipline(white); /* XXX Refactor with source_token() */ if (tok.getType() == EOF && s.isAutopop()) { // System.out.println("Autopop " + s); - Token mark = pop_source(true); + final Token mark = pop_source(true); if (mark != null) return mark; } @@ -697,7 +729,7 @@ public class Preprocessor implements Closeable { } /* processes and expands a macro. */ - private boolean macro(Macro m, Token orig) + private boolean macro(final Macro m, final Token orig) throws IOException, LexerException { Token tok; @@ -817,7 +849,7 @@ public class Preprocessor implements Closeable { "macro " + m.getName() + " has " + m.getArgs() + " parameters " + "but given " + args.size() + " args"); - /* We could replay the arg tokens, but I + /* We could replay the arg tokens, but I * note that GNU cpp does exactly what we do, * i.e. output the macro name and chew the args. */ @@ -825,7 +857,7 @@ public class Preprocessor implements Closeable { } } - for (Argument a : args) { + for (final Argument a : args) { a.expand(this); } @@ -848,12 +880,12 @@ public class Preprocessor implements Closeable { new NumericValue(10, Integer.toString(orig.getLine())))} ), true); } else if (m == __FILE__) { - StringBuilder buf = new StringBuilder("\""); + final StringBuilder buf = new StringBuilder("\""); String name = getSource().getName(); if (name == null) name = "<no file>"; for (int i = 0; i < name.length(); i++) { - char c = name.charAt(i); + final char c = name.charAt(i); switch (c) { case '\\': buf.append("\\\\"); @@ -867,7 +899,7 @@ public class Preprocessor implements Closeable { } } buf.append("\""); - String text = buf.toString(); + final String text = buf.toString(); push_source(new FixedTokenSource( new Token[]{new Token(STRING, orig.getLine(), orig.getColumn(), @@ -876,7 +908,7 @@ public class Preprocessor implements Closeable { } else if (m == __COUNTER__) { /* This could equivalently have been done by adding * a special Macro subclass which overrides getTokens(). */ - int value = this.counter++; + final int value = this.counter++; push_source(new FixedTokenSource( new Token[]{new Token(NUMBER, orig.getLine(), orig.getColumn(), @@ -895,17 +927,17 @@ public class Preprocessor implements Closeable { */ /* I'd rather this were done lazily, but doing so breaks spec. */ @Nonnull - /* pp */ List<Token> expand(@Nonnull List<Token> arg) + /* pp */ List<Token> expand(@Nonnull final List<Token> arg) throws IOException, LexerException { - List<Token> expansion = new ArrayList<Token>(); + final List<Token> expansion = new ArrayList<Token>(); boolean space = false; push_source(new FixedTokenSource(arg), false); EXPANSION: for (;;) { - Token tok = expanded_token(); + final Token tok = expanded_token(); switch (tok.getType()) { case EOF: break EXPANSION; @@ -941,14 +973,13 @@ public class Preprocessor implements Closeable { return source_skipline(false); } /* if predefined */ - - String name = tok.getText(); + final String name = tok.getText(); if ("defined".equals(name)) { error(tok, "Cannot redefine name 'defined'"); return source_skipline(false); } - Macro m = new Macro(getSource(), name); + final Macro m = new Macro(getSource(), name); List<String> args; tok = source_token(); @@ -1058,7 +1089,7 @@ public class Preprocessor implements Closeable { if (space) m.addToken(Token.space); space = false; - Token la = source_token_nonwhite(); + final Token la = source_token_nonwhite(); if (la.getType() == IDENTIFIER && ((idx = args.indexOf(la.getText())) != -1)) { m.addToken(new Token(M_STRING, @@ -1098,26 +1129,26 @@ public class Preprocessor implements Closeable { tok = source_token(); } - if (getFeature(Feature.DEBUG)) + if (getFeature(Feature.DEBUG)) { LOG.debug("Defined macro " + m); + } addMacro(m); return tok; /* NL or EOF. */ - } @Nonnull private Token undef() throws IOException, LexerException { - Token tok = source_token_nonwhite(); + final Token tok = source_token_nonwhite(); if (tok.getType() != IDENTIFIER) { error(tok, "Expected identifier, not " + tok.getText()); if (tok.getType() == NL || tok.getType() == EOF) return tok; } else { - Macro m = getMacro(tok.getText()); + final Macro m = getMacro(tok.getText()); if (m != null) { /* XXX error if predefined */ macros.remove(m.getName()); @@ -1173,15 +1204,15 @@ public class Preprocessor implements Closeable { * @throws LexerException if the include fails, and the error handler is fatal. */ private void include( - @CheckForNull String parent, int line, - @Nonnull String name, boolean quoted, boolean next) + @CheckForNull final String parent, final int line, + @Nonnull final String name, final boolean quoted, final boolean next) throws IOException, LexerException { if (name.startsWith("/")) { - VirtualFile file = filesystem.getFile(name); + final VirtualFile file = filesystem.getFile(name); if (include(file)) return; - StringBuilder buf = new StringBuilder(); + final StringBuilder buf = new StringBuilder(); buf.append("File not found: ").append(name); error(line, 0, buf.toString()); return; @@ -1190,22 +1221,22 @@ public class Preprocessor implements Closeable { VirtualFile pdir = null; if (quoted) { if (parent != null) { - VirtualFile pfile = filesystem.getFile(parent); + final VirtualFile pfile = filesystem.getFile(parent); pdir = pfile.getParentFile(); } if (pdir != null) { - VirtualFile ifile = pdir.getChildFile(name); + final VirtualFile ifile = pdir.getChildFile(name); if (include(ifile)) return; } if (include(quoteincludepath, name)) return; } else { - int idx = name.indexOf('/'); + final int idx = name.indexOf('/'); if (idx != -1) { - String frameworkName = name.substring(0, idx); - String headerName = name.substring(idx + 1); - String headerPath = frameworkName + ".framework/Headers/" + headerName; + final String frameworkName = name.substring(0, idx); + final String headerName = name.substring(idx + 1); + final String headerPath = frameworkName + ".framework/Headers/" + headerName; if (include(frameworkspath, headerPath)) return; } @@ -1214,24 +1245,24 @@ public class Preprocessor implements Closeable { if (include(sysincludepath, name)) return; - StringBuilder buf = new StringBuilder(); + final StringBuilder buf = new StringBuilder(); buf.append("File not found: ").append(name); buf.append(" in"); if (quoted) { buf.append(" .").append('(').append(pdir).append(')'); - for (String dir : quoteincludepath) + for (final String dir : quoteincludepath) buf.append(" ").append(dir); } - for (String dir : sysincludepath) + for (final String dir : sysincludepath) buf.append(" ").append(dir); error(line, 0, buf.toString()); } @Nonnull - private Token include(boolean next) + private Token include(final boolean next) throws IOException, LexerException { - LexerSource lexer = (LexerSource) source; + final LexerSource lexer = (LexerSource) source; try { lexer.setInclude(true); Token tok = token_nonwhite(); @@ -1242,7 +1273,7 @@ public class Preprocessor implements Closeable { if (tok.getType() == STRING) { /* XXX Use the original text, not the value. * Backslashes must not be treated as escapes here. */ - StringBuilder buf = new StringBuilder((String) tok.getValue()); + final StringBuilder buf = new StringBuilder((String) tok.getValue()); HEADER: for (;;) { tok = token_nonwhite(); @@ -1291,18 +1322,18 @@ public class Preprocessor implements Closeable { } } - protected void pragma_once(@Nonnull Token name) + protected void pragma_once(@Nonnull final Token name) throws IOException, LexerException { - Source s = this.source; + final Source s = this.source; if (!onceseenpaths.add(s.getPath())) { - Token mark = pop_source(true); + final Token mark = pop_source(true); // FixedTokenSource should never generate a linemarker on exit. if (mark != null) push_source(new FixedTokenSource(Arrays.asList(mark)), true); } } - protected void pragma(@Nonnull Token name, @Nonnull List<Token> value) + protected void pragma(@Nonnull final Token name, @Nonnull final List<Token> value) throws IOException, LexerException { if (getFeature(Feature.PRAGMA_ONCE)) { @@ -1351,7 +1382,7 @@ public class Preprocessor implements Closeable { } Token tok; - List<Token> value = new ArrayList<Token>(); + final List<Token> value = new ArrayList<Token>(); VALUE: for (;;) { tok = source_token(); @@ -1385,10 +1416,10 @@ public class Preprocessor implements Closeable { } /* For #error and #warning. */ - private void error(@Nonnull Token pptok, boolean is_error) + private void error(@Nonnull final Token pptok, final boolean is_error) throws IOException, LexerException { - StringBuilder buf = new StringBuilder(); + final StringBuilder buf = new StringBuilder(); buf.append('#').append(pptok.getText()).append(' '); /* Peculiar construction to ditch first whitespace. */ Token tok = source_token_nonwhite(); @@ -1418,10 +1449,10 @@ public class Preprocessor implements Closeable { throws IOException, LexerException { for (;;) { - Token tok = source_token(); + final Token tok = source_token(); // System.out.println("Source token is " + tok); if (tok.getType() == IDENTIFIER) { - Macro m = getMacro(tok.getText()); + final Macro m = getMacro(tok.getText()); if (m == null) return tok; if (source.isExpanding(m)) @@ -1504,7 +1535,7 @@ public class Preprocessor implements Closeable { return tok; } - private void expr_untoken(@Nonnull Token tok) + private void expr_untoken(@Nonnull final Token tok) throws LexerException { if (expr_token != null) throw new InternalException( @@ -1513,7 +1544,7 @@ public class Preprocessor implements Closeable { expr_token = tok; } - private int expr_priority(@Nonnull Token op) { + private int expr_priority(@Nonnull final Token op) { switch (op.getType()) { case '/': return 11; @@ -1601,7 +1632,7 @@ public class Preprocessor implements Closeable { lhs = -expr(11); break; case NUMBER: - NumericValue value = (NumericValue) tok.getValue(); + final NumericValue value = (NumericValue) tok.getValue(); lhs = value.longValue(); break; case CHARACTER: @@ -1624,8 +1655,8 @@ public class Preprocessor implements Closeable { EXPR: for (;;) { // System.out.println("expr: lhs is " + lhs + ", pri = " + priority); - Token op = expr_token(); - int pri = expr_priority(op); /* 0 if not a binop. */ + final Token op = expr_token(); + final int pri = expr_priority(op); /* 0 if not a binop. */ if (pri == 0 || priority >= pri) { expr_untoken(op); @@ -1707,7 +1738,7 @@ public class Preprocessor implements Closeable { error(tok, "Missing : in conditional expression. Got " + tok.getText()); return 0; } - long falseResult = expr(0); + final long falseResult = expr(0); lhs = (lhs != 0) ? rhs : falseResult; } break; @@ -1728,14 +1759,14 @@ public class Preprocessor implements Closeable { } @Nonnull - private Token toWhitespace(@Nonnull Token tok) { - String text = tok.getText(); - int len = text.length(); + private Token toWhitespace(@Nonnull final Token tok) { + final String text = tok.getText(); + final int len = text.length(); boolean cr = false; int nls = 0; for (int i = 0; i < len; i++) { - char c = text.charAt(i); + final char c = text.charAt(i); switch (c) { case '\r': @@ -1759,7 +1790,7 @@ public class Preprocessor implements Closeable { } } - char[] cbuf = new char[nls]; + final char[] cbuf = new char[nls]; Arrays.fill(cbuf, '\n'); return new Token(WHITESPACE, tok.getLine(), tok.getColumn(), @@ -1774,9 +1805,9 @@ public class Preprocessor implements Closeable { for (;;) { Token tok; if (!isActive()) { - Source s = getSource(); + final Source s = getSource(); if (s == null) { - Token t = next_source(); + final Token t = next_source(); if (t.getType() == P_LINE && !getFeature(Feature.LINEMARKERS)) continue; return t; @@ -1896,7 +1927,7 @@ public class Preprocessor implements Closeable { return tok; case IDENTIFIER: - Macro m = getMacro(tok.getText()); + final Macro m = getMacro(tok.getText()); if (m == null) return tok; if (source.isExpanding(m)) @@ -1934,7 +1965,7 @@ public class Preprocessor implements Closeable { + tok.getText()); return source_skipline(false); } - PreprocessorCommand ppcmd = PreprocessorCommand.forText(tok.getText()); + final PreprocessorCommand ppcmd = PreprocessorCommand.forText(tok.getText()); if (ppcmd == null) { error(tok, "Unknown preprocessor directive " @@ -2055,8 +2086,8 @@ public class Preprocessor implements Closeable { + tok.getText()); return source_skipline(false); } else { - String text = tok.getText(); - boolean exists + final String text = tok.getText(); + final boolean exists = macros.containsKey(text); states.peek().setActive(exists); return source_skipline(true); @@ -2076,8 +2107,8 @@ public class Preprocessor implements Closeable { + tok.getText()); return source_skipline(false); } else { - String text = tok.getText(); - boolean exists + final String text = tok.getText(); + final boolean exists = macros.containsKey(text); states.peek().setActive(!exists); return source_skipline(true); @@ -2141,7 +2172,7 @@ public class Preprocessor implements Closeable { public Token token() throws IOException, LexerException { - Token tok = _token(); + final Token tok = _token(); if (getFeature(Feature.DEBUG)) LOG.debug("pp: Returning " + tok); return tok; @@ -2149,7 +2180,7 @@ public class Preprocessor implements Closeable { @Override public String toString() { - StringBuilder buf = new StringBuilder(); + final StringBuilder buf = new StringBuilder(); Source s = getSource(); while (s != null) { @@ -2157,8 +2188,8 @@ public class Preprocessor implements Closeable { s = s.getParent(); } - Map<String, Macro> macros = new TreeMap<String, Macro>(getMacros()); - for (Macro macro : macros.values()) { + final Map<String, Macro> macros = new TreeMap<String, Macro>(getMacros()); + for (final Macro macro : macros.values()) { buf.append("#").append("macro ").append(macro).append("\n"); } @@ -2175,7 +2206,7 @@ public class Preprocessor implements Closeable { s = s.getParent(); } } - for (Source s : inputs) { + for (final Source s : inputs) { s.close(); } } diff --git a/src/main/java/org/anarres/cpp/PreprocessorCommand.java b/src/main/java/com/jogamp/gluegen/jcpp/PreprocessorCommand.java index 3938360..a01a04b 100644 --- a/src/main/java/org/anarres/cpp/PreprocessorCommand.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/PreprocessorCommand.java @@ -3,7 +3,7 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; diff --git a/src/main/java/org/anarres/cpp/PreprocessorListener.java b/src/main/java/com/jogamp/gluegen/jcpp/PreprocessorListener.java index 48308d8..1feb1d6 100644 --- a/src/main/java/org/anarres/cpp/PreprocessorListener.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/PreprocessorListener.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import javax.annotation.Nonnull; diff --git a/src/main/java/org/anarres/cpp/ResourceFileSystem.java b/src/main/java/com/jogamp/gluegen/jcpp/ResourceFileSystem.java index 43d6732..83cd248 100644 --- a/src/main/java/org/anarres/cpp/ResourceFileSystem.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/ResourceFileSystem.java @@ -3,7 +3,7 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.IOException; import java.io.InputStream; diff --git a/src/main/java/org/anarres/cpp/Source.java b/src/main/java/com/jogamp/gluegen/jcpp/Source.java index a4e1bd9..e254190 100644 --- a/src/main/java/org/anarres/cpp/Source.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/Source.java @@ -14,19 +14,21 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.Closeable; import java.io.IOException; import java.util.Iterator; + import javax.annotation.CheckForNull; import javax.annotation.Nonnegative; import javax.annotation.Nonnull; -import static org.anarres.cpp.Token.CCOMMENT; -import static org.anarres.cpp.Token.CPPCOMMENT; -import static org.anarres.cpp.Token.EOF; -import static org.anarres.cpp.Token.NL; -import static org.anarres.cpp.Token.WHITESPACE; + +import static com.jogamp.gluegen.jcpp.Token.CCOMMENT; +import static com.jogamp.gluegen.jcpp.Token.CPPCOMMENT; +import static com.jogamp.gluegen.jcpp.Token.EOF; +import static com.jogamp.gluegen.jcpp.Token.NL; +import static com.jogamp.gluegen.jcpp.Token.WHITESPACE; /** * An input to the Preprocessor. @@ -94,7 +96,7 @@ public abstract class Source implements Iterable<Token>, Closeable { * * Sources form a singly linked list. */ - /* pp */ void setParent(Source parent, boolean autopop) { + /* pp */ void setParent(final Source parent, final boolean autopop) { this.parent = parent; this.autopop = autopop; } @@ -104,13 +106,13 @@ public abstract class Source implements Iterable<Token>, Closeable { * * Sources form a singly linked list. */ - /* pp */ final Source getParent() { + public final Source getParent() { return parent; } // @OverrideMustInvoke - /* pp */ void init(Preprocessor pp) { + /* pp */ void init(final Preprocessor pp) { setListener(pp.getListener()); this.werror = pp.getWarnings().contains(Warning.ERROR); } @@ -122,7 +124,7 @@ public abstract class Source implements Iterable<Token>, Closeable { * used, but if you are using a Source as a standalone object, * you may wish to call this. */ - public void setListener(PreprocessorListener pl) { + public void setListener(final PreprocessorListener pl) { this.listener = pl; } @@ -135,7 +137,7 @@ public abstract class Source implements Iterable<Token>, Closeable { */ @CheckForNull public String getPath() { - Source parent = getParent(); + final Source parent = getParent(); if (parent != null) return parent.getPath(); return null; @@ -146,7 +148,7 @@ public abstract class Source implements Iterable<Token>, Closeable { */ @CheckForNull public String getName() { - Source parent = getParent(); + final Source parent = getParent(); if (parent != null) return parent.getName(); return null; @@ -157,7 +159,7 @@ public abstract class Source implements Iterable<Token>, Closeable { */ @Nonnegative public int getLine() { - Source parent = getParent(); + final Source parent = getParent(); if (parent == null) return 0; return parent.getLine(); @@ -167,7 +169,7 @@ public abstract class Source implements Iterable<Token>, Closeable { * Returns the current column number within this Source. */ public int getColumn() { - Source parent = getParent(); + final Source parent = getParent(); if (parent == null) return 0; return parent.getColumn(); @@ -178,8 +180,8 @@ public abstract class Source implements Iterable<Token>, Closeable { * * This is used to prevent macro recursion. */ - /* pp */ boolean isExpanding(@Nonnull Macro m) { - Source parent = getParent(); + /* pp */ boolean isExpanding(@Nonnull final Macro m) { + final Source parent = getParent(); if (parent != null) return parent.isExpanding(m); return false; @@ -204,7 +206,7 @@ public abstract class Source implements Iterable<Token>, Closeable { /* This is an incredibly lazy way of disabling warnings when * the source is not active. */ - /* pp */ void setActive(boolean b) { + /* pp */ void setActive(final boolean b) { this.active = b; } @@ -238,11 +240,11 @@ public abstract class Source implements Iterable<Token>, Closeable { * @return the NL token. */ @Nonnull - public Token skipline(boolean white) + public Token skipline(final boolean white) throws IOException, LexerException { for (;;) { - Token tok = token(); + final Token tok = token(); switch (tok.getType()) { case EOF: /* There ought to be a newline before EOF. @@ -271,7 +273,7 @@ public abstract class Source implements Iterable<Token>, Closeable { } } - protected void error(int line, int column, String msg) + protected void error(final int line, final int column, final String msg) throws LexerException { if (listener != null) listener.handleError(this, line, column, msg); @@ -279,7 +281,7 @@ public abstract class Source implements Iterable<Token>, Closeable { throw new LexerException("Error at " + line + ":" + column + ": " + msg); } - protected void warning(int line, int column, String msg) + protected void warning(final int line, final int column, final String msg) throws LexerException { if (werror) error(line, column, msg); diff --git a/src/main/java/org/anarres/cpp/SourceIterator.java b/src/main/java/com/jogamp/gluegen/jcpp/SourceIterator.java index c7fae18..db29822 100644 --- a/src/main/java/org/anarres/cpp/SourceIterator.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/SourceIterator.java @@ -14,13 +14,14 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.IOException; import java.util.Iterator; import java.util.NoSuchElementException; + import javax.annotation.Nonnull; -import static org.anarres.cpp.Token.EOF; +import static com.jogamp.gluegen.jcpp.Token.EOF; /** * An Iterator for {@link Source Sources}, diff --git a/src/main/java/org/anarres/cpp/State.java b/src/main/java/com/jogamp/gluegen/jcpp/State.java index b6f3ada..dc96006 100644 --- a/src/main/java/org/anarres/cpp/State.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/State.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; /* pp */ class State { diff --git a/src/main/java/org/anarres/cpp/StringLexerSource.java b/src/main/java/com/jogamp/gluegen/jcpp/StringLexerSource.java index e3b365a..a26fbe3 100644 --- a/src/main/java/org/anarres/cpp/StringLexerSource.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/StringLexerSource.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.StringReader; diff --git a/src/main/java/org/anarres/cpp/Token.java b/src/main/java/com/jogamp/gluegen/jcpp/Token.java index d0e2e6f..0167bd6 100644 --- a/src/main/java/org/anarres/cpp/Token.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/Token.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; diff --git a/src/main/java/org/anarres/cpp/TokenSnifferSource.java b/src/main/java/com/jogamp/gluegen/jcpp/TokenSnifferSource.java index b6ad57a..7c49072 100644 --- a/src/main/java/org/anarres/cpp/TokenSnifferSource.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/TokenSnifferSource.java @@ -14,11 +14,12 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.IOException; import java.util.List; -import static org.anarres.cpp.Token.EOF; + +import static com.jogamp.gluegen.jcpp.Token.EOF; @Deprecated /* pp */ class TokenSnifferSource extends Source { diff --git a/src/main/java/org/anarres/cpp/TokenType.java b/src/main/java/com/jogamp/gluegen/jcpp/TokenType.java index 86df097..e481bab 100644 --- a/src/main/java/org/anarres/cpp/TokenType.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/TokenType.java @@ -3,14 +3,16 @@ * To change this template file, choose Tools | Templates * and open the template in the editor. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.util.ArrayList; import java.util.List; + import javax.annotation.CheckForNull; import javax.annotation.Nonnegative; import javax.annotation.Nonnull; -import static org.anarres.cpp.Token.*; + +import static com.jogamp.gluegen.jcpp.Token.*; /** * diff --git a/src/main/java/org/anarres/cpp/VirtualFile.java b/src/main/java/com/jogamp/gluegen/jcpp/VirtualFile.java index 9e1302e..a453890 100644 --- a/src/main/java/org/anarres/cpp/VirtualFile.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/VirtualFile.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.IOException; import javax.annotation.CheckForNull; diff --git a/src/main/java/org/anarres/cpp/VirtualFileSystem.java b/src/main/java/com/jogamp/gluegen/jcpp/VirtualFileSystem.java index 9d04857..a377753 100644 --- a/src/main/java/org/anarres/cpp/VirtualFileSystem.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/VirtualFileSystem.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import javax.annotation.Nonnull; diff --git a/src/main/java/org/anarres/cpp/Warning.java b/src/main/java/com/jogamp/gluegen/jcpp/Warning.java index de1b8b6..9e39e7e 100644 --- a/src/main/java/org/anarres/cpp/Warning.java +++ b/src/main/java/com/jogamp/gluegen/jcpp/Warning.java @@ -14,7 +14,7 @@ * or implied. See the License for the specific language governing * permissions and limitations under the License. */ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; /** * Warning classes which may optionally be emitted by the Preprocessor. diff --git a/src/main/java/org/anarres/cpp/BuildMetadata.java b/src/main/java/org/anarres/cpp/BuildMetadata.java deleted file mode 100644 index 79de407..0000000 --- a/src/main/java/org/anarres/cpp/BuildMetadata.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.anarres.cpp; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; -import javax.annotation.Nonnull; - -/** - * Returns information about the build. - * - * @author shevek - */ -public class BuildMetadata { - - public static final String RESOURCE = "/META-INF/jcpp.properties"; - private static BuildMetadata INSTANCE; - - /** @throws RuntimeException if the properties file cannot be found on the classpath. */ - @Nonnull - public static synchronized BuildMetadata getInstance() { - try { - if (INSTANCE == null) - INSTANCE = new BuildMetadata(); - return INSTANCE; - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - private final Properties properties = new Properties(); - - private BuildMetadata() throws IOException { - URL url = BuildMetadata.class.getResource(RESOURCE); - InputStream in = url.openStream(); - try { - properties.load(in); - } finally { - in.close(); - } - } - - @Nonnull - public Map<? extends String, ? extends String> asMap() { - Map<String, String> out = new HashMap<String, String>(); - for (Map.Entry<Object, Object> e : properties.entrySet()) - out.put(String.valueOf(e.getKey()), String.valueOf(e.getValue())); - return out; - } - - @Nonnull - public com.github.zafarkhaja.semver.Version getVersion() { - return com.github.zafarkhaja.semver.Version.valueOf(properties.getProperty("Implementation-Version")); - } - - @Nonnull - public Date getBuildDate() throws ParseException { - // Build-Date=2015-01-01_10:09:09 - String text = properties.getProperty("Build-Date"); - SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss"); - return format.parse(text); - } - - public String getChangeId() { - return properties.getProperty("Change"); - } -} diff --git a/src/main/java/org/anarres/cpp/Main.java b/src/main/java/org/anarres/cpp/Main.java deleted file mode 100644 index 3bef07b..0000000 --- a/src/main/java/org/anarres/cpp/Main.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Anarres C Preprocessor - * Copyright (c) 2007-2015, Shevek - * - * 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. - */ -package org.anarres.cpp; - -import java.io.File; -import java.io.PrintStream; -import java.util.Arrays; -import java.util.EnumSet; -import java.util.List; -import javax.annotation.Nonnull; -import joptsimple.OptionParser; -import joptsimple.OptionSet; -import joptsimple.OptionSpec; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * (Currently a simple test class). - */ -public class Main { - - private static final Logger LOG = LoggerFactory.getLogger(Main.class); - - @Nonnull - private static CharSequence getWarnings() { - StringBuilder buf = new StringBuilder(); - for (Warning w : Warning.values()) { - if (buf.length() > 0) - buf.append(", "); - String name = w.name().toLowerCase(); - buf.append(name.replace('_', '-')); - } - return buf; - } - - public static void main(String[] args) throws Exception { - (new Main()).run(args); - } - - public void run(String[] args) throws Exception { - - OptionParser parser = new OptionParser(); - OptionSpec<?> helpOption = parser.accepts("help", - "Displays command-line help.") - .forHelp(); - OptionSpec<?> versionOption = parser.acceptsAll(Arrays.asList("version"), - "Displays the product version (" + BuildMetadata.getInstance().getVersion() + ") and exits.") - .forHelp(); - - OptionSpec<?> debugOption = parser.acceptsAll(Arrays.asList("debug"), - "Enables debug output."); - - OptionSpec<String> defineOption = parser.acceptsAll(Arrays.asList("define", "D"), - "Defines the given macro.") - .withRequiredArg().ofType(String.class).describedAs("name[=definition]"); - OptionSpec<String> undefineOption = parser.acceptsAll(Arrays.asList("undefine", "U"), - "Undefines the given macro, previously either builtin or defined using -D.") - .withRequiredArg().describedAs("name"); - OptionSpec<File> includeOption = parser.accepts("include", - "Process file as if \"#" + "include \"file\"\" appeared as the first line of the primary source file.") - .withRequiredArg().ofType(File.class).describedAs("file"); - OptionSpec<File> incdirOption = parser.acceptsAll(Arrays.asList("incdir", "I"), - "Adds the directory dir to the list of directories to be searched for header files.") - .withRequiredArg().ofType(File.class).describedAs("dir"); - OptionSpec<File> iquoteOption = parser.acceptsAll(Arrays.asList("iquote"), - "Adds the directory dir to the list of directories to be searched for header files included using \"\".") - .withRequiredArg().ofType(File.class).describedAs("dir"); - OptionSpec<String> warningOption = parser.acceptsAll(Arrays.asList("warning", "W"), - "Enables the named warning class (" + getWarnings() + ").") - .withRequiredArg().ofType(String.class).describedAs("warning"); - OptionSpec<Void> noWarningOption = parser.acceptsAll(Arrays.asList("no-warnings", "w"), - "Disables ALL warnings."); - OptionSpec<File> inputsOption = parser.nonOptions() - .ofType(File.class).describedAs("Files to process."); - - OptionSet options = parser.parse(args); - - if (options.has(helpOption)) { - parser.printHelpOn(System.out); - return; - } - - if (options.has(versionOption)) { - version(System.out); - return; - } - - Preprocessor pp = new Preprocessor(); - pp.addFeature(Feature.DIGRAPHS); - pp.addFeature(Feature.TRIGRAPHS); - pp.addFeature(Feature.LINEMARKERS); - pp.addWarning(Warning.IMPORT); - pp.setListener(new DefaultPreprocessorListener()); - pp.addMacro("__JCPP__"); - pp.getSystemIncludePath().add("/usr/local/include"); - pp.getSystemIncludePath().add("/usr/include"); - pp.getFrameworksPath().add("/System/Library/Frameworks"); - pp.getFrameworksPath().add("/Library/Frameworks"); - pp.getFrameworksPath().add("/Local/Library/Frameworks"); - - if (options.has(debugOption)) - pp.addFeature(Feature.DEBUG); - - if (options.has(noWarningOption)) - pp.getWarnings().clear(); - - for (String warning : options.valuesOf(warningOption)) { - warning = warning.toUpperCase(); - warning = warning.replace('-', '_'); - if (warning.equals("ALL")) - pp.addWarnings(EnumSet.allOf(Warning.class)); - else - pp.addWarning(Enum.valueOf(Warning.class, warning)); - } - - for (String arg : options.valuesOf(defineOption)) { - int idx = arg.indexOf('='); - if (idx == -1) - pp.addMacro(arg); - else - pp.addMacro(arg.substring(0, idx), arg.substring(idx + 1)); - } - for (String arg : options.valuesOf(undefineOption)) { - pp.getMacros().remove(arg); - } - - for (File dir : options.valuesOf(incdirOption)) - pp.getSystemIncludePath().add(dir.getAbsolutePath()); - for (File dir : options.valuesOf(iquoteOption)) - pp.getQuoteIncludePath().add(dir.getAbsolutePath()); - for (File file : options.valuesOf(includeOption)) - // Comply exactly with spec. - pp.addInput(new StringLexerSource("#" + "include \"" + file + "\"\n")); - - List<File> inputs = options.valuesOf(inputsOption); - if (inputs.isEmpty()) { - pp.addInput(new InputLexerSource(System.in)); - } else { - for (File input : inputs) - pp.addInput(new FileLexerSource(input)); - } - - if (pp.getFeature(Feature.DEBUG)) { - LOG.info("#" + "include \"...\" search starts here:"); - for (String dir : pp.getQuoteIncludePath()) - LOG.info(" " + dir); - LOG.info("#" + "include <...> search starts here:"); - for (String dir : pp.getSystemIncludePath()) - LOG.info(" " + dir); - LOG.info("End of search list."); - } - - try { - for (;;) { - Token tok = pp.token(); - if (tok == null) - break; - if (tok.getType() == Token.EOF) - break; - System.out.print(tok.getText()); - } - } catch (Exception e) { - StringBuilder buf = new StringBuilder("Preprocessor failed:\n"); - Source s = pp.getSource(); - while (s != null) { - buf.append(" -> ").append(s).append("\n"); - s = s.getParent(); - } - LOG.error(buf.toString(), e); - } - - } - - private static void version(@Nonnull PrintStream out) { - BuildMetadata metadata = BuildMetadata.getInstance(); - out.println("Anarres Java C Preprocessor version " + metadata.getVersion() + " change-id " + metadata.getChangeId()); - out.println("Copyright (C) 2007-2015 Shevek (http://www.anarres.org/)."); - out.println("This is free software; see the source for copying conditions. There is NO"); - out.println("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."); - } -} diff --git a/src/main/velocity/org/anarres/cpp/Version.java b/src/main/velocity/org/anarres/cpp/Version.java deleted file mode 100644 index cedd6bb..0000000 --- a/src/main/velocity/org/anarres/cpp/Version.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Anarres C Preprocessor - * Copyright (c) 2007-2008, Shevek - * - * 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. - */ - -package org.anarres.cpp; - -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - -/** - * System version metadata for Anarres Java C Preprocessor ${version}. - * - * This class contains a main() and may be run to print the version. - */ -public class Version { - - /* Don't instantiate me */ - private Version() { - } - - private static final String VERSION = "${version}"; - - private static final int major; - private static final int minor; - private static final int patch; - private static final String modifier; - - static { - String[] tmp = VERSION.split("[\\.-]"); - major = Integer.parseInt(tmp[0]); - minor = Integer.parseInt(tmp[1]); - patch = Integer.parseInt(tmp[2]); - modifier = (tmp.length > 3) ? tmp[3] : null; - } - - @Nonnull - public static String getVersion() { - return VERSION; - } - - public static int getMajor() { - return major; - } - - public static int getMinor() { - return minor; - } - - public static int getPatch() { - return patch; - } - - @CheckForNull - public static String getModifier() { - return modifier; - } - - public static boolean isSnapshot() { - return "SNAPSHOT".equalsIgnoreCase(getModifier()); - } - - public static void main(String[] args) { - System.out.println("Version " + VERSION); - System.out.println("getVersion() returns " + getVersion()); - System.out.println("getMajor() returns " + getMajor()); - System.out.println("getMinor() returns " + getMinor()); - System.out.println("getPatch() returns " + getPatch()); - } - -} diff --git a/src/scripts/jcpp b/src/scripts/jcpp deleted file mode 100755 index ed167c5..0000000 --- a/src/scripts/jcpp +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh - -CPP_JAR=anarres-cpp.jar - -if [ -n "$CPP_ROOT" ] ; then - CPP_ROOT="$CPP_ROOT" -elif [ -f lib/$CPP_JAR ] ; then - CPP_ROOT="." -elif [ -f ../lib/$CPP_JAR ] ; then - CPP_ROOT=".." -elif [ -f $(dirname $0)/lib/$CPP_JAR ] ; then - CPP_ROOT=$(dirname $0) -else - echo "Could not find $CPP_JAR. Please set CPP_ROOT." - exit 1 -fi - -if [ -z "$CPP_LIB" ] ; then - CPP_LIB=$CPP_ROOT/lib -fi - -if [ -z "$CPP_CLASSPATH" ] ; then - CPP_CLASSPATH="$(ls $CPP_LIB/*.jar | tr '\n' ':')" -fi - -if [ -z "$CPP_MAINCLASS" ] ; then - CPP_MAINCLASS=org.anarres.cpp.Main -fi - -CPP_JFLAGS="-Xmx128M" - -exec java $CPP_JFLAGS -cp "$CPP_CLASSPATH" $CPP_MAINCLASS "$@" diff --git a/src/scripts/release.sh b/src/scripts/release.sh deleted file mode 100644 index cd88d95..0000000 --- a/src/scripts/release.sh +++ /dev/null @@ -1,5 +0,0 @@ -rsync -avP build/dist/anarres-cpp-*.tar.gz [email protected]:public_html/projects/jcpp/ -rsync -avP --exclude=.svn --exclude=autohandler build/javadoc [email protected]:public_html/projects/jcpp/ -cp build/tar/lib/anarres-cpp.jar /home/shevek/java/iengine/trunk/lib/runtime/jcpp/ -cp build/tar/lib/anarres-cpp.jar /home/shevek/java/karma/trunk/lib/dp/ -cp build/tar/lib/anarres-cpp.jar /home/shevek/java/dp/trunk/lib/runtime/cpp/ diff --git a/src/test/java/org/anarres/cpp/CppReaderTest.java b/src/test/java/com/jogamp/gluegen/jcpp/CppReaderTest.java index c901722..870663d 100644 --- a/src/test/java/org/anarres/cpp/CppReaderTest.java +++ b/src/test/java/com/jogamp/gluegen/jcpp/CppReaderTest.java @@ -1,26 +1,37 @@ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.BufferedReader; +import java.io.IOException; import java.io.StringReader; import java.util.Collections; + import javax.annotation.Nonnull; + +import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.runners.MethodSorters; + +import com.jogamp.gluegen.test.junit.generation.BuildEnvironment; +import com.jogamp.junit.util.SingletonJunitCase; + import static org.junit.Assert.assertEquals; -public class CppReaderTest { +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class CppReaderTest extends SingletonJunitCase { + + public static String testCppReader(@Nonnull final String in, final Feature... f) throws Exception { + final String inclpath = BuildEnvironment.gluegenRoot + "/jcpp/src/test/resources" ; - public static String testCppReader(@Nonnull String in, Feature... f) - throws Exception { System.out.println("Testing " + in); - StringReader r = new StringReader(in); - CppReader p = new CppReader(r); + final StringReader r = new StringReader(in); + final CppReader p = new CppReader(r); p.getPreprocessor().setSystemIncludePath( - Collections.singletonList("src/test/resources") + Collections.singletonList(inclpath) ); p.getPreprocessor().addFeatures(f); - BufferedReader b = new BufferedReader(p); + final BufferedReader b = new BufferedReader(p); - StringBuilder out = new StringBuilder(); + final StringBuilder out = new StringBuilder(); String line; while ((line = b.readLine()) != null) { System.out.println(" >> " + line); @@ -47,7 +58,7 @@ public class CppReaderTest { public void testPragmaOnce() throws Exception { // The newlines are irrelevant, We want exactly one "foo" - String out = testCppReader("#include <once.c>\n", Feature.PRAGMA_ONCE); + final String out = testCppReader("#include <once.c>\n", Feature.PRAGMA_ONCE); assertEquals("foo", out.trim()); } @@ -58,4 +69,9 @@ public class CppReaderTest { testCppReader("#include <once.c>\n", Feature.PRAGMA_ONCE, Feature.LINEMARKERS); } + public static void main(final String args[]) throws IOException { + final String tstname = CppReaderTest.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } + } diff --git a/src/test/java/org/anarres/cpp/ErrorTest.java b/src/test/java/com/jogamp/gluegen/jcpp/ErrorTest.java index 42240d4..ad6a1b4 100644 --- a/src/test/java/org/anarres/cpp/ErrorTest.java +++ b/src/test/java/com/jogamp/gluegen/jcpp/ErrorTest.java @@ -1,17 +1,24 @@ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.IOException; + +import org.junit.FixMethodOrder; import org.junit.Test; -import static org.anarres.cpp.Token.*; +import org.junit.runners.MethodSorters; + +import com.jogamp.junit.util.SingletonJunitCase; + +import static com.jogamp.gluegen.jcpp.Token.*; import static org.junit.Assert.*; -public class ErrorTest { +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ErrorTest extends SingletonJunitCase { - private boolean testError(Preprocessor p) + private boolean testError(final Preprocessor p) throws LexerException, IOException { for (;;) { - Token tok = p.token(); + final Token tok = p.token(); if (tok.getType() == EOF) break; if (tok.getType() == INVALID) @@ -20,7 +27,7 @@ public class ErrorTest { return false; } - private void testError(String input) throws Exception { + private void testError(final String input) throws Exception { StringLexerSource sl; DefaultPreprocessorListener pl; Preprocessor p; @@ -33,7 +40,7 @@ public class ErrorTest { try { assertTrue(testError(p)); fail("Lexing unexpectedly succeeded without listener."); - } catch (LexerException e) { + } catch (final LexerException e) { /* required */ } diff --git a/src/test/java/com/jogamp/gluegen/jcpp/IncludeAbsoluteTest.java b/src/test/java/com/jogamp/gluegen/jcpp/IncludeAbsoluteTest.java new file mode 100644 index 0000000..9008ebe --- /dev/null +++ b/src/test/java/com/jogamp/gluegen/jcpp/IncludeAbsoluteTest.java @@ -0,0 +1,55 @@ +package com.jogamp.gluegen.jcpp; + +import java.io.File; +import java.io.IOException; +import java.io.Reader; + +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import com.jogamp.common.util.IOUtil; +import com.jogamp.gluegen.Logging; +import com.jogamp.gluegen.Logging.LoggerIf; +import com.jogamp.gluegen.test.junit.generation.BuildEnvironment; +import com.jogamp.junit.util.SingletonJunitCase; + +import static org.junit.Assert.*; + +/** + * + * @author shevek + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class IncludeAbsoluteTest extends SingletonJunitCase { + + private static final LoggerIf LOG = Logging.getLogger(IncludeAbsoluteTest.class); + + @Test + public void testAbsoluteInclude() throws Exception { + final String filepath = BuildEnvironment.gluegenRoot + "/jcpp/src/test/resources/absolute.h" ; + LOG.info("filepath: " + filepath); + + final File file = new File(filepath); + assertTrue(file.exists()); + final String slashifiedFilePath = IOUtil.slashify(file.getAbsolutePath(), true, false); + LOG.info("slashifiedFilePath: " + slashifiedFilePath); + + // Expects something like: + // WINDOWS: "/C:/projects/jogamp/gluegen/jcpp/src/test/resources/absolute.h" + // UNIX: "/projects/jogamp/gluegen/jcpp/src/test/resources/absolute.h" + final String input = "#include <" + slashifiedFilePath + ">\n"; + LOG.info("Input: " + input); + final Preprocessor pp = new Preprocessor(); + pp.addInput(new StringLexerSource(input, true)); + final Reader r = new CppReader(pp); + final String output = IOUtil.appendCharStream(new StringBuilder(), r).toString(); + r.close(); + LOG.info("Output: " + output); + assertTrue(output.contains("absolute-result")); + } + public static void main(final String args[]) throws IOException { + final String tstname = IncludeAbsoluteTest.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } +} diff --git a/src/test/java/org/anarres/cpp/JavaFileSystemTest.java b/src/test/java/com/jogamp/gluegen/jcpp/JavaFileSystemTest.java index 6e6f834..3477d97 100644 --- a/src/test/java/org/anarres/cpp/JavaFileSystemTest.java +++ b/src/test/java/com/jogamp/gluegen/jcpp/JavaFileSystemTest.java @@ -1,15 +1,22 @@ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.FileNotFoundException; + +import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.runners.MethodSorters; + +import com.jogamp.junit.util.SingletonJunitCase; + import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -public class JavaFileSystemTest { +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class JavaFileSystemTest extends SingletonJunitCase { @Test public void testJavaFileSystem() throws Exception { - JavaFileSystem fs = new JavaFileSystem(); + final JavaFileSystem fs = new JavaFileSystem(); VirtualFile f; /* Anyone who has this file on their Unix box is messed up. */ @@ -18,7 +25,7 @@ public class JavaFileSystemTest { f.getSource(); /* drop on floor */ assertTrue("Got a source for a non-file", f.isFile()); - } catch (FileNotFoundException e) { + } catch (final FileNotFoundException e) { assertFalse("Got no source for a file", f.isFile()); } @@ -29,7 +36,7 @@ public class JavaFileSystemTest { System.out.println("Opened stdio.h"); assertTrue("Got a source for a non-file", f.isFile()); - } catch (FileNotFoundException e) { + } catch (final FileNotFoundException e) { System.out.println("Failed to open stdio.h"); assertFalse("Got no source for a file", f.isFile()); } diff --git a/src/test/java/org/anarres/cpp/JoinReaderTest.java b/src/test/java/com/jogamp/gluegen/jcpp/JoinReaderTest.java index bb9cc2d..4193f3f 100644 --- a/src/test/java/org/anarres/cpp/JoinReaderTest.java +++ b/src/test/java/com/jogamp/gluegen/jcpp/JoinReaderTest.java @@ -1,19 +1,26 @@ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.StringReader; + +import org.junit.FixMethodOrder; import org.junit.Test; +import org.junit.runners.MethodSorters; + +import com.jogamp.junit.util.SingletonJunitCase; + import static org.junit.Assert.assertEquals; -public class JoinReaderTest { +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class JoinReaderTest extends SingletonJunitCase { - private void testJoinReader(String in, String out, boolean tg) + private void testJoinReader(final String in, final String out, final boolean tg) throws Exception { System.out.println("Testing " + in + " => " + out); - StringReader r = new StringReader(in); - JoinReader j = new JoinReader(r, tg); + final StringReader r = new StringReader(in); + final JoinReader j = new JoinReader(r, tg); for (int i = 0; i < out.length(); i++) { - int c = j.read(); + final int c = j.read(); System.out.println("At offset " + i + ": " + (char) c); assertEquals(out.charAt(i), c); } @@ -21,7 +28,7 @@ public class JoinReaderTest { assertEquals(-1, j.read()); } - private void testJoinReader(String in, String out) + private void testJoinReader(final String in, final String out) throws Exception { testJoinReader(in, out, true); testJoinReader(in, out, false); diff --git a/src/test/java/org/anarres/cpp/LexerSourceTest.java b/src/test/java/com/jogamp/gluegen/jcpp/LexerSourceTest.java index 38d0a6f..4283073 100644 --- a/src/test/java/org/anarres/cpp/LexerSourceTest.java +++ b/src/test/java/com/jogamp/gluegen/jcpp/LexerSourceTest.java @@ -1,33 +1,40 @@ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.util.Arrays; + +import org.junit.FixMethodOrder; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import static org.anarres.cpp.PreprocessorTest.assertType; -import static org.anarres.cpp.Token.*; +import org.junit.runners.MethodSorters; + +import com.jogamp.gluegen.Logging; +import com.jogamp.gluegen.Logging.LoggerIf; +import com.jogamp.junit.util.SingletonJunitCase; + +import static com.jogamp.gluegen.jcpp.PreprocessorTest.assertType; +import static com.jogamp.gluegen.jcpp.Token.*; import static org.junit.Assert.*; -public class LexerSourceTest { +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class LexerSourceTest extends SingletonJunitCase { - private static final Logger LOG = LoggerFactory.getLogger(LexerSourceTest.class); + private static final LoggerIf LOG = Logging.getLogger(LexerSourceTest.class); - public static void testLexerSource(String in, boolean textmatch, int... out) + public static void testLexerSource(final String in, final boolean textmatch, final int... out) throws Exception { LOG.info("Testing '" + in + "' => " + Arrays.toString(out)); - StringLexerSource s = new StringLexerSource(in); + final StringLexerSource s = new StringLexerSource(in); - StringBuilder buf = new StringBuilder(); + final StringBuilder buf = new StringBuilder(); for (int i = 0; i < out.length; i++) { - Token tok = s.token(); + final Token tok = s.token(); LOG.info("Token is " + tok); assertType(out[i], tok); // assertEquals(col, tok.getColumn()); buf.append(tok.getText()); } - Token tok = s.token(); + final Token tok = s.token(); LOG.info("Token is " + tok); assertType(EOF, tok); diff --git a/src/test/java/org/anarres/cpp/NumericValueTest.java b/src/test/java/com/jogamp/gluegen/jcpp/NumericValueTest.java index 5551942..036ee93 100644 --- a/src/test/java/org/anarres/cpp/NumericValueTest.java +++ b/src/test/java/com/jogamp/gluegen/jcpp/NumericValueTest.java @@ -1,34 +1,41 @@ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; import java.io.IOException; + +import org.junit.FixMethodOrder; import org.junit.Test; -import static org.anarres.cpp.Token.*; +import org.junit.runners.MethodSorters; + +import com.jogamp.junit.util.SingletonJunitCase; + +import static com.jogamp.gluegen.jcpp.Token.*; import static org.junit.Assert.*; /** * * @author shevek */ -public class NumericValueTest { +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class NumericValueTest extends SingletonJunitCase { - private Token testNumericValue(String in) throws IOException, LexerException { - StringLexerSource s = new StringLexerSource(in); + private Token testNumericValue(final String in) throws IOException, LexerException { + final StringLexerSource s = new StringLexerSource(in); - Token tok = s.token(); + final Token tok = s.token(); System.out.println("Token is " + tok); assertEquals(NUMBER, tok.getType()); - Token eof = s.token(); + final Token eof = s.token(); assertEquals("Didn't get EOF, but " + tok, EOF, eof.getType()); return tok; } - private void testNumericValue(String in, double out) throws IOException, LexerException { + private void testNumericValue(final String in, final double out) throws IOException, LexerException { System.out.println("Testing '" + in + "' -> " + out); - Token tok = testNumericValue(in); + final Token tok = testNumericValue(in); assertEquals(in, tok.getText()); - NumericValue value = (NumericValue) tok.getValue(); + final NumericValue value = (NumericValue) tok.getValue(); assertEquals("Double mismatch", out, value.doubleValue(), 0.01d); assertEquals("Float mismatch", (float) out, value.floatValue(), 0.01f); assertEquals("Long mismatch", (long) out, value.longValue()); @@ -89,7 +96,7 @@ public class NumericValueTest { try { testNumericValue("097", 97); fail("No warning."); - } catch (LexerException e) { + } catch (final LexerException e) { } } diff --git a/src/test/java/org/anarres/cpp/PreprocessorTest.java b/src/test/java/com/jogamp/gluegen/jcpp/PreprocessorTest.java index 13bd944..c4a4b06 100644 --- a/src/test/java/org/anarres/cpp/PreprocessorTest.java +++ b/src/test/java/com/jogamp/gluegen/jcpp/PreprocessorTest.java @@ -1,29 +1,42 @@ -package org.anarres.cpp; +package com.jogamp.gluegen.jcpp; +import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PipedInputStream; import java.io.PipedOutputStream; +import java.util.List; +import java.util.logging.Level; + +import org.junit.Assert; import org.junit.Before; +import org.junit.FixMethodOrder; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import static org.anarres.cpp.Token.*; +import org.junit.runners.MethodSorters; + +import com.jogamp.gluegen.Logging; +import com.jogamp.gluegen.Logging.LoggerIf; +import com.jogamp.junit.util.SingletonJunitCase; + +import static com.jogamp.gluegen.jcpp.Token.*; import static org.junit.Assert.*; -public class PreprocessorTest { +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class PreprocessorTest extends SingletonJunitCase { - private static final Logger LOG = LoggerFactory.getLogger(PreprocessorTest.class); + private static final LoggerIf LOG = Logging.getLogger(PreprocessorTest.class); private OutputStreamWriter writer; private Preprocessor p; @Before public void setUp() throws Exception { + LOG.setLevel(Level.INFO); final PipedOutputStream po = new PipedOutputStream(); writer = new OutputStreamWriter(po); p = new Preprocessor(); + // p.addFeature(Feature.DEBUG); p.addInput( new LexerSource( new InputStreamReader( @@ -35,10 +48,9 @@ public class PreprocessorTest { } private static class I { - private final String t; - public I(String t) { + public I(final String t) { this.t = t; } @@ -51,10 +63,28 @@ public class PreprocessorTest { return getText(); } } - - private static I I(String t) { + private static I I(final String t) { return new I(t); } + private static class N { + private final String t; + + public N(final String t) { + this.t = t; + } + + public String getText() { + return t; + } + + @Override + public String toString() { + return getText(); + } + } + private static N N(final String t) { + return new N(t); + } /* * When writing tests in this file, remember the preprocessor @@ -63,7 +93,7 @@ public class PreprocessorTest { * the following input line. */ @Test - public void testPreprocessor() throws Exception { + public void test01Preprocessor() throws Exception { /* Magic macros */ testInput("line = __LINE__\n", I("line"), WHITESPACE, '=', WHITESPACE, NUMBER @@ -75,7 +105,11 @@ public class PreprocessorTest { /* Simple definitions */ testInput("#define A a /* a defined */\n", NL); + testInput("A /* a */\n", NL, I("a"), WHITESPACE, CCOMMENT); + testConstMacro("A", true, I("a")); testInput("#define B b /* b defined */\n", NL); + testInput("B /* b */\n", NL, I("b"), WHITESPACE, CCOMMENT); + testConstMacro("B", false, I("b")); testInput("#define C c /* c defined */\n", NL); /* Expansion of arguments */ @@ -107,20 +141,54 @@ public class PreprocessorTest { /* Redefinitions, undefinitions. */ testInput("#define two three\n", NL); + testInput("two /* three */\n", NL, I("three"), WHITESPACE, CCOMMENT); testInput("one /* one */\n", NL, I("one"), WHITESPACE, CCOMMENT); + testConstMacro("two", false, I("three")); + testConstMacro("two", true, I("three")); + testInput("#define one two\n", NL); testInput("one /* three */\n", NL, I("three"), WHITESPACE, CCOMMENT); + testConstMacro("one", false, I("two")); + testConstMacro("one", true, I("three")); + testInput("#undef two\n", NL); + testInput("one /* two */\n", NL, I("two"), WHITESPACE, CCOMMENT); + testConstMacro("one", false, I("two")); + testConstMacro("one", true, I("two")); + testInput("#define two five\n", NL); testInput("one /* five */\n", NL, I("five"), WHITESPACE, CCOMMENT); + testConstMacro("one", false, I("two")); + testConstMacro("one", true, I("five")); + testInput("#undef two\n", NL); testInput("one /* two */\n", NL, I("two"), WHITESPACE, CCOMMENT); + testConstMacro("one", false, I("two")); + testConstMacro("one", true, I("two")); + testInput("#undef one\n", NL); testInput("#define one four\n", NL); testInput("one /* four */\n", NL, I("four"), WHITESPACE, CCOMMENT); + testConstMacro("one", false, I("four")); + testConstMacro("one", true, I("four")); + testInput("#undef one\n", NL); testInput("#define one one\n", NL); testInput("one /* one */\n", NL, I("one"), WHITESPACE, CCOMMENT); + testConstMacro("one", false, I("one")); + testConstMacro("one", true, I("one")); + + testInput("#define NUM1 1\n", NL); + testInput("#define NUM4 ( 1 << ( NUM1 + NUM1 ) )\n", NL); + testInput("NUM4 /* ( 1 << ( 1 + 1 ) ) */\n", NL, + '(', WHITESPACE, N("1"), WHITESPACE, LSH, WHITESPACE, + '(', WHITESPACE, N("1"), WHITESPACE, '+', WHITESPACE, N("1"), WHITESPACE, ')', WHITESPACE, ')', + WHITESPACE, CCOMMENT); + testConstMacro("NUM4", false, '(', WHITESPACE, N("1"), WHITESPACE, LSH, WHITESPACE, + '(', WHITESPACE, I("NUM1"), WHITESPACE, '+', WHITESPACE, I("NUM1"), WHITESPACE, ')', + WHITESPACE, ')'); + testConstMacro("NUM4", true, '(', WHITESPACE, N("1"), WHITESPACE, LSH, WHITESPACE, + '(', WHITESPACE, N("1"), WHITESPACE, '+', WHITESPACE, N("1"), WHITESPACE, ')', WHITESPACE, ')'); /* Variadic macros. */ testInput("#define var(x...) a x __VA_ARGS__ b\n", NL); @@ -186,12 +254,12 @@ public class PreprocessorTest { Token t; do { t = p.token(); - LOG.warn("Remaining token " + t); + LOG.warning("Remaining token " + t); } while (t.getType() != EOF); } @Test - public void testPreprocessorUnterminated() throws Exception { + public void test02PreprocessorUnterminated() throws Exception { testInput("#ifndef X\na\n#else\nb\n"); // Bug #16 writer.close(); @@ -199,32 +267,38 @@ public class PreprocessorTest { Token t; do { t = p.token(); - LOG.warn("Remaining token " + t); + LOG.warning("Remaining token " + t); } while (t.getType() != EOF); } - public static void assertType(int type, Token t) { - String typeExpect = TokenType.getTokenName(type); - String typeActual = TokenType.getTokenName(t.getType()); + public static void assertType(final int type, final Token t) { + final String typeExpect = TokenType.getTokenName(type); + final String typeActual = TokenType.getTokenName(t.getType()); assertEquals("Expected " + typeExpect + " but got " + typeActual, type, t.getType()); } - private void testInput(String in, Object... out) + private void testInput(final String in, final Object... out) throws Exception { LOG.info("Input: " + in); writer.write(in); writer.flush(); - for (Object v : out) { - Token t = p.token(); - LOG.info(String.valueOf(t)); + for (final Object v : out) { + final Token t = p.token(); + LOG.info("READ: "+String.valueOf(t)); if (v instanceof String) { if (t.getType() != STRING) fail("Expected STRING, but got " + t); assertEquals(v, t.getValue()); } else if (v instanceof I) { - if (t.getType() != IDENTIFIER) + if (t.getType() != IDENTIFIER) { fail("Expected IDENTIFIER " + v + ", but got " + t); + } assertEquals(((I) v).getText(), t.getText()); + } else if (v instanceof N) { + if (t.getType() != NUMBER) { + fail("Expected NUMBER " + v + ", but got " + t); + } + assertEquals(((N) v).getText(), t.getText()); } else if (v instanceof Character) { assertType(((Character) v).charValue(), t); } else if (v instanceof Integer) { @@ -234,4 +308,69 @@ public class PreprocessorTest { } } } + // slow .. + private Macro findMacro(final List<Macro> macros, final String macroName) { + final int count = macros.size(); + for(int i=0; i<count; i++) { + final Macro m = macros.get(i); + if( m.getName().equals(macroName) ) { + return m; + } + } + return null; + } + private void dumpMacros(final List<Macro> macros) { + final int count = macros.size(); + System.err.println("Macro count: "+count); + for(int i=0; i<count; i++) { + final Macro m = macros.get(i); + System.err.println(" ["+i+"]: "+m); + } + } + private void testConstMacro(final String macroName, final boolean expandMacro, final Object... out) + throws Exception { + final List<Macro> macros = p.getMacros(expandMacro); + final Macro m = findMacro(macros, macroName); + if( null == m ) { + dumpMacros(macros); + } + Assert.assertNotNull("Macro <"+macroName+"> is missing!", m); + Assert.assertFalse(m.isFunctionLike()); + + final Source s = new MacroTokenSource(m, null); + try { + for (final Object v : out) { + final Token t = s.token(); + LOG.info("READ: "+String.valueOf(t)); + if (v instanceof String) { + if (t.getType() != STRING) { + fail("Expected STRING, but got " + t); + } + assertEquals(v, t.getValue()); + } else if (v instanceof I) { + if (t.getType() != IDENTIFIER) { + fail("Expected IDENTIFIER " + v + ", but got " + t); + } + assertEquals(((I) v).getText(), t.getText()); + } else if (v instanceof N) { + if (t.getType() != NUMBER) { + fail("Expected NUMBER " + v + ", but got " + t); + } + assertEquals(((N) v).getText(), t.getText()); + } else if (v instanceof Character) { + assertType(((Character) v).charValue(), t); + } else if (v instanceof Integer) { + assertType(((Number) v).intValue(), t); + } else { + fail("Bad object " + v.getClass()); + } + } + } finally { + s.close(); + } + } + public static void main(final String args[]) throws IOException { + final String tstname = PreprocessorTest.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } } diff --git a/src/test/java/com/jogamp/gluegen/jcpp/TokenPastingWhitespaceTest.java b/src/test/java/com/jogamp/gluegen/jcpp/TokenPastingWhitespaceTest.java new file mode 100644 index 0000000..ff556ad --- /dev/null +++ b/src/test/java/com/jogamp/gluegen/jcpp/TokenPastingWhitespaceTest.java @@ -0,0 +1,59 @@ +package com.jogamp.gluegen.jcpp; + +import com.jogamp.common.util.IOUtil; + +import java.io.IOException; +import java.io.Reader; + +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +import com.jogamp.gluegen.Logging; +import com.jogamp.gluegen.Logging.LoggerIf; +import com.jogamp.junit.util.SingletonJunitCase; + +import static org.junit.Assert.*; + +/** + * https://github.com/shevek/jcpp/issues/25 + * + * @author shevek + */ +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TokenPastingWhitespaceTest extends SingletonJunitCase { + + private static final LoggerIf LOG = Logging.getLogger(TokenPastingWhitespaceTest.class); + + @Test + public void test01WhitespacePasting() throws IOException { + final Preprocessor pp = new Preprocessor(); + testWhitespacePastingImpl(pp); + } + void testWhitespacePastingImpl(final Preprocessor pp) throws IOException { + pp.addInput(new StringLexerSource( + "#define ONE(arg) one_##arg\n" + + "#define TWO(arg) ONE(two_##arg)\n" + + "\n" + + "TWO(good)\n" + + "TWO( /* evil newline */\n" + + " bad)\n" + + "\n" + + "ONE(good)\n" + + "ONE( /* evil newline */\n" + + " bad)\n", true)); + final Reader r = new CppReader(pp); + final String text = IOUtil.appendCharStream(new StringBuilder(), r).toString().trim(); + LOG.info("Output is:\n" + text); + assertEquals("one_two_good\n" + + "one_two_bad\n" + + "\n" + + "one_good\n" + + "one_bad", text); + } + + public static void main(final String args[]) throws IOException { + final String tstname = TokenPastingWhitespaceTest.class.getName(); + org.junit.runner.JUnitCore.main(tstname); + } +} diff --git a/src/test/java/org/anarres/cpp/BuildMetadataTest.java b/src/test/java/org/anarres/cpp/BuildMetadataTest.java deleted file mode 100644 index 42dc071..0000000 --- a/src/test/java/org/anarres/cpp/BuildMetadataTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.anarres.cpp; - -import com.google.common.base.Charsets; -import com.google.common.io.Resources; -import java.net.URL; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * @author shevek - */ -public class BuildMetadataTest { - - private static final Logger LOG = LoggerFactory.getLogger(BuildMetadataTest.class); - - @Test - public void testProperties() throws Exception { - URL url = Resources.getResource("META-INF/jcpp.properties"); - String text = Resources.asCharSource(url, Charsets.ISO_8859_1).read(); - LOG.info("Metadata is " + text); - } - - @Test - public void testMetadata() throws Exception { - BuildMetadata metadata = BuildMetadata.getInstance(); - LOG.info("Version is " + metadata.getVersion()); - LOG.info("BuildDate is " + metadata.getBuildDate()); - LOG.info("ChangeId is " + metadata.getChangeId()); - } - -} diff --git a/src/test/java/org/anarres/cpp/IncludeAbsoluteTest.java b/src/test/java/org/anarres/cpp/IncludeAbsoluteTest.java deleted file mode 100644 index df7ffb7..0000000 --- a/src/test/java/org/anarres/cpp/IncludeAbsoluteTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.anarres.cpp; - -import com.google.common.io.CharStreams; -import java.io.BufferedReader; -import java.io.File; -import java.io.Reader; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import static org.junit.Assert.*; - -/** - * - * @author shevek - */ -public class IncludeAbsoluteTest { - - private static final Logger LOG = LoggerFactory.getLogger(IncludeAbsoluteTest.class); - - @Test - public void testAbsoluteInclude() throws Exception { - File file = new File("build/resources/test/absolute.h"); - assertTrue(file.exists()); - - String input = "#include <" + file.getAbsolutePath() + ">\n"; - LOG.info("Input: " + input); - Preprocessor pp = new Preprocessor(); - pp.addInput(new StringLexerSource(input, true)); - Reader r = new CppReader(pp); - String output = CharStreams.toString(r); - r.close(); - LOG.info("Output: " + output); - assertTrue(output.contains("absolute-result")); - } -} diff --git a/src/test/java/org/anarres/cpp/MainTest.java b/src/test/java/org/anarres/cpp/MainTest.java deleted file mode 100644 index 5ff7350..0000000 --- a/src/test/java/org/anarres/cpp/MainTest.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.anarres.cpp; - -import org.junit.Test; - -public class MainTest { - - @Test - public void testMain() throws Exception { - Main.main(new String[]{"--version"}); - } -} diff --git a/src/test/java/org/anarres/cpp/PragmaTest.java b/src/test/java/org/anarres/cpp/PragmaTest.java deleted file mode 100644 index 342bd52..0000000 --- a/src/test/java/org/anarres/cpp/PragmaTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.anarres.cpp; - -import com.google.common.base.Charsets; -import com.google.common.io.CharSource; -import com.google.common.io.CharStreams; -import com.google.common.io.Files; -import java.io.File; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import static org.junit.Assert.*; - -/** - * - * @author shevek - */ -public class PragmaTest { - - private static final Logger LOG = LoggerFactory.getLogger(PragmaTest.class); - - @Test - public void testPragma() throws Exception { - File file = new File("build/resources/test/pragma.c"); - assertTrue(file.exists()); - - CharSource source = Files.asCharSource(file, Charsets.UTF_8); - CppReader r = new CppReader(source.openBufferedStream()); - r.getPreprocessor().setListener(new DefaultPreprocessorListener()); - String output = CharStreams.toString(r); - r.close(); - LOG.info("Output: " + output); - // assertTrue(output.contains("absolute-result")); - } -} diff --git a/src/test/java/org/anarres/cpp/RegressionTest.java b/src/test/java/org/anarres/cpp/RegressionTest.java deleted file mode 100644 index 3ce3568..0000000 --- a/src/test/java/org/anarres/cpp/RegressionTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.anarres.cpp; - -import com.google.common.base.Charsets; -import com.google.common.io.CharStreams; -import com.google.common.io.Files; -import com.google.common.io.PatternFilenameFilter; -import java.io.File; -import java.io.StringReader; -import java.util.ArrayList; -import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import static org.junit.Assert.assertEquals; - -/** - * - * @author shevek - */ -@RunWith(Parameterized.class) -public class RegressionTest { - - private static final Logger LOG = LoggerFactory.getLogger(RegressionTest.class); - - @Parameterized.Parameters(name = "{0}") - public static List<Object[]> data() throws Exception { - List<Object[]> out = new ArrayList<Object[]>(); - - File dir = new File("build/resources/test/regression"); - for (File inFile : dir.listFiles(new PatternFilenameFilter(".*\\.in"))) { - String name = Files.getNameWithoutExtension(inFile.getName()); - File outFile = new File(dir, name + ".out"); - out.add(new Object[]{name, inFile, outFile}); - } - - return out; - } - - private final String name; - private final File inFile; - private final File outFile; - - public RegressionTest(String name, File inFile, File outFile) { - this.name = name; - this.inFile = inFile; - this.outFile = outFile; - } - - @Test - public void testRegression() throws Exception { - String inText = Files.toString(inFile, Charsets.UTF_8); - LOG.info("Read " + name + ":\n" + inText); - CppReader cppReader = new CppReader(new StringReader(inText)); - String cppText = CharStreams.toString(cppReader); - LOG.info("Generated " + name + ":\n" + cppText); - if (outFile.exists()) { - String outText = Files.toString(outFile, Charsets.UTF_8); - LOG.info("Expected " + name + ":\n" + outText); - assertEquals(outText, inText); - } - - } -} diff --git a/src/test/java/org/anarres/cpp/TokenPastingWhitespaceTest.java b/src/test/java/org/anarres/cpp/TokenPastingWhitespaceTest.java deleted file mode 100644 index 2e6a2b5..0000000 --- a/src/test/java/org/anarres/cpp/TokenPastingWhitespaceTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.anarres.cpp; - -import com.google.common.io.CharStreams; -import java.io.IOException; -import java.io.Reader; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import static org.junit.Assert.*; - -/** - * https://github.com/shevek/jcpp/issues/25 - * - * @author shevek - */ -public class TokenPastingWhitespaceTest { - - private static final Logger LOG = LoggerFactory.getLogger(TokenPastingWhitespaceTest.class); - - @Test - public void testWhitespacePasting() throws IOException { - Preprocessor pp = new Preprocessor(); - pp.addInput(new StringLexerSource( - "#define ONE(arg) one_##arg\n" - + "#define TWO(arg) ONE(two_##arg)\n" - + "\n" - + "TWO(good)\n" - + "TWO( /* evil newline */\n" - + " bad)\n" - + "\n" - + "ONE(good)\n" - + "ONE( /* evil newline */\n" - + " bad)\n", true)); - Reader r = new CppReader(pp); - String text = CharStreams.toString(r).trim(); - LOG.info("Output is:\n" + text); - assertEquals("one_two_good\n" - + "one_two_bad\n" - + "\n" - + "one_good\n" - + "one_bad", text); - } -} diff --git a/src/test/java/org/anarres/cpp/VaArgsPastingTest.java b/src/test/java/org/anarres/cpp/VaArgsPastingTest.java deleted file mode 100644 index f1bcbcd..0000000 --- a/src/test/java/org/anarres/cpp/VaArgsPastingTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.anarres.cpp; - -import com.google.common.io.CharStreams; -import java.io.IOException; -import java.io.Reader; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import static org.junit.Assert.*; - -/** - * - * @author shevek - */ -public class VaArgsPastingTest { - - private static final Logger LOG = LoggerFactory.getLogger(VaArgsPastingTest.class); - - @Test - public void testWhitespacePasting() throws IOException { - String input - = "#define REGULAR_ARGS(x, y) foo(x, y)\n" - + "#define REGULAR_ELLIPSIS(x, y...) foo(x, y)\n" - + "#define REGULAR_VAARGS(x, ...) foo(x, __VA_ARGS__)\n" - + "#define PASTE_ARGS(x, y) foo(x, ## y)\n" - + "#define PASTE_ELLIPSIS(x, y...) foo(x, ## y)\n" - + "#define PASTE_VAARGS(x, ...) foo(x, ## __VA_ARGS__)\n" - + "" - + "REGULAR_ARGS(a, b) // REGULAR_ARGS 2\n" - + "REGULAR_ELLIPSIS(a, b) // REGULAR_ELLIPSIS 2\n" - + "REGULAR_ELLIPSIS(a) // REGULAR_ELLIPSIS 1\n" - + "REGULAR_VAARGS(a, b) // REGULAR_VAARGS 2\n" - + "REGULAR_VAARGS(a) // REGULAR_VAARGS 1\n" - + "" - + "PASTE_ARGS(a, b) // PASTE_ARGS 2\n" - + "PASTE_ELLIPSIS(a, b) // PASTE_ELLIPSIS 2\n" - + "PASTE_ELLIPSIS(a) // PASTE_ELLIPSIS 1\n" - + "PASTE_VAARGS(a, b) // PASTE_VAARGS 2\n" - + "PASTE_VAARGS(a) // PASTE_VAARGS 1\n"; - LOG.info("Input is:\n" + input); - Preprocessor pp = new Preprocessor(); - pp.addFeature(Feature.KEEPCOMMENTS); - pp.addInput(new StringLexerSource(input, true)); - Reader r = new CppReader(pp); - String output = CharStreams.toString(r).trim(); - LOG.info("Output is:\n" + output); - assertEquals("foo(a, b) // REGULAR_ARGS 2\n" - + "foo(a, b) // REGULAR_ELLIPSIS 2\n" - + "foo(a, ) // REGULAR_ELLIPSIS 1\n" - + "foo(a, b) // REGULAR_VAARGS 2\n" - + "foo(a, ) // REGULAR_VAARGS 1\n" - + "foo(a,b) // PASTE_ARGS 2\n" // cpp outputs a warning and a space after the comma, similar below. - + "foo(a,b) // PASTE_ELLIPSIS 2\n" - + "foo(a) // PASTE_ELLIPSIS 1\n" - + "foo(a,b) // PASTE_VAARGS 2\n" - + "foo(a) // PASTE_VAARGS 1", output); - } -} |