├── .gitattributes
├── .github
├── dco.yml
├── pull_request_template.md
└── workflows
│ └── mirror.yml
├── .gitignore
├── LICENSE
├── README.md
├── RELEASE_SUPPORT.md
├── build.gradle
├── doc
└── parser
│ └── TreeNodes.dia
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── kiara.gradle
├── pom.xml
├── settings.gradle
├── src
├── it
│ └── java
│ │ └── com
│ │ └── eprosima
│ │ └── integration
│ │ ├── Command.java
│ │ ├── Test.java
│ │ └── TestManager.java
└── main
│ ├── antlr
│ └── com
│ │ └── eprosima
│ │ └── idl
│ │ └── parser
│ │ └── grammar
│ │ └── IDL.g4
│ ├── antlr4
│ └── kiara
│ │ └── com
│ │ └── eprosima
│ │ └── idl
│ │ └── parser
│ │ └── grammar
│ │ └── KIARAIDL.g4
│ ├── java
│ └── com
│ │ └── eprosima
│ │ ├── idl
│ │ ├── context
│ │ │ └── Context.java
│ │ ├── generator
│ │ │ └── manager
│ │ │ │ ├── TemplateErrorListener.java
│ │ │ │ ├── TemplateGroup.java
│ │ │ │ ├── TemplateManager.java
│ │ │ │ ├── TemplateST.java
│ │ │ │ ├── TemplateSTGroup.java
│ │ │ │ └── TemplateUtil.java
│ │ ├── parser
│ │ │ ├── exception
│ │ │ │ ├── ParseException.java
│ │ │ │ └── RuntimeGenerationException.java
│ │ │ ├── listener
│ │ │ │ └── DefaultErrorListener.java
│ │ │ ├── strategy
│ │ │ │ └── DefaultErrorStrategy.java
│ │ │ ├── tree
│ │ │ │ ├── Annotation.java
│ │ │ │ ├── AnnotationDeclaration.java
│ │ │ │ ├── AnnotationMember.java
│ │ │ │ ├── ConstDeclaration.java
│ │ │ │ ├── Definition.java
│ │ │ │ ├── DefinitionContainer.java
│ │ │ │ ├── Exception.java
│ │ │ │ ├── Export.java
│ │ │ │ ├── ExportContainer.java
│ │ │ │ ├── Inherits.java
│ │ │ │ ├── Interface.java
│ │ │ │ ├── Module.java
│ │ │ │ ├── Notebook.java
│ │ │ │ ├── Operation.java
│ │ │ │ ├── Param.java
│ │ │ │ ├── Specification.java
│ │ │ │ ├── TreeNode.java
│ │ │ │ └── TypeDeclaration.java
│ │ │ └── typecode
│ │ │ │ ├── AliasTypeCode.java
│ │ │ │ ├── AnyTypeCode.java
│ │ │ │ ├── ArrayTypeCode.java
│ │ │ │ ├── Bitfield.java
│ │ │ │ ├── BitfieldSpec.java
│ │ │ │ ├── Bitmask.java
│ │ │ │ ├── BitmaskTypeCode.java
│ │ │ │ ├── BitsetTypeCode.java
│ │ │ │ ├── CollectionElement.java
│ │ │ │ ├── ContainerTypeCode.java
│ │ │ │ ├── EnumMember.java
│ │ │ │ ├── EnumTypeCode.java
│ │ │ │ ├── Kind.java
│ │ │ │ ├── MapTypeCode.java
│ │ │ │ ├── Member.java
│ │ │ │ ├── MemberAppliedAnnotations.java
│ │ │ │ ├── MemberedTypeCode.java
│ │ │ │ ├── PrimitiveTypeCode.java
│ │ │ │ ├── SequenceTypeCode.java
│ │ │ │ ├── SetTypeCode.java
│ │ │ │ ├── StringTypeCode.java
│ │ │ │ ├── StructTypeCode.java
│ │ │ │ ├── TypeCode.java
│ │ │ │ ├── UnionMember.java
│ │ │ │ └── UnionTypeCode.java
│ │ ├── test
│ │ │ └── TestIDLParser.java
│ │ └── util
│ │ │ ├── Pair.java
│ │ │ └── Util.java
│ │ ├── log
│ │ ├── ColorMessage.java
│ │ └── Log.java
│ │ └── solution
│ │ ├── GUIDGenerator.java
│ │ ├── Project.java
│ │ └── Solution.java
│ └── resources
│ └── com
│ └── eprosima
│ └── idl
│ └── templates
│ ├── CTypes.stg
│ ├── JavaTypes.stg
│ ├── Types.stg
│ ├── TypesCInterface.stg
│ └── idlTypes.stg
└── test
└── idls
└── xtypes
├── dds-builtin_types.idl
├── dds-language_binding.idl
├── dds-xtypes_discovery.idl
└── dds-xtypes_typeobject.idl
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Set default behaviour, in case users don't have core.autocrlf set.
2 | * text=auto
3 |
4 | # Explicitly declare text files we want to always be normalized and converted
5 | # to native line endings on checkout.
6 | *.c text
7 | *.cpp text
8 | *.cxx text
9 | *.h text
10 | *.java text
11 | *.stg text
12 | *.idl text
13 |
14 | # Declare files that will always have CRLF line endings on checkout.
15 | *.sln text eol=crlf
16 | *.vcxproj text eol=crlf
17 | *.vcxproj.filters text eol=crlf
18 | *.bat text eol=crlf
19 |
20 | # Denote all files that are truly binary and should not be modified.
21 | *.png binary
22 | *.jpg binary
23 |
24 | # To diff LibreOffice documents.
25 | # It is needed next configuration value: diff.odf.textconv=odt2txt
26 | *.ods diff=odf
27 | *.odt diff=odf
28 | *.odp diff=odf
29 |
--------------------------------------------------------------------------------
/.github/dco.yml:
--------------------------------------------------------------------------------
1 | require:
2 | members: false
3 |
--------------------------------------------------------------------------------
/.github/pull_request_template.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 | ## Description
13 |
14 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | ## Contributor Checklist
33 |
34 |
38 |
39 | - [ ] Commit messages follow the project guidelines.
40 | - [ ] Tests that thoroughly check the new feature have been added/Regression tests checking the bug and its fix have been added; the added tests pass locally
41 | - [ ] Any new/modified methods have been properly documented.
42 | - [ ] Changes are backport compatible: they do **NOT** break ABI nor change library core behavior.
43 | - [ ] Changes are API compatible.
44 | - [ ] Applicable backports have been included in the description.
45 |
46 | ## Reviewer Checklist
47 |
48 | - [ ] The PR has a milestone assigned.
49 | - [ ] The title and description correctly express the PR's purpose.
50 | - [ ] Check contributor checklist is correct.
51 |
--------------------------------------------------------------------------------
/.github/workflows/mirror.yml:
--------------------------------------------------------------------------------
1 | # .github/workflows/mirror.yml
2 | on:
3 | push:
4 | branches:
5 | - 'master'
6 | jobs:
7 | mirror_job:
8 | runs-on: ubuntu-latest
9 | name: Mirror master branch to API & ABI compatible minor version branches
10 | strategy:
11 | fail-fast: false
12 | matrix:
13 | dest_branch:
14 | - '4.1.x'
15 | - '4.x'
16 | steps:
17 | - name: Mirror action step
18 | id: mirror
19 | uses: eProsima/eProsima-CI/external/mirror-branch-action@v0
20 | with:
21 | github-token: ${{ secrets.GITHUB_TOKEN }}
22 | source: 'master'
23 | dest: ${{ matrix.dest_branch }}
24 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Backup GVim files.
2 | *~
3 | # Temporaly GVim files.
4 | *.swp
5 | # Visual Studio user configuration files.
6 | *.vcxproj.user
7 | *.sdf
8 | *.opensdf
9 | *.suo
10 | # Visual Studio build directories.
11 | Debug*/
12 | Release*/
13 | ipch/
14 | objs/
15 | output/
16 | bin/
17 | # Lib directory
18 | lib/
19 | # Tags info
20 | tags
21 | cscope.out
22 | # Compiled python objects
23 | *.pyc
24 |
25 | #### Project files ####
26 |
27 | # Generated Java source
28 | /src/main/generated-java/
29 | src/com/eprosima/idl/parser/grammar/IDLLexer.java
30 | src/com/eprosima/idl/parser/grammar/IDLLexer.smap
31 | src/com/eprosima/idl/parser/grammar/IDLParser.java
32 | src/com/eprosima/idl/parser/grammar/IDLParser.smap
33 | src/com/eprosima/idl/parser/grammar/IDLTokenTypes.java
34 | src/com/eprosima/idl/parser/grammar/IDLTokenTypes.txt
35 | /target/
36 | /build
37 | /.gradle
38 |
39 | # IntelliJ files
40 | .idea
41 | *.iml
42 |
43 | # Eclipse files
44 | .project
45 | .classpath
46 | .settings
47 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # IDL Parser
2 |
3 | *eProsima IDL Parser* is a Java library that provides API to extract information about an IDL file defined following the [OMG Interface Definition Language specification](https://www.omg.org/spec/IDL/4.2/About-IDL).
4 |
5 | ## Commercial support
6 |
7 | Looking for commercial support? Write us to info@eprosima.com
8 |
9 | Find more about us at [eProsima’s webpage](https://eprosima.com/).
10 |
--------------------------------------------------------------------------------
/RELEASE_SUPPORT.md:
--------------------------------------------------------------------------------
1 | # Release support
2 |
3 | Please, refer to the [master branch](https://github.com/eProsima/IDL-Parser/blob/master/RELEASE_SUPPORT.md) for the latest version of this document.
4 |
5 | *eProsima IDL parser* maintains several releases with different support cycles.
6 | **All of them are attached to different *eProsima Fast DDS-Gen* releases.**
7 |
8 | ## *eProsima Fast DDS-Gen* and *IDL parser* supported version compatibility
9 |
10 | |Fast DDS-Gen Version|IDL parser Version|IDL parser Version branch|IDL parser Latest Release|
11 | |--------------------|------------------|-------------------------|-------------------------|
12 | |4.0|4.0|[4.0.x](https://github.com/eProsima/IDL-Parser/tree/4.0.x)|[v4.0.4](https://github.com/eProsima/IDL-Parser/releases/tag/v4.0.4)|
13 | |3.3|3.0|[3.0.x](https://github.com/eProsima/IDL-Parser/tree/3.0.x)|[v3.0.1](https://github.com/eProsima/IDL-Parser/releases/tag/v3.0.1)|
14 | |2.5|1.5|[1.5.x](https://github.com/eProsima/IDL-Parser/tree/1.5.x)|[v1.5.0](https://github.com/eProsima/IDL-Parser/releases/tag/v1.5.0)|
15 | |2.1|1.2|[1.2.x](https://github.com/eProsima/IDL-Parser/tree/1.2.x)|[v1.2.0](https://github.com/eProsima/IDL-Parser/releases/tag/v1.2.0)|
16 |
17 | ## *eProsima Fast DDS-Gen* and *IDL parser* previously supported version compatibility
18 |
19 | |Fast DDS-Gen Version|IDL parser Version|IDL parser Version branch|IDL parser Latest Release|Release Date|EOL Date|
20 | |--------------------|------------------|-------------------------|-------------------------|------------|--------|
21 | |3.2|3.0|[3.0.x](https://github.com/eProsima/IDL-Parser/tree/3.0.x)|[v3.0.0](https://github.com/eProsima/IDL-Parser/releases/tag/v3.0.0)|December 2023|July 2024|
22 | |3.1|2.0|[2.0.x](https://github.com/eProsima/IDL-Parser/tree/2.0.x)|[v2.0.0](https://github.com/eProsima/IDL-Parser/releases/tag/v2.0.0)|November 2023|March 2024|
23 | |2.5|1.6|[1.6.x](https://github.com/eProsima/IDL-Parser/tree/1.6.x)|[v1.6.0](https://github.com/eProsima/IDL-Parser/releases/tag/v1.6.0)|June 2023|February 2024|
24 |
25 | For detailed information about the lifecycle of the different *Fast DDS-Gen* versions (and their corresponding counterpart in this repository), please refer to the [release support section of the Fast DDS-Gen repository](https://github.com/eProsima/Fast-DDS-Gen/blob/master/RELEASE_SUPPORT.md).
26 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // internal plugins
16 | apply plugin: 'java-library'
17 | apply plugin: 'maven-publish'
18 | apply plugin: 'eclipse' // Eclipse integration
19 | apply plugin: 'antlr'
20 |
21 | description = """"""
22 |
23 | ext {
24 | publishURL = project.hasProperty('publishURL') ? project.publishURL.toString() : ''
25 | publishUsername = project.hasProperty('publishUsername') ? project.publishUsername.toString() : ''
26 | publishPassword = project.hasProperty('publishPassword') ? project.publishPassword.toString() : ''
27 | }
28 |
29 | repositories {
30 | mavenCentral()
31 | }
32 |
33 | dependencies {
34 | antlr('org.antlr:antlr4:4.13.0')
35 | implementation group: 'org.openjdk.nashorn', name: 'nashorn-core', version:'15.4'
36 | }
37 |
38 | generateGrammarSource {
39 | arguments += ["-long-messages", "-package", "com.eprosima.idl.parser.grammar"]
40 | }
41 |
42 | compileJava {
43 | sourceCompatibility = 1.8
44 | targetCompatibility = 1.8
45 | options.compilerArgs.add('-Xlint:deprecation')
46 | options.compilerArgs.add('-Xlint:unchecked')
47 | }
48 |
49 | // add the generated source files to the list of java sources
50 |
51 | sourceSets {
52 | main {
53 | java {
54 | srcDir 'src/main/java'
55 | srcDir 'src/it/java' //integration tests
56 | }
57 | }
58 | }
59 |
60 | group = "com.eprosima"
61 | version = "4.1.0"
62 |
63 | //general properties
64 | jar {
65 | duplicatesStrategy 'exclude'
66 | from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
67 | archiveBaseName = 'idlparser'
68 | manifest {
69 | attributes("Created-By": "eProsima", "Main-Class": "com.eprosima.idl.test.TestIDLParser")
70 | }
71 | }
72 |
73 | task sourceJar(type: Jar, dependsOn: classes) {
74 | classifier = 'sources'
75 | from sourceSets.main.allJava
76 | }
77 |
78 | /**
79 | * Set up publishing. User must set the following properties
80 | * in ~/.gradle/gradle.properties or pass via -Pproperty=value
81 | * on command line.
82 | *
83 | * publishUsername=yourusername
84 | * publishPassword=yourpassword
85 | * publishUrl=https://some.url/maven/orgname/reponame/projectname
86 | */
87 | publishing {
88 | publications {
89 | mavenJava(MavenPublication) {
90 | artifactId = "idl-parser"
91 | from components.java
92 |
93 | artifact sourceJar {
94 | classifier 'sources'
95 | }
96 | }
97 | }
98 | repositories {
99 | maven {
100 | url publishURL
101 | credentials.username = publishUsername
102 | credentials.password = publishPassword
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/doc/parser/TreeNodes.dia:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eProsima/IDL-Parser/eb21a465673557d0c7e528b56f83a6e1738a0c50/doc/parser/TreeNodes.dia
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eProsima/IDL-Parser/eb21a465673557d0c7e528b56f83a6e1738a0c50/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Nov 12 12:30:06 CET 2014
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/kiara.gradle:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // In this section you declare the used plugins
16 | // community plugins
17 | plugins {
18 | id "me.champeau.gradle.antlr4" version "0.1" // antlr4 community plugin.
19 | }
20 |
21 | // internal plugins
22 | apply plugin: 'java'
23 | apply plugin: 'maven' // only needed to generate POM or to upload artifacts to maven repos.
24 | apply plugin: 'eclipse' // Eclipse integration
25 | apply plugin: 'idea' // InteliJ IDEA integration
26 | apply plugin: 'project-report'
27 |
28 | //general properties
29 | jar {
30 | baseName = 'kiaraparser'
31 | version = '0.1.0'
32 | }
33 |
34 | description = """"""
35 |
36 | // java plugin properties
37 | sourceCompatibility = 1.8
38 | targetCompatibility = 1.8
39 |
40 | // additional compile options (linters)
41 | tasks.withType(JavaCompile) {
42 | options.compilerArgs.add('-Xlint:deprecation')
43 | options.compilerArgs.add('-Xlint:unchecked')
44 | }
45 |
46 | // maven-plugin properties
47 | group = 'com.eprosima.idl'
48 |
49 | // antlr4-plugin configuration
50 | // make the Java compile task depend on the antlr4 task
51 | compileJava.dependsOn antlr4
52 | // add the generated source files to the list of java sources
53 | sourceSets.main.java.srcDirs += antlr4.output
54 | // add antlr4 to classpath
55 | configurations {
56 | compile.extendsFrom antlr4
57 | }
58 |
59 | // In this section you declare where to find the dependencies of your project
60 | // see also: http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html#N10621
61 | repositories {
62 | // You can declare any Maven/Ivy/file repository here.
63 | // e.g. for 'jcenter.bintray.com' for resolving your dependencies use:
64 | // jcenter()
65 | // and/or use the standard mavenCentral repositoy:
66 | mavenCentral()
67 | // and/or use use a custom maven repository:
68 | // maven { url "http://repo.mycompany.com/maven2" }
69 | }
70 |
71 | dependencies {
72 | compile group: 'org.antlr', name: 'antlr4', version:'4.5'
73 | compile group: 'org.antlr', name: 'stringtemplate', version:'3.2'
74 | }
75 |
76 | antlr4.source = project.file("src/main/antlr4/kiara")
77 | antlr4.listener = true
78 | antlr4.visitor = true
79 | antlr4.extraArgs=['-package', 'com.eprosima.idl.parser.grammar']
80 |
81 | // make the Java compile task depend on the antlr4 task
82 | compileJava.dependsOn antlr4
83 |
84 | // add the generated source files to the list of java sources
85 | sourceSets.main.java.srcDirs += antlr4.output
86 |
87 | // add antlr4 to classpath
88 | configurations {
89 | compile.extendsFrom antlr4
90 | }
91 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 | com.eprosima.idl
6 | com.eprosima.idl
7 | 4.1.0
8 | jar
9 |
10 |
11 | idlparser-${project.version}
12 |
13 |
14 | org.antlr
15 | antlr4-maven-plugin
16 | 4.5
17 |
18 | src/main/antlr
19 |
20 | -package
21 | com.eprosima.idl.parser.grammar
22 |
23 |
24 |
25 |
26 | antlr
27 |
28 | antlr4
29 |
30 |
31 |
32 |
33 |
34 | maven-compiler-plugin
35 | 3.1
36 |
37 | 1.8
38 | 1.8
39 |
40 |
41 |
42 |
43 | maven-assembly-plugin
44 | 3.1.1
45 |
46 |
47 | package
48 |
49 | single
50 |
51 |
52 |
53 |
54 |
55 | jar-with-dependencies
56 |
57 | ${project.finalName}
58 | false
59 |
60 |
61 |
62 |
63 | org.apache.maven.plugins
64 | maven-jar-plugin
65 | 3.1.1
66 |
67 |
68 |
69 | **/log4j.properties
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 | org.antlr
80 | antlr4
81 | 4.5
82 |
83 |
84 | org.antlr
85 | stringtemplate
86 | 3.2
87 |
88 |
89 |
90 | UTF-8
91 | 1.8
92 | 1.8
93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'com.kiara'
2 |
--------------------------------------------------------------------------------
/src/it/java/com/eprosima/integration/Command.java:
--------------------------------------------------------------------------------
1 | package com.eprosima.integration;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.File;
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 | import java.io.InputStreamReader;
8 | import java.util.Arrays;
9 | import java.util.List;
10 | import java.util.ArrayList;
11 | import java.util.concurrent.CompletableFuture;
12 |
13 | public class Command
14 | {
15 | private Command()
16 | {
17 | }
18 |
19 | static CompletableFuture readOutStream(
20 | InputStream is)
21 | {
22 | return CompletableFuture.supplyAsync(() -> {
23 | try (
24 | InputStreamReader isr = new InputStreamReader(is);
25 | BufferedReader br = new BufferedReader(isr);
26 | ) {
27 | StringBuilder res = new StringBuilder();
28 | String inputLine;
29 | while ((inputLine = br.readLine()) != null)
30 | {
31 | res.append(inputLine).append(System.lineSeparator());
32 | }
33 | return res.toString();
34 | }
35 | catch (Throwable e)
36 | {
37 | throw new RuntimeException("problem with executing program", e);
38 | }
39 | });
40 | }
41 |
42 | public static boolean execute(
43 | String command,
44 | String from,
45 | boolean print_only_stderr,
46 | boolean fail_if_stderr)
47 | {
48 | try
49 | {
50 | System.out.println("Executing command: " + command);
51 | List arguments = Arrays.asList(command.split(" "));
52 | ProcessBuilder processBuilder = new ProcessBuilder(arguments);
53 | processBuilder.directory(from != null ? new File(from) : null);
54 |
55 | Process process = processBuilder.start();
56 |
57 | CompletableFuture soutFut = readOutStream(process.getInputStream());
58 | CompletableFuture serrFut = readOutStream(process.getErrorStream());
59 | CompletableFuture resultFut =
60 | soutFut.thenCombine(serrFut, (stdout, stderr) ->
61 | {
62 | if (2 < stderr.length())
63 | {
64 | System.err.println("------------------------------ stderr -------------------------------------");
65 | System.err.println(stderr);
66 | }
67 |
68 | return stdout;
69 | });
70 | // get stdout once ready, blocking
71 | String result = resultFut.get();
72 | process.waitFor();
73 | boolean status = (process.exitValue() == 0) && (!fail_if_stderr || 2 >= serrFut.get().length());
74 |
75 | if (!status || !print_only_stderr)
76 | {
77 | System.err.println("------------------------------ stdout -------------------------------------");
78 | System.out.println(result);
79 | }
80 |
81 | return status;
82 | }
83 | catch (IOException e)
84 | {
85 | System.err.println("Error executing: " + command);
86 | e.printStackTrace();
87 | return false;
88 | }
89 | catch (InterruptedException e)
90 | {
91 | System.err.println("Error Interrupted execution: " + command);
92 | e.printStackTrace();
93 | return false;
94 | }
95 | catch (Exception e)
96 | {
97 | System.err.println("Error: " + command);
98 | e.printStackTrace();
99 | return false;
100 | }
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/src/it/java/com/eprosima/integration/Test.java:
--------------------------------------------------------------------------------
1 | package com.eprosima.integration;
2 |
3 | import java.io.File;
4 | import java.util.List;
5 |
6 | public class Test
7 | {
8 |
9 | private String idl;
10 | private String outputPath;
11 | private boolean errorOutputOnly;
12 |
13 | public Test(String idl, String outputPath, boolean errorOutputOnly)
14 | {
15 | this.idl = idl;
16 | this.outputPath = outputPath + "/" + idl;
17 | this.errorOutputOnly = errorOutputOnly;
18 | }
19 | ;
20 | public String getIDL()
21 | {
22 | return idl;
23 | }
24 |
25 | public boolean prepare()
26 | {
27 | File outputPathFolder = new File(outputPath + "/build");
28 | boolean prepared = false;
29 | if(outputPathFolder.exists() && outputPathFolder.isDirectory())
30 | {
31 | prepared = true;
32 | }
33 | else
34 | {
35 | prepared= outputPathFolder.mkdirs();
36 | }
37 |
38 | if(prepared)
39 | {
40 | System.out.println("Done!");
41 | }
42 | return prepared;
43 | }
44 |
45 | public boolean generate(
46 | String generatorName,
47 | String inputPath,
48 | String exampleArch,
49 | boolean testFlag)
50 | {
51 | String program = "java -jar " + generatorName + ".jar";
52 | String flags = " -replace -example" + " " + exampleArch + (testFlag ? " -test -default-container-prealloc-size 50" : "");
53 | String output = " -d " + outputPath;
54 |
55 | String idlPath = " " + inputPath + "/" + idl + ".idl";
56 |
57 | if (idl.equals("external") || idl.equals("declarations"))
58 | {
59 | flags = flags + " -no-typeobjectsupport";
60 | }
61 |
62 | String command = program + flags + output + idlPath;
63 |
64 | return Command.execute(command, null, errorOutputOnly, true);
65 | }
66 |
67 | public boolean generate(
68 | String generatorName,
69 | String inputPath,
70 | boolean testFlag)
71 | {
72 | String program = "java -jar " + generatorName + ".jar";
73 | String flags = " -replace -example" + (testFlag ? " -test -default-container-prealloc-size 50" : "");
74 | String output = " -d " + outputPath;
75 |
76 | String idlPath = " " + inputPath + "/" + idl + ".idl";
77 |
78 | if (idl.equals("external") || idl.equals("declarations"))
79 | {
80 | flags = flags + " -no-typeobjectsupport";
81 | }
82 |
83 | String command = program + flags + output + idlPath;
84 | return Command.execute(command, null, errorOutputOnly, true);
85 | }
86 |
87 | public boolean configure(List cMakeArguments)
88 | {
89 | String arguments = cMakeArguments.toString().replaceFirst("\\[", " ").replaceAll(",|\\]", "");
90 | return Command.execute("cmake .." + arguments, outputPath + "/build", errorOutputOnly, false);
91 | }
92 |
93 | public boolean compile()
94 | {
95 | return Command.execute("make", outputPath + "/build", errorOutputOnly, true);
96 | }
97 |
98 | public boolean run()
99 | {
100 | return Command.execute("ctest -V", outputPath + "/build", errorOutputOnly, false);
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/it/java/com/eprosima/integration/TestManager.java:
--------------------------------------------------------------------------------
1 | package com.eprosima.integration;
2 |
3 | import java.util.ArrayList;
4 |
5 | import java.util.Arrays;
6 | import java.util.Iterator;
7 | import java.util.List;
8 | import java.io.File;
9 |
10 |
11 | public class TestManager
12 | {
13 | public enum TestLevel
14 | {
15 | PREPARE(0),
16 | GENERATE(1),
17 | CONFIGURE(2),
18 | COMPILE(3),
19 | RUN(4);
20 |
21 | private int value;
22 |
23 | TestLevel(int value)
24 | {
25 | this.value = value;
26 | }
27 |
28 | public int getValue()
29 | {
30 | return value;
31 | }
32 | }
33 |
34 | private TestLevel level;
35 | private ArrayList idlFiles;
36 | private String generatorName;
37 | private String inputPath;
38 | private String outputPath;
39 | private String exampleArch;
40 | private List cMakeArgs;
41 | private boolean errorOutputOnly;
42 |
43 | public TestManager(
44 | TestLevel level,
45 | String generatorName,
46 | String inputPath,
47 | String outputPath,
48 | List list_tests,
49 | List blacklist_tests)
50 | {
51 | this.level = level;
52 | this.idlFiles = new ArrayList<>();
53 | processIDLsDirectory(inputPath, list_tests, blacklist_tests);
54 | this.generatorName = generatorName;
55 | this.inputPath = inputPath;
56 | this.outputPath = outputPath;
57 | this.exampleArch = null;
58 | this.cMakeArgs = new ArrayList();
59 | this.errorOutputOnly = true;
60 | }
61 |
62 | public TestManager(
63 | TestLevel level,
64 | String generatorName,
65 | String inputPath,
66 | String outputPath,
67 | String exampleArch,
68 | List list_tests,
69 | List blacklist_tests)
70 | {
71 | this.level = level;
72 | this.idlFiles = new ArrayList<>();
73 | processIDLsDirectory(inputPath, list_tests, blacklist_tests);
74 | this.generatorName = generatorName;
75 | this.inputPath = inputPath;
76 | this.outputPath = outputPath;
77 | this.exampleArch = exampleArch;
78 | this.cMakeArgs = new ArrayList();
79 | this.errorOutputOnly = true;
80 | }
81 |
82 | public void processIDLsDirectory(
83 | String directoryPath,
84 | List list_tests,
85 | List blacklist_tests)
86 | {
87 | File directory = new File(directoryPath);
88 | if (!directory.isDirectory())
89 | {
90 | System.err.println("Error: Invalid directory path");
91 | return;
92 | }
93 |
94 | File[] files = directory.listFiles((dir, name) -> name.endsWith(".idl"));
95 | if (files == null || files.length == 0)
96 | {
97 | System.out.println("No IDL files found in the directory");
98 | return;
99 | }
100 |
101 | for (File file : files)
102 | {
103 | String idlName = file.getName().replaceAll("\\.idl$", "");
104 |
105 | if ((null == list_tests || list_tests.contains(idlName)) &&
106 | (null == blacklist_tests || !blacklist_tests.contains(idlName)))
107 | {
108 | idlFiles.add(idlName);
109 | }
110 | }
111 | }
112 |
113 | public void showOutputOnlyAtErrors(boolean value)
114 | {
115 | errorOutputOnly = value;
116 | }
117 |
118 | public void addCMakeArguments(String... args)
119 | {
120 | cMakeArgs.addAll(Arrays.asList(args));
121 | }
122 |
123 | public void addTests(String... id_files)
124 | {
125 | idlFiles.addAll(Arrays.asList(id_files));
126 | }
127 |
128 | public void removeTests(String... args)
129 | {
130 | idlFiles.removeAll(Arrays.asList(args));
131 | }
132 |
133 | public boolean runTests()
134 | {
135 | for (String idlFile : idlFiles)
136 | {
137 | Test test = new Test(idlFile, outputPath, errorOutputOnly);
138 | if (!run(test))
139 | {
140 | return false;
141 | }
142 | }
143 |
144 | return true;
145 | }
146 |
147 | private boolean prepare(Test test)
148 | {
149 | printHeader(test.getIDL(), TestLevel.PREPARE);
150 | return printlnStatus(test.prepare());
151 | }
152 |
153 | public boolean generate(Test test)
154 | {
155 | boolean precondition = prepare(test);
156 | if (precondition && level.getValue() >= TestLevel.GENERATE.getValue())
157 | {
158 | printHeader(test.getIDL(), TestLevel.GENERATE);
159 |
160 | if (exampleArch == null)
161 | {
162 | return printlnStatus(test.generate(generatorName, inputPath, level == TestLevel.RUN));
163 | } else {
164 | return printlnStatus(test.generate(generatorName, inputPath, exampleArch, level == TestLevel.RUN));
165 | }
166 | }
167 |
168 | return precondition;
169 | }
170 |
171 | public boolean configure(Test test)
172 | {
173 | boolean precondition = generate(test);
174 | if(precondition && level.getValue() >= TestLevel.CONFIGURE.getValue())
175 | {
176 | printHeader(test.getIDL(), TestLevel.CONFIGURE);
177 | return printlnStatus(test.configure(cMakeArgs));
178 | }
179 |
180 | return precondition;
181 | }
182 |
183 | public boolean compile(Test test)
184 | {
185 | boolean precondition = configure(test);
186 | if(precondition && level.getValue() >= TestLevel.COMPILE.getValue())
187 | {
188 | printHeader(test.getIDL(), TestLevel.COMPILE);
189 | return printlnStatus(test.compile());
190 | }
191 |
192 | return precondition;
193 | }
194 |
195 | private boolean run(Test test)
196 | {
197 | boolean precondition = compile(test);
198 | if(precondition && level.getValue() >= TestLevel.RUN.getValue())
199 | {
200 | printHeader(test.getIDL(), TestLevel.RUN);
201 |
202 | return printlnStatus(test.run());
203 | }
204 |
205 | return precondition;
206 | }
207 |
208 | private void printHeader(String idl, TestLevel level)
209 | {
210 | System.out.println("\n\n>>> " + idl + " TEST: " + level.toString() + "...");
211 | }
212 |
213 | private boolean printlnStatus(boolean status)
214 | {
215 | System.out.println(" RESULT: " + (status ? "OK!" : "ERROR"));
216 | return status;
217 | }
218 | }
219 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/generator/manager/TemplateErrorListener.java:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.generator.manager;
16 |
17 | import org.stringtemplate.v4.STErrorListener;
18 | import org.stringtemplate.v4.misc.STMessage;
19 |
20 | import com.eprosima.log.ColorMessage;
21 |
22 | public class TemplateErrorListener implements STErrorListener
23 | {
24 | private TemplateManager manager_;
25 | public TemplateErrorListener(TemplateManager manager)
26 | {
27 | manager_ = manager;
28 | }
29 |
30 | @Override
31 | public void compileTimeError(STMessage msg)
32 | {
33 | System.err.println(ColorMessage.error() + msg.toString());
34 | if (null != manager_)
35 | {
36 | manager_.set_st_error();
37 | }
38 | }
39 |
40 | @Override
41 | public void runTimeError(STMessage msg)
42 | {
43 | System.err.println(ColorMessage.error() + msg.toString());
44 | if (null != manager_)
45 | {
46 | manager_.set_st_error();
47 | }
48 | }
49 |
50 | @Override
51 | public void IOError(STMessage msg)
52 | {
53 | System.err.println(ColorMessage.error() + msg.toString());
54 | if (null != manager_)
55 | {
56 | manager_.set_st_error();
57 | }
58 | }
59 |
60 | @Override
61 | public void internalError(STMessage msg)
62 | {
63 | System.err.println(ColorMessage.error() + msg.toString());
64 | if (null != manager_)
65 | {
66 | manager_.set_st_error();
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/generator/manager/TemplateGroup.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.generator.manager;
16 |
17 | import java.io.StringWriter;
18 | import java.util.Iterator;
19 | import java.util.Map;
20 | import java.util.HashMap;
21 | import java.util.Set;
22 | import java.util.Map.Entry;
23 | import java.util.List;
24 | import java.util.ArrayList;
25 |
26 | import org.stringtemplate.v4.AutoIndentWriter;
27 | import org.stringtemplate.v4.ST;
28 | import org.stringtemplate.v4.STWriter;
29 |
30 | import com.eprosima.log.Log;
31 |
32 | public class TemplateGroup
33 | {
34 | private Map m_templates = new HashMap();
35 | private Map> m_extensionstemplates = new HashMap>();
36 | private TemplateErrorListener error_listener_ = null;
37 | private TemplateManager manager_ = null;
38 |
39 | public TemplateGroup(TemplateManager manager)
40 | {
41 | manager_ = manager;
42 | error_listener_ = new TemplateErrorListener(manager);
43 | }
44 |
45 | public void addTemplate(String groupname, TemplateST template)
46 | {
47 | m_templates.put(groupname, template);
48 | }
49 |
50 | public void addTemplate(String groupname, TemplateST template, List extensionstemplates)
51 | {
52 | addTemplate(groupname, template);
53 | m_extensionstemplates.put(groupname + "_" + template.get_st().getName(), extensionstemplates);
54 | }
55 |
56 | public TemplateST getTemplate(String groupname)
57 | {
58 | TemplateST template = m_templates.get(groupname);
59 |
60 | //If there is extensiones, add them before return the template.
61 | if(m_extensionstemplates.containsKey(groupname + "_" + template.get_st().getName()))
62 | {
63 | List extemplates = new ArrayList();
64 | List extensions = m_extensionstemplates.get(groupname + "_" + template.get_st().getName());
65 |
66 | for(ST extension : extensions)
67 | {
68 | extemplates.add(extension);
69 | }
70 |
71 | template.get_st().add("extensions", extemplates);
72 | }
73 |
74 | return template;
75 | }
76 |
77 | public void setAttribute(String attribute, TemplateGroup tg)
78 | {
79 | if(tg != null)
80 | {
81 | Set> set = m_templates.entrySet();
82 | Iterator> it = set.iterator();
83 |
84 | while(it.hasNext())
85 | {
86 | Map.Entry m = it.next();
87 |
88 | // Call setAttribute
89 | TemplateST template = tg.getTemplate(m.getKey());
90 |
91 | if(template != null)
92 | {
93 | // Before render, set the current TemplateSTGroup in TemplateManager.
94 | manager_.set_current_template_stgroup(m.getValue().get_template_stgroup());
95 |
96 | Log.printDebug("setting attribute (TemplateGroup) to template group " + m.getKey() + " from " +
97 | template.get_st().getName() + " to " + m.getValue().get_st().getName());
98 | StringWriter out = new StringWriter();
99 | STWriter wr = new AutoIndentWriter(out);
100 | template.get_st().write(wr, error_listener_);
101 | String out_string = out.toString();
102 |
103 | if (!out_string.isBlank())
104 | {
105 | m.getValue().get_st().add(attribute, out.toString());
106 | }
107 |
108 | // Unset the current TemplateSTGroup in TemplateManager.
109 | manager_.set_current_template_stgroup(null);
110 | }
111 | }
112 | }
113 | }
114 |
115 | public void setAttribute(String attribute, Object obj1)
116 | {
117 | Set> set = m_templates.entrySet();
118 | Iterator> it = set.iterator();
119 |
120 | while(it.hasNext())
121 | {
122 | Map.Entry m = it.next();
123 |
124 | // Call setAttribute
125 | Log.printDebug("setting attribute (obj1) to template group " + m.getKey() + " to " +
126 | m.getValue().get_st().getName());
127 | TemplateST template = m.getValue();
128 | template.get_st().add(attribute, obj1);
129 | // Update extensions
130 | List extensions = m_extensionstemplates.get(m.getKey() + "_" + template.get_st().getName());
131 | if(extensions != null)
132 | {
133 | for(ST extension : extensions)
134 | {
135 | extension.add(attribute, obj1);
136 | }
137 | }
138 | }
139 | }
140 | }
141 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/generator/manager/TemplateManager.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.generator.manager;
16 |
17 | import java.util.Iterator;
18 | import java.util.Map;
19 | import java.util.HashMap;
20 | import java.util.Map.Entry;
21 | import java.util.Set;
22 | import java.util.List;
23 | import java.util.ArrayList;
24 |
25 | import org.stringtemplate.v4.*;
26 | import org.stringtemplate.v4.misc.STMessage;
27 |
28 | public class TemplateManager
29 | {
30 | private Map m_groups = new HashMap();
31 |
32 | private boolean st_error_ = false;
33 |
34 | private TemplateSTGroup current_template_stgroup_ = null;
35 |
36 | public TemplateSTGroup addGroup(String groupname)
37 | {
38 | TemplateSTGroup group = new TemplateSTGroup(groupname);
39 | m_groups.put(groupname, group);
40 | return group;
41 | }
42 |
43 | public TemplateSTGroup addGroupFromString(String groupname, String text)
44 | {
45 | TemplateSTGroup group = new TemplateSTGroup(groupname, text);
46 | m_groups.put(groupname, group);
47 | return group;
48 | }
49 |
50 | public TemplateGroup createTemplateGroup(String templatename)
51 | {
52 | TemplateGroup tg = new TemplateGroup(this);
53 | Set> set = m_groups.entrySet();
54 | Iterator> it = set.iterator();
55 |
56 | while(it.hasNext())
57 | {
58 | Map.Entry m = it.next();
59 |
60 | // Obtain instance
61 | TemplateST template = new TemplateST(m.getValue(), templatename);
62 | tg.addTemplate(m.getKey(), template);
63 | }
64 |
65 | return tg;
66 | }
67 |
68 |
69 | public STGroup createStringTemplateGroup(String templateGroupName)
70 | {
71 | return new STGroupFile(templateGroupName, '$', '$');
72 | }
73 |
74 | public void set_st_error()
75 | {
76 | st_error_ = true;
77 | }
78 |
79 | public boolean get_st_error()
80 | {
81 | return st_error_;
82 | }
83 |
84 | public void set_current_template_stgroup(TemplateSTGroup template_stgroup)
85 | {
86 | current_template_stgroup_ = template_stgroup;
87 | }
88 |
89 | public boolean is_enabled_custom_property_in_current_group(String custom_property)
90 | {
91 | if (null != current_template_stgroup_)
92 | {
93 | return current_template_stgroup_.is_enabled_custom_property(custom_property);
94 | }
95 |
96 | return false;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/generator/manager/TemplateST.java:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.generator.manager;
16 |
17 | import org.stringtemplate.v4.*;
18 |
19 | public class TemplateST
20 | {
21 | public TemplateST(TemplateSTGroup parent_group, String template_name)
22 | {
23 | parent_group_ = parent_group;
24 | st_ = parent_group_.get_stgroup().getInstanceOf(template_name);
25 | }
26 |
27 | public ST get_st()
28 | {
29 | return st_;
30 | }
31 |
32 | public TemplateSTGroup get_template_stgroup()
33 | {
34 | return parent_group_;
35 | }
36 |
37 | private ST st_ = null;
38 | private TemplateSTGroup parent_group_ = null;
39 | };
40 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/generator/manager/TemplateSTGroup.java:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.generator.manager;
16 |
17 | import org.stringtemplate.v4.*;
18 | import java.util.ArrayList;
19 |
20 | public class TemplateSTGroup
21 | {
22 | public TemplateSTGroup(String groupname)
23 | {
24 | st_group_ = new STGroupFile(groupname, '$', '$');
25 | }
26 |
27 | public TemplateSTGroup(String groupname, String text)
28 | {
29 | st_group_ = new STGroupString(groupname, text, '$', '$');
30 | }
31 |
32 | public STGroup get_stgroup()
33 | {
34 | return st_group_;
35 | }
36 |
37 | /*!
38 | * @brief Checks a custom property was added in this template group.
39 | */
40 | public boolean is_enabled_custom_property(String custom_property)
41 | {
42 | return custom_properties.contains(custom_property);
43 | }
44 |
45 | /*!
46 | * @brief Enables a custom property.
47 | */
48 | public void enable_custom_property(String custom_property)
49 | {
50 | custom_properties.add(custom_property);
51 | }
52 |
53 | private STGroup st_group_ = null;
54 |
55 | //! List of custom properties added by the user.
56 | ArrayList custom_properties = new ArrayList();
57 | };
58 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/exception/ParseException.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.exception;
16 |
17 | import org.antlr.v4.runtime.RecognitionException;
18 | import org.antlr.v4.runtime.Token;
19 |
20 | public class ParseException extends RecognitionException
21 | {
22 | public ParseException()
23 | {
24 | super("", null, null, null);
25 | }
26 |
27 | public ParseException(Token token, String message)
28 | {
29 | super(message, null, null, null);
30 |
31 | if(token != null)
32 | setOffendingToken(token);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/exception/RuntimeGenerationException.java:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.exception;
16 |
17 | import java.lang.Exception;
18 | import com.eprosima.log.ColorMessage;
19 |
20 | public class RuntimeGenerationException extends Exception
21 | {
22 | public RuntimeGenerationException()
23 | {
24 | super("");
25 | }
26 |
27 | public RuntimeGenerationException(String message)
28 | {
29 | super(ColorMessage.error() + message);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/listener/DefaultErrorListener.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.listener;
16 |
17 | import org.antlr.v4.runtime.BaseErrorListener;
18 | import org.antlr.v4.runtime.RecognitionException;
19 | import org.antlr.v4.runtime.Recognizer;
20 | import com.eprosima.log.ColorMessage;
21 | import com.eprosima.idl.context.Context;
22 | import java.util.Stack;
23 | import com.eprosima.idl.util.Pair;
24 |
25 | public class DefaultErrorListener extends BaseErrorListener
26 | {
27 | public DefaultErrorListener(Context ctx)
28 | {
29 | ctx_ = ctx;
30 | }
31 |
32 | @Override
33 | public void syntaxError(Recognizer, ?> recognizer, Object offendingSymbol,
34 | int line, int charPositionInLine, String msg, RecognitionException ex)
35 | {
36 | // Check if it is a included file.
37 | Stack> stack = ctx_.getScopeFilesStack();
38 |
39 | if(stack.size() > 0)
40 | {
41 | boolean first = true;
42 | for(int count = stack.size() - 1; count >= 0; --count)
43 | {
44 | String message = "";
45 |
46 | if(first)
47 | {
48 | message = "In file included from ";
49 | first = false;
50 | }
51 | else
52 | {
53 | message = " ";
54 | }
55 |
56 | message += ColorMessage.bold(stack.get(count).first());
57 | message += ":";
58 | message += ColorMessage.bold(stack.get(count).second().toString());
59 | message += ":0";
60 |
61 | if(count != 0)
62 | message += ",";
63 | else
64 | message += ":";
65 |
66 | System.out.println(message);
67 | }
68 | }
69 |
70 | int realLine = line - ctx_.getCurrentIncludeLine();
71 | System.out.println(ColorMessage.bold(ctx_.getScopeFile() + ":" + realLine + ":" + charPositionInLine + ": ") +
72 | ColorMessage.red("error: ") + msg);
73 | }
74 |
75 | private Context ctx_;
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/strategy/DefaultErrorStrategy.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.strategy;
16 |
17 | import com.eprosima.log.ColorMessage;
18 | import com.eprosima.idl.parser.exception.ParseException;
19 | import org.antlr.v4.runtime.Parser;
20 | import org.antlr.v4.runtime.RecognitionException;
21 | import org.antlr.v4.runtime.NoViableAltException;
22 | import org.antlr.v4.runtime.InputMismatchException;
23 | import org.antlr.v4.runtime.FailedPredicateException;
24 | import org.antlr.v4.runtime.Token;
25 |
26 | public class DefaultErrorStrategy extends org.antlr.v4.runtime.DefaultErrorStrategy
27 | {
28 | public static final DefaultErrorStrategy INSTANCE = new DefaultErrorStrategy();
29 |
30 | @Override
31 | public void reportError(Parser recognizer, RecognitionException e)
32 | {
33 | if (inErrorRecoveryMode(recognizer)) {
34 | // System.err.print("[SPURIOUS] ");
35 | return; // don't report spurious errors
36 | }
37 | beginErrorCondition(recognizer);
38 | if ( e instanceof NoViableAltException ) {
39 | reportNoViableAlternative(recognizer, (NoViableAltException) e);
40 | }
41 | else if ( e instanceof InputMismatchException ) {
42 | reportInputMismatch(recognizer, (InputMismatchException)e);
43 | }
44 | else if ( e instanceof FailedPredicateException ) {
45 | reportFailedPredicate(recognizer, (FailedPredicateException)e);
46 | }
47 | else if ( e instanceof ParseException) {
48 | if(e.getOffendingToken() != null)
49 | {
50 | String message = ColorMessage.bold(getTokenErrorDisplay(e.getOffendingToken()) + " ") + e.getMessage();
51 | recognizer.notifyErrorListeners(e.getOffendingToken(), message, e);
52 | }
53 | else
54 | recognizer.notifyErrorListeners(e.getMessage());
55 | }
56 | else {
57 | System.err.println("unknown recognition error type: "+e.getClass().getName());
58 | recognizer.notifyErrorListeners(e.getOffendingToken(), e.getMessage(), e);
59 | }
60 | }
61 |
62 | @Override
63 | protected void reportUnwantedToken(Parser recognizer)
64 | {
65 | if (inErrorRecoveryMode(recognizer))
66 | {
67 | return;
68 | }
69 |
70 | beginErrorCondition(recognizer);
71 | Token t = recognizer.getCurrentToken();
72 | String tokenName = getTokenErrorDisplay(t);
73 | String msg = "Unexpected input " + ColorMessage.bold(tokenName);
74 | recognizer.notifyErrorListeners(t, msg, null);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/AnnotationDeclaration.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | import com.eprosima.idl.context.Context;
18 | import com.eprosima.idl.parser.typecode.TypeCode;
19 | import com.eprosima.idl.parser.typecode.EnumTypeCode;
20 | import com.eprosima.idl.parser.typecode.AliasTypeCode;
21 | import com.eprosima.idl.parser.tree.ConstDeclaration;
22 |
23 | import java.util.List;
24 | import java.util.ArrayList;
25 | import java.util.Vector;
26 | import java.util.HashMap;
27 | import org.antlr.v4.runtime.Token;
28 |
29 | public class AnnotationDeclaration extends TreeNode implements Definition
30 | {
31 | public AnnotationDeclaration(String scopeFile, boolean isInScope, String scope, String name, Token token)
32 | {
33 | super(scopeFile, isInScope, scope, name, token);
34 | m_members = new HashMap();
35 | m_enums = new Vector();
36 | m_consts = new Vector();
37 | m_typedefs = new Vector();
38 | }
39 |
40 | public List getMembers()
41 | {
42 | return new ArrayList(m_members.values());
43 | }
44 |
45 | public int getMembersSize()
46 | {
47 | return m_members.values().size();
48 | }
49 |
50 | public void addMembers(AnnotationDeclaration annotation)
51 | {
52 | m_members.putAll(annotation.m_members);
53 | }
54 |
55 | public boolean addMember(AnnotationMember member)
56 | {
57 | // Check that in case of an Enum the given value is in the enumeration.
58 | // ParseException is thrown otherwise.
59 | member.getEnumStringValue();
60 | if(!m_members.containsKey(member.getName()))
61 | {
62 | m_members.put(member.getName(), member);
63 | return true;
64 | }
65 |
66 | return false;
67 | }
68 |
69 | public void setParent(Object obj)
70 | {
71 | m_parent = obj;
72 | }
73 |
74 | public Object getParent()
75 | {
76 | return m_parent;
77 | }
78 |
79 | @Override
80 | public boolean isIsModule()
81 | {
82 | return false;
83 | }
84 |
85 | @Override
86 | public boolean isIsException()
87 | {
88 | return false;
89 | }
90 |
91 | @Override
92 | public boolean isIsInterface()
93 | {
94 | return false;
95 | }
96 |
97 | @Override
98 | public boolean isIsTypeDeclaration()
99 | {
100 | return false;
101 | }
102 |
103 | @Override
104 | public boolean isIsConstDeclaration()
105 | {
106 | return false;
107 | }
108 |
109 | @Override
110 | public boolean isIsAnnotation()
111 | {
112 | return true;
113 | }
114 |
115 | public void addEnums(Vector enums)
116 | {
117 | for (TypeCode tc : enums)
118 | {
119 | m_enums.add((EnumTypeCode)tc);
120 | }
121 | }
122 |
123 | public void addConstDecl(ConstDeclaration consts)
124 | {
125 | m_consts.add(consts);
126 | }
127 |
128 | public void addTypeDefs(Vector typedefs)
129 | {
130 | for (TypeCode tc : typedefs)
131 | {
132 | m_typedefs.add((AliasTypeCode)tc);
133 | }
134 | }
135 |
136 | public List getEnums()
137 | {
138 | return new ArrayList(m_enums);
139 | }
140 |
141 | public EnumTypeCode getEnum(String name)
142 | {
143 | for (EnumTypeCode etc : m_enums)
144 | {
145 | if (etc.getName().equals(name))
146 | {
147 | return etc;
148 | }
149 | }
150 | return null;
151 | }
152 |
153 | public List getConstDecls()
154 | {
155 | return new ArrayList(m_consts);
156 | }
157 |
158 | public ConstDeclaration getConstDecl(String name)
159 | {
160 | for (ConstDeclaration cdcl : m_consts)
161 | {
162 | if (cdcl.getName().equals(name))
163 | {
164 | return cdcl;
165 | }
166 | }
167 | return null;
168 | }
169 |
170 | public List getTypeDefs()
171 | {
172 | return new ArrayList(m_typedefs);
173 | }
174 |
175 | public AliasTypeCode getTypeDef(String name)
176 | {
177 | for (AliasTypeCode atc : m_typedefs)
178 | {
179 | if (atc.getName().equals(name))
180 | {
181 | return atc;
182 | }
183 | }
184 | return null;
185 | }
186 |
187 | public TypeCode getTypeCode(String name)
188 | {
189 | TypeCode result = getTypeDef(name);
190 | if (result == null)
191 | {
192 | result = getEnum(name);
193 | }
194 | return result;
195 | }
196 |
197 | private Object m_parent = null;
198 | private HashMap m_members = null;
199 | private Vector m_enums = null;
200 | private Vector m_consts = null;
201 | private Vector m_typedefs = null;
202 | }
203 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/AnnotationMember.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | import com.eprosima.idl.parser.exception.ParseException;
18 | import com.eprosima.idl.parser.typecode.Member;
19 | import com.eprosima.idl.parser.typecode.EnumMember;
20 | import com.eprosima.idl.parser.typecode.EnumTypeCode;
21 | import com.eprosima.idl.parser.typecode.TypeCode;
22 |
23 | public class AnnotationMember
24 | {
25 | public AnnotationMember(String name, TypeCode typecode, String value)
26 | {
27 | m_typecode = typecode;
28 | m_name = name;
29 | m_value = value;
30 | }
31 |
32 | public AnnotationMember(AnnotationMember ann)
33 | {
34 | m_typecode = ann.m_typecode;
35 | m_name = ann.m_name;
36 | m_value = ann.m_value;
37 | }
38 |
39 | public String getName()
40 | {
41 | return m_name;
42 | }
43 |
44 | /*
45 | * @brief This function is used with (previous c) types because array names contains [].
46 | */
47 |
48 | public TypeCode getTypecode()
49 | {
50 | return m_typecode;
51 | }
52 |
53 | public String getValue()
54 | {
55 | if (m_typecode.isIsEnumType())
56 | {
57 | EnumTypeCode enumTC = (EnumTypeCode)m_typecode;
58 | int idx = 0;
59 | int default_idx = 0;
60 | for (Member m : enumTC.getMembers())
61 | {
62 | if (m.getName().equals(m_value))
63 | {
64 | return Integer.toString(idx);
65 | }
66 | else if (m.isAnnotationDefaultLiteral())
67 | {
68 | default_idx = idx;
69 | }
70 | idx++;
71 | }
72 | return Integer.toString(default_idx);
73 | }
74 | else if (m_typecode.isIsStringType() || m_typecode.isIsWStringType())
75 | {
76 | if (m_value != null)
77 | {
78 | if (m_value.startsWith("\"") && m_value.endsWith("\""))
79 | {
80 | return m_value.substring(1, m_value.length() - 1);
81 | }
82 | }
83 | if (m_typecode.isIsWStringType())
84 | {
85 | return "L\"\"";
86 | }
87 | return "";
88 | }
89 | else if (m_typecode.isPrimitiveType())
90 | {
91 | if (m_value != null)
92 | {
93 | // Check if the string starts with "0x" to determine if it's hexadecimal
94 | if (m_value.startsWith("0x")) {
95 | // If it's hexadecimal, parse it using parseInt with radix 16
96 | return Integer.toString(Integer.parseInt(m_value.substring(2), 16));
97 | } else {
98 | return m_value;
99 | }
100 | }
101 | return m_typecode.getInitialValue();
102 | }
103 | return m_value;
104 | }
105 |
106 | public String getEnumStringValue()
107 | {
108 | if (m_value != null && m_typecode.isIsEnumType())
109 | {
110 | EnumTypeCode enumTC = (EnumTypeCode)m_typecode;
111 | for (Member m : enumTC.getMembers())
112 | {
113 | String value = m_value;
114 | if (value.startsWith("\"") && value.endsWith("\""))
115 | {
116 | value = value.substring(1, value.length() - 1);
117 | }
118 | String[] value_with_scopes = value.split("::");
119 | value = value_with_scopes[value_with_scopes.length - 1];
120 | if (m.getName().equals(value))
121 | {
122 | return value;
123 | }
124 | }
125 | throw new ParseException(null, m_value + " is not a valid label for " + m_name);
126 | }
127 | return m_value;
128 | }
129 |
130 | public void setValue(String value)
131 | {
132 | m_value = value;
133 | }
134 |
135 | public boolean isIsVerbatimPlacement()
136 | {
137 | return getName().equals(Annotation.placement_str);
138 | }
139 |
140 | public boolean isIsVerbatimLanguage()
141 | {
142 | return getName().equals(Annotation.language_str);
143 | }
144 |
145 | public boolean isIsVerbatimText()
146 | {
147 | return getName().equals(Annotation.text_str);
148 | }
149 |
150 | public boolean isIsMax()
151 | {
152 | return getName().equals(Annotation.max_str);
153 | }
154 |
155 | public boolean isIsMin()
156 | {
157 | return getName().equals(Annotation.min_str);
158 | }
159 |
160 | private String m_name = null;
161 |
162 | private TypeCode m_typecode = null;
163 |
164 | private String m_value = null;
165 | }
166 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/ConstDeclaration.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | import com.eprosima.idl.context.Context;
18 | import com.eprosima.idl.parser.typecode.TypeCode;
19 |
20 | import org.antlr.v4.runtime.Token;
21 |
22 | public class ConstDeclaration extends DefinitionContainer implements Definition, Export
23 | {
24 | public ConstDeclaration(
25 | String scopeFile,
26 | boolean isInScope,
27 | String scope,
28 | String name,
29 | TypeCode typecode,
30 | String value,
31 | String evaluated_value,
32 | Token token)
33 | {
34 | super(scopeFile, isInScope, scope, name, token);
35 |
36 | m_typecode = typecode;
37 | m_value = value;
38 | evaluated_value_ = evaluated_value;
39 | // Set as parent to the Typecode.
40 | m_typecode.setParent(this);
41 | }
42 |
43 | public TypeCode getTypeCode()
44 | {
45 | return m_typecode;
46 | }
47 |
48 | public String getEvaluatedValue()
49 | {
50 | return evaluated_value_;
51 | }
52 |
53 | public String getValue()
54 | {
55 | return m_value;
56 | }
57 |
58 | public void setParent(Object obj)
59 | {
60 | m_parent = obj;
61 | }
62 |
63 | public Object getParent()
64 | {
65 | return m_parent;
66 | }
67 |
68 | @Override
69 | public boolean isIsModule()
70 | {
71 | return false;
72 | }
73 |
74 | @Override
75 | public boolean isIsOperation()
76 | {
77 | return false;
78 | }
79 |
80 | @Override
81 | public boolean isIsException()
82 | {
83 | return false;
84 | }
85 |
86 | @Override
87 | public boolean isIsInterface()
88 | {
89 | return false;
90 | }
91 |
92 | @Override
93 | public boolean isIsTypeDeclaration()
94 | {
95 | return false;
96 | }
97 |
98 | @Override
99 | public boolean isIsConstDeclaration()
100 | {
101 | return true;
102 | }
103 |
104 | @Override
105 | public boolean resolve(Context ctx)
106 | {
107 | return true;
108 | }
109 |
110 | @Override
111 | public boolean isIsAnnotation()
112 | {
113 | return false;
114 | }
115 |
116 | private String evaluated_value_ = null;
117 | private TypeCode m_typecode = null;
118 | private String m_value = null;
119 | private Object m_parent = null;
120 | }
121 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/Definition.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | public interface Definition
18 | {
19 | enum Kind
20 | {
21 | MODULE,
22 | INTERFACE,
23 | EXCEPTION,
24 | TYPE_DECLARATION,
25 | CONST_DECLARATION,
26 | ANNOTATION
27 | };
28 |
29 | void setParent(Object obj);
30 |
31 | Object getParent();
32 |
33 | public boolean isIsModule();
34 |
35 | public boolean isIsInterface();
36 |
37 | public boolean isIsException();
38 |
39 | public boolean isIsTypeDeclaration();
40 |
41 | public boolean isIsConstDeclaration();
42 |
43 | public boolean isIsAnnotation();
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/DefinitionContainer.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | import java.util.ArrayList;
18 | import org.antlr.v4.runtime.Token;
19 |
20 | public class DefinitionContainer extends TreeNode
21 | {
22 | protected DefinitionContainer(String scopeFile, boolean isInScope, String scope, String name, Token token)
23 | {
24 | super(scopeFile, isInScope, scope, name, token);
25 |
26 | m_definitions = new ArrayList();
27 | }
28 |
29 | public void add(Definition def)
30 | {
31 | m_definitions.add(def);
32 | def.setParent(this);
33 | }
34 |
35 | public ArrayList getDefinitions()
36 | {
37 | return m_definitions;
38 | }
39 |
40 | private ArrayList m_definitions;
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/Exception.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | import com.eprosima.idl.context.Context;
18 | import com.eprosima.idl.parser.typecode.Member;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 | import org.antlr.v4.runtime.Token;
23 |
24 | public class Exception extends TreeNode implements Export, Definition
25 | {
26 | public Exception(String scopeFile, boolean isInScope, String scope, String name, Token token)
27 | {
28 | super(scopeFile, isInScope, scope, name, token);
29 |
30 | m_members = new ArrayList();
31 | }
32 |
33 | @Override
34 | public boolean isIsModule()
35 | {
36 | return false;
37 | }
38 |
39 | @Override
40 | public boolean isIsInterface()
41 | {
42 | return false;
43 | }
44 |
45 | @Override
46 | public boolean isIsTypeDeclaration()
47 | {
48 | return false;
49 | }
50 |
51 | @Override
52 | public boolean isIsConstDeclaration()
53 | {
54 | return false;
55 | }
56 |
57 | public void setParent(Object obj)
58 | {
59 | m_parent = obj;
60 | }
61 |
62 | public Object getParent()
63 | {
64 | return m_parent;
65 | }
66 |
67 | @Override
68 | public boolean isIsOperation()
69 | {
70 | return false;
71 | }
72 |
73 | @Override
74 | public boolean isIsException()
75 | {
76 | return true;
77 | }
78 |
79 | @Override
80 | public boolean isIsAnnotation()
81 | {
82 | return false;
83 | }
84 |
85 | public List getMembers()
86 | {
87 | return m_members;
88 | }
89 |
90 | public int addMember(Member member)
91 | {
92 | m_members.add(member);
93 | member.set_index(m_members.size() - 1);
94 | return m_members.size() - 1;
95 | }
96 |
97 | @Override
98 | public boolean resolve(Context ctx)
99 | {
100 | return true;
101 | }
102 |
103 | @Override
104 | protected boolean isDeclaredInsideInterface()
105 | {
106 | return m_parent instanceof Interface;
107 | }
108 |
109 | private Object m_parent = null;
110 | private List m_members = null;
111 | }
112 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/Export.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | import com.eprosima.idl.context.Context;
18 |
19 | public interface Export
20 | {
21 | void setParent(Object obj);
22 |
23 | Object getParent();
24 |
25 | public boolean isIsOperation();
26 |
27 | public boolean isIsException();
28 |
29 | public boolean isIsTypeDeclaration();
30 |
31 | public boolean isIsConstDeclaration();
32 |
33 | // TODO Capturar el error en la gramatica y saltarlo.
34 | public boolean resolve(Context ctx);
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/ExportContainer.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | import java.util.ArrayList;
18 | import org.antlr.v4.runtime.Token;
19 |
20 | public class ExportContainer extends TreeNode
21 | {
22 | protected ExportContainer(String scopeFile, boolean isInScope, String scope, String name, Token token)
23 | {
24 | super(scopeFile, isInScope, scope, name, token);
25 |
26 | m_exports = new ArrayList();
27 | }
28 |
29 | public void add(Export exp)
30 | {
31 | m_exports.add(exp);
32 | exp.setParent(this);
33 | }
34 |
35 | public ArrayList getExports()
36 | {
37 | return m_exports;
38 | }
39 |
40 | private ArrayList m_exports;
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/Inherits.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | import com.eprosima.idl.context.Context;
18 | import com.eprosima.idl.parser.exception.ParseException;
19 | import com.eprosima.idl.parser.typecode.TypeCode;
20 |
21 | public interface Inherits
22 | {
23 | /*!
24 | * @brief This function links the super type to the object.
25 | * @param ctx Context used in the IDL parser. Can be useful for developers.
26 | * @param parent Super TypeCode to be linked.
27 | * @throw ParseException if the super type has already been defined.
28 | */
29 | public void addInheritance(Context ctx, TypeCode parent) throws ParseException;
30 |
31 | /*!
32 | * @brief This function returns the super type linked with the object.
33 | * XTypes v1.3 Clause 7.2.2.4.5 The Type System supports single inheritance of Aggregated Types.
34 | * @return Linked super type.
35 | */
36 | public TypeCode getInheritance();
37 |
38 | public TypeCode getEnclosedInheritance();
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/Interface.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | import java.util.ArrayList;
18 | import java.util.Map;
19 | import java.util.HashMap;
20 |
21 | import org.antlr.v4.runtime.Token;
22 |
23 | public class Interface extends ExportContainer implements Definition
24 | {
25 | public Interface(String scopeFile, boolean isInScope, String scope, String name, Token tk)
26 | {
27 | super(scopeFile, isInScope, scope, name, tk);
28 |
29 | m_bases = new HashMap();
30 | }
31 |
32 |
33 | public void setParent(Object obj)
34 | {
35 | m_parent = obj;
36 | }
37 |
38 | public Object getParent()
39 | {
40 | return m_parent;
41 | }
42 |
43 | @Override
44 | public boolean isIsModule()
45 | {
46 | return false;
47 | }
48 |
49 | @Override
50 | public boolean isIsInterface()
51 | {
52 | return true;
53 | }
54 |
55 | @Override
56 | public boolean isIsException()
57 | {
58 | return false;
59 | }
60 |
61 | @Override
62 | public boolean isIsTypeDeclaration()
63 | {
64 | return false;
65 | }
66 |
67 | @Override
68 | public boolean isIsConstDeclaration()
69 | {
70 | return false;
71 | }
72 |
73 | @Override
74 | public boolean isIsAnnotation()
75 | {
76 | return false;
77 | }
78 |
79 | public boolean addBase(Interface interf)
80 | {
81 | Interface prev = m_bases.put(interf.getName(), interf);
82 |
83 | if(prev != null)
84 | return false;
85 |
86 | return true;
87 | }
88 |
89 | public ArrayList getBases()
90 | {
91 | return new ArrayList(m_bases.values());
92 | }
93 |
94 | /*!
95 | * @brief This function returns the exception defined inside the interface.
96 | */
97 | public Exception getException(String currentScope, String ename)
98 | {
99 | com.eprosima.idl.parser.tree.Exception exception = null;
100 |
101 | for(int count = 0; exception == null && count < getExports().size(); ++count)
102 | {
103 | int lastIndex = -1;
104 |
105 | if(getExports().get(count).isIsException())
106 | {
107 | String tmpname = ((com.eprosima.idl.parser.tree.Exception)getExports().get(count)).getScopedname();
108 |
109 | if(tmpname.equals(ename))
110 | {
111 | exception = (com.eprosima.idl.parser.tree.Exception)getExports().get(count);
112 | }
113 | else
114 | {
115 | // Probar si no tiene scope, con el scope actual.
116 | if(exception == null && ((lastIndex = ename.lastIndexOf("::")) == -1) &&
117 | tmpname.equals(currentScope + ename))
118 | {
119 | exception = (com.eprosima.idl.parser.tree.Exception)getExports().get(count);
120 | }
121 | }
122 | }
123 | }
124 |
125 | return exception;
126 | }
127 |
128 | /*!
129 | * @brief This function returns all operations of the interface.
130 | * This function is used in the string templates.
131 | */
132 | public ArrayList getOperations()
133 | {
134 | if(m_operations == null)
135 | {
136 | m_operations = new ArrayList();
137 |
138 | // Get own operations.
139 | for(int count = 0; count < getExports().size(); ++count)
140 | {
141 | if(getExports().get(count).isIsOperation())
142 | {
143 | m_operations.add((Operation)getExports().get(count));
144 | }
145 | }
146 | }
147 |
148 | return m_operations;
149 | }
150 |
151 | public ArrayList getAll_operations()
152 | {
153 | if(m_all_operations == null)
154 | {
155 | m_all_operations = new ArrayList();
156 |
157 | // Get parent operations.
158 | for(Interface iface : m_bases.values())
159 | {
160 | m_all_operations.addAll(iface.getAll_operations());
161 | }
162 |
163 | // Get own operations.
164 | for(int count = 0; count < getExports().size(); ++count)
165 | {
166 | if(getExports().get(count).isIsOperation())
167 | {
168 | m_all_operations.add((Operation)getExports().get(count));
169 | }
170 | }
171 | }
172 |
173 | return m_all_operations;
174 | }
175 |
176 | /*!
177 | * @brief This function is used in stringtemplates to not generate module in some cases (Right now in generated (previous c) idl).
178 | */
179 | public boolean isThereAreDeclarations()
180 | {
181 | boolean returnedValue = false;
182 |
183 | for(int count = 0; !returnedValue && count < getExports().size(); ++count)
184 | {
185 | returnedValue = getExports().get(count).isIsTypeDeclaration() ||
186 | getExports().get(count).isIsConstDeclaration() || getExports().get(count).isIsException();
187 | }
188 |
189 | return returnedValue;
190 | }
191 |
192 | private Object m_parent = null;
193 |
194 | //! Contains all interfaces it inherits from.
195 | private Map m_bases = null;
196 | //! Contains all operations.
197 | private ArrayList m_operations = null;
198 | private ArrayList m_all_operations = null;
199 | }
200 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/Module.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | import java.util.ArrayList;
18 |
19 | import org.antlr.v4.runtime.Token;
20 |
21 | public class Module extends DefinitionContainer implements Definition
22 | {
23 | public Module(String scopeFile, boolean isInScope, String scope, String name, Token tk)
24 | {
25 | super(scopeFile, isInScope, scope, name, tk);
26 | }
27 |
28 | public void setParent(Object obj)
29 | {
30 | m_parent = obj;
31 | }
32 |
33 | public Object getParent()
34 | {
35 | return m_parent;
36 | }
37 |
38 |
39 | /*!
40 | * @brief This function is used in stringtemplates to not generate module in some cases (Right now in RequestReply.idl).
41 | */
42 | public boolean isThereAreValidDefinitions()
43 | {
44 | boolean returnedValue = false;
45 |
46 | for(int count = 0; !returnedValue && count < getDefinitions().size(); ++count)
47 | {
48 | returnedValue = getDefinitions().get(count).isIsInterface();
49 | }
50 |
51 | return returnedValue;
52 | }
53 |
54 | /*!
55 | * @brief This function is used in stringtemplates to not generate module in some cases (Right now in generated (previous c) idl).
56 | */
57 | public boolean isThereAreDeclarations()
58 | {
59 | boolean returnedValue = false;
60 |
61 | for(int count = 0; !returnedValue && count < getDefinitions().size(); ++count)
62 | {
63 | if(getDefinitions().get(count).isIsInterface())
64 | {
65 | returnedValue = ((Interface)getDefinitions().get(count)).isThereAreDeclarations();
66 | }
67 | else
68 | {
69 | returnedValue = getDefinitions().get(count).isIsTypeDeclaration() ||
70 | getDefinitions().get(count).isIsException();
71 | }
72 | }
73 |
74 | return returnedValue;
75 | }
76 |
77 | @Override
78 | public boolean isIsModule()
79 | {
80 | return true;
81 | }
82 |
83 | @Override
84 | public boolean isIsInterface()
85 | {
86 | return false;
87 | }
88 |
89 | @Override
90 | public boolean isIsException()
91 | {
92 | return false;
93 | }
94 |
95 | @Override
96 | public boolean isIsTypeDeclaration()
97 | {
98 | return false;
99 | }
100 |
101 | @Override
102 | public boolean isIsConstDeclaration()
103 | {
104 | return false;
105 | }
106 |
107 | @Override
108 | public boolean isIsAnnotation()
109 | {
110 | return false;
111 | }
112 |
113 | ////////// RESTful block //////////
114 |
115 | public String getResourceCompleteBaseUri()
116 | {
117 | Annotation baseUri = getAnnotations().get("RESOURCES_BASE_URI");
118 | String baseUriStr = baseUri.getValue("value");
119 |
120 | if(baseUriStr != null)
121 | {
122 | // Remove http://
123 | int posInit = baseUriStr.indexOf("//");
124 |
125 | if(posInit == -1)
126 | posInit = 0;
127 | else
128 | posInit += 2;
129 |
130 | return baseUriStr.substring(posInit);
131 | }
132 |
133 | return baseUriStr;
134 | }
135 |
136 | /*
137 | * @brief This function return the base URI without the host.
138 | * Also all spaces are converted to %20.
139 | */
140 | public String getResourceBaseUri()
141 | {
142 | String baseUri = getResourceCompleteBaseUri();
143 |
144 | if(baseUri != null)
145 | {
146 | // Remove host
147 | int posEnd = baseUri.indexOf('/');
148 |
149 | if(posEnd == -1)
150 | return "";
151 | else
152 | return baseUri.substring(posEnd).replace(" ", "%20");
153 | }
154 |
155 | return null;
156 | }
157 |
158 | /*
159 | * @brief This function return the base URI without the host.
160 | * Also all spaces are converted to %20.
161 | */
162 | public String getResourceBaseUriWithoutLastBackslace()
163 | {
164 | String baseUri = getResourceBaseUri();
165 |
166 | if(baseUri != null)
167 | {
168 | if(!baseUri.isEmpty() && baseUri.charAt(baseUri.length() - 1) == '/')
169 | {
170 | if(baseUri.length() > 1)
171 | baseUri = baseUri.substring(0, baseUri.length() - 1);
172 | else
173 | baseUri = "";
174 | }
175 | return baseUri;
176 | }
177 |
178 | return null;
179 | }
180 |
181 | public String getResourceHost() {
182 | Annotation path = getAnnotations().get("RESOURCES_BASE_URI");
183 | String pathStr = path.getValue("value");
184 |
185 | // Remove http://
186 | int posInit = pathStr.indexOf("//");
187 | if(posInit == -1)
188 | posInit = 0;
189 | else
190 | posInit += 2;
191 |
192 | // Remove path
193 | int posEnd = pathStr.indexOf('/', posInit);
194 |
195 | if(posEnd == -1)
196 | posEnd = pathStr.length()-1;
197 |
198 | return pathStr.substring(posInit, posEnd);
199 | }
200 |
201 | ////////// End RESTful block //////////
202 |
203 | private Object m_parent = null;
204 | }
205 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/Notebook.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | import com.eprosima.idl.context.Context;
18 |
19 | import java.util.Map;
20 |
21 | public interface Notebook
22 | {
23 | /*!
24 | * @brief This function links all annotations to the object.
25 | * @param ctx Context used in the IDL parser. Can be useful for developers.
26 | * @param annotations Annotations to be linked.
27 | */
28 | public void addAnnotation(Context ctx, Annotation annotation);
29 |
30 | /*!
31 | * @brief This function returns all annotations linked with the object.
32 | * @return Map with the linked annotations.
33 | */
34 | public Map getAnnotations();
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/Operation.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | import com.eprosima.idl.context.Context;
18 | import com.eprosima.idl.parser.typecode.TypeCode;
19 | import com.eprosima.idl.parser.tree.Param;
20 |
21 | import java.util.ArrayList;
22 | import org.antlr.v4.runtime.Token;
23 |
24 | public class Operation extends TreeNode implements Export
25 | {
26 | public Operation(String scopeFile, boolean isInScope, String scope, String name, Token tk)
27 | {
28 | super(scopeFile, isInScope, scope, name, tk);
29 |
30 | m_params = new ArrayList();
31 | m_exceptions = new ArrayList();
32 | m_unresolvedExceptions = new ArrayList();
33 | }
34 |
35 | public void setParent(Object obj)
36 | {
37 | m_parent = obj;
38 | }
39 |
40 | public Object getParent()
41 | {
42 | return m_parent;
43 | }
44 |
45 | public boolean isIsOperation()
46 | {
47 | return true;
48 | }
49 |
50 | @Override
51 | public boolean isIsException()
52 | {
53 | return false;
54 | }
55 |
56 | @Override
57 | public boolean isIsTypeDeclaration()
58 | {
59 | return false;
60 | }
61 |
62 | @Override
63 | public boolean isIsConstDeclaration()
64 | {
65 | return false;
66 | }
67 |
68 | public void setOneway(boolean b)
69 | {
70 | m_isOneway = b;
71 | }
72 |
73 | public boolean isOneway()
74 | {
75 | return m_isOneway;
76 | }
77 |
78 | public void add(Param param)
79 | {
80 | m_params.add(param);
81 | param.setParent(this);
82 | }
83 |
84 | public ArrayList getParameters()
85 | {
86 | return m_params;
87 | }
88 |
89 | public ArrayList getInputparam()
90 | {
91 | ArrayList input = new ArrayList();
92 |
93 | for(int count = 0; count < m_params.size(); ++count)
94 | if(m_params.get(count).isInput())
95 | input.add(m_params.get(count));
96 |
97 | return input;
98 | }
99 |
100 | public ArrayList getOutputparam()
101 | {
102 | ArrayList output = new ArrayList();
103 |
104 | for(int count = 0; count < m_params.size(); ++count)
105 | if(m_params.get(count).isOutput())
106 | output.add(m_params.get(count));
107 |
108 | return output;
109 | }
110 |
111 | public ArrayList getInoutputparam()
112 | {
113 | ArrayList inoutput = new ArrayList();
114 |
115 | for(int count = 0; count < m_params.size(); ++count)
116 | if(m_params.get(count).isInput() && m_params.get(count).isOutput())
117 | inoutput.add(m_params.get(count));
118 |
119 | return inoutput;
120 | }
121 |
122 | // TODO Delete when standard change.
123 | public void setRettype(TypeCode rettype)
124 | {
125 | if(rettype != null)
126 | {
127 | m_rettype = rettype;
128 | m_rettypeparam = new Param("return_", m_rettype, Param.Kind.OUT_PARAM);
129 | }
130 | }
131 |
132 | public TypeCode getRettype()
133 | {
134 | return m_rettype;
135 | }
136 |
137 | public Param getRettypeparam()
138 | {
139 | return m_rettypeparam;
140 | }
141 |
142 | public void addException(com.eprosima.idl.parser.tree.Exception exception)
143 | {
144 | m_exceptions.add(exception);
145 | }
146 |
147 | public ArrayList getExceptions()
148 | {
149 | return m_exceptions;
150 | }
151 |
152 | public void addUnresolvedException(String ename)
153 | {
154 | m_unresolvedExceptions.add(ename);
155 | }
156 |
157 | @Override
158 | public boolean resolve(Context ctx)
159 | {
160 | //Resolve unresolved exceptions. This unresolved exceptions should be exceptions of the parent interface.
161 |
162 | if(m_parent != null)
163 | {
164 | if(m_parent instanceof Interface)
165 | {
166 | Interface ifc = (Interface)m_parent;
167 |
168 | for(int count = 0; count < m_unresolvedExceptions.size(); ++count)
169 | {
170 | com.eprosima.idl.parser.tree.Exception ex = ifc.getException(ctx.getScope(), m_unresolvedExceptions.get(count));
171 |
172 | if(ex != null)
173 | {
174 |
175 | m_exceptions.add(ex);
176 | }
177 | else
178 | {
179 | System.out.println("ERROR: The definition of exception " + m_unresolvedExceptions.get(count) +
180 | " was not found");
181 | //TODO
182 | //return false;
183 | }
184 | }
185 |
186 | return true;
187 | }
188 | else
189 | {
190 | System.out.println("ERROR: Parent is not an interface");
191 | }
192 | }
193 | else
194 | {
195 | System.out.println("ERROR: Not parent for operation");
196 | }
197 |
198 | return false;
199 | }
200 |
201 | @Override
202 | protected boolean isDeclaredInsideInterface()
203 | {
204 | return true;
205 | }
206 |
207 | private Object m_parent = null;
208 | private boolean m_isOneway = false;
209 | private ArrayList m_params;
210 | private ArrayList m_exceptions;
211 | private ArrayList m_unresolvedExceptions;
212 | private TypeCode m_rettype = null;
213 | private Param m_rettypeparam = null;
214 | }
215 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/Param.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | import com.eprosima.idl.parser.typecode.TypeCode;
18 | import com.eprosima.idl.context.Context;
19 |
20 | import java.util.Map;
21 | import java.util.HashMap;
22 |
23 | public class Param implements Notebook
24 | {
25 | public enum Kind
26 | {
27 | IN_PARAM,
28 | OUT_PARAM,
29 | INOUT_PARAM
30 | };
31 |
32 | public boolean isInput()
33 | {
34 | if(m_kind == Kind.IN_PARAM || m_kind == Kind.INOUT_PARAM)
35 | {
36 | return true;
37 | }
38 |
39 | return false;
40 | }
41 |
42 | public boolean isOutput()
43 | {
44 | if(m_kind == Kind.OUT_PARAM || m_kind == Kind.INOUT_PARAM)
45 | {
46 | return true;
47 | }
48 |
49 | return false;
50 | }
51 |
52 | public boolean isOnlyOutput()
53 | {
54 | if(m_kind == Kind.OUT_PARAM)
55 | {
56 | return true;
57 | }
58 |
59 | return false;
60 | }
61 |
62 | public String getComment()
63 | {
64 | if(m_kind == Kind.IN_PARAM)
65 | return "in";
66 | else if(m_kind == Kind.OUT_PARAM)
67 | return "out";
68 | else if(m_kind == Kind. INOUT_PARAM)
69 | return "inout";
70 |
71 | return "error";
72 | }
73 |
74 | public Param(String name, TypeCode typecode, Kind kind)
75 | {
76 | m_name = name;
77 | m_typecode = typecode;
78 | m_kind = kind;
79 | }
80 |
81 | public Param(String name, Definition definition, Kind kind)
82 | {
83 | m_name = name;
84 | m_definition = definition;
85 | m_kind = kind;
86 | }
87 |
88 | public String getName()
89 | {
90 | return m_name;
91 | }
92 |
93 | public TypeCode getTypecode()
94 | {
95 | return m_typecode;
96 | }
97 |
98 | public Definition getDefinition()
99 | {
100 | return m_definition;
101 | }
102 |
103 | public void setParent(Object obj)
104 | {
105 | m_parent = obj;
106 | }
107 |
108 | public Object getParent()
109 | {
110 | return m_parent;
111 | }
112 |
113 | @Override
114 | public void addAnnotation(Context ctx, Annotation annotation)
115 | {
116 | if(annotation != null)
117 | {
118 | m_annotations.put(annotation.getName(), annotation);
119 | }
120 | }
121 |
122 | @Override
123 | public Map getAnnotations()
124 | {
125 | return m_annotations;
126 | }
127 |
128 | private Kind m_kind = Kind.IN_PARAM;
129 | private String m_name = null;
130 | private TypeCode m_typecode = null;
131 | private Definition m_definition = null;
132 | private Object m_parent = null;
133 | //! Map that stores the annotations of the parameter.
134 | private HashMap m_annotations = new HashMap();
135 | }
136 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/Specification.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | public class Specification
21 | {
22 | public Specification()
23 | {
24 | m_definitions = new ArrayList();
25 | }
26 |
27 | public void setDefinitions(List children) { m_definitions = children; }
28 | public List getDefinitions() { return m_definitions; }
29 | public void addChild(Definition child) { m_definitions.add(child); }
30 |
31 | private List m_definitions;
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/TreeNode.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | import com.eprosima.idl.context.Context;
18 | import com.eprosima.idl.parser.exception.RuntimeGenerationException;
19 |
20 | import java.util.Map;
21 | import java.util.HashMap;
22 |
23 | import org.antlr.v4.runtime.Token;
24 |
25 | public class TreeNode implements Notebook
26 | {
27 | public TreeNode(String scopeFile, boolean isInScope, String scope, String name, Token tk)
28 | {
29 | m_scopeFile = scopeFile;
30 | m_isinscope = isInScope;
31 | m_name = name;
32 | m_scope = scope;
33 | m_annotations = new HashMap();
34 | tk_ = tk;
35 | }
36 |
37 | public String getScopeFile()
38 | {
39 | return m_scopeFile;
40 | }
41 |
42 | public boolean isInScope()
43 | {
44 | return m_isinscope;
45 | }
46 |
47 | public String getName()
48 | {
49 | return m_name;
50 | }
51 |
52 | public String getScopedname()
53 | {
54 | if(m_scope == null || m_scope.isEmpty())
55 | {
56 | return m_name;
57 | }
58 |
59 | return m_scope + "::" + m_name;
60 | }
61 |
62 | public String getROS2Scopedname()
63 | {
64 | if(m_scope == null || m_scope.isEmpty())
65 | {
66 | return m_name;
67 | }
68 |
69 | return m_scope + "::dds_::" + m_name + "_";
70 | }
71 |
72 | public String getCScopedname()
73 | {
74 | if(m_scope.isEmpty())
75 | {
76 | return m_name;
77 | }
78 |
79 | return m_scope.replace("::", "_") + "_" + m_name;
80 | }
81 |
82 | public String getJavaScopedname()
83 | {
84 | if(m_scope.isEmpty())
85 | {
86 | return m_name;
87 | }
88 |
89 | return m_scope.replace("::", ".") + "." + m_name;
90 | }
91 |
92 | public String getScope()
93 | {
94 | return m_scope;
95 | }
96 |
97 | /*!
98 | * @ingroup api_for_stg
99 | * @brief This function returns the namespace where the type would be declared.
100 | * @return Namespace where the type would be declared.
101 | */
102 | public String getNamespace()
103 | {
104 | String namespace = m_scope;
105 | // Remove last scope when declared inside an Interface
106 | if (isDeclaredInsideInterface())
107 | {
108 | int last_index = m_scope.lastIndexOf("::");
109 | if (last_index == -1)
110 | {
111 | namespace = "";
112 | }
113 | else
114 | {
115 | namespace = m_scope.substring(0, last_index);
116 | }
117 | }
118 | return namespace;
119 | }
120 |
121 | protected boolean isDeclaredInsideInterface()
122 | {
123 | return false;
124 | }
125 |
126 | /*
127 | * @brief This function returns the scoped name of the interface but
128 | * changing "::" by "_".
129 | */
130 | public String getFormatedScopedname()
131 | {
132 | String ret = null;
133 |
134 | if(m_scope == null || m_scope.isEmpty())
135 | {
136 | ret = m_name;
137 | }
138 | else
139 | {
140 | ret = m_scope + "::" + m_name;
141 | }
142 |
143 | return ret.replaceAll("::", "_");
144 | }
145 |
146 | public boolean getHasScope()
147 | {
148 | return !(m_scope == null || m_scope.isEmpty());
149 | }
150 |
151 | @Override
152 | public void addAnnotation(Context ctx, Annotation annotation)
153 | {
154 | if(annotation != null)
155 | {
156 | m_annotations.put(annotation.getName(), annotation);
157 | }
158 | }
159 |
160 | @Override
161 | public Map getAnnotations()
162 | {
163 | return m_annotations;
164 | }
165 |
166 | /**
167 | * @ingroup api_for_stg
168 | * @brief This function checks if the node is annotated as nested.
169 | *
170 | * It is designed so it can be used in the templates with `$if(node.annotatedAsNested)$`
171 | *
172 | * @return true if the node is annotated as nested, false otherwise.
173 | */
174 | public boolean isAnnotatedAsNested()
175 | {
176 | Annotation ann = m_annotations.get(Annotation.nested_str);
177 | if (ann != null)
178 | {
179 | try
180 | {
181 | return ann.getValue().toUpperCase().equals(Annotation.capitalized_true_str);
182 | }
183 | catch (RuntimeGenerationException ex)
184 | {
185 | // Should not be called as @nested annotation has only one parameter
186 | }
187 | }
188 | return false;
189 | }
190 |
191 | public Token getToken()
192 | {
193 | return tk_;
194 | }
195 |
196 | private String m_scopeFile = null;
197 | private boolean m_isinscope = false;
198 | private String m_name = null;
199 | private String m_scope = null;
200 | //! Map that stores the annotations of the interface.
201 | private HashMap m_annotations = null;
202 | //! IDL Parser token
203 | Token tk_ = null;
204 | }
205 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/tree/TypeDeclaration.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.tree;
16 |
17 | import com.eprosima.idl.context.Context;
18 | import com.eprosima.idl.parser.typecode.TypeCode;
19 |
20 | import org.antlr.v4.runtime.Token;
21 |
22 | public class TypeDeclaration extends TreeNode implements Definition, Export
23 | {
24 | public TypeDeclaration(String scopeFile, boolean isInScope, String scope, String name, TypeCode typecode, Token token)
25 | {
26 | super(scopeFile, isInScope, scope, name, token);
27 |
28 | m_typecode = typecode;
29 | // Set as parent to the Typecode.
30 | m_typecode.setParent(this);
31 | for(Annotation annotation : typecode.getAnnotationList())
32 | {
33 | addAnnotation(null, annotation);
34 | }
35 | }
36 |
37 | public TypeCode getTypeCode()
38 | {
39 | return m_typecode;
40 | }
41 |
42 | public void setParent(Object obj)
43 | {
44 | m_parent = obj;
45 | }
46 |
47 | public Object getParent()
48 | {
49 | return m_parent;
50 | }
51 |
52 | @Override
53 | public boolean isIsModule()
54 | {
55 | return false;
56 | }
57 |
58 | @Override
59 | public boolean isIsOperation()
60 | {
61 | return false;
62 | }
63 |
64 | @Override
65 | public boolean isIsException()
66 | {
67 | return false;
68 | }
69 |
70 | @Override
71 | public boolean isIsInterface()
72 | {
73 | return false;
74 | }
75 |
76 | @Override
77 | public boolean isIsTypeDeclaration()
78 | {
79 | return true;
80 | }
81 |
82 | @Override
83 | public boolean isIsConstDeclaration()
84 | {
85 | return false;
86 | }
87 |
88 | @Override
89 | public boolean isIsAnnotation()
90 | {
91 | return false;
92 | }
93 |
94 | @Override
95 | public boolean resolve(Context ctx)
96 | {
97 | return true;
98 | }
99 |
100 | @Override
101 | public boolean isAnnotatedAsNested()
102 | {
103 | if (getParent() instanceof Interface)
104 | {
105 | return true;
106 | }
107 |
108 | return super.isAnnotatedAsNested();
109 | }
110 |
111 | @Override
112 | protected boolean isDeclaredInsideInterface()
113 | {
114 | return m_parent instanceof Interface;
115 | }
116 |
117 | private TypeCode m_typecode = null;
118 | private Object m_parent = null;
119 | }
120 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/typecode/AnyTypeCode.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.typecode;
16 |
17 |
18 | /**
19 | * Temporal type that will be resolved at compilation time.
20 | */
21 | public class AnyTypeCode extends TypeCode
22 | {
23 | public AnyTypeCode()
24 | {
25 | super(Kind.KIND_NULL);
26 | }
27 |
28 | @Override
29 | public String getNamespace()
30 | {
31 | return null;
32 | }
33 |
34 | @Override
35 | public String getCppTypename()
36 | {
37 | return null;
38 | }
39 |
40 | @Override
41 | public String getCTypename()
42 | {
43 | return null;
44 | }
45 |
46 | @Override
47 | public String getJavaTypename()
48 | {
49 | return null;
50 | }
51 |
52 | @Override
53 | public String getIdlTypename()
54 | {
55 | return null;
56 | }
57 |
58 | @Override
59 | public boolean isPrimitive()
60 | {
61 | return false;
62 | }
63 |
64 | @Override
65 | public String getTypeIdentifier()
66 | {
67 | return null;
68 | }
69 |
70 | @Override
71 | public boolean isPrimitiveType()
72 | {
73 | return false;
74 | }
75 |
76 | @Override
77 | public String getInitialValue()
78 | {
79 | return "";
80 | }
81 |
82 | @Override
83 | public String getSize()
84 | {
85 | return null;
86 | }
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/typecode/Bitfield.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.typecode;
16 |
17 |
18 |
19 | public class Bitfield extends Member
20 | {
21 | public Bitfield()
22 | {
23 | super();
24 | }
25 |
26 | public Bitfield(BitsetTypeCode typecode, BitfieldSpec spec, String name)
27 | {
28 | super(typecode, name);
29 | m_spec = spec;
30 | }
31 |
32 | public void setBasePosition(
33 | int position)
34 | {
35 | m_base = position;
36 | }
37 |
38 | public int getBasePosition()
39 | {
40 | return m_base;
41 | }
42 |
43 | public BitfieldSpec getSpec()
44 | {
45 | return m_spec;
46 | }
47 |
48 | /*!
49 | * @ingroup api_for_stg
50 | * @brief This function check if the bitfield was defined by name.
51 | * @return true if the bitfield was defined by name in the IDL file. false otherwise.
52 | */
53 | public boolean getIsDefined()
54 | {
55 | return !getName().isEmpty();
56 | }
57 |
58 | /*!
59 | * @ingroup api_for_stg
60 | * @brief This function returns a string containing the mask in hexadecimal which can be used to make bitwise AND
61 | * operation over the bitfield.
62 | * @return The bit mask in hexadecimal.
63 | */
64 | public String getBitmask()
65 | {
66 | String mask = "";
67 | int mod = m_spec.getBitSize() / 4;
68 | int rest = m_spec.getBitSize() % 4;
69 |
70 | while (0 != mod)
71 | {
72 | mask += "F";
73 | --mod;
74 | }
75 |
76 | switch(rest)
77 | {
78 | case 1:
79 | mask = "1" + mask;
80 | break;
81 | case 2:
82 | mask = "3" + mask;
83 | break;
84 | case 3:
85 | mask = "7" + mask;
86 | break;
87 | default:
88 | break;
89 | }
90 |
91 | if (mask.isEmpty())
92 | {
93 | mask = "0";
94 | }
95 |
96 | return "0x" + mask;
97 | }
98 |
99 | @Override
100 | public boolean isIsPlain()
101 | {
102 | return true;
103 | }
104 |
105 | @Override
106 | public boolean isIsBounded()
107 | {
108 | return true;
109 | }
110 |
111 | private int m_base = -1;
112 | private BitfieldSpec m_spec = null;
113 | }
114 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/typecode/BitfieldSpec.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.typecode;
16 |
17 | public class BitfieldSpec
18 | {
19 | public static int generateKind(
20 | String bitsize)
21 | {
22 | int size = Integer.parseInt(bitsize);
23 | if (size == 1)
24 | {
25 | return Kind.KIND_BOOLEAN;
26 | }
27 | else if (size <= 8)
28 | {
29 | return Kind.KIND_UINT8;
30 | }
31 | else if (size <= 16)
32 | {
33 | return Kind.KIND_USHORT;
34 | }
35 | else if (size <= 32)
36 | {
37 | return Kind.KIND_ULONG;
38 | }
39 | else if (size <= 64)
40 | {
41 | return Kind.KIND_ULONGLONG;
42 | }
43 |
44 | return Kind.KIND_ULONG;
45 | }
46 |
47 | public BitfieldSpec(
48 | String scope,
49 | String bitsize,
50 | TypeCode type)
51 | {
52 | m_kind = Kind.KIND_BITFIELD;
53 | m_scope = scope;
54 | m_type = type;
55 | m_bitsize = bitsize;
56 | }
57 |
58 | public String getScope()
59 | {
60 | return m_scope;
61 | }
62 |
63 | public boolean getHasScope()
64 | {
65 | return !m_scope.isEmpty();
66 | }
67 |
68 | public String getNamespace()
69 | {
70 | return "";
71 | }
72 |
73 | public String getCppTypename()
74 | {
75 | return m_type.getCppTypename();
76 | }
77 |
78 | public String getCTypename()
79 | {
80 | return m_type.getCTypename();
81 | }
82 |
83 | public String getJavaTypename()
84 | {
85 | return m_type.getJavaTypename();
86 | }
87 |
88 | public String getIdlTypename() // TODO al template?
89 | {
90 | if (m_type == null)
91 | {
92 | return "bitfield <" + m_bitsize + ">";
93 | }
94 | else
95 | {
96 | return "bitfield <" + m_bitsize + ", " + m_type.getIdlTypename() + ">";
97 | }
98 | }
99 |
100 | public boolean isPrimitive()
101 | {
102 | return true; // Use it as alias of m_type
103 | }
104 |
105 | public int getBitSize()
106 | {
107 | if (m_bitsize == null)
108 | {
109 | return 0;
110 | }
111 | return Integer.parseInt(m_bitsize);
112 | }
113 |
114 | public String getSize()
115 | {
116 | return (m_type != null) ? m_type.getSize() : "0";
117 | }
118 |
119 | public TypeCode getTypecode()
120 | {
121 | return m_type;
122 | }
123 |
124 | public String getInitialValue()
125 | {
126 | return m_type.getInitialValue();
127 | }
128 |
129 | private int m_kind = Kind.KIND_NULL;
130 |
131 | private TypeCode m_type = null;
132 |
133 | private String m_scope = null;
134 |
135 | private String m_bitsize = null;
136 | }
137 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/typecode/Bitmask.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.typecode;
16 |
17 |
18 |
19 | public class Bitmask extends Member
20 | {
21 | public Bitmask()
22 | {
23 | super();
24 | }
25 |
26 | public Bitmask(BitmaskTypeCode typecode, String name)
27 | {
28 | super(typecode, name);
29 | }
30 |
31 | public void setPosition(
32 | int position)
33 | {
34 | m_position = position;
35 | }
36 |
37 | public int getPosition()
38 | {
39 | return m_position;
40 | }
41 |
42 | @Override
43 | public boolean isIsPlain()
44 | {
45 | return true;
46 | }
47 |
48 | @Override
49 | public boolean isIsBounded()
50 | {
51 | return true;
52 | }
53 |
54 | private int m_position = -1;
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/typecode/BitsetTypeCode.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.typecode;
16 |
17 | import java.util.ArrayList;
18 | import java.util.LinkedHashMap;
19 | import java.util.List;
20 | import org.stringtemplate.v4.ST;
21 |
22 | import com.eprosima.idl.context.Context;
23 | import com.eprosima.idl.parser.exception.ParseException;
24 | import com.eprosima.idl.parser.tree.Inherits;
25 |
26 |
27 | public class BitsetTypeCode extends MemberedTypeCode implements Inherits
28 | {
29 | public BitsetTypeCode(
30 | String scope,
31 | String name)
32 | {
33 | super(Kind.KIND_BITSET, scope, name);
34 | }
35 |
36 | @Override
37 | public boolean isIsBitsetType()
38 | {
39 | return true;
40 | }
41 |
42 | @Override
43 | public boolean isObjectType()
44 | {
45 | return true;
46 | }
47 |
48 | @Override
49 | public String getCppTypename()
50 | {
51 | ST st = getCppTypenameFromStringTemplate();
52 | st.add("name", getScopedname());
53 | return st.render();
54 | }
55 |
56 | @Override
57 | public String getCTypename()
58 | {
59 | ST st = getCTypenameFromStringTemplate();
60 | st.add("name", getCScopedname());
61 | return st.render();
62 | }
63 |
64 | @Override
65 | public String getJavaTypename()
66 | {
67 | ST st = getJavaTypenameFromStringTemplate();
68 | st.add("name", getJavaScopedname());
69 | return st.render();
70 | }
71 |
72 | @Override
73 | public String getIdlTypename()
74 | {
75 | ST st = getIdlTypenameFromStringTemplate();
76 | st.add("name", getScopedname());
77 | return st.render();
78 | }
79 |
80 | /*!
81 | * @ingroup api_for_stg
82 | * @brief This function returns all bitfields including the inherited ones.
83 | * @return A list of all bitfields.
84 | */
85 | public List getBitfields()
86 | {
87 | ArrayList result = new ArrayList();
88 | result.addAll(m_bitfields.values());
89 | return result;
90 | }
91 |
92 | /*!
93 | * @ingroup api_for_stg
94 | * @brief This function returns all bitfields including the inherited ones which were defined by name.
95 | * @return A list of all bitfields defined by name.
96 | */
97 | public List getDefinedBitfields()
98 | {
99 | ArrayList result = new ArrayList();
100 | for (Bitfield bitfield : m_bitfields.values())
101 | {
102 | if (bitfield.getIsDefined())
103 | {
104 | result.add(bitfield);
105 | }
106 | }
107 | return result;
108 | }
109 |
110 | public boolean addBitfield(
111 | Bitfield bitfield)
112 | {
113 | if (null == bitfield.getName())
114 | {
115 | bitfield.setName("");
116 | }
117 |
118 | String key = bitfield.getName();
119 |
120 | if (key.isEmpty())
121 | {
122 | ++annonymous_index_;
123 | key = "_annonymous_" + Integer.toString(annonymous_index_);
124 | }
125 |
126 | if (!m_bitfields.containsKey(key))
127 | {
128 | m_bitfields.put(key, bitfield);
129 | bitfield.setBasePosition(m_current_base);
130 | m_current_base += bitfield.getSpec().getBitSize();
131 |
132 | if (bitfield.getIsDefined())
133 | {
134 | addMember(bitfield);
135 | }
136 |
137 | return true;
138 | }
139 | return false;
140 | }
141 |
142 | /*!
143 | * @ingroup api_for_g4
144 | * @brief This function adds the inherited Bitset to this Bitset instance.
145 | * Internally add the member from inherited Bitset to this instance, making a plain bitset as defined in IDL to
146 | * C++11 2021.
147 | * @param ctx Parser context.
148 | * @param parent Inherited Bitset
149 | */
150 | @Override
151 | public void addInheritance(
152 | Context ctx,
153 | TypeCode parent) throws ParseException
154 | {
155 | if (super_type_ == null && parent instanceof BitsetTypeCode)
156 | {
157 | enclosed_super_type_ = (BitsetTypeCode)parent;
158 | super_type_ = parent;
159 | }
160 | else if (super_type_ == null && parent instanceof AliasTypeCode)
161 | {
162 | AliasTypeCode alias = (AliasTypeCode)parent;
163 | if (alias.getContentTypeCode() instanceof BitsetTypeCode)
164 | {
165 | enclosed_super_type_ = (BitsetTypeCode)alias.getContentTypeCode();
166 | }
167 | else
168 | {
169 | throw new ParseException(null, "Given alias does not correspond to a bitset");
170 | }
171 | super_type_ = parent;
172 | }
173 | else if (super_type_ != null)
174 | {
175 | throw new ParseException(null, "Only single type inheritance is supported");
176 | }
177 | else
178 | {
179 | throw new ParseException(null, "Inheritance must correspond to the name of a previously defined bitset");
180 | }
181 |
182 | //{{{ Add members of inherited Bitset.
183 | if (null != enclosed_super_type_)
184 | {
185 | enclosed_super_type_.m_bitfields.forEach((key, bitfield) ->
186 | {
187 | Bitfield new_bitfield = new Bitfield(this, bitfield.getSpec(), bitfield.getName());
188 | m_bitfields.put(key, bitfield);
189 | m_current_base += bitfield.getSpec().getBitSize();
190 |
191 | if (bitfield.getIsDefined())
192 | {
193 | addMember(bitfield);
194 | }
195 | });
196 | }
197 | //}}}
198 | }
199 |
200 | @Override
201 | public TypeCode getInheritance()
202 | {
203 | return super_type_;
204 | }
205 |
206 | @Override
207 | public TypeCode getEnclosedInheritance()
208 | {
209 | return enclosed_super_type_;
210 | }
211 |
212 | public int getBitSize()
213 | {
214 | return m_current_base;
215 | }
216 |
217 | private int annonymous_index_ = 0;
218 | private BitsetTypeCode enclosed_super_type_ = null;
219 | private TypeCode super_type_ = null;
220 | private LinkedHashMap m_bitfields = new LinkedHashMap();
221 | private int m_current_base = 0;
222 | }
223 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/typecode/CollectionElement.java:
--------------------------------------------------------------------------------
1 | // Copyright 2023 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.typecode;
16 |
17 | public class CollectionElement extends MemberAppliedAnnotations
18 | {
19 | public CollectionElement()
20 | {
21 | super();
22 | }
23 |
24 | public CollectionElement(TypeCode typecode)
25 | {
26 | super();
27 | typecode_ = typecode;
28 | }
29 |
30 | public TypeCode getTypecode()
31 | {
32 | return typecode_;
33 | }
34 |
35 | public void setTypecode(TypeCode typecode)
36 | {
37 | typecode_ = typecode;
38 | }
39 |
40 | private TypeCode typecode_ = null;
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/typecode/ContainerTypeCode.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.typecode;
16 |
17 | import com.eprosima.idl.parser.tree.Definition;
18 |
19 | public abstract class ContainerTypeCode extends TypeCode
20 | {
21 | public static String default_unbounded_max_size = "0";
22 |
23 | protected ContainerTypeCode(int kind)
24 | {
25 | super(kind);
26 | }
27 |
28 | @Override
29 | public String getNamespace()
30 | {
31 | return "";
32 | }
33 |
34 | @Override
35 | public abstract String getCppTypename();
36 |
37 | @Override
38 | public abstract String getCTypename();
39 |
40 | @Override
41 | public abstract String getIdlTypename();
42 |
43 | public TypeCode getContentTypeCode()
44 | {
45 | return collection_element_.getTypecode();
46 | }
47 |
48 | public Definition getContentDefinition()
49 | {
50 | return m_contentDefinition;
51 | }
52 |
53 | public void setContentTypeCode(TypeCode contentTypeCode)
54 | {
55 | collection_element_.setTypecode(contentTypeCode);
56 | }
57 |
58 | public void setContentDefinition(Definition contentDefinition)
59 | {
60 | m_contentDefinition = contentDefinition;
61 | }
62 |
63 | public int getDepth()
64 | {
65 | int ret = 1;
66 |
67 | if (collection_element_.getTypecode().isPrimitive())
68 | {
69 | return ret;
70 | }
71 | else
72 | {
73 | if (collection_element_.getTypecode() instanceof ContainerTypeCode)
74 | {
75 | ret += ((ContainerTypeCode) collection_element_.getTypecode()).getDepth();
76 | }
77 | }
78 |
79 | return ret;
80 | }
81 |
82 | @Override
83 | public boolean isIsPlain()
84 | {
85 | if (collection_element_.getTypecode() != null)
86 | {
87 | return collection_element_.getTypecode().isIsPlain();
88 | }
89 | return false;
90 | }
91 |
92 | @Override
93 | public boolean isIsBounded()
94 | {
95 | if (collection_element_.getTypecode() != null)
96 | {
97 | return collection_element_.getTypecode().isIsBounded();
98 | }
99 | return false;
100 | }
101 |
102 | private CollectionElement collection_element_ = new CollectionElement();
103 | private Definition m_contentDefinition = null;
104 | }
105 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/typecode/EnumMember.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.typecode;
16 |
17 | public class EnumMember extends Member
18 | {
19 | public EnumMember(String name)
20 | {
21 | super(null, name);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/typecode/EnumTypeCode.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.typecode;
16 |
17 | import org.stringtemplate.v4.ST;
18 |
19 |
20 | public class EnumTypeCode extends MemberedTypeCode
21 | {
22 | public EnumTypeCode(
23 | String scope,
24 | String name)
25 | {
26 | super(Kind.KIND_ENUM, scope, name);
27 | }
28 |
29 | @Override
30 | public boolean isPrimitive()
31 | {
32 | return true;
33 | }
34 |
35 | @Override
36 | public boolean isIsType_c()
37 | {
38 | return true;
39 | }
40 |
41 | @Override
42 | public boolean isIsEnumType()
43 | {
44 | return true;
45 | }
46 |
47 | @Override
48 | public String getTypeIdentifier()
49 | {
50 | return "EK_MINIMAL";
51 | }
52 |
53 | @Override
54 | public boolean isObjectType()
55 | {
56 | return true;
57 | }
58 |
59 | public void addMember(
60 | EnumMember member)
61 | {
62 | addMember((Member)member);
63 | }
64 |
65 | @Override
66 | public String getCppTypename()
67 | {
68 | ST st = getCppTypenameFromStringTemplate();
69 | st.add("name", getScopedname());
70 | return st.render();
71 | }
72 |
73 | @Override
74 | public String getCTypename()
75 | {
76 | ST st = getCTypenameFromStringTemplate();
77 | st.add("name", getCScopedname());
78 | return st.render();
79 | }
80 |
81 | @Override
82 | public String getJavaTypename()
83 | {
84 | ST st = getJavaTypenameFromStringTemplate();
85 | st.add("name", getJavaScopedname());
86 | return st.render();
87 | }
88 |
89 | @Override
90 | public String getIdlTypename()
91 | {
92 | ST st = getIdlTypenameFromStringTemplate();
93 | st.add("name", getScopedname());
94 | return st.render();
95 | }
96 |
97 | @Override
98 | public String getInitialValue()
99 | {
100 | if (getMembers().size() > 0)
101 | {
102 | return getScopedname() + "::" + getMembers().get(0).getName();
103 | }
104 |
105 | return "";
106 | }
107 |
108 | @Override
109 | public String getJavaInitialValue()
110 | {
111 | if (getMembers().size() > 0)
112 | {
113 | return javapackage + getJavaScopedname() + "." + getMembers().get(0).getName();
114 | }
115 |
116 | return "";
117 | }
118 |
119 | @Override
120 | public String getSize()
121 | {
122 | return "4";
123 | }
124 |
125 | @Override
126 | public boolean isIsBounded()
127 | {
128 | return true;
129 | }
130 |
131 | @Override
132 | public boolean isIsPlain()
133 | {
134 | return true;
135 | }
136 |
137 | public int getBitBound()
138 | {
139 | // TODO: pending @bit_bound annotation application to enum types
140 | return 32;
141 | }
142 |
143 | }
144 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/typecode/Kind.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.typecode;
16 |
17 |
18 | public class Kind
19 | {
20 | public static final int KIND_NULL = 0x00000000;
21 | public static final int KIND_SHORT = 0x00000001;
22 | public static final int KIND_LONG = 0x00000002;
23 | public static final int KIND_USHORT = 0x00000003;
24 | public static final int KIND_ULONG = 0x00000004;
25 | public static final int KIND_FLOAT = 0x00000005;
26 | public static final int KIND_DOUBLE = 0x00000006;
27 | public static final int KIND_BOOLEAN = 0x00000007;
28 | public static final int KIND_CHAR = 0x00000008;
29 | public static final int KIND_OCTET = 0x00000009;
30 | public static final int KIND_STRUCT = 0x0000000a;
31 | public static final int KIND_UNION = 0x0000000b;
32 | public static final int KIND_ENUM = 0x0000000c;
33 | public static final int KIND_STRING = 0x0000000d;
34 | public static final int KIND_SEQUENCE = 0x0000000e;
35 | public static final int KIND_ARRAY = 0x0000000f;
36 | public static final int KIND_ALIAS = 0x00000010;
37 | public static final int KIND_LONGLONG = 0x00000011;
38 | public static final int KIND_ULONGLONG = 0x00000012;
39 | public static final int KIND_LONGDOUBLE = 0x00000013;
40 | public static final int KIND_WCHAR = 0x00000014;
41 | public static final int KIND_WSTRING = 0x00000015;
42 | public static final int KIND_VALUE = 0x00000016;
43 | public static final int KIND_SPARSE = 0x00000017;
44 | public static final int KIND_SET = 0x00000018;
45 | public static final int KIND_MAP = 0x00000019;
46 | public static final int KIND_BITSET = 0x0000001A;
47 | public static final int KIND_BITMASK = 0x0000001B;
48 | public static final int KIND_BITFIELD = 0x0000001C;
49 | public static final int KIND_INT8 = 0x0000001D;
50 | public static final int KIND_UINT8 = 0x0000001E;
51 | }
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/typecode/MapTypeCode.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.typecode;
16 |
17 | import org.stringtemplate.v4.ST;
18 | import com.eprosima.idl.parser.tree.Definition;
19 |
20 |
21 | public class MapTypeCode extends ContainerTypeCode
22 | {
23 | public MapTypeCode(
24 | String maxsize,
25 | String evaluated_maxsize)
26 | {
27 | super(Kind.KIND_MAP);
28 | m_maxsize = maxsize;
29 | evaluated_maxsize_ = evaluated_maxsize;
30 | }
31 |
32 | public boolean isIsType_19()
33 | {
34 | return true;
35 | }
36 |
37 |
38 | /*!
39 | * @ingroup api_for_stg
40 | * @brief This function can be used to check if TypeIdentifier's kind is the small one or the large one.
41 | * @return @e false if map is unbound or smaller than 256.
42 | * Otherwise @e true is returned.
43 | */
44 | public boolean getIsTypeIdentifierKindLarge()
45 | {
46 | if (!isUnbound() && Integer.parseInt(evaluated_maxsize_) >= 256)
47 | {
48 | return true;
49 | }
50 |
51 | return false;
52 | }
53 |
54 | /*!
55 | * @ingroup api_for_stg
56 | * @brief This function can be used to retrieve the TypeIdentifier's kind.
57 | * @return @e TI_PLAIN_MAP_SMALL if map is unbound or smaller than 256.
58 | * Otherwise @e TI_PLAIN_MAP_LARGE is returned.
59 | */
60 | @Override
61 | public String getTypeIdentifier()
62 | {
63 | if (getIsTypeIdentifierKindLarge())
64 | {
65 | return "TI_PLAIN_MAP_LARGE";
66 | }
67 | return "TI_PLAIN_MAP_SMALL";
68 | }
69 |
70 | @Override
71 | public boolean isPlainType()
72 | {
73 | return true;
74 | }
75 |
76 | @Override
77 | public boolean isIsMapType()
78 | {
79 | return true;
80 | }
81 |
82 | @Override
83 | public String getCppTypename()
84 | {
85 | ST st = getCppTypenameFromStringTemplate();
86 | st.add("key", getKeyTypeCode().getCppTypename());
87 | st.add("value", getValueTypeCode().getCppTypename());
88 | st.add("maxsize", m_maxsize);
89 | return st.render();
90 | }
91 |
92 | @Override
93 | public String getCTypename()
94 | {
95 | ST st = getCTypenameFromStringTemplate();
96 | st.add("key", getKeyTypeCode().getCTypename());
97 | st.add("value", getValueTypeCode().getCTypename());
98 | st.add("maxsize", m_maxsize);
99 | return st.render();
100 | }
101 |
102 | @Override
103 | public String getJavaTypename()
104 | {
105 | ST st = getJavaTypenameFromStringTemplate();
106 | st.add("key", getKeyTypeCode().getJavaTypename());
107 | st.add("value", getValueTypeCode().getJavaTypename());
108 | st.add("maxsize", m_maxsize);
109 | return st.render();
110 | }
111 |
112 | @Override
113 | public String getIdlTypename()
114 | {
115 | ST st = getIdlTypenameFromStringTemplate();
116 | st.add("key", getKeyTypeCode().getIdlTypename());
117 | st.add("value", getValueTypeCode().getIdlTypename());
118 | st.add("maxsize", m_maxsize);
119 | return st.render();
120 | }
121 |
122 | @Override
123 | public String getMaxsize()
124 | {
125 | if (m_maxsize == null)
126 | {
127 | return default_unbounded_max_size;
128 | }
129 |
130 | return m_maxsize;
131 | }
132 |
133 | @Override
134 | public String getEvaluatedMaxsize()
135 | {
136 | if (evaluated_maxsize_ == null)
137 | {
138 | return getMaxsize();
139 | }
140 |
141 | return evaluated_maxsize_;
142 | }
143 |
144 | public TypeCode getKeyTypeCode()
145 | {
146 | return m_keyTypeCode;
147 | }
148 |
149 | public void setKeyTypeCode(
150 | TypeCode keyTypeCode)
151 | {
152 | m_keyTypeCode = keyTypeCode;
153 | }
154 |
155 | public TypeCode getValueTypeCode()
156 | {
157 | return m_valueTypeCode;
158 | }
159 |
160 | public void setValueTypeCode(
161 | TypeCode valueTypeCode)
162 | {
163 | m_valueTypeCode = valueTypeCode;
164 | }
165 |
166 | public Definition getKeyDefinition()
167 | {
168 | return m_keyDefinition;
169 | }
170 |
171 | public void setKeyDefinition(
172 | Definition keyDefinition)
173 | {
174 | m_keyDefinition = keyDefinition;
175 | }
176 |
177 | public Definition getValueDefinition()
178 | {
179 | return m_valueDefinition;
180 | }
181 |
182 | public void setValueDefinition(
183 | Definition valueDefinition)
184 | {
185 | m_valueDefinition = valueDefinition;
186 | }
187 |
188 | /**
189 | * This API is to check if this specific collection has a bound set.
190 | * It does not check if the complete collection is bounded or not.
191 | */
192 | public boolean isUnbound()
193 | {
194 | return null == m_maxsize;
195 | }
196 |
197 | @Override
198 | public boolean isIsPlain()
199 | {
200 | return false;
201 | }
202 |
203 | /**
204 | * This API is to check if ultimately the collection element is bounded.
205 | * In order to check if this specific collection has bounds, please use isUnbound API.
206 | */
207 | @Override
208 | public boolean isIsBounded()
209 | {
210 | if (m_maxsize == null)
211 | {
212 | return false;
213 | }
214 |
215 | if (m_keyTypeCode != null && m_valueTypeCode != null)
216 | {
217 | return m_keyTypeCode.isIsBounded() && m_valueTypeCode.isIsBounded();
218 | }
219 | return false;
220 | }
221 |
222 | private TypeCode m_keyTypeCode = null;
223 | private TypeCode m_valueTypeCode = null;
224 | private Definition m_keyDefinition = null;
225 | private Definition m_valueDefinition = null;
226 | private String m_maxsize = null;
227 | private String evaluated_maxsize_ = null;
228 | }
229 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/typecode/Member.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.typecode;
16 |
17 | import com.eprosima.idl.parser.exception.RuntimeGenerationException;
18 | import com.eprosima.idl.parser.tree.Annotation;
19 |
20 | public class Member extends MemberAppliedAnnotations
21 | {
22 | public Member()
23 | {
24 | super();
25 | }
26 |
27 | public Member(TypeCode typecode, String name)
28 | {
29 | super();
30 | m_typecode = typecode;
31 | m_name = name;
32 | }
33 |
34 | public String getName()
35 | {
36 | return m_name;
37 | }
38 |
39 | public String getJavaName() {
40 | if (m_name != null) {
41 | Character firstChar =Character.toUpperCase(m_name.charAt(0));
42 | String javaName = firstChar.toString();
43 | if (m_name.length() > 1) {
44 | javaName += m_name.substring(1);
45 | }
46 | return javaName;
47 | }
48 | return null;
49 | }
50 |
51 | /*
52 | * @brief This function is used with (previous c) types because array names contains [].
53 | */
54 |
55 | public TypeCode getTypecode()
56 | {
57 | return m_typecode;
58 | }
59 |
60 | public void setName(String name)
61 | {
62 | m_name = name;
63 | }
64 |
65 | public void setTypecode(TypeCode typecode)
66 | {
67 | m_typecode = typecode;
68 | }
69 |
70 | public boolean isIsPlain()
71 | {
72 | if (m_typecode != null && !isAnnotationOptional())
73 | {
74 | return m_typecode.isIsPlain();
75 | }
76 | return false;
77 | }
78 |
79 | public boolean isIsBounded()
80 | {
81 | if (m_typecode != null)
82 | {
83 | return m_typecode.isIsBounded();
84 | }
85 | return false;
86 | }
87 |
88 | /*!
89 | * Sets the member's id.
90 | *
91 | * This function is intended to be called by MemberTypeCode.
92 | */
93 | public void set_id(int id)
94 | {
95 | id_ = id;
96 | }
97 |
98 | /*!
99 | * Return the MemberId as Integer.
100 | */
101 | public int get_id()
102 | {
103 | return id_;
104 | }
105 |
106 | /*!
107 | * Return the MemberId as String in hexadecimal format.
108 | */
109 | public String getId()
110 | {
111 | return String.format("0x%08x", id_);
112 | }
113 |
114 | /*!
115 | * Sets the order of definition of the member.
116 | *
117 | * This function is intended to be called by MemberTypeCode.
118 | */
119 | public void set_index(int index)
120 | {
121 | index_ = index;
122 | }
123 |
124 | public int getIndex()
125 | {
126 | return index_;
127 | }
128 |
129 | public boolean isAnnotationId()
130 | {
131 | return null != getAnnotations().get(Annotation.id_str);
132 | }
133 |
134 | public String getAnnotationIdValue() throws RuntimeGenerationException
135 | {
136 | Annotation ann = getAnnotations().get(Annotation.id_str);
137 | if (ann == null)
138 | {
139 | throw new RuntimeGenerationException("Error in member " + m_name + ": @" + Annotation.id_str +
140 | " annotation not found.");
141 | }
142 |
143 | return ann.getValue();
144 | }
145 |
146 | public boolean isAnnotationHashid()
147 | {
148 | return null != getAnnotations().get(Annotation.hashid_str);
149 | }
150 |
151 | public String getAnnotationHashidValue() throws RuntimeGenerationException
152 | {
153 | Annotation ann = getAnnotations().get(Annotation.hashid_str);
154 | if (ann == null)
155 | {
156 | throw new RuntimeGenerationException("Error in member " + m_name + ": @" + Annotation.hashid_str +
157 | " annotation not found.");
158 | }
159 |
160 | return ann.getValue();
161 | }
162 |
163 | private String m_name = null;
164 |
165 | private TypeCode m_typecode = null;
166 |
167 | public static final int MEMBER_ID_INVALID = 0x0FFFFFFF;
168 |
169 | private int id_ = MEMBER_ID_INVALID;
170 |
171 | private int index_ = 0;
172 | }
173 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/typecode/SequenceTypeCode.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.typecode;
16 |
17 | import com.eprosima.idl.parser.typecode.StringTypeCode;
18 | import com.eprosima.idl.parser.typecode.MapTypeCode;
19 | import org.stringtemplate.v4.ST;
20 |
21 |
22 | public class SequenceTypeCode extends ContainerTypeCode
23 | {
24 | public SequenceTypeCode(
25 | String maxsize,
26 | String evaluated_maxsize)
27 | {
28 | super(Kind.KIND_SEQUENCE);
29 | m_maxsize = maxsize;
30 | evaluated_maxsize_ = evaluated_maxsize;
31 | }
32 |
33 | @Override
34 | public boolean isIsType_e()
35 | {
36 | return true;
37 | }
38 |
39 | /*!
40 | * @ingroup api_for_stg
41 | * @brief This function can be used to check if TypeIdentifier's kind is the small one or the large one.
42 | * @return @e false if sequence is unbound or smaller than 256.
43 | * Otherwise @e true is returned.
44 | */
45 | public boolean getIsTypeIdentifierKindLarge()
46 | {
47 | if (!isUnbound() && Integer.parseInt(evaluated_maxsize_) >= 256)
48 | {
49 | return true;
50 | }
51 |
52 | return false;
53 | }
54 |
55 | /*!
56 | * @ingroup api_for_stg
57 | * @brief This function can be used to retrieve the TypeIdentifier's kind.
58 | * @return @e TI_PLAIN_SEQUENCE_SMALL if sequence is unbound or smaller than 256.
59 | * Otherwise @e TI_PLAIN_SEQUENCE_LARGE is returned.
60 | */
61 | @Override
62 | public String getTypeIdentifier()
63 | {
64 | if (getIsTypeIdentifierKindLarge())
65 | {
66 | return "TI_PLAIN_SEQUENCE_LARGE";
67 | }
68 | return "TI_PLAIN_SEQUENCE_SMALL";
69 | }
70 |
71 | @Override
72 | public boolean isPlainType()
73 | {
74 | return true;
75 | }
76 |
77 | @Override
78 | public boolean isIsSequenceType()
79 | {
80 | return true;
81 | }
82 |
83 | @Override
84 | public String getCppTypename()
85 | {
86 | ST st = getCppTypenameFromStringTemplate();
87 | st.add("ctx", ctx);
88 | st.add("type", getContentTypeCode().getCppTypename());
89 | String contenttype = getContentTypeCode().getCppTypename().replaceAll("::", "_");
90 | if (getContentTypeCode() instanceof StringTypeCode)
91 | {
92 | contenttype = contenttype.replace("*", "_ptr_") + ((StringTypeCode)getContentTypeCode()).getMaxsize();
93 | }
94 | st.add("contenttype", contenttype);
95 | st.add("maxsize", m_maxsize);
96 | return st.render();
97 | }
98 |
99 | @Override
100 | public String getCTypename()
101 | {
102 | ST st = getCTypenameFromStringTemplate();
103 | st.add("type", getContentTypeCode().getCTypename());
104 | st.add("maxsize", getMaxsize());
105 | return st.render();
106 | }
107 |
108 | public String getCTypeDimensions()
109 | {
110 | String dimensions = "[" + getMaxsize() + "]";
111 | if (getContentTypeCode() instanceof StringTypeCode)
112 | {
113 | dimensions += "[" + ((StringTypeCode)getContentTypeCode()).getMaxsize() + "]";
114 | }
115 |
116 | return dimensions;
117 | }
118 |
119 | @Override
120 | public String getJavaTypename()
121 | {
122 | ST st = getJavaTypenameFromStringTemplate();
123 | st.add("type", getContentTypeCode().getJavaTypename());
124 | st.add("maxsize", m_maxsize);
125 | return st.render();
126 | }
127 |
128 | @Override
129 | public String getIdlTypename()
130 | {
131 | ST st = getIdlTypenameFromStringTemplate();
132 | st.add("type", getContentTypeCode().getIdlTypename());
133 | st.add("maxsize", m_maxsize);
134 | return st.render();
135 | }
136 |
137 | @Override
138 | public String getMaxsize()
139 | {
140 | if (m_maxsize == null)
141 | {
142 | return default_unbounded_max_size;
143 | }
144 |
145 | return m_maxsize;
146 | }
147 |
148 | @Override
149 | public String getEvaluatedMaxsize()
150 | {
151 | if (evaluated_maxsize_ == null)
152 | {
153 | return getMaxsize();
154 | }
155 |
156 | return evaluated_maxsize_;
157 | }
158 |
159 | /**
160 | * This API is to check if this specific collection has a bound set.
161 | * It does not check if the complete collection is bounded or not.
162 | */
163 | public boolean isUnbound()
164 | {
165 | return null == m_maxsize;
166 | }
167 |
168 | @Override
169 | public boolean isIsPlain()
170 | {
171 | return false;
172 | }
173 |
174 | /**
175 | * This API is to check if ultimately the collection element is bounded.
176 | * In order to check if this specific collection has bounds, please use isUnbound API.
177 | */
178 | @Override
179 | public boolean isIsBounded()
180 | {
181 | boolean ret_value = false;
182 |
183 | if (m_maxsize != null)
184 | {
185 | boolean should_set_and_unset = getContentTypeCode().isForwarded() && !detect_recursive_;
186 | if (should_set_and_unset)
187 | {
188 | detect_recursive_ = true;
189 | ret_value = super.isIsBounded();
190 | detect_recursive_ = false;
191 | }
192 | else
193 | {
194 | ret_value = super.isIsBounded();
195 | }
196 | }
197 |
198 | return ret_value;
199 | }
200 |
201 | private String m_maxsize = null;
202 |
203 | private String evaluated_maxsize_ = null;
204 |
205 | protected boolean detect_recursive_ = false;
206 | }
207 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/typecode/SetTypeCode.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.typecode;
16 |
17 | import org.stringtemplate.v4.ST;
18 |
19 |
20 | public class SetTypeCode extends ContainerTypeCode
21 | {
22 | public SetTypeCode(
23 | String maxsize,
24 | String evaluate_maxsize)
25 | {
26 | super(Kind.KIND_SET);
27 | m_maxsize = maxsize;
28 | evaluated_maxsize_ = evaluate_maxsize;
29 | }
30 |
31 | @Override
32 | public boolean isIsType_e()
33 | {
34 | return true;
35 | }
36 |
37 | @Override
38 | public String getTypeIdentifier()
39 | {
40 | return "TI_PLAIN_SEQUENCE_SMALL";
41 | }
42 |
43 | @Override
44 | public boolean isPlainType()
45 | {
46 | return true;
47 | }
48 |
49 | @Override
50 | public boolean isIsSetType()
51 | {
52 | return true;
53 | }
54 |
55 | @Override
56 | public String getCppTypename()
57 | {
58 | ST st = getCppTypenameFromStringTemplate();
59 | st.add("type", getContentTypeCode().getCppTypename());
60 | st.add("maxsize", m_maxsize);
61 | return st.render();
62 | }
63 |
64 | @Override
65 | public String getCTypename()
66 | {
67 | ST st = getCTypenameFromStringTemplate();
68 | st.add("type", getContentTypeCode().getCTypename());
69 | st.add("maxsize", m_maxsize);
70 | return st.render();
71 | }
72 |
73 | @Override
74 | public String getJavaTypename()
75 | {
76 | ST st = getJavaTypenameFromStringTemplate();
77 | st.add("type", getContentTypeCode().getJavaTypename());
78 | st.add("maxsize", m_maxsize);
79 | return st.render();
80 | }
81 |
82 | @Override
83 | public String getIdlTypename()
84 | {
85 | ST st = getIdlTypenameFromStringTemplate();
86 | st.add("type", getContentTypeCode().getIdlTypename());
87 | st.add("maxsize", m_maxsize);
88 | return st.render();
89 | }
90 |
91 | public String getMaxsize()
92 | {
93 | if (m_maxsize == null)
94 | {
95 | return default_unbounded_max_size;
96 | }
97 |
98 | return m_maxsize;
99 | }
100 |
101 | public String getEvaluatedMaxsize()
102 | {
103 | if (evaluated_maxsize_ == null)
104 | {
105 | return getMaxsize();
106 | }
107 |
108 | return evaluated_maxsize_;
109 | }
110 |
111 | @Override
112 | public boolean isIsPlain()
113 | {
114 | return false;
115 | }
116 |
117 | @Override
118 | public boolean isIsBounded()
119 | {
120 | if (m_maxsize == null)
121 | {
122 | return false;
123 | }
124 |
125 | return super.isIsBounded();
126 | }
127 |
128 | private String m_maxsize = null;
129 |
130 | private String evaluated_maxsize_ = null;
131 | }
132 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/typecode/StringTypeCode.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.typecode;
16 |
17 | import com.eprosima.idl.util.Pair;
18 | import org.stringtemplate.v4.ST;
19 |
20 |
21 | public class StringTypeCode extends TypeCode
22 | {
23 | public StringTypeCode(
24 | int kind,
25 | String maxsize,
26 | String evaluated_maxsize)
27 | {
28 | super(kind);
29 | m_maxsize = maxsize;
30 | evaluated_maxsize_ = evaluated_maxsize;
31 | }
32 |
33 | @Override
34 | public boolean isIsType_d()
35 | {
36 | return true;
37 | }
38 |
39 | /*!
40 | * @ingroup api_for_stg
41 | * @brief This function can be used to check if TypeIdentifier's kind is the small one or the large one.
42 | * @return @e false if string is unbound or smaller than 256.
43 | * Otherwise @e true is returned.
44 | */
45 | public boolean getIsTypeIdentifierKindLarge()
46 | {
47 | if (isIsBounded() && Integer.parseInt(evaluated_maxsize_) >= 256)
48 | {
49 | return true;
50 | }
51 |
52 | return false;
53 | }
54 |
55 | /*!
56 | * @ingroup api_for_stg
57 | * @brief This function can be used to retrieve the TypeIdentifier's kind.
58 | * @return @e TI_STRING8_SMALL or TI_STRING16_SMALL if string is unbound or smaller than 256.
59 | * Otherwise @e TI_STRING8_LARGE or TI_STRING16_LARGE is returned.
60 | */
61 | @Override
62 | public String getTypeIdentifier()
63 | {
64 | switch (getKind())
65 | {
66 | case Kind.KIND_STRING:
67 | if (getIsTypeIdentifierKindLarge())
68 | {
69 | return "TI_STRING8_LARGE";
70 | }
71 | else
72 | {
73 | return "TI_STRING8_SMALL";
74 | }
75 | case Kind.KIND_WSTRING:
76 | if (getIsTypeIdentifierKindLarge())
77 | {
78 | return "TI_STRING16_LARGE";
79 | }
80 | else
81 | {
82 | return "TI_STRING16_SMALL";
83 | }
84 | default:
85 | return "TK_None";
86 | }
87 | }
88 |
89 | @Override
90 | public boolean isPlainType()
91 | {
92 | return true;
93 | }
94 |
95 | @Override
96 | public boolean isIsStringType()
97 | {
98 | return getKind() == Kind.KIND_STRING;
99 | }
100 |
101 | @Override
102 | public boolean isIsWStringType()
103 | {
104 | return getKind() == Kind.KIND_WSTRING;
105 | }
106 |
107 | @Override
108 | public String getNamespace()
109 | {
110 | return "";
111 | }
112 |
113 | @Override
114 | public String getCppTypename()
115 | {
116 | ST st = getCppTypenameFromStringTemplate();
117 | st.add("max_size", m_maxsize);
118 | return st.render();
119 | }
120 |
121 | @Override
122 | public String getCTypename()
123 | {
124 | ST st = getCTypenameFromStringTemplate();
125 | st.add("maxsize", getMaxsize());
126 | return st.render();
127 | }
128 |
129 | @Override
130 | public String getJavaTypename()
131 | {
132 | return getJavaTypenameFromStringTemplate().toString();
133 | }
134 |
135 | @Override
136 | public String getIdlTypename()
137 | {
138 | return getIdlTypenameFromStringTemplate().toString();
139 | }
140 |
141 | @Override
142 | public String getMaxsize()
143 | {
144 | if (m_maxsize == null)
145 | {
146 | return "255";
147 | }
148 |
149 | return m_maxsize;
150 | }
151 |
152 | @Override
153 | public String getEvaluatedMaxsize()
154 | {
155 | if (evaluated_maxsize_ == null)
156 | {
157 | return getMaxsize();
158 | }
159 |
160 | return evaluated_maxsize_;
161 | }
162 |
163 | @Override
164 | public boolean isIsPlain()
165 | {
166 | return false;
167 | }
168 |
169 | @Override
170 | public boolean isIsBounded()
171 | {
172 | return (m_maxsize != null);
173 | }
174 |
175 | private String m_maxsize = null;
176 | private String evaluated_maxsize_ = null;
177 | }
178 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/parser/typecode/UnionMember.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.parser.typecode;
16 |
17 | import java.util.List;
18 |
19 | public class UnionMember extends Member
20 | {
21 | public UnionMember(TypeCode typecode, String name, List labels, boolean isDefault)
22 | {
23 | super(typecode, name);
24 | m_internallabels = labels;
25 | m_default = isDefault;
26 | }
27 |
28 | public List getInternalLabels()
29 | {
30 | return m_internallabels;
31 | }
32 |
33 | public List getLabels()
34 | {
35 | return m_labels;
36 | }
37 |
38 | public int getLabelsSize()
39 | {
40 | return m_labels.size();
41 | }
42 |
43 | public void setLabels(List labels)
44 | {
45 | m_labels = labels;
46 | }
47 |
48 | public List getJavaLabels()
49 | {
50 | return m_javalabels;
51 | }
52 |
53 | public void setJavaLabels(List labels)
54 | {
55 | m_javalabels = labels;
56 | }
57 |
58 | public boolean isDefault()
59 | {
60 | return m_default;
61 | }
62 |
63 | private List m_internallabels = null;
64 | private List m_labels = null;
65 | private List m_javalabels = null;
66 |
67 | private boolean m_default = false;
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/util/Pair.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.util;
16 |
17 | public class Pair
18 | {
19 | public Pair(F first, S second)
20 | {
21 | m_first = first;
22 | m_second = second;
23 | }
24 |
25 | public F first()
26 | {
27 | return m_first;
28 | }
29 |
30 | public S second()
31 | {
32 | return m_second;
33 | }
34 |
35 | private F m_first = null;
36 |
37 | private S m_second = null;
38 | }
39 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/idl/util/Util.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.idl.util;
16 |
17 | import java.io.File;
18 |
19 | public class Util
20 | {
21 | public static String getIDLFileNameOnly(String idlFilename)
22 | {
23 | int index = -1;
24 | String auxString = idlFilename, returnedValue = null;
25 |
26 | index = idlFilename.lastIndexOf(File.separator);
27 |
28 | if(index == -1)
29 | {
30 | index = idlFilename.lastIndexOf('/');
31 | }
32 |
33 | if(index != -1)
34 | {
35 | auxString = idlFilename.substring(index + 1);
36 | }
37 |
38 | // Remove '.idl'
39 | returnedValue = auxString.substring(0, auxString.length() - 4);
40 |
41 | return returnedValue;
42 | }
43 |
44 | public static String getIDLFileOnly(String idlFileURL)
45 | {
46 | int index = -1;
47 | String returnedValue = null;
48 |
49 | index = idlFileURL.lastIndexOf(File.separator);
50 |
51 | if(index == -1)
52 | index = idlFileURL.lastIndexOf('/');
53 |
54 | if(index != -1)
55 | returnedValue = idlFileURL.substring(index + 1);
56 | else
57 | returnedValue = idlFileURL;
58 |
59 | return returnedValue;
60 | }
61 |
62 | public static String getIDLFileDirectoryOnly(String idlFileURL)
63 | {
64 | int index = -1;
65 | String returnedValue = null;
66 |
67 | index = idlFileURL.lastIndexOf(File.separator);
68 |
69 | if(index == -1)
70 | index = idlFileURL.lastIndexOf('/');
71 |
72 | if(index != -1)
73 | returnedValue = idlFileURL.substring(0, index + 1);
74 |
75 | return returnedValue;
76 | }
77 |
78 | public static String stringTrimAll(String str)
79 | {
80 | String trimstr = str.replaceAll("\\s+", "");
81 | return trimstr;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/log/ColorMessage.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.log;
16 |
17 | public class ColorMessage
18 | {
19 | public static void load()
20 | {
21 | String os = System.getProperty("os.name");
22 |
23 | if(os.equals("Linux"))
24 | {
25 | ANSI_RESET = "\033[0m";
26 | ANSI_BOLD = "\033[1m";
27 | ANSI_BOLD_RED = "\033[1;31m";
28 | ANSI_BOLD_YELLOW = "\033[1;33m";
29 | ANSI_BOLD_BLUE = "\033[1;34m";
30 | }
31 | }
32 |
33 | public static String bold(String text)
34 | {
35 | return ANSI_BOLD + text + ANSI_RESET;
36 | }
37 |
38 | public static String red(String text)
39 | {
40 | return ANSI_BOLD_RED + text + ANSI_RESET;
41 | }
42 |
43 | public static String yellow(String text)
44 | {
45 | return ANSI_BOLD_YELLOW + text + ANSI_RESET;
46 | }
47 |
48 | public static String debug()
49 | {
50 | return ANSI_BOLD_BLUE + "DEBUG: " + ANSI_RESET;
51 | }
52 |
53 | public static String debug(String function)
54 | {
55 | return ANSI_BOLD_BLUE + "DEBUG<" + function + ">: " + ANSI_RESET;
56 | }
57 |
58 | public static String warning()
59 | {
60 | return ANSI_BOLD_YELLOW + "WARNING: " + ANSI_RESET;
61 | }
62 |
63 | public static String error()
64 | {
65 | return ANSI_BOLD_RED + "ERROR: " + ANSI_RESET;
66 | }
67 |
68 | public static String error(String function)
69 | {
70 | return ANSI_BOLD_RED + "ERROR<" + function + ">: " + ANSI_RESET;
71 | }
72 |
73 | private static String ANSI_RESET = "";
74 | private static String ANSI_BOLD = "";
75 | private static String ANSI_BOLD_RED = "";
76 | private static String ANSI_BOLD_YELLOW = "";
77 | private static String ANSI_BOLD_BLUE = "";
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/log/Log.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.log;
16 |
17 | import com.eprosima.log.ColorMessage;
18 |
19 | public class Log
20 | {
21 | public static final int DEBUG = 0;
22 | public static final int INFO = 1;
23 | public static final int WARNING = 2;
24 | public static final int ERROR = 3;
25 |
26 | public static void printDebug(String message)
27 | {
28 | if(m_level <= DEBUG)
29 | System.out.println(ColorMessage.debug() + message);
30 | }
31 |
32 | public static void printDebug(String function, String message)
33 | {
34 | if(m_level < DEBUG)
35 | System.out.println(ColorMessage.debug(function) + message);
36 | }
37 |
38 | public static int m_level = ERROR;
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/solution/GUIDGenerator.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.solution;
16 |
17 | import java.security.MessageDigest;
18 | import java.security.NoSuchAlgorithmException;
19 |
20 | public class GUIDGenerator
21 | {
22 | static MessageDigest digester = null;
23 |
24 | synchronized public static String genGUID(String name)
25 | {
26 | if(digester == null)
27 | {
28 | try
29 | {
30 | digester = MessageDigest.getInstance("SHA-1");
31 | }
32 | catch (NoSuchAlgorithmException nsae)
33 | {
34 | nsae.printStackTrace();
35 | }
36 | }
37 |
38 | assert(digester != null) : "Digester Was null";
39 |
40 | digester.reset();
41 |
42 | byte digest[] = digester.digest(name.toLowerCase().getBytes());
43 |
44 | assert(digest.length >= 16): "Digest too short";
45 |
46 | StringBuffer buf = new StringBuffer();
47 | String hex = null;
48 | for(int i = 0; i < 16; i++)
49 | {
50 | hex = Integer.toHexString(digest[i]);
51 | if(hex.length() == 1){
52 | buf.append('0');
53 | }else if(hex.length()> 2){
54 | hex = hex.substring(hex.length() - 2);
55 | }
56 | buf.append(hex.toUpperCase());
57 | if(i == 3 || i == 5 || i == 7 || i == 9){
58 | buf.append('-');
59 | }
60 | }
61 | return buf.toString();
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/solution/Project.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.solution;
16 |
17 | import java.util.ArrayList;
18 | import java.util.LinkedHashSet;
19 |
20 | import com.eprosima.solution.GUIDGenerator;
21 | import com.eprosima.idl.util.Util;
22 |
23 | public class Project
24 | {
25 | public Project(String name, String file, LinkedHashSet dependencies)
26 | {
27 | m_name = name;
28 | m_file = file;
29 | m_dependencies = dependencies;
30 | m_commonsrcfiles = new ArrayList();
31 | m_commonincludefiles = new ArrayList();
32 | m_commontestingfiles = new ArrayList();
33 | m_typeobjecttestingfiles = new ArrayList();
34 | }
35 |
36 | public void setParent(Solution sol)
37 | {
38 | m_parent = sol;
39 | }
40 |
41 | public Solution getParent()
42 | {
43 | return m_parent;
44 | }
45 |
46 | public String getName()
47 | {
48 | return m_name;
49 | }
50 |
51 | public String getFile()
52 | {
53 | return m_file;
54 | }
55 |
56 | public void addCommonSrcFile(String file)
57 | {
58 | m_commonsrcfiles.add(file);
59 | }
60 |
61 | public ArrayList getCommonSrcFiles()
62 | {
63 | return m_commonsrcfiles;
64 | }
65 |
66 | public void addCommonIncludeFile(String file)
67 | {
68 | m_commonincludefiles.add(file);
69 | }
70 |
71 | public ArrayList getCommonIncludeFiles()
72 | {
73 | return m_commonincludefiles;
74 | }
75 |
76 | public void addCommonTestingFile(String file)
77 | {
78 | m_commontestingfiles.add(file);
79 | }
80 |
81 | public ArrayList getCommonTestingFiles()
82 | {
83 | return m_commontestingfiles;
84 | }
85 |
86 | public void addTypeObjectTestingFile(String file)
87 | {
88 | m_typeobjecttestingfiles.add(file);
89 | }
90 |
91 | public ArrayList getTypeObjectTestingFiles()
92 | {
93 | return m_typeobjecttestingfiles;
94 | }
95 |
96 | /*!
97 | * @brief Used in string templates.
98 | */
99 | public ArrayList getDependencies()
100 | {
101 | ArrayList array = new ArrayList(m_dependencies);
102 |
103 | for(int count = 0; count < array.size(); ++count)
104 | {
105 | array.set(count, Util.getIDLFileNameOnly(array.get(count).toString()));
106 | }
107 |
108 | return array;
109 | }
110 |
111 | /*!
112 | * @brief Used in string templates.
113 | */
114 | public String getGuid()
115 | {
116 | return GUIDGenerator.genGUID(m_file);
117 | }
118 |
119 | /*!
120 | * @brief Used in string templates.
121 | */
122 | public ArrayList getDependenciesGuids()
123 | {
124 | ArrayList deps = new ArrayList(m_dependencies);
125 | ArrayList array = new ArrayList();
126 |
127 | for(int count = 0; count < deps.size(); ++count)
128 | {
129 | if(!m_parent.getOS().contains("Windows") ||
130 | m_parent.existsProject(deps.get(count)))
131 | {
132 | array.add(GUIDGenerator.genGUID(deps.get(count)));
133 | }
134 | }
135 |
136 | return array;
137 | }
138 |
139 | public ArrayList getFullDependencies()
140 | {
141 | return new ArrayList(m_dependencies);
142 | }
143 |
144 | private String m_name = null;
145 | private String m_file = null;
146 | private ArrayList m_commonsrcfiles = null;
147 | private ArrayList m_commonincludefiles = null;
148 | private ArrayList m_commontestingfiles = null;
149 | private ArrayList m_typeobjecttestingfiles = null;
150 | private LinkedHashSet m_dependencies = null;
151 | String m_guid = null;
152 | Solution m_parent = null;
153 | }
154 |
--------------------------------------------------------------------------------
/src/main/java/com/eprosima/solution/Solution.java:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | package com.eprosima.solution;
16 |
17 | import com.eprosima.idl.parser.exception.RuntimeGenerationException;
18 | import com.eprosima.log.ColorMessage;
19 | import java.util.ArrayList;
20 |
21 | public class Solution
22 | {
23 | public Solution()
24 | {
25 | m_projects = new ArrayList();
26 | m_libraryPaths = new ArrayList();
27 | m_libraries = new ArrayList();
28 | m_includes = new ArrayList();
29 | m_defines = new ArrayList();
30 |
31 | // Detect OS
32 | m_os = System.getProperty("os.name");
33 | }
34 |
35 | public void addProject(Project project)
36 | {
37 | project.setParent(this);
38 | m_projects.add(project);
39 | }
40 |
41 | public String getOS()
42 | {
43 | return m_os;
44 | }
45 |
46 | /*!
47 | * @brief This solution orders projects by dependencies. Used in string templates.
48 | */
49 | public ArrayList getProjects()
50 | {
51 | if(m_cacheprojects == null)
52 | {
53 | ArrayList tmpArray = new ArrayList(m_projects);
54 | m_cacheprojects = new ArrayList();
55 |
56 | while(tmpArray.size() > 0)
57 | {
58 | Project proj = (Project)tmpArray.remove(0);
59 |
60 | // Search dependencies in project that was already processed.
61 | ArrayList deps = proj.getFullDependencies();
62 |
63 | boolean candidate = true;
64 | for(int count = 0; candidate && count < deps.size(); ++count)
65 | {
66 | boolean found = false;
67 |
68 | for(int acount = 0; !found && acount < m_cacheprojects.size(); ++acount)
69 | {
70 | if(compareNames((String)deps.get(count), m_cacheprojects.get(acount).getFile()))
71 | {
72 | found = true;
73 | }
74 | }
75 |
76 | if(!found)
77 | {
78 | // Search in the rest of projects to process.
79 | for(int rcount = 0; !found && rcount < tmpArray.size(); ++rcount)
80 | {
81 | if(compareNames((String)deps.get(count), tmpArray.get(rcount).getFile()))
82 | {
83 | found = true;
84 | }
85 | }
86 |
87 | // If found put the project to the end of the tmpArray.
88 | if(found)
89 | {
90 | tmpArray.add(proj);
91 | candidate = false;
92 | }
93 | else
94 | {
95 | System.out.println(ColorMessage.yellow("warning:") + " File " + deps.get(count) + " wasn't parsed in this execution. The generated example will not work. "
96 | + "To generate a successful example, try to execute this application passing all necessary IDL files.");
97 | }
98 | }
99 | }
100 |
101 | if(candidate)
102 | m_cacheprojects.add(proj);
103 | }
104 | }
105 |
106 | return m_cacheprojects;
107 | }
108 |
109 | /*!
110 | * @brief Only valid if one IDL is passed to Fast DDS-Gen. Used only in testing environment.
111 | */
112 | public Project getMainProject() throws RuntimeGenerationException
113 | {
114 | ArrayList projects = getProjects();
115 | if (projects.isEmpty())
116 | {
117 | throw new RuntimeGenerationException("Error: no projects have been defined");
118 | }
119 | return (Project)projects.get(projects.size() - 1);
120 | }
121 |
122 | public boolean existsProject(String name)
123 | {
124 | boolean ret = false;
125 | for(int i = 0; i < m_projects.size(); ++i)
126 | {
127 | if(compareNames(m_projects.get(i).getFile(), name))
128 | {
129 | ret = true;
130 | break;
131 | }
132 | }
133 |
134 | return ret;
135 | }
136 |
137 | public boolean compareNames(String dep, String file)
138 | {
139 | if(m_os.contains("Windows"))
140 | {
141 | return dep.toLowerCase().equals(file.toLowerCase());
142 | }
143 |
144 | return dep.equals(file);
145 | }
146 |
147 | public void addLibraryPath(String libraryPath)
148 | {
149 | m_libraryPaths.add(libraryPath);
150 | }
151 |
152 | public ArrayList getLibraryPaths()
153 | {
154 | return m_libraryPaths;
155 | }
156 |
157 | public void addLibrary(String library)
158 | {
159 | m_libraries.add(library);
160 | }
161 |
162 | public ArrayList getLibraries()
163 | {
164 | return m_libraries;
165 | }
166 |
167 | public void addInclude(String include)
168 | {
169 | m_includes.add(include);
170 | }
171 |
172 | public ArrayList getIncludes()
173 | {
174 | return m_includes;
175 | }
176 |
177 | public void addDefine(String define)
178 | {
179 | m_defines.add(define);
180 | }
181 |
182 | public ArrayList getDefines()
183 | {
184 | return m_defines;
185 | }
186 |
187 | private ArrayList m_projects = null;
188 | private ArrayList m_cacheprojects = null;
189 | private ArrayList m_libraryPaths = null;
190 | private ArrayList m_libraries = null;
191 | private ArrayList m_includes = null;
192 | private ArrayList m_defines = null;
193 |
194 | // OS
195 | String m_os = null;
196 | }
197 |
--------------------------------------------------------------------------------
/src/main/resources/com/eprosima/idl/templates/CTypes.stg:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | group Types;
16 |
17 | type_5() ::= <>
18 |
19 | type_6() ::= <>
20 |
21 | type_13() ::= <>
22 |
23 | type_1() ::= <>
24 |
25 | type_2() ::= <>
26 |
27 | type_11() ::= <>
28 |
29 | type_3() ::= <>
30 |
31 | type_4() ::= <>
32 |
33 | type_12() ::= <>
34 |
35 | type_8() ::= <>
36 |
37 | type_14() ::= <>
38 |
39 | type_7() ::= <>
40 |
41 | type_9() ::= <>
42 |
43 | type_d(maxsize) ::= <>
44 |
45 | type_1a(name, type) ::= <<$name$>>
46 |
47 | type_1b(name) ::= <<$name$>>
48 |
49 | type_1d(name) ::= <>
50 |
51 | type_1e(name) ::= <>
52 |
53 | //TODO
54 | type_15() ::= <>
55 |
56 | type_f_first(prev) ::= <<$prev$>>
57 | type_f_second(prev, size) ::= <<>>
58 | type_f(firs, secon, type) ::= <<$firs$$type$$secon$>>
59 |
60 | type_a(name) ::= <<$name$>>
61 |
62 | type_b(name) ::= <<$name$>>
63 |
64 | type_c(name) ::= <<$name$>>
65 |
66 | type_10(name) ::= <<$name$>>
67 |
68 | type_19() ::= <>
69 |
70 | // TODO Para que sirve empty en FastBuffers?
71 | type_e(type, maxsize, empty) ::= <<$type$$empty$>>
72 |
--------------------------------------------------------------------------------
/src/main/resources/com/eprosima/idl/templates/JavaTypes.stg:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | group Types;
16 |
17 | type_5(package) ::= <>
18 |
19 | type_6(package) ::= <>
20 |
21 | type_13(package) ::= <>
22 |
23 | type_1(package) ::= <>
24 |
25 | type_2(package) ::= <>
26 |
27 | type_11(package) ::= <>
28 |
29 | type_3(package) ::= <>
30 |
31 | type_4(package) ::= <>
32 |
33 | type_12(package) ::= <>
34 |
35 | type_8(package) ::= <>
36 |
37 | type_14(package) ::= <>
38 |
39 | type_7(package) ::= <>
40 |
41 | type_9(package) ::= <>
42 |
43 | type_d(package) ::= <>
44 |
45 | type_15(package) ::= <>
46 |
47 | type_19(package) ::= <>
48 |
49 | type_f_first(prev) ::= <>
50 | type_f_second(prev, size) ::= <<, $size$>$prev$>>
51 | type_f(package, firs, secon, type) ::= <<$firs$$type$$secon$>>
52 |
53 | type_a(package, name) ::= <<$package$$name$>>
54 |
55 | type_b(package, name) ::= <<$package$$name$>>
56 |
57 | type_c(package, name) ::= <<$package$$name$>>
58 |
59 | type_10(package, name) ::= <<$name$>>
60 |
61 | // TODO Para que sirve empty en FastBuffers?
62 | type_e(package, type, maxsize, empty) ::= <$empty$>>
63 |
64 | type_e_content_types ::= [
65 | "int":"Integer",
66 | default:
67 | ]
68 |
--------------------------------------------------------------------------------
/src/main/resources/com/eprosima/idl/templates/Types.stg:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | group Types;
16 |
17 | type_5() ::= <>
18 |
19 | type_6() ::= <>
20 |
21 | type_13() ::= <>
22 |
23 | type_1() ::= <>
24 |
25 | type_2() ::= <>
26 |
27 | type_11() ::= <>
28 |
29 | type_3() ::= <>
30 |
31 | type_4() ::= <>
32 |
33 | type_12() ::= <>
34 |
35 | type_8() ::= <>
36 |
37 | type_14() ::= <>
38 |
39 | type_7() ::= <>
40 |
41 | type_9() ::= <>
42 |
43 | type_d(max_size) ::= <<$if(max_size)$eprosima::fastcdr::fixed_string<$max_size$>$else$std::string$endif$>>
44 |
45 | type_15(max_size) ::= <>
46 |
47 | type_19(key, value, maxsize, empty) ::= <$empty$>>
48 |
49 | type_f_first(prev) ::= <>
50 | type_f_second(prev, size) ::= <<, $size$>$prev$>>
51 | type_f(firs, secon, type) ::= <<$firs$$type$$secon$>>
52 |
53 | type_a(name) ::= <<$name$>>
54 |
55 | type_b(name) ::= <<$name$>>
56 |
57 | type_c(name) ::= <<$name$>>
58 |
59 | type_10(name) ::= <<$name$>>
60 |
61 | // TODO Para que sirve empty en FastBuffers?
62 | type_e(ctx, type, contenttype, maxsize, empty) ::= <$empty$>>
63 |
64 | type_1a(name, type) ::= <<$name$>>
65 |
66 | type_1b(name) ::= <<$name$>>
67 |
68 | type_1d(name) ::= <>
69 |
70 | type_1e(name) ::= <>
71 |
--------------------------------------------------------------------------------
/src/main/resources/com/eprosima/idl/templates/TypesCInterface.stg:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | group Types;
16 |
17 | type_5() ::= <>
18 |
19 | type_6() ::= <>
20 |
21 | type_13() ::= <>
22 |
23 | type_1() ::= <>
24 |
25 | type_2() ::= <>
26 |
27 | type_11() ::= <>
28 |
29 | type_3() ::= <>
30 |
31 | type_4() ::= <>
32 |
33 | type_12() ::= <>
34 |
35 | type_8() ::= <>
36 |
37 | type_14() ::= <>
38 |
39 | type_7() ::= <>
40 |
41 | type_9() ::= <>
42 |
43 | type_d() ::= <>
44 |
45 | type_15() ::= <>
46 |
47 | type_19(key, value, maxsize, empty) ::= <$empty$>>
48 |
49 | type_f_first(prev) ::= <>
50 | type_f_second(prev, size) ::= <<, $size$>$prev$>>
51 | type_f(firs, secon, type) ::= <<$firs$$type$$secon$>>
52 |
53 | type_a(name) ::= <<$name$>>
54 |
55 | type_b(name) ::= <<$name$>>
56 |
57 | type_c(name) ::= <<$name$>>
58 |
59 | type_10(name) ::= <<$name$>>
60 |
61 | // TODO Para que sirve empty en FastBuffers?
62 | type_e(ctx, type, contenttype, maxsize, empty) ::= <<$ctx.filename$_$contenttype$Seq_$maxsize$_t>>
63 |
64 | type_1a(name, type) ::= <<$name$>>
65 |
66 | type_1b(name) ::= <<$name$>>
67 |
68 | type_1d(name) ::= <>
69 |
70 | type_1e(name) ::= <>
71 |
--------------------------------------------------------------------------------
/src/main/resources/com/eprosima/idl/templates/idlTypes.stg:
--------------------------------------------------------------------------------
1 | // Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // http://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | group Types;
16 |
17 | type_5() ::= <>
18 |
19 | type_6() ::= <>
20 |
21 | type_13() ::= <>
22 |
23 | type_1() ::= <>
24 |
25 | type_2() ::= <>
26 |
27 | type_11() ::= <>
28 |
29 | type_3() ::= <>
30 |
31 | type_4() ::= <>
32 |
33 | type_12() ::= <>
34 |
35 | type_8() ::= <>
36 |
37 | type_14() ::= <>
38 |
39 | type_7() ::= <>
40 |
41 | type_9() ::= <>
42 |
43 | type_d() ::= <>
44 |
45 | type_15() ::= <>
46 |
47 | type_f_first(prev) ::= <>
48 | type_f_second(prev, size) ::= <<, $size$>$prev$>>
49 | type_f(firs, secon, type) ::= <<$firs$$type$$secon$>>
50 |
51 | type_a(name) ::= <<$name$>>
52 |
53 | type_b(name) ::= <<$name$>>
54 |
55 | type_c(name) ::= <<$name$>>
56 |
57 | type_10(name) ::= <<$name$>>
58 |
59 | type_e(type, maxsize, empty) ::= <$empty$>>
60 |
61 | type_19(key, value, maxsize, empty) ::= <