diff options
author | truebrain <truebrain@openttd.org> | 2011-11-29 23:27:26 +0000 |
---|---|---|
committer | truebrain <truebrain@openttd.org> | 2011-11-29 23:27:26 +0000 |
commit | 4d91f645c15bb3128adf969afcf7f15bd0f14fa0 (patch) | |
tree | 8ccc602deda6aa29bedcd19f697558348e7af3d6 /src/ai | |
parent | 2c877b074ed656a6cf1d4d4e415cce407980add5 (diff) | |
download | openttd-4d91f645c15bb3128adf969afcf7f15bd0f14fa0.tar.xz |
(svn r23370) -Add: support @api tag in API header files, to select which API should receive the defined classes and functions
Diffstat (limited to 'src/ai')
-rw-r--r-- | src/ai/api/squirrel_export.awk | 158 | ||||
-rwxr-xr-x | src/ai/api/squirrel_export.sh | 27 |
2 files changed, 144 insertions, 41 deletions
diff --git a/src/ai/api/squirrel_export.awk b/src/ai/api/squirrel_export.awk index f3896ba5c..dcfd4f893 100644 --- a/src/ai/api/squirrel_export.awk +++ b/src/ai/api/squirrel_export.awk @@ -40,6 +40,39 @@ function dump_class_templates(name) } } +function dump_fileheader() +{ + # Break the Id tag, so SVN doesn't replace it + print "/* $I" "d$ */" + print "" + print "/*" + print " * This file is part of OpenTTD." + print " * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2." + print " * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." + print " * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>." + print " */" + print "" + print "/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */" + print "" + print "#include \"../../script/api/" filename "\"" +} + +function reset_reader() +{ + enum_size = 0 + enum_value_size = 0 + enum_string_to_error_size = 0 + enum_error_to_string_size = 0 + struct_size = 0 + method_size = 0 + static_method_size = 0 + virtual_class = "false" + cls = "" + start_squirrel_define_on_next_line = "false" + cls_level = 0 + cls_in_api = "" +} + BEGIN { enum_size = 0 enum_value_size = 0 @@ -52,26 +85,35 @@ BEGIN { virtual_class = "false" super_cls = "" cls = "" + api_selected = "" + cls_in_api = "" start_squirrel_define_on_next_line = "false" + has_fileheader = "false" cls_level = 0 RS = "\r|\n" } /@file/ { - # Break it, so SVN doesn't replace it - print "/* $I" "d$ */" - print "" - print "/*" - print " * This file is part of OpenTTD." - print " * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2." - print " * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." - print " * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>." - print " */" - print "" - print "/* THIS FILE IS AUTO-GENERATED; PLEASE DO NOT ALTER MANUALLY */" - print "" - gsub("^" tolower(api) "_", "script_", $3) - print "#include \"../../script/api/" $3 "\"" + filename = $3 + gsub("^" tolower(api) "_", "script_", filename) +} + +/^([ ]*)\* @api/ { + # By default, classes are not selected + if (cls_level == 0) api_selected = "false" + + gsub("^([ ]*)", "", $0) + gsub("* @api ", "", $0) + + if ($0 == "none") { + api_selected = "false" + } else if ($0 == "-all") { + api_selected = "false" + } else if (match($0, "-" tolower(api))) { + api_selected = "false" + } else if (match($0, tolower(api))) { + api_selected = "true" + } } # Remove the old squirrel stuff @@ -84,10 +126,16 @@ BEGIN { # We only want to have public functions exported for now /^( *)class/ { if (cls_level == 0) { + if (api_selected == "") { + print "Class '"$2"' has no @api. It won't be published to any API." > "/dev/stderr" + api_selected = "false" + } public = "false" cls_param[0] = "" cls_param[1] = 1 cls_param[2] = "x" + cls_in_api = api_selected + api_selected = "" cls = $2 if (match($4, "public") || match($4, "protected") || match($4, "private")) { super_cls = $5 @@ -95,8 +143,13 @@ BEGIN { super_cls = $4 } } else if (cls_level == 1) { - struct_size++ - structs[struct_size] = cls "::" $2 + if (api_selected == "") api_selected = cls_in_api + + if (api_selected == "true") { + struct_size++ + structs[struct_size] = cls "::" $2 + } + api_selected = "" } cls_level++ next @@ -119,11 +172,6 @@ BEGIN { } { if (doxygen_skip == "true") next } -# Ignore functions that shouldn't be exported to squirrel -/^#ifndef EXPORT_SKIP/ { export_skip = "true"; next; } -/^#endif \/\* EXPORT_SKIP \*\// { export_skip = "false"; next; } -{ if (export_skip == "true") next } - # Ignore the comments /^#/ { next; } /\/\*.*\*\// { comment = "false"; next; } @@ -134,20 +182,42 @@ BEGIN { # We need to make specialized conversions for structs /^( *)struct/ { cls_level++ + + # Check if we want to publish this struct + if (api_selected == "") api_selected = cls_in_api + if (api_selected == "false") { + api_selected = "" + next + } + api_selected = "" + if (public == "false") next if (cls_level != 1) next + struct_size++ structs[struct_size] = cls "::" $2 + next } # We need to make specialized conversions for enums /^( *)enum/ { cls_level++ - if (public == "false") next; + + # Check if we want to publish this enum + if (api_selected == "") api_selected = cls_in_api + if (api_selected == "false") { + api_selected = "" + next + } + api_selected = "" + + if (public == "false") next + in_enum = "true" enum_size++ enums[enum_size] = cls "::" $2 + next } @@ -168,6 +238,16 @@ BEGIN { # Empty/white lines. When we may do the Squirrel export, do that export. /^([ ]*)$/ { if (start_squirrel_define_on_next_line == "false") next + + if (cls_in_api != "true") { + reset_reader() + next + } + if (has_fileheader == "false") { + dump_fileheader() + has_fileheader = "true" + } + spaces = " "; public = "false" namespace_opened = "false" @@ -310,17 +390,9 @@ BEGIN { print " SQ" api_cls ".PostRegister(engine);" print "}" - enum_size = 0 - enum_value_size = 0 - enum_string_to_error_size = 0 - enum_error_to_string_size = 0 - struct_size = 0 - method_size = 0 - static_method_size = 0 - virtual_class = "false" - cls = "" - start_squirrel_define_on_next_line = "false" - cls_level = 0 + reset_reader() + + next } # Skip non-public functions @@ -370,7 +442,13 @@ BEGIN { # Add a method to the list /^.*\(.*\).*$/ { if (cls_level != 1) next - if (match($0, "~")) next + if (match($0, "~")) { + if (api_selected != "") { + print "Destructor for '"cls"' has @api. Tag ignored." > "/dev/stderr" + api_selected = "" + } + next + } is_static = match($0, "static") if (match($0, "virtual")) { @@ -389,6 +467,10 @@ BEGIN { funcname = $2 if ($1 == cls && funcname == "") { + if (api_selected != "") { + print "Constructor for '"cls"' has @api. Tag ignored." > "/dev/stderr" + api_selected = "" + } cls_param[0] = param_s if (param_s == "") next } else if (funcname == "") next @@ -422,6 +504,14 @@ BEGIN { } } + # Check if we want to publish this function + if (api_selected == "") api_selected = cls_in_api + if (api_selected == "false") { + api_selected = "" + next + } + api_selected = "" + if ($1 == cls && funcname == "") { cls_param[1] = len; cls_param[2] = types; diff --git a/src/ai/api/squirrel_export.sh b/src/ai/api/squirrel_export.sh index 4cb66a7e2..891a522d7 100755 --- a/src/ai/api/squirrel_export.sh +++ b/src/ai/api/squirrel_export.sh @@ -26,13 +26,20 @@ apiuc=`echo ${apilc} | tr [a-z] [A-Z]` if [ -z "$1" ]; then for f in `ls ../../script/api/*.hpp`; do - bf=`basename $f | sed s/script/${apilc}/` - case "${bf}" in - # these files should not be changed by this script - "ai_controller.hpp" | "ai_object.hpp" | "ai_types.hpp" | "ai_changelog.hpp" | "ai_info_docs.hpp" ) continue; - esac + bf=`basename ${f} | sed s/script/${apilc}/` + + # ScriptController has custom code, and should not be generated + if [ "`basename ${f}`" = "script_controller.hpp" ]; then continue; fi + ${AWK} -v api=${apiuc} -f squirrel_export.awk ${f} > ${bf}.tmp - if ! [ -f "${bf}.sq" ] || [ -n "`diff -I '$Id' ${bf}.tmp ${bf}.sq 2> /dev/null || echo boo`" ]; then + + if [ "`wc -l ${bf}.tmp | cut -d\ -f1`" = "0" ]; then + if [ -f "${bf}.sq" ]; then + echo "Deleted: ${bf}.sq" + svn del --force ${bf}.sq > /dev/null 2>&1 + fi + rm -f ${bf}.tmp + elif ! [ -f "${bf}.sq" ] || [ -n "`diff -I '$Id' ${bf}.tmp ${bf}.sq 2> /dev/null || echo boo`" ]; then mv ${bf}.tmp ${bf}.sq echo "Updated: ${bf}.sq" svn add ${bf}.sq > /dev/null 2>&1 @@ -44,7 +51,13 @@ if [ -z "$1" ]; then done else ${AWK} -v api=${apiuc} -f squirrel_export.awk $1 > $1.tmp - if ! [ -f "${f}.sq" ] || [ -n "`diff -I '$Id' $1.sq $1.tmp 2> /dev/null || echo boo`" ]; then + if [ `wc -l $1.tmp | cut -d\ -f1` -eq "0" ]; then + if [ -f "$1.sq" ]; then + echo "Deleted: $1.sq" + svn del --force $1.sq > /dev/null 2>&1 + fi + rm -f $1.tmp + elif ! [ -f "${f}.sq" ] || [ -n "`diff -I '$Id' $1.sq $1.tmp 2> /dev/null || echo boo`" ]; then mv $1.tmp $1.sq echo "Updated: $1.sq" svn add $1.sq > /dev/null 2>&1 |