[asterisk-scf-commits] asterisk-scf/release/slice-plugins.git branch "master" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Wed Jan 19 17:19:50 CST 2011
branch "master" has been created
at ead493adb17229f07700cafc8b8b88500628bbac (commit)
- Log -----------------------------------------------------------------
commit ead493adb17229f07700cafc8b8b88500628bbac
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Wed Jan 19 17:19:00 2011 -0600
Require CMake 2.8 or later.
Add license and copyright information.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2f1ad27..f9b281b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 2.6)
+cmake_minimum_required(VERSION 2.8)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..ff0499c
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,84 @@
+Asterisk SCF is distributed by Digium, Inc. (Digium) under the GNU
+General Public License version 2 (GPLv2) and is also available under
+alternative licenses negotiated directly with Digium. If you obtained
+Asterisk SCF under the GPLv2, then those terms apply to all programs
+you distribute that communicate using the Asterisk SCF object
+interfaces (APIs) on objects provided by Asterisk SCF's components, as
+defined below. A copy of the GPLv2 is included in the Asterisk SCF
+source tree in the file COPYING.txt.
+
+Asterisk SCF is a collection of programs that communicate with each
+other over defined APIs. This communication can occur within a single
+process (if two programs are loaded into a suitable container),
+between processes on a single machine, between processes on different
+machines, or some combination. In addition, these APIs are usable
+across a number of platforms and also across a variety of programming
+languages, many of which are interpreted (scripting)
+languages. Because of this flexibility and the possible ambiguity in
+interpretation of the provisions of the GPLv2 as they apply to
+Asterisk SCF, Digium makes the following statement:
+
+ It is Digium's interpretation that because the Asterisk SCF APIs,
+ by definition, expose direct, and indirect, complex remote, and
+ non-remote, function calls on objects provided by Asterisk SCF's
+ programs, that usage of these APIs between the program hosting the
+ object(s) and the program accessing the object(s) creates a
+ derivative work that must be covered wholly by GPLv2, even if the
+ mechanism used to invoke the function calls employs a
+ cross-process or network connection. As a result, any program that
+ employs the Asterisk SCF APIs to perform its intended functions,
+ and would not be able to perform those intended functions without
+ using these APIs to communicate with Asterisk SCF programs, or
+ derivatives of Asterisk SCF programs, is subject to the terms of
+ the GPLv2 when it is distributed, unless the distributor of the
+ program has obtained explicit written permission from Digium to
+ distribute it under a different license.
+
+Digium is able to grant, at its sole discretion, permission for
+companies, individuals or organizations to distribute programs that
+use the Asterisk SCF APIs under open source or proprietary
+terms. Digium is able to do this because all components of the
+Asterisk SCF package are either copyrighted by Digium, because Digium
+has been granted a sufficient license by the component's copyright
+holder(s), or some combination thereof.
+
+Digium grants specific permission for anyone to distribute programs
+that use the Asterisk SCF APIs and also use the OpenSSL toolkit, Ice
+(Internet Communication Engine) from ZeroC and/or the UW IMAP toolkit
+("Open Source Exceptions"), even though the terms of the GPLv2 do not
+allow such distribution. This permission only extends to distributions
+that properly acknowledge and comply with the terms of the licenses on
+the Open Source Exceptions that are used in addition to the terms of
+the GPLv2.
+
+If you wish to use Asterisk SCF code in other GPLv2 programs, there is
+no requirement that you provide the same permissions for these Open
+Source Exceptions to recipients of your programs (although if you have
+written a program for Asterisk SCF, Digium would strongly encourage
+you to grant the same permissions granted by Digium).
+
+The 'Ice' and 'ZeroC' names are trademarks of ZeroC, Inc.
+
+The "Asterisk SCF" name and logos are trademarks owned by Digium and
+use of them is subject to Digium's trademark licensing policies. If
+you wish to use these trademarks for purposes other than unmodified
+redistribution of Asterisk SCF source code obtained from Digium, you
+should contact Digium's licensing department to determine the
+necessary steps you must take. For more information on this policy,
+please read:
+
+http://www.digium.com/en/company/profile/trademarkpolicy.php
+
+If you have any questions regarding our licensing policy, please contact us:
+
++1.877.344.4861 (via telephone in the USA)
++1.256.428.6000 (via telephone outside the USA)
++1.256.864.0464 (via FAX inside or outside the USA)
+IAX2/pbx.digium.com (via IAX2)
+sip:6000 at digium.com (via SIP)
+licensing at digium.com (via email)
+
+Digium, Inc.
+445 Jan Davis Drive NW
+Huntsville, AL 35806
+USA
diff --git a/src/SliceVisitorPattern.cpp b/src/SliceVisitorPattern.cpp
index 86b245b..1d28767 100644
--- a/src/SliceVisitorPattern.cpp
+++ b/src/SliceVisitorPattern.cpp
@@ -1,3 +1,14 @@
+/*
+ * SliceVisitorPattern - a Slice translator plugin to populate
+ * 'visitor' interfaces automatically.
+ *
+ * Copyright (C) 2011, Digium, Inc.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
#include <Slice/Parser.h>
#include <Slice/Util.h>
#include <Slice/Plugin.h>
commit 339964f61298bd20c399f587fb0bb5fee470db7b
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Tue Jan 18 06:55:08 2011 -0600
Use FindIce.cmake.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2fb8905..2f1ad27 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,7 @@
cmake_minimum_required(VERSION 2.6)
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
+
# If a build type has not been explicitly specified then use debug
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING
@@ -19,113 +21,6 @@ macro(set_cache_var)
set(${ARGV} CACHE INTERNAL Bob FORCE)
endmacro()
-# Function which scans a path for matching files or directories,
-# whose names end with a standard version number string, and
-# returns the one with the 'highest' version found, or NOTFOUND
-# if there were no matches. Single-character globs (?) can
-# be used in the base string, but not multi-character globs (*).
-function(find_best_version output base)
- get_filename_component(base_full "${base}" ABSOLUTE)
- file(GLOB path_list "${base_full}*")
- string(LENGTH "${base_full}" base_length)
- foreach(path ${path_list})
- get_filename_component(path_full "${path}" ABSOLUTE)
- string(LENGTH "${path_full}" path_length)
- math(EXPR get "${path_length} - ${base_length}")
- string(SUBSTRING "${path_full}" ${base_length} ${get} ver)
- if(NOT DEFINED best_ver)
- set(best_ver ${ver})
- set(best_path "${path_full}")
- elseif(best_ver VERSION_LESS ver)
- set(best_ver ${ver})
- set(best_path "${path_full}")
- endif()
- endforeach()
- if(DEFINED best_ver)
- set(${output} "${best_path}" PARENT_SCOPE)
- else()
- set(${output} "NOTFOUND" PARENT_SCOPE)
- endif()
-endfunction()
-
-# Find Ice installation for a specific major/minor version
-function(find_ICE version)
- set(ice "$ENV{ICE_HOME}")
- if(NOT ice)
- if(WIN32)
- find_best_version(ice "C:/Ice-${version}")
- elseif(UNIX)
- find_best_version(ice "/opt/Ice-${version}")
- endif()
- endif()
-
- if(NOT ice)
- message(FATAL_ERROR "Could not find an installation of Ice with version ${version}")
- endif()
- find_path(ICE_SLICE_DIR Ice/Current.ice PATHS "${ice}/../slice" "${ice}/slice" NO_DEFAULT_PATH)
- if(ICE_SLICE_DIR)
- message(STATUS "Found Ice Slice definitions in ${ICE_SLICE_DIR}")
- else()
- message(FATAL_ERROR "Ice installation located at ${ice} is incomplete or broken (missing 'slice' directory)")
- endif()
- file(TO_CMAKE_PATH "${ice}" ice_cmake_path)
- set_cache_var(ICE_DIR "${ice_cmake_path}")
-endfunction()
-
-# Find Ice headers and libraries for CXX components
-function(find_ICE_CXX)
- find_path(ICE_CXX_INCLUDE_DIR Ice/Ice.h PATHS "${ICE_DIR}/include" NO_DEFAULT_PATH)
- if(ICE_CXX_INCLUDE_DIR)
- message(STATUS "Found Ice headers for CXX in ${ICE_CXX_INCLUDE_DIR}")
- else()
- message(FATAL_ERROR "Failed to find Ice headers for CXX")
- endif()
- # This block essentially tricks the GNU compiler into treating the Ice header files as system headers. This has
- # the benefit of having warnings emitted by the headers NOT treated as errors, even if the compiler has been told
- # to do so. This is currently being utilized by the C++0x support in this file so that Ice itself does not have to
- # be updated to be C++0x safe.
- if(CMAKE_COMPILER_IS_GNUCXX)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem ${ICE_CXX_INCLUDE_DIR}"
- CACHE STRING "Flags used by the compiler during release builds." FORCE)
- endif()
-endfunction()
-
-# Find an Ice library for CXX components
-function(find_ICE_CXX_library LIBRARY)
- if(NOT ICE_CXX_LIB_${LIBRARY})
- if(WIN32)
- string(TOLOWER ${LIBRARY} lib)
- find_library(ICE_CXX_LIB_RELEASE_${LIBRARY} ${lib} PATHS "${ICE_DIR}/lib" NO_DEFAULT_PATH)
- if(ICE_CXX_LIB_RELEASE_${LIBRARY})
- message(STATUS "Found Ice ${LIBRARY} library for CXX (release build) at ${ICE_CXX_LIB_RELEASE_${LIBRARY}}")
- list(APPEND ficxxl_libs optimized "${ICE_CXX_LIB_RELEASE_${LIBRARY}}")
- endif()
- find_library(ICE_CXX_LIB_DEBUG_${LIBRARY} ${lib}d PATHS "${ICE_DIR}/lib" NO_DEFAULT_PATH)
- if(ICE_CXX_LIB_DEBUG_${LIBRARY})
- message(STATUS "Found Ice ${LIBRARY} library for CXX (debug build) at ${ICE_CXX_LIB_DEBUG_${LIBRARY}}")
- list(APPEND ficxxl_libs debug "${ICE_CXX_LIB_DEBUG_${LIBRARY}}")
- endif()
- if(ficxxl_libs)
- set_cache_var(ICE_CXX_LIB_${LIBRARY} ${ficxxl_libs})
- else()
- message(FATAL_ERROR "Failed to find Ice ${LIBRARY} library for CXX")
- endif()
- elseif(UNIX)
- find_library(ICE_CXX_LIB_${LIBRARY} ${LIBRARY} PATHS "${ICE_DIR}/lib" "${ICE_DIR}/lib32" "${ICE_DIR}/lib64" NO_DEFAULT_PATH)
- if(ICE_CXX_LIB_${LIBRARY})
- message(STATUS "Found Ice ${LIBRARY} library for CXX at ${ICE_CXX_LIB_${LIBRARY}}")
- else()
- message(FATAL_ERROR "Failed to find Ice ${LIBRARY} library for CXX")
- endif()
- endif()
- endif()
-
- if(UNIX)
- get_filename_component(library_path ${ICE_CXX_LIB_${LIBRARY}} PATH)
- link_directories(${library_path})
- endif()
-endfunction()
-
project("Digium Slice Translator Plugins" CXX)
if(CMAKE_COMPILER_IS_GNUCXX)
@@ -146,14 +41,9 @@ if(WIN32)
set(CMAKE_DEBUG_POSTFIX "d")
endif()
-find_ICE(3.4)
-find_ICE_CXX()
-find_ICE_CXX_library(Ice)
-find_ICE_CXX_library(IceUtil)
-find_ICE_CXX_library(Slice)
+find_package(Ice 3.4 REQUIRED IceUtil Slice)
-message(STATUS "Include directories ${ICE_CXX_INCLUDE_DIR}")
-include_directories("${ICE_CXX_INCLUDE_DIR}")
+include_directories("${ICE_INCLUDE_DIR}")
set(CMAKE_INSTALL_PREFIX ${ICE_DIR})
diff --git a/cmake/FindIce.cmake b/cmake/FindIce.cmake
new file mode 100644
index 0000000..1b93fba
--- /dev/null
+++ b/cmake/FindIce.cmake
@@ -0,0 +1,299 @@
+#
+# FindIce.cmake - a CMake module for using ZeroC Ice
+#
+# Copyright (C) 2010-2011, Digium, Inc.
+#
+# This program is free software, distributed under the terms of
+# the GNU General Public License Version 2.
+#
+# Usage:
+#
+# This module supports the standard find_package() syntax, including
+# REQUIRED, QUIET and EXACT. It *never* searches for Ice along the system
+# PATH or any other CMake-provided default paths; instead, it will only
+# search in predefined locations, which are:
+#
+# ENV{ICE_HOME} if the ICE_HOME environment variable is set,
+# only that location is checked
+# /opt/Ice-<version> on UNIX-type platforms, subdirectories
+# of /opt are checked
+# C:/Ice-<version> on Windows platforms, subdirectories of C: are
+# checked
+#
+# These are the standard locations for Ice installations performed by the
+# ZeroC Ice packages; if Ice is installed in a non-standard location, then
+# ICE_HOME should be set to indicate where it is located.
+#
+# Syntax:
+#
+# find_package(Ice <major>.<minor>[.<patch>] [...])
+#
+# On the first call to this module, a major and minor version number
+# *MUST* be provided; if they are provided on subsequent calls, they
+# are ignored. During the first call, the locations listed above are
+# checked to find the highest-numbered version of Ice installed that
+# is compatible with the requested major and minor versions, unless
+# EXACT is specified, in which case only the single version specified
+# will be found (if it is available). Note that not specifying a patch
+# version number means it defaults to '0' (zero), so specifying
+# "Ice 3.4 EXACT" would in fact look for Ice 3.4.0 and no other version.
+#
+# For any call to this module, one or more COMPONENTS can be specified,
+# (and REQUIRED can be used to indicate they are not optional); each
+# name specified is expected to be a library provided with Ice, and
+# suitable tests are performed to ensure that library is part of the
+# Ice installation that was found.
+#
+# Variables used by this module:
+#
+# Ice_DEBUG If this is set to any value, the module will emit
+# debugging messages as each step of its operations
+# are performed.
+#
+# Variables set by this module:
+#
+# ICE_FOUND Will be set if a compatible version of Ice was found
+#
+# ICE_DIR The top-level directory of the Ice installation
+#
+# ICE_INCLUDE_DIR The directory containing C++ include files
+#
+# ICE_SLICE_DIR The directory containing Slice files for the
+# libraries provided with Ice
+#
+# ICE_CXX_FLAGS Any compiler flags that should be used when compiling
+# code that uses Ice
+#
+# ICE_VERSION The Ice version (complete)
+# ICE_VERSION_MAJOR The Ice major version
+# ICE_VERSION_MINOR The Ice minor version
+# ICE_VERSION_PATCH The Ice patch version
+#
+# For each component requested, sets (with <component> uppercased):
+#
+# ICE_<component>_FOUND Will be set if the component (library)
+# was found
+#
+# ICE_<component>_LIBRARY The path to the library, possibly
+# including both optimized and debug
+# if they are available
+#
+# ICE_<component>_LIBRARY_DEBUG The path to the library, as a debug
+# build if it is available, otherwise as
+# an optimized build
+#
+# ICE_<component>_LIBRARY_RELEASE The path to the library, as an optimized
+# build if it is available, otherwise as
+# a debug build
+#
+
+find_package(PackageHandleStandardArgs)
+find_package(PackageComponentHandleStandardArgs)
+
+function(_ice_set_cache_path var value reason)
+ set("${var}" "${value}" CACHE PATH "${reason}" FORCE)
+ mark_as_advanced(FORCE "${var}")
+endfunction()
+
+function(_ice_set_cache_filepath var value reason)
+ set("${var}" "${value}" CACHE FILEPATH "${reason}" FORCE)
+ mark_as_advanced(FORCE "${var}")
+endfunction()
+
+function(_ice_set_cache_string var value reason)
+ set("${var}" "${value}" CACHE STRING "${reason}" FORCE)
+ mark_as_advanced(FORCE "${var}")
+endfunction()
+
+function(_ice_find_library library)
+ string(TOUPPER "${library}" upper)
+
+ set(_ice_debug_suffix "${CMAKE_DEBUG_POSTFIX}")
+
+ find_library(ICE_${upper}_LIBRARY_RELEASE NAMES "${library}" NO_DEFAULT_PATH PATHS "${ICE_DIR}" PATH_SUFFIXES "lib" "lib32" "lib64")
+ find_library(ICE_${upper}_LIBRARY_DEBUG NAMES "${library}${_ice_debug_suffix}" NO_DEFAULT_PATH PATHS "${ICE_DIR}" PATH_SUFFIXES "lib" "lib32" "lib64")
+
+ mark_as_advanced(ICE_${upper}_LIBRARY_RELEASE ICE_${upper}_LIBRARY_DEBUG)
+
+ if(ICE_${upper}_LIBRARY_DEBUG OR ICE_${upper}_LIBRARY_RELEASE)
+ _ice_set_cache_string(ICE_${upper}_FOUND ON "The Ice ${library} library was found")
+ endif()
+
+ if(Ice_DEBUG)
+ message(STATUS
+ "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "${library} library (release) found at ${ICE_${upper}_LIBRARY_RELEASE} "
+ "${library} library (debug) found at ${ICE_${upper}_LIBRARY_DEBUG} ")
+ endif()
+endfunction()
+
+# Lifted (and then modified) from FindBoost.cmake, which got it from FindQt4.cmake.
+function(_ice_adjust_lib_vars library)
+ string(TOUPPER "${library}" upper)
+ if(ICE_${upper}_LIBRARY_DEBUG AND ICE_${upper}_LIBRARY_RELEASE)
+ # if the generator supports configuration types then set
+ # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value
+ if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE)
+ set(ICE_${upper}_LIBRARY optimized "${ICE_${upper}_LIBRARY_RELEASE}" debug "${ICE_${upper}_LIBRARY_DEBUG}")
+ else()
+ # if there are no configuration types and CMAKE_BUILD_TYPE has no value
+ # then just use the release libraries
+ set(ICE_${upper}_LIBRARY "${ICE_${upper}_LIBRARY_RELEASE}")
+ endif()
+ endif()
+
+ # if only the release version was found, set the debug variable also to the release version
+ if(ICE_${upper}_LIBRARY_RELEASE AND NOT ICE_${upper}_LIBRARY_DEBUG)
+ _ice_set_cache_filepath(ICE_${upper}_LIBRARY_DEBUG "${ICE_${upper}_LIBRARY_RELEASE}" "Path to a library.")
+ set(ICE_${upper}_LIBRARY "${ICE_${upper}_LIBRARY_RELEASE}")
+ endif()
+
+ # if only the debug version was found, set the release variable also to the debug version
+ if(ICE_${upper}_LIBRARY_DEBUG AND NOT ICE_${upper}_LIBRARY_RELEASE)
+ _ice_set_cache_filepath(ICE_${upper}_LIBRARY_RELEASE "${ICE_${upper}_LIBRARY_DEBUG}" "Path to a library.")
+ set(ICE_${upper}_LIBRARY "${ICE_${upper}_LIBRARY_DEBUG}")
+ endif()
+
+ if(ICE_${upper}_LIBRARY)
+ _ice_set_cache_string(ICE_${upper}_LIBRARY "${ICE_${upper}_LIBRARY}" "The Ice ${library} library")
+ endif()
+endfunction()
+
+if(NOT ICE_DIR)
+ if(NOT Ice_FIND_VERSION)
+ find_package_handle_standard_args(Ice "Major and minor version numbers (at least) must be supplied to find Ice." ICE_DIR)
+ endif()
+
+ if($ENV{ICE_HOME})
+ # if ICE_HOME is set, we will only look there; if the version present there
+ # does not satisfy the requested version, then the search will fail
+ list(APPEND _ice_candidate_dirs "$ENV{ICE_HOME}")
+ else()
+ if(Ice_FIND_VERSION_EXACT)
+ # we prefer to find an Ice directory without a patch version specified if possible, so put
+ # that in the list first
+ list(APPEND _ice_candidate_versions
+ "${Ice_FIND_VERSION_MAJOR}.${Ice_FIND_VERSION_MINOR}"
+ "${Ice_FIND_VERSION_MAJOR}.${Ice_FIND_VERSION_MINOR}.${Ice_FIND_VERSION_PATCH}")
+ else()
+ # we prefer to find an Ice directory without a patch version specified if possible, so put
+ # that in the list first
+ list(APPEND _ice_candidate_versions
+ "${Ice_FIND_VERSION_MAJOR}.${Ice_FIND_VERSION_MINOR}")
+
+ # next, search for any patch version greater-than or equal-to what was requested
+ foreach(patch RANGE 10 0 -1)
+ if(NOT "${Ice_FIND_VERSION_MAJOR}.${Ice_FIND_VERSION_MINOR}.${patch}" VERSION_LESS "${Ice_FIND_VERSION}")
+ list(APPEND _ice_candidate_versions
+ "${Ice_FIND_VERSION_MAJOR}.${Ice_FIND_VERSION_MINOR}.${patch}")
+ endif()
+ endforeach()
+
+ endif()
+
+ # now convert each candidate version into a directory path
+ foreach(version IN LISTS _ice_candidate_versions)
+ if(WIN32)
+ list(APPEND _ice_candidate_dirs "C:/Ice-${version}")
+ elseif(UNIX)
+ list(APPEND _ice_candidate_dirs "/opt/Ice-${version}")
+ endif()
+ endforeach()
+
+ endif()
+
+ if(Ice_DEBUG)
+ message(STATUS
+ "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "will search for Ice in these directories: ${_ice_candidate_dirs}")
+ endif()
+
+ # since we may find a copy of Ice with a directory name that matches one of our candidates
+ # but does not provide an adequate version, we have to be prepared to search repeatedly
+ # until either an adequate version is found or all the candidates are exhausted
+ while(NOT ICE_DIR)
+ find_path(ICE_INCLUDE_DIR NAMES "IceUtil/Config.h" PATHS ${_ice_candidate_dirs} PATH_SUFFIXES "include" NO_DEFAULT_PATH)
+
+ # if nothing was found, then stop now
+ if(NOT ICE_INCLUDE_DIR)
+ break()
+ endif()
+
+ if(Ice_DEBUG)
+ message(STATUS
+ "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "found Ice includes at: ${ICE_INCLUDE_DIR}")
+ endif()
+
+ get_filename_component(_ice_possible_dir "${ICE_INCLUDE_DIR}" PATH)
+
+ # now check the embedded version in the IceUtil/Config.h file to ensure it
+ # satisfies the version requested
+ file(READ "${ICE_INCLUDE_DIR}/IceUtil/Config.h" _ice_config_contents)
+ string(REGEX REPLACE ".*#define.*ICE_STRING_VERSION.*\"([0-9]+\\.[0-9]+\\.[0-9]+)\".*" "\\1" _ice_config_version "${_ice_config_contents}")
+
+ if(Ice_DEBUG)
+ message(STATUS
+ "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Ice version detected: ${_ice_config_version}")
+ endif()
+
+ if((NOT Ice_FIND_VERSION_EXACT) OR (${_ice_config_version} VERSION_EQUAL ${Ice_FIND_VERSION}))
+ _ice_set_cache_path(ICE_DIR "${_ice_possible_dir}" "Location of Ice")
+ _ice_set_cache_string(ICE_VERSION "${_ice_config_version}" "Version of Ice")
+ string(REGEX REPLACE "([0-9]+)\\.[0-9]+\\.[0-9]+" "\\1" _ice_version_major "${_ice_config_version}")
+ _ice_set_cache_string(ICE_VERSION_MAJOR "${_ice_version_major}" "Version of Ice (major)")
+ string(REGEX REPLACE "[0-9]+\\.([0-9]+)\\.[0-9]+" "\\1" _ice_version_minor "${_ice_config_version}")
+ _ice_set_cache_string(ICE_VERSION_MINOR "${_ice_version_minor}" "Version of Ice (minor)")
+ string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+)" "\\1" _ice_version_patch "${_ice_config_version}")
+ _ice_set_cache_string(ICE_VERSION_PATCH "${_ice_version_patch}" "Version of Ice (patch)")
+ break()
+ endif()
+
+ if(Ice_DEBUG)
+ message(STATUS
+ "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] "
+ "Ice version ${_ice_config_version} does not match requested ${Ice_FIND_VERSION}")
+ endif()
+
+ # we are in EXACT find mode, and the version in the directory found
+ # does not satisfy the requested version... so remove this directory
+ # as a candidate and try again
+ list(REMOVE_ITEM _ice_candidate_dirs "${_ice_possible_dir}")
+ unset(ICE_INCLUDE_DIR CACHE)
+ endwhile()
+
+ if(ICE_DIR)
+ mark_as_advanced(FORCE ICE_INCLUDE_DIR)
+
+ find_path(ICE_SLICE_DIR "Ice/Current.ice" PATHS "${ICE_DIR}" PATH_SUFFIXES "slice" NO_DEFAULT_PATH)
+ if(NOT ICE_SLICE_DIR)
+ message(WARNING "Ice installation located at ${ICE_DIR} is incomplete or broken (missing 'slice' directory)")
+ else()
+ mark_as_advanced(FORCE ICE_SLICE_DIR)
+ endif()
+
+ # This block essentially tricks the GNU compiler into treating the Ice header files as system headers. This has
+ # the benefit of having warnings emitted by the headers NOT treated as errors, even if the compiler has been told
+ # to do so. This is being utilized so that Ice itself does not have to be updated to be C++0x safe.
+ if(CMAKE_COMPILER_IS_GNUCXX)
+ _ice_set_cache_string(ICE_CXX_FLAGS "-isystem ${ICE_INCLUDE_DIR}" "Ice-specific compiler flags")
+ endif()
+
+ endif()
+
+ find_package_handle_standard_args(Ice DEFAULT_MSG ICE_DIR ICE_SLICE_DIR ICE_INCLUDE_DIR)
+endif()
+
+if(ICE_DIR)
+ foreach(component IN LISTS Ice_FIND_COMPONENTS)
+ string(TOUPPER "${component}" upper)
+ if(NOT ICE_${upper}_FOUND)
+ _ice_find_library("${component}")
+ if(ICE_${upper}_FOUND)
+ _ice_adjust_lib_vars("${component}")
+ endif()
+ find_package_component_handle_standard_args(Ice "${component}" DEFAULT_MSG ICE_${upper}_LIBRARY)
+ endif()
+ endforeach()
+endif()
diff --git a/cmake/FindPackageComponentHandleStandardArgs.cmake b/cmake/FindPackageComponentHandleStandardArgs.cmake
new file mode 100644
index 0000000..bd95606
--- /dev/null
+++ b/cmake/FindPackageComponentHandleStandardArgs.cmake
@@ -0,0 +1,85 @@
+#=============================================================================
+# Copyright 2007-2009 Kitware, Inc.
+# Copyright 2011, Digium, Inc.
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+#
+# * Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# * The names of Kitware, Inc., the Insight Consortium, or the names of
+# any consortium members, or of any contributors, may not be used to
+# endorse or promote products derived from this software without
+# specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
+# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#=============================================================================
+#
+# FIND_PACKAGE_COMPONENT_HANDLE_STANDARD_ARGS(NAME COMPONENT (DEFAULT_MSG|"Custom failure message") VAR1 ... )
+# This macro is intended to be used in FindXXX.cmake modules files.
+# It handles the REQUIRED and QUIET argument to FIND_PACKAGE().
+# The package is found if all variables listed are TRUE.
+
+INCLUDE(FindPackageMessage)
+FUNCTION(FIND_PACKAGE_COMPONENT_HANDLE_STANDARD_ARGS _NAME _COMP _FAIL_MSG _VAR1 )
+
+ IF("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
+ SET(_FAIL_MESSAGE "Could NOT find ${_NAME} component ${_COMP}")
+ ELSE("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
+ SET(_FAIL_MESSAGE "${_FAIL_MSG}")
+ ENDIF("${_FAIL_MSG}" STREQUAL "DEFAULT_MSG")
+
+ STRING(TOUPPER ${_COMP} _COMP_UPPER)
+
+ # collect all variables which were not found, so they can be printed, so the
+ # user knows better what went wrong (#6375)
+ SET(MISSING_VARS "")
+ SET(DETAILS "")
+ SET(${_COMP_UPPER}_FOUND TRUE)
+ IF(NOT ${_VAR1})
+ SET(${_COMP_UPPER}_FOUND FALSE)
+ SET(MISSING_VARS " ${_VAR1}")
+ ELSE(NOT ${_VAR1})
+ SET(DETAILS "${DETAILS}[${${_VAR1}}]")
+ ENDIF(NOT ${_VAR1})
+
+ # check if all passed variables are valid
+ FOREACH(_CURRENT_VAR ${ARGN})
+ IF(NOT ${_CURRENT_VAR})
+ SET(${_COMP_UPPER}_FOUND FALSE)
+ SET(MISSING_VARS "${MISSING_VARS} ${_CURRENT_VAR}")
+ ELSE(NOT ${_CURRENT_VAR})
+ SET(DETAILS "${DETAILS}[${${_CURRENT_VAR}}]")
+ ENDIF(NOT ${_CURRENT_VAR})
+ ENDFOREACH(_CURRENT_VAR)
+
+ IF (${_COMP_UPPER}_FOUND)
+ FIND_PACKAGE_MESSAGE(${_NAME} "Found ${_NAME} component ${_COMP}: ${${_VAR1}}" "${DETAILS}")
+ ELSE (${_COMP_UPPER}_FOUND)
+ IF (${_NAME}_FIND_REQUIRED)
+ MESSAGE(FATAL_ERROR "${_FAIL_MESSAGE} (missing: ${MISSING_VARS})")
+ ELSE (${_NAME}_FIND_REQUIRED)
+ IF (NOT ${_NAME}_FIND_QUIETLY)
+ MESSAGE(STATUS "${_FAIL_MESSAGE} (missing: ${MISSING_VARS})")
+ ENDIF (NOT ${_NAME}_FIND_QUIETLY)
+ ENDIF (${_NAME}_FIND_REQUIRED)
+ ENDIF (${_COMP_UPPER}_FOUND)
+
+ENDFUNCTION(FIND_PACKAGE_COMPONENT_HANDLE_STANDARD_ARGS)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c446890..b1245a1 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,4 +1,3 @@
-add_library(SliceVisitorPattern SHARED SliceVisitorPattern.cpp)
-target_link_libraries(SliceVisitorPattern ${ICE_CXX_LIB_Ice} ${ICE_CXX_LIB_IceUtil} ${ICE_CXX_LIB_Slice})
-
+add_library(SliceVisitorPattern MODULE SliceVisitorPattern.cpp)
+target_link_libraries(SliceVisitorPattern ${ICE_ICEUTIL_LIBRARY} ${ICE_SLICE_LIBRARY})
install(TARGETS SliceVisitorPattern LIBRARY DESTINATION lib RUNTIME DESTINATION bin)
commit 6cda871fc97e9cfe281a762fa5684c12e4b1744f
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Fri Jan 7 07:20:08 2011 -0600
Make installation path settings compatible with Windows.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e698409..2fb8905 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -155,4 +155,6 @@ find_ICE_CXX_library(Slice)
message(STATUS "Include directories ${ICE_CXX_INCLUDE_DIR}")
include_directories("${ICE_CXX_INCLUDE_DIR}")
+set(CMAKE_INSTALL_PREFIX ${ICE_DIR})
+
add_subdirectory(src)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index af49413..c446890 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,9 +1,4 @@
add_library(SliceVisitorPattern SHARED SliceVisitorPattern.cpp)
target_link_libraries(SliceVisitorPattern ${ICE_CXX_LIB_Ice} ${ICE_CXX_LIB_IceUtil} ${ICE_CXX_LIB_Slice})
-if(WIN32)
- get_filename_component(library_path ${ICE_CXX_LIB_DEBUG_Ice} PATH)
-else()
- get_filename_component(library_path ${ICE_CXX_LIB_Ice} PATH)
-endif()
-install(TARGETS SliceVisitorPattern LIBRARY DESTINATION ${library_path})
+install(TARGETS SliceVisitorPattern LIBRARY DESTINATION lib RUNTIME DESTINATION bin)
commit 14c36ad0edcb4ff448d1ed2099e6c99abed57fc2
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Fri Jan 7 07:16:59 2011 -0600
Add build directory to repository.
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index 378eac2..0000000
--- a/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-build
diff --git a/build/.gitignore b/build/.gitignore
new file mode 100644
index 0000000..72e8ffc
--- /dev/null
+++ b/build/.gitignore
@@ -0,0 +1 @@
+*
commit 00c4790440092cb608cc58f63b7335d08a84e404
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Thu Jan 6 18:18:00 2011 -0600
Explicitly link to libraries to make Windows builds happy.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5fa164f..e698409 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -149,6 +149,8 @@ endif()
find_ICE(3.4)
find_ICE_CXX()
find_ICE_CXX_library(Ice)
+find_ICE_CXX_library(IceUtil)
+find_ICE_CXX_library(Slice)
message(STATUS "Include directories ${ICE_CXX_INCLUDE_DIR}")
include_directories("${ICE_CXX_INCLUDE_DIR}")
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f68ab39..af49413 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,4 +1,5 @@
add_library(SliceVisitorPattern SHARED SliceVisitorPattern.cpp)
+target_link_libraries(SliceVisitorPattern ${ICE_CXX_LIB_Ice} ${ICE_CXX_LIB_IceUtil} ${ICE_CXX_LIB_Slice})
if(WIN32)
get_filename_component(library_path ${ICE_CXX_LIB_DEBUG_Ice} PATH)
commit a1626334e6aea8343ed69b3c25709854a56d4090
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Thu Jan 6 18:01:47 2011 -0600
Quick fix for Windows path issue.
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index facbcf7..f68ab39 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,4 +1,8 @@
add_library(SliceVisitorPattern SHARED SliceVisitorPattern.cpp)
-get_filename_component(library_path ${ICE_CXX_LIB_Ice} PATH)
+if(WIN32)
+ get_filename_component(library_path ${ICE_CXX_LIB_DEBUG_Ice} PATH)
+else()
+ get_filename_component(library_path ${ICE_CXX_LIB_Ice} PATH)
+endif()
install(TARGETS SliceVisitorPattern LIBRARY DESTINATION ${library_path})
commit 48ced450203f5dfff2417c0e0ea09b0c33904515
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Thu Jan 6 17:58:45 2011 -0600
Fix bug and remove IceBox testing.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1d3f585..5fa164f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -70,16 +70,6 @@ function(find_ICE version)
endif()
file(TO_CMAKE_PATH "${ice}" ice_cmake_path)
set_cache_var(ICE_DIR "${ice_cmake_path}")
-
- # find icebox executable
- # XXX Need to look for iceboxd.exe for debug windows builds
- find_program(ICEBOX icebox PATHS "${ICE_DIR}/bin" NO_DEFAULT_PATH)
-
- if(ICEBOX)
- message(STATUS "Found icebox at ${ICEBOX}")
- else()
- message(WARNING "Failed to find icebox ${ICE_DIR}")
- endif()
endfunction()
# Find Ice headers and libraries for CXX components
@@ -153,7 +143,7 @@ endif()
# On Windows, 'debug' libraries should have a "d" suffix to indicate that they
# are debug libraries
if(WIN32)
- set(CMAKE_DEBUG_POSTFIX "d" PARENT_SCOPE)
+ set(CMAKE_DEBUG_POSTFIX "d")
endif()
find_ICE(3.4)
commit d94bbeb493eff3ab76ec63a233c9960935492f15
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Thu Jan 6 16:21:59 2011 -0600
Add support for Python (which required knowing how to generate an
'empty' function body).
Change some names to be consistent with names in the Ice code.
diff --git a/src/SliceVisitorPattern.cpp b/src/SliceVisitorPattern.cpp
index 0114368..86b245b 100644
--- a/src/SliceVisitorPattern.cpp
+++ b/src/SliceVisitorPattern.cpp
@@ -46,6 +46,7 @@ protected:
// The function returns a StringList; each string in the list will be placed into the
// function body in a language-appropriate manner.
virtual StringList generateVisitFunctionBody(const string&, const ClassDefPtr&, const ClassDefPtr&, const string&) = 0;
+ virtual StringList generateEmptyFunctionBody() = 0;
private:
// This map contains the list of classes known to be visitors;
@@ -163,11 +164,7 @@ VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
// won't actually produce output for the include file.
if(derivedVisitor->includeLevel() == 0)
{
- // it is necessary to provide a non-empty body for the operation
- // to keep it from being abstract
- StringList body;
- body.push_back("");
- GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, body);
+ GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, generateEmptyFunctionBody());
gop->createParamDecl("item", p->declaration(), false);
}
// There is no need to actually generate operations into the visited
@@ -213,11 +210,7 @@ VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
{
if(derivedVisitor->includeLevel() == 0)
{
- // it is necessary to provide a non-empty body for the operation
- // to keep it from being abstract
- StringList body;
- body.push_back("");
- GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, body);
+ GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, generateEmptyFunctionBody());
gop->createParamDecl("item", p->declaration(), false);
}
if(p->includeLevel() == 0)
@@ -251,10 +244,10 @@ VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
return false;
}
-class ICE_DECLSPEC_EXPORT CPPVisitor : public VisitorPatternVisitor
+class ICE_DECLSPEC_EXPORT CPlusPlusVisitor : public VisitorPatternVisitor
{
public:
- CPPVisitor()
+ CPlusPlusVisitor()
{
_useWstring.push(0);
}
@@ -306,6 +299,7 @@ public:
protected:
StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
+ StringList generateEmptyFunctionBody();
private:
stack<int> _useWstring;
@@ -333,26 +327,29 @@ private:
}
};
-class ICE_DECLSPEC_EXPORT CSVisitor : public VisitorPatternVisitor
+class ICE_DECLSPEC_EXPORT CsVisitor : public VisitorPatternVisitor
{
protected:
StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
+ StringList generateEmptyFunctionBody();
};
class ICE_DECLSPEC_EXPORT JavaVisitor : public VisitorPatternVisitor
{
protected:
StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
+ StringList generateEmptyFunctionBody();
};
class ICE_DECLSPEC_EXPORT PythonVisitor : public VisitorPatternVisitor
{
protected:
StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
+ StringList generateEmptyFunctionBody();
};
StringList
-CPPVisitor::generateVisitFunctionBody(const string& paramName,
+CPlusPlusVisitor::generateVisitFunctionBody(const string& paramName,
const ClassDefPtr& baseVisitor,
const ClassDefPtr& derivedVisitor,
const string& operationName)
@@ -387,6 +384,15 @@ CPPVisitor::generateVisitFunctionBody(const string& paramName,
}
StringList
+CPlusPlusVisitor::generateEmptyFunctionBody()
+{
+ StringList body;
+
+ body.push_back("");
+ return body;
+}
+
+StringList
JavaVisitor::generateVisitFunctionBody(const string& paramName,
const ClassDefPtr& baseVisitor,
const ClassDefPtr& derivedVisitor,
@@ -415,7 +421,16 @@ JavaVisitor::generateVisitFunctionBody(const string& paramName,
}
StringList
-CSVisitor::generateVisitFunctionBody(const string& paramName,
+JavaVisitor::generateEmptyFunctionBody()
+{
+ StringList body;
+
+ body.push_back("");
+ return body;
+}
+
+StringList
+CsVisitor::generateVisitFunctionBody(const string& paramName,
const ClassDefPtr& baseVisitor,
const ClassDefPtr& derivedVisitor,
const string& operationName)
@@ -442,12 +457,36 @@ CSVisitor::generateVisitFunctionBody(const string& paramName,
}
StringList
+CsVisitor::generateEmptyFunctionBody()
+{
+ StringList body;
+
+ body.push_back("");
+ return body;
+}
+
+StringList
PythonVisitor::generateVisitFunctionBody(const string& paramName,
const ClassDefPtr& baseVisitor,
const ClassDefPtr& derivedVisitor,
const string& operationName)
{
- return StringList();
+ ostringstream ostr;
+ StringList body;
+
+ ostr << paramName << "." << operationName << "(self);";
+ body.push_back(ostr.str());
+
+ return body;
+}
+
+StringList
+PythonVisitor::generateEmptyFunctionBody()
+{
+ StringList body;
+
+ body.push_back("pass");
+ return body;
}
extern "C"
@@ -459,10 +498,10 @@ extern "C"
switch(language)
{
case LanguageCPlusPlus:
- result->push_back(new CPPVisitor());
+ result->push_back(new CPlusPlusVisitor());
break;
case LanguageCs:
- result->push_back(new CSVisitor());
+ result->push_back(new CsVisitor());
break;
case LanguageJava:
result->push_back(new JavaVisitor());
commit 6db266d8b484f5bc4562f8d091065b56fb71a900
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Thu Jan 6 14:53:30 2011 -0600
Generate appropriate function body for C# translation, and mark
some GeneratedOperations as 'override', since C# requires that.
diff --git a/src/SliceVisitorPattern.cpp b/src/SliceVisitorPattern.cpp
index 9e9550e..0114368 100644
--- a/src/SliceVisitorPattern.cpp
+++ b/src/SliceVisitorPattern.cpp
@@ -3,6 +3,7 @@
#include <Slice/Plugin.h>
#include <Slice/CPlusPlusUtil.h>
#include <Slice/JavaUtil.h>
+#include <Slice/CsUtil.h>
using namespace std;
using namespace Slice;
@@ -176,6 +177,10 @@ VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
{
GeneratedOperationPtr gop = p->createGeneratedOperation("visit", 0,
generateVisitFunctionBody("visitor", baseVisitor, derivedVisitor, "visit" + p->name()));
+ if(baseVisitor != derivedVisitor)
+ {
+ gop->setOverride(true);
+ }
gop->createParamDecl("visitor", baseVisitor->declaration(), false);
}
return false;
@@ -219,6 +224,7 @@ VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
{
GeneratedOperationPtr gop = p->createGeneratedOperation("visit", 0,
generateVisitFunctionBody("visitor", baseVisitor, derivedVisitor, "visit" + p->name()));
+ gop->setOverride(true);
gop->createParamDecl("visitor", baseVisitor->declaration(), false);
}
}
@@ -414,7 +420,25 @@ CSVisitor::generateVisitFunctionBody(const string& paramName,
const ClassDefPtr& derivedVisitor,
const string& operationName)
{
- return StringList();
+ ostringstream ostr;
+ StringList body;
+ string derivedVisitorString = CsGenerator::typeToString(derivedVisitor->declaration());
+
+ if(baseVisitor != derivedVisitor)
+ {
+ ostr << "if (" << paramName << " is " << derivedVisitorString << ")";
+ body.push_back(ostr.str());
+ ostr.str("");
+ ostr << "((" << derivedVisitorString << ") " << paramName << ")";
+ }
+ else
+ {
+ ostr << paramName;
+ }
+ ostr << "." << operationName << "(this);";
+ body.push_back(ostr.str());
+
+ return body;
}
StringList
commit d09388b8943776275a25767811d702370b34d033
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Thu Jan 6 11:38:17 2011 -0600
Use direct access to CPlusPlusUtil and JavaUtil identifier conversion
functions instead of LanguageHelper mechanism.
diff --git a/src/SliceVisitorPattern.cpp b/src/SliceVisitorPattern.cpp
index 77d6659..9e9550e 100644
--- a/src/SliceVisitorPattern.cpp
+++ b/src/SliceVisitorPattern.cpp
@@ -1,6 +1,8 @@
#include <Slice/Parser.h>
#include <Slice/Util.h>
#include <Slice/Plugin.h>
+#include <Slice/CPlusPlusUtil.h>
+#include <Slice/JavaUtil.h>
using namespace std;
using namespace Slice;
@@ -44,8 +46,6 @@ protected:
// function body in a language-appropriate manner.
virtual StringList generateVisitFunctionBody(const string&, const ClassDefPtr&, const ClassDefPtr&, const string&) = 0;
- VisitorPatternVisitor(ParserVisitor::LanguageHelper* helper) : ParserVisitor(helper) { }
-
private:
// This map contains the list of classes known to be visitors;
// the key is the fully-scoped named of the class, and the value
@@ -248,41 +248,101 @@ VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
class ICE_DECLSPEC_EXPORT CPPVisitor : public VisitorPatternVisitor
{
public:
- CPPVisitor(ParserVisitor::LanguageHelper* helper) : VisitorPatternVisitor(helper) { }
+ CPPVisitor()
+ {
+ _useWstring.push(0);
+ }
+
+ virtual bool visitModuleStart(const ModulePtr& in)
+ {
+ setUseWstring(in);
+ return true;
+ }
+
+ virtual void visitModuleEnd(const ModulePtr& in)
+ {
+ resetUseWstring();
+ }
+
+ virtual bool visitClassDefStart(const ClassDefPtr& in)
+ {
+ setUseWstring(in);
+ VisitorPatternVisitor::visitClassDefStart(in);
+ return true;
+ }
+
+ virtual void visitClassDefEnd(const ClassDefPtr& in)
+ {
+ resetUseWstring();
+ }
+
+ virtual bool visitExceptionStart(const ExceptionPtr& in)
+ {
+ setUseWstring(in);
+ return true;
+ }
+
+ virtual void visitExceptionEnd(const ExceptionPtr& in)
+ {
+ resetUseWstring();
+ }
+
+ virtual bool visitStructStart(const StructPtr& in)
+ {
+ setUseWstring(in);
+ return true;
+ }
+
+ virtual void visitStructEnd(const StructPtr& in)
+ {
+ resetUseWstring();
+ }
+
protected:
StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
+
private:
- CPPVisitor();
+ stack<int> _useWstring;
+
+ void setUseWstring(ContainedPtr p)
+ {
+ StringList metaData = p->getMetaData();
+ if(find(metaData.begin(), metaData.end(), "cpp:type:wstring") != metaData.end())
+ {
+ _useWstring.push(TypeContextUseWstring);
+ }
+ else if(find(metaData.begin(), metaData.end(), "cpp:type:string") != metaData.end())
+ {
+ _useWstring.push(0);
+ }
+ else
+ {
+ _useWstring.push(_useWstring.top());
+ }
+ }
+
+ void resetUseWstring()
+ {
+ _useWstring.pop();
+ }
};
class ICE_DECLSPEC_EXPORT CSVisitor : public VisitorPatternVisitor
{
-public:
- CSVisitor(ParserVisitor::LanguageHelper* helper) : VisitorPatternVisitor(helper) { }
protected:
StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
-private:
- CSVisitor();
};
class ICE_DECLSPEC_EXPORT JavaVisitor : public VisitorPatternVisitor
{
-public:
- JavaVisitor(ParserVisitor::LanguageHelper* helper) : VisitorPatternVisitor(helper) { }
protected:
StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
-private:
- JavaVisitor();
};
class ICE_DECLSPEC_EXPORT PythonVisitor : public VisitorPatternVisitor
{
-public:
- PythonVisitor(ParserVisitor::LanguageHelper* helper) : VisitorPatternVisitor(helper) { }
protected:
StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
-private:
- PythonVisitor();
};
StringList
@@ -293,7 +353,8 @@ CPPVisitor::generateVisitFunctionBody(const string& paramName,
{
ostringstream ostr;
StringList body;
- string derivedVisitorString = _languageHelper->typeToString(derivedVisitor->declaration(), derivedVisitor->getMetaData());
+ string derivedVisitorString = typeToString(derivedVisitor->declaration(), derivedVisitor->getMetaData(),
+ _useWstring.top());
if(baseVisitor != derivedVisitor)
{
@@ -327,7 +388,8 @@ JavaVisitor::generateVisitFunctionBody(const string& paramName,
{
ostringstream ostr;
StringList body;
- string derivedVisitorString = _languageHelper->typeToString(derivedVisitor->declaration(), derivedVisitor->getMetaData());
+ string derivedVisitorString = JavaGenerator::typeToString(derivedVisitor->declaration(), JavaGenerator::TypeModeMember,
+ "", derivedVisitor->getMetaData(), false);
if(baseVisitor != derivedVisitor)
{
@@ -367,22 +429,22 @@ PythonVisitor::generateVisitFunctionBody(const string& paramName,
extern "C"
{
ICE_DECLSPEC_EXPORT VisitorList*
- create(Language language, ParserVisitor::LanguageHelper* helper)
+ create(Language language)
{
VisitorList* result = new VisitorList();
switch(language)
{
- case LanguageCXX:
- result->push_back(new CPPVisitor(helper));
+ case LanguageCPlusPlus:
+ result->push_back(new CPPVisitor());
break;
- case LanguageCS:
- result->push_back(new CSVisitor(helper));
+ case LanguageCs:
+ result->push_back(new CSVisitor());
break;
case LanguageJava:
- result->push_back(new JavaVisitor(helper));
+ result->push_back(new JavaVisitor());
break;
case LanguagePython:
- result->push_back(new PythonVisitor(helper));
+ result->push_back(new PythonVisitor());
break;
default:
cerr << "SliceVisitorPattern plugin does not support language " << language << "." << endl;
commit b096fc094a69d8a40a6c59ee6f083835c6ceb8ce
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Wed Jan 5 17:58:25 2011 -0600
Use new simplified plugin visitor interface.
Use new LanguageHelper interface to properly represent Slice type
names in generated function bodies.
diff --git a/src/SliceVisitorPattern.cpp b/src/SliceVisitorPattern.cpp
index 3f45e8a..77d6659 100644
--- a/src/SliceVisitorPattern.cpp
+++ b/src/SliceVisitorPattern.cpp
@@ -27,7 +27,7 @@ using namespace Slice::Plugin;
// where FOO is the name of the class to be visited. The operation
// receives the visited class object as a parameter.
-class VisitorPatternVisitor : public PluginVisitor
+class VisitorPatternVisitor : public ParserVisitor
{
public:
virtual bool visitClassDefStart(const ClassDefPtr&);
@@ -44,6 +44,8 @@ protected:
// function body in a language-appropriate manner.
virtual StringList generateVisitFunctionBody(const string&, const ClassDefPtr&, const ClassDefPtr&, const string&) = 0;
+ VisitorPatternVisitor(ParserVisitor::LanguageHelper* helper) : ParserVisitor(helper) { }
+
private:
// This map contains the list of classes known to be visitors;
// the key is the fully-scoped named of the class, and the value
@@ -245,26 +247,42 @@ VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
class ICE_DECLSPEC_EXPORT CPPVisitor : public VisitorPatternVisitor
{
+public:
+ CPPVisitor(ParserVisitor::LanguageHelper* helper) : VisitorPatternVisitor(helper) { }
protected:
StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
+private:
+ CPPVisitor();
};
class ICE_DECLSPEC_EXPORT CSVisitor : public VisitorPatternVisitor
{
+public:
+ CSVisitor(ParserVisitor::LanguageHelper* helper) : VisitorPatternVisitor(helper) { }
protected:
StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
+private:
+ CSVisitor();
};
class ICE_DECLSPEC_EXPORT JavaVisitor : public VisitorPatternVisitor
{
+public:
+ JavaVisitor(ParserVisitor::LanguageHelper* helper) : VisitorPatternVisitor(helper) { }
protected:
StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
+private:
+ JavaVisitor();
};
class ICE_DECLSPEC_EXPORT PythonVisitor : public VisitorPatternVisitor
{
+public:
+ PythonVisitor(ParserVisitor::LanguageHelper* helper) : VisitorPatternVisitor(helper) { }
protected:
StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
+private:
+ PythonVisitor();
};
StringList
@@ -275,6 +293,7 @@ CPPVisitor::generateVisitFunctionBody(const string& paramName,
{
ostringstream ostr;
StringList body;
+ string derivedVisitorString = _languageHelper->typeToString(derivedVisitor->declaration(), derivedVisitor->getMetaData());
if(baseVisitor != derivedVisitor)
{
@@ -282,7 +301,7 @@ CPPVisitor::generateVisitFunctionBody(const string& paramName,
// IceUtil::Handle-derived shared pointer. Since that is the case, we can use
// the dynamicCast() operation defined by IceUtil::Handle to convert the pointer
// into a derived visitor class pointer.
- ostr << derivedVisitor->scoped() << "Ptr v = " << derivedVisitor->scoped() << "Ptr::dynamicCast(" << paramName << ");";
+ ostr << derivedVisitorString << " v = " << derivedVisitorString << "::dynamicCast(" << paramName << ");";
body.push_back(ostr.str());
ostr.str("");
ostr << "if (!v) return;";
@@ -306,14 +325,32 @@ JavaVisitor::generateVisitFunctionBody(const string& paramName,
const ClassDefPtr& derivedVisitor,
const string& operationName)
{
- return StringList();
+ ostringstream ostr;
+ StringList body;
+ string derivedVisitorString = _languageHelper->typeToString(derivedVisitor->declaration(), derivedVisitor->getMetaData());
+
+ if(baseVisitor != derivedVisitor)
+ {
+ ostr << "if (" << paramName << " instanceof " << derivedVisitorString << ")";
+ body.push_back(ostr.str());
+ ostr.str("");
+ ostr << "((" << derivedVisitorString << ") " << paramName << ")";
+ }
+ else
+ {
+ ostr << paramName;
+ }
+ ostr << "." << operationName << "(this);";
+ body.push_back(ostr.str());
+
+ return body;
}
StringList
CSVisitor::generateVisitFunctionBody(const string& paramName,
- const ClassDefPtr& baseVisitor,
- const ClassDefPtr& derivedVisitor,
- const string& operationName)
+ const ClassDefPtr& baseVisitor,
+ const ClassDefPtr& derivedVisitor,
+ const string& operationName)
{
return StringList();
}
@@ -329,23 +366,23 @@ PythonVisitor::generateVisitFunctionBody(const string& paramName,
extern "C"
{
- ICE_DECLSPEC_EXPORT PluginVisitorList*
- create(Language language)
+ ICE_DECLSPEC_EXPORT VisitorList*
+ create(Language language, ParserVisitor::LanguageHelper* helper)
{
- PluginVisitorList* result = new PluginVisitorList();
+ VisitorList* result = new VisitorList();
switch(language)
{
case LanguageCXX:
- result->push_back(new CPPVisitor);
+ result->push_back(new CPPVisitor(helper));
break;
case LanguageCS:
- result->push_back(new CSVisitor);
+ result->push_back(new CSVisitor(helper));
break;
case LanguageJava:
- result->push_back(new JavaVisitor);
+ result->push_back(new JavaVisitor(helper));
break;
case LanguagePython:
- result->push_back(new PythonVisitor);
+ result->push_back(new PythonVisitor(helper));
break;
default:
cerr << "SliceVisitorPattern plugin does not support language " << language << "." << endl;
commit 53ecd412781c6c0149095a4b02679398eeb3931f
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Wed Jan 5 17:57:58 2011 -0600
Don't try to check for the CXX compiler type before learning what it is.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cf65d40..1d3f585 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,11 +11,6 @@ endif()
# for consistency
string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE)
-if(CMAKE_COMPILER_IS_GNUCXX)
- set(CMAKE_CXX_FLAGS_DEBUG "-Werror -Wall -g3"
- CACHE STRING "Flags used by the compiler during debug builds." FORCE)
-endif()
-
if(WIN32 AND ${CMAKE_BUILD_TYPE} STREQUAL profile)
message(FATAL_ERROR "Profile builds not supported")
endif()
@@ -143,6 +138,11 @@ endfunction()
project("Digium Slice Translator Plugins" CXX)
+if(CMAKE_COMPILER_IS_GNUCXX)
+ set(CMAKE_CXX_FLAGS_DEBUG "-Werror -Wall -g3"
+ CACHE STRING "Flags used by the compiler during debug builds." FORCE)
+endif()
+
if(WIN32)
message(STATUS "Setting SLICE_EXPORT definition for Windows plugins")
add_definitions(-DSLICE_EXPORT=__declspec\(dllexport\))
commit d3f29246702159f4ca0dea9950b5701da027ec6a
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Tue Jan 4 07:16:06 2011 -0600
Add framework for additional languages.
Add error handling for unsupported languages.
diff --git a/src/SliceVisitorPattern.cpp b/src/SliceVisitorPattern.cpp
index 96d950a..3f45e8a 100644
--- a/src/SliceVisitorPattern.cpp
+++ b/src/SliceVisitorPattern.cpp
@@ -243,19 +243,35 @@ VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
return false;
}
-class ICE_DECLSPEC_EXPORT CPPVisitorPatternVisitor : public VisitorPatternVisitor
+class ICE_DECLSPEC_EXPORT CPPVisitor : public VisitorPatternVisitor
+{
+protected:
+ StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
+};
+
+class ICE_DECLSPEC_EXPORT CSVisitor : public VisitorPatternVisitor
+{
+protected:
+ StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
+};
+
+class ICE_DECLSPEC_EXPORT JavaVisitor : public VisitorPatternVisitor
+{
+protected:
+ StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
+};
+
+class ICE_DECLSPEC_EXPORT PythonVisitor : public VisitorPatternVisitor
{
protected:
StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
};
-// This function is fairly straightforward; see VisitorPatternVisitor above for a description
-// of its parameters and return value.
StringList
-CPPVisitorPatternVisitor::generateVisitFunctionBody(const string& paramName,
- const ClassDefPtr& baseVisitor,
- const ClassDefPtr& derivedVisitor,
- const string& operationName)
+CPPVisitor::generateVisitFunctionBody(const string& paramName,
+ const ClassDefPtr& baseVisitor,
+ const ClassDefPtr& derivedVisitor,
+ const string& operationName)
{
ostringstream ostr;
StringList body;
@@ -284,13 +300,59 @@ CPPVisitorPatternVisitor::generateVisitFunctionBody(const string& paramName,
return body;
}
+StringList
+JavaVisitor::generateVisitFunctionBody(const string& paramName,
+ const ClassDefPtr& baseVisitor,
+ const ClassDefPtr& derivedVisitor,
+ const string& operationName)
+{
+ return StringList();
+}
+
+StringList
+CSVisitor::generateVisitFunctionBody(const string& paramName,
+ const ClassDefPtr& baseVisitor,
+ const ClassDefPtr& derivedVisitor,
+ const string& operationName)
+{
+ return StringList();
+}
+
+StringList
+PythonVisitor::generateVisitFunctionBody(const string& paramName,
+ const ClassDefPtr& baseVisitor,
+ const ClassDefPtr& derivedVisitor,
+ const string& operationName)
+{
+ return StringList();
+}
+
extern "C"
{
ICE_DECLSPEC_EXPORT PluginVisitorList*
- create(Plugin::Language language)
+ create(Language language)
{
PluginVisitorList* result = new PluginVisitorList();
- result->push_back(new CPPVisitorPatternVisitor);
+ switch(language)
+ {
+ case LanguageCXX:
+ result->push_back(new CPPVisitor);
+ break;
+ case LanguageCS:
+ result->push_back(new CSVisitor);
+ break;
+ case LanguageJava:
+ result->push_back(new JavaVisitor);
+ break;
+ case LanguagePython:
+ result->push_back(new PythonVisitor);
+ break;
+ default:
+ cerr << "SliceVisitorPattern plugin does not support language " << language << "." << endl;
+ delete result;
+ result = 0;
+ break;
+ }
return result;
}
}
commit 4640e586f45e3fe06c33e0972f1bad13db8efb78
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Mon Jan 3 17:46:16 2011 -0600
Remove debug message.
diff --git a/src/SliceVisitorPattern.cpp b/src/SliceVisitorPattern.cpp
index 7eb07c6..96d950a 100644
--- a/src/SliceVisitorPattern.cpp
+++ b/src/SliceVisitorPattern.cpp
@@ -289,7 +289,6 @@ extern "C"
ICE_DECLSPEC_EXPORT PluginVisitorList*
create(Plugin::Language language)
{
- cout << "PluginVisitor being created" << endl;
PluginVisitorList* result = new PluginVisitorList();
result->push_back(new CPPVisitorPatternVisitor);
return result;
commit c28e97bd01ecaa10f06ac9b3353c77262137e1ad
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Mon Jan 3 17:44:58 2011 -0600
Update to use Slice/Plugin header and provide factory function.
Add installation to CMake script.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cab23f5..cf65d40 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -157,8 +157,8 @@ if(WIN32)
endif()
find_ICE(3.4)
-
find_ICE_CXX()
+find_ICE_CXX_library(Ice)
message(STATUS "Include directories ${ICE_CXX_INCLUDE_DIR}")
include_directories("${ICE_CXX_INCLUDE_DIR}")
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f133ff5..facbcf7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1 +1,4 @@
add_library(SliceVisitorPattern SHARED SliceVisitorPattern.cpp)
+
+get_filename_component(library_path ${ICE_CXX_LIB_Ice} PATH)
+install(TARGETS SliceVisitorPattern LIBRARY DESTINATION ${library_path})
diff --git a/src/SliceVisitorPattern.cpp b/src/SliceVisitorPattern.cpp
index 1edc664..7eb07c6 100644
--- a/src/SliceVisitorPattern.cpp
+++ b/src/SliceVisitorPattern.cpp
@@ -1,8 +1,10 @@
#include <Slice/Parser.h>
#include <Slice/Util.h>
+#include <Slice/Plugin.h>
using namespace std;
using namespace Slice;
+using namespace Slice::Plugin;
// This Visitor iterates over the parse tree looking for 'visitor'
// metadata directives; after validation, it uses these directives
@@ -25,7 +27,7 @@ using namespace Slice;
// where FOO is the name of the class to be visited. The operation
// receives the visited class object as a parameter.
-class VisitorPatternVisitor : public ParserVisitor
+class VisitorPatternVisitor : public PluginVisitor
{
public:
virtual bool visitClassDefStart(const ClassDefPtr&);
@@ -241,7 +243,7 @@ VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
return false;
}
-class CPPVisitorPatternVisitor : public VisitorPatternVisitor
+class ICE_DECLSPEC_EXPORT CPPVisitorPatternVisitor : public VisitorPatternVisitor
{
protected:
StringList generateVisitFunctionBody(const std::string&, const ClassDefPtr&, const ClassDefPtr&, const std::string&);
@@ -281,3 +283,15 @@ CPPVisitorPatternVisitor::generateVisitFunctionBody(const string& paramName,
return body;
}
+
+extern "C"
+{
+ ICE_DECLSPEC_EXPORT PluginVisitorList*
+ create(Plugin::Language language)
+ {
+ cout << "PluginVisitor being created" << endl;
+ PluginVisitorList* result = new PluginVisitorList();
+ result->push_back(new CPPVisitorPatternVisitor);
+ return result;
+ }
+}
commit 990fda591a845534e6a655d285dbd08beed2d59c
Author: Kevin P. Fleming <kpfleming at digium.com>
Date: Mon Jan 3 13:35:31 2011 -0600
Import more of the needed code.
diff --git a/src/SliceVisitorPattern.cpp b/src/SliceVisitorPattern.cpp
index 40ff3de..1edc664 100644
--- a/src/SliceVisitorPattern.cpp
+++ b/src/SliceVisitorPattern.cpp
@@ -28,35 +28,35 @@ using namespace Slice;
class VisitorPatternVisitor : public ParserVisitor
{
public:
- virtual bool visitClassDefStart(const ClassDefPtr&);
+ virtual bool visitClassDefStart(const ClassDefPtr&);
protected:
- // This function generates the function body for the 'visit' functions
- // in the visited classes. Its parameters are:
- // 1 - the name assigned to the parameter this function will receive (the visitor object)
- // 2 - the base visitor class (the parameter's type)
- // 3 - the derived visitor class (where the visit<FOO> operation is defined)
- // 4 - the name of the operation that should be called on the visitor
- //
- // The function returns a StringList; each string in the list will be placed into the
- // function body in a language-appropriate manner.
- virtual StringList generateVisitFunctionBody(const string&, const ClassDefPtr&, const ClassDefPtr&, const string&) = 0;
+ // This function generates the function body for the 'visit' functions
+ // in the visited classes. Its parameters are:
+ // 1 - the name assigned to the parameter this function will receive (the visitor object)
+ // 2 - the base visitor class (the parameter's type)
+ // 3 - the derived visitor class (where the visit<FOO> operation is defined)
+ // 4 - the name of the operation that should be called on the visitor
+ //
+ // The function returns a StringList; each string in the list will be placed into the
+ // function body in a language-appropriate manner.
+ virtual StringList generateVisitFunctionBody(const string&, const ClassDefPtr&, const ClassDefPtr&, const string&) = 0;
private:
- // This map contains the list of classes known to be visitors;
- // the key is the fully-scoped named of the class, and the value
- // is a pointer to the class definition.
- map<string, ClassDefPtr> _visitorClasses;
- // This map contains the list of base classes that can be visited;
- // the key is the fully scoped named of the class, and the value
- // is a pair consisting of pointers to the class definitions for
- // the visiting classes. The first element is the base visitor class,
- // which defines the type of the parameter to the 'visit' operation
- // generated in the visited class. The second element is the derived
- // visitor class (which might be the same as the base visitor class),
- // which defines the type the parameter must be cast to in order to
- // invoke the visit<FOO> operation on the visitor as described above.
- map<string, pair<ClassDefPtr, ClassDefPtr> > _visitableBases;
+ // This map contains the list of classes known to be visitors;
+ // the key is the fully-scoped named of the class, and the value
+ // is a pointer to the class definition.
+ map<string, ClassDefPtr> _visitorClasses;
+ // This map contains the list of base classes that can be visited;
+ // the key is the fully scoped named of the class, and the value
+ // is a pair consisting of pointers to the class definitions for
+ // the visiting classes. The first element is the base visitor class,
+ // which defines the type of the parameter to the 'visit' operation
+ // generated in the visited class. The second element is the derived
+ // visitor class (which might be the same as the base visitor class),
+ // which defines the type the parameter must be cast to in order to
+ // invoke the visit<FOO> operation on the visitor as described above.
+ map<string, pair<ClassDefPtr, ClassDefPtr> > _visitableBases;
};
// This function attempts to locate a base of the specified class that has been marked
@@ -68,175 +68,216 @@ findVisitableBase(const map<string, pair<ClassDefPtr, ClassDefPtr> >& visitableB
const ClassDefPtr& p, ClassDefPtr& baseVisitor,
ClassDefPtr& derivedVisitor)
{
- ClassList bases = p->allBases();
- for(ClassList::const_iterator q = bases.begin(); q != bases.end(); q++)
- {
- map<string, pair<ClassDefPtr, ClassDefPtr> >::const_iterator it = visitableBases.find((*q)->scoped());
- if(it != visitableBases.end())
- {
- baseVisitor = it->second.first;
- derivedVisitor = it->second.second;
- return *q;
- }
- }
- return 0;
+ ClassList bases = p->allBases();
+ for(ClassList::const_iterator q = bases.begin(); q != bases.end(); q++)
+ {
+ map<string, pair<ClassDefPtr, ClassDefPtr> >::const_iterator it = visitableBases.find((*q)->scoped());
+ if(it != visitableBases.end())
+ {
+ baseVisitor = it->second.first;
+ derivedVisitor = it->second.second;
+ return *q;
+ }
+ }
+ return 0;
}
bool
VisitorPatternVisitor::visitClassDefStart(const ClassDefPtr& p)
{
- ostringstream ostr;
+ ostringstream ostr;
- // First, search for classes tagged with the 'visitor' or 'visitor:XYZ'
- // metadata directives. If they are found, validate the conditions they
- // are used in and report warnings if the conditions are not appropriate.
- StringList metaData = p->getMetaData();
- for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); q++)
- {
- if(*q == "visitor")
- {
- if(!p->isLocal())
- {
- ostr << "ignoring invalid metadata `visitor`: directive can only be applied "
- << "to local classes but `" << p->name() << "` is not local";
- emitWarning(p->file(), p->line(), ostr.str());
- return false;
- }
- else if(p->isInterface())
- {
- ostr << "ignoring invalid metadata `visitor`: directive can only be applied "
- << "to local classes but `" << p->name() << "` is an interface";
- emitWarning(p->file(), p->line(), ostr.str());
- return false;
- }
- else
- {
- // Remember this class as a visiting class.
- _visitorClasses[p->scoped()] = p;
- return false;
- }
- }
- else if(q->find("visitor:", 0) == 0)
- {
- if(p->isInterface())
- {
- ostr << "ignoring invalid `" << *q << "` metadata: directive can only be applied "
- << "to classes, but `" << p->name() << "` is an interface";
- emitWarning(p->file(), p->line(), ostr.str());
- return false;
- }
- else if(p->isAbstract())
- {
- ostr << "ignoring invalid `" << *q << "` metadata: directive can only be applied "
- << "to concrete classes, but `" << p->name() << "` is abstract";
- emitWarning(p->file(), p->line(), ostr.str());
- return false;
- }
- else
- {
- // Attempt to find the specified visiting class in the list of known
- // visiting classes.
- const string visitor = (*q).substr(8);
- map<string, ClassDefPtr>::const_iterator it = _visitorClasses.find(visitor);
- if(it != _visitorClasses.end())
- {
- // Initially, assume the base visitor class will be the specified class.
- ClassDefPtr baseVisitor = it->second, derivedVisitor;
- // Note that the return value of this function is ignored; because this
- // class has been directly marked with the 'visitor' metadata, we already
- // know it must support a visitor; the function is being called
- // to determine if there is a different base visitor class that must be
- // supported.
- findVisitableBase(_visitableBases, p, baseVisitor, derivedVisitor);
- // We know our derived visitor class is the one specified in the directive.
- derivedVisitor = it->second;
- // Remember this class as a visitable base, so that any classes that extend
- // it will automatically be visitable as well.
- _visitableBases[p->scoped()] = make_pair(baseVisitor, derivedVisitor);
- // There is no need to actually generate operations into the visitor
- // class if it was defined in an include file, since the translator
- // won't actually produce output for the include file.
- if(derivedVisitor->includeLevel() == 0)
- {
- // it is necessary to provide a non-empty body for the operation
- // to keep it from being abstract
- StringList body;
- body.push_back("");
- GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, body);
- gop->createParamDecl("item", p->declaration(), false);
- }
- // There is no need to actually generate operations into the visited
- // class if it was defined in an include file, since the translator
- // won't actually produce output for the include file.
- if(p->includeLevel() == 0)
- {
- GeneratedOperationPtr gop = p->createGeneratedOperation("visit", 0,
- generateVisitFunctionBody("visitor", baseVisitor, derivedVisitor, "visit" + p->name()));
- gop->createParamDecl("visitor", baseVisitor->declaration(), false);
- }
- return false;
- }
- else
- {
- ostr << "ignoring invalid `" << *q << "` metadata: directive specified on "
- << "class `" << p->name() << "` but specified interface '" << visitor << "` was "
- << "not marked with `visitor` metadata directive";
- emitWarning(p->file(), p->line(), ostr.str());
- return false;
- }
- }
- }
- }
+ // First, search for classes tagged with the 'visitor' or 'visitor:XYZ'
+ // metadata directives. If they are found, validate the conditions they
+ // are used in and report warnings if the conditions are not appropriate.
+ StringList metaData = p->getMetaData();
+ for(StringList::const_iterator q = metaData.begin(); q != metaData.end(); q++)
+ {
+ if(*q == "visitor")
+ {
+ if(!p->isLocal())
+ {
+ ostr << "ignoring invalid metadata `visitor`: directive can only be applied "
+ << "to local classes but `" << p->name() << "` is not local";
+ emitWarning(p->file(), p->line(), ostr.str());
+ return false;
+ }
+ else if(p->isInterface())
+ {
+ ostr << "ignoring invalid metadata `visitor`: directive can only be applied "
+ << "to local classes but `" << p->name() << "` is an interface";
+ emitWarning(p->file(), p->line(), ostr.str());
+ return false;
+ }
+ else
+ {
+ // Remember this class as a visiting class.
+ _visitorClasses[p->scoped()] = p;
+ return false;
+ }
+ }
+ else if(q->find("visitor:", 0) == 0)
+ {
+ if(p->isInterface())
+ {
+ ostr << "ignoring invalid `" << *q << "` metadata: directive can only be applied "
+ << "to classes, but `" << p->name() << "` is an interface";
+ emitWarning(p->file(), p->line(), ostr.str());
+ return false;
+ }
+ else if(p->isAbstract())
+ {
+ ostr << "ignoring invalid `" << *q << "` metadata: directive can only be applied "
+ << "to concrete classes, but `" << p->name() << "` is abstract";
+ emitWarning(p->file(), p->line(), ostr.str());
+ return false;
+ }
+ else
+ {
+ // Attempt to find the specified visiting class in the list of known
+ // visiting classes.
+ const string visitor = (*q).substr(8);
+ map<string, ClassDefPtr>::const_iterator it = _visitorClasses.find(visitor);
+ if(it != _visitorClasses.end())
+ {
+ // Initially, assume the base visitor class will be the specified class.
+ ClassDefPtr baseVisitor = it->second, derivedVisitor;
+ // Note that the return value of this function is ignored; because this
+ // class has been directly marked with the 'visitor' metadata, we already
+ // know it must support a visitor; the function is being called
+ // to determine if there is a different base visitor class that must be
+ // supported.
+ findVisitableBase(_visitableBases, p, baseVisitor, derivedVisitor);
+ // We know our derived visitor class is the one specified in the directive.
+ derivedVisitor = it->second;
+ // Remember this class as a visitable base, so that any classes that extend
+ // it will automatically be visitable as well.
+ _visitableBases[p->scoped()] = make_pair(baseVisitor, derivedVisitor);
+ // There is no need to actually generate operations into the visitor
+ // class if it was defined in an include file, since the translator
+ // won't actually produce output for the include file.
+ if(derivedVisitor->includeLevel() == 0)
+ {
+ // it is necessary to provide a non-empty body for the operation
+ // to keep it from being abstract
+ StringList body;
+ body.push_back("");
+ GeneratedOperationPtr gop = derivedVisitor->createGeneratedOperation("visit" + p->name(), 0, body);
+ gop->createParamDecl("item", p->declaration(), false);
+ }
+ // There is no need to actually generate operations into the visited
+ // class if it was defined in an include file, since the translator
+ // won't actually produce output for the include file.
+ if(p->includeLevel() == 0)
+ {
+ GeneratedOperationPtr gop = p->createGeneratedOperation("visit", 0,
+ generateVisitFunctionBody("visitor", baseVisitor, derivedVisitor, "visit" + p->name()));
+ gop->createParamDecl("visitor", baseVisitor->declaration(), false);
+ }
+ return false;
+ }
+ else
+ {
+ ostr << "ignoring invalid `" << *q << "` metadata: directive specified on "
+ << "class `" << p->name() << "` but specified interface '" << visitor << "` was "
+ << "not marked with `visitor` metadata directive";
+ emitWarning(p->file(), p->line(), ostr.str());
+ return false;
+ }
+ }
+ }
+ }
- // Only classes are supported by 'visitor' metadata inheritance.
... 587 lines suppressed ...
--
asterisk-scf/release/slice-plugins.git
More information about the asterisk-scf-commits
mailing list