Skip to content

Instantly share code, notes, and snippets.

@saki7
Last active September 25, 2017 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saki7/fe994c42c82a756b92e23c7fadd107e0 to your computer and use it in GitHub Desktop.
Save saki7/fe994c42c82a756b92e23c7fadd107e0 to your computer and use it in GitHub Desktop.
Project generator for Eclipse CDT bug #512297
# This is a project generator script for the Eclipse CDT bug 512297.
# For details, see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=512297
# Note: You need Ruby 2.3 or above.
# This script is distributed under public domain.
require 'fileutils'
ROOT_PATH = "cdt-stackoverflow"
LIB_PATH = "#{ROOT_PATH}/sample-library"
PARSER_KILLER_1_APP_PATH = "#{ROOT_PATH}/parser-killer-1-application"
PARSER_KILLER_2_APP_PATH = "#{ROOT_PATH}/parser-killer-2-application"
PARSER_KILLER_3_APP_PATH = "#{ROOT_PATH}/parser-killer-3-application"
AST_BUILDER_KILLER_1_APP_PATH = "#{ROOT_PATH}/ast-builder-killer-1-application"
FileUtils.mkdir_p ROOT_PATH
FileUtils.mkdir_p LIB_PATH
FileUtils.mkdir_p PARSER_KILLER_1_APP_PATH
FileUtils.mkdir_p PARSER_KILLER_2_APP_PATH
FileUtils.mkdir_p PARSER_KILLER_3_APP_PATH
FileUtils.mkdir_p AST_BUILDER_KILLER_1_APP_PATH
File.open("#{LIB_PATH}/any.hpp", 'w') {|f|
f.puts <<~EOS
template<class T>
struct any {};
EOS
}
PARSER_KILLER_1_THRESHOLD = 400
File.open("#{PARSER_KILLER_1_APP_PATH}/main.cpp", 'w') {|f|
f.puts <<~EOS
#include "../sample-library/any.hpp"
EOS
f.print 'typedef '
PARSER_KILLER_1_THRESHOLD.times do
f.print 'any<'
end
f.print 'int'
PARSER_KILLER_1_THRESHOLD.times do
f.print '>'
end
f.puts ' parser_killer_type;'
f.puts <<~EOS
int main()
{
parser_killer_type parser_killer_1;
}
EOS
}
File.open("#{LIB_PATH}/infinite.hpp", 'w') {|f|
f.puts <<~EOS
template<class... Ts>
struct infinite;
template<class Infinite, int N>
struct infinite_generator
{
typedef infinite<typename infinite_generator<Infinite, N-1>::type> type;
};
template<class Infinite>
struct infinite_generator<Infinite, 0>
{
typedef Infinite type;
};
template<class... Ts>
struct infinite
{
typedef infinite<Ts...> self_type;
template<class T>
infinite<self_type, T> operator|(T) const
{
return {};
}
template<int N>
static typename infinite_generator<self_type, N>::type generate()
{
return typename infinite_generator<self_type, N>::type();
}
};
EOS
}
PARSER_KILLER_2_THRESHOLD = 400
File.open("#{PARSER_KILLER_2_APP_PATH}/main.cpp", 'w') {|f|
f.puts <<~EOS
#include "../sample-library/infinite.hpp"
EOS
f.puts <<~EOS
int main()
{
typedef infinite<int> expr;
EOS
f.puts " auto parser_killer_2 = expr::generate<#{PARSER_KILLER_2_THRESHOLD}>();"
f.puts <<~EOS
}
EOS
}
PARSER_KILLER_3_THRESHOLD = 400
File.open("#{PARSER_KILLER_3_APP_PATH}/main.cpp", 'w') {|f|
f.puts <<~EOS
#include "../sample-library/infinite.hpp"
int main()
{
typedef infinite<int> generator;
auto factor_0 = generator();
EOS
(1..PARSER_KILLER_3_THRESHOLD).each do |i|
f.print " auto factor_#{i} = factor_#{i-1} | generator();\n"
end
f.puts <<~EOS
}
EOS
}
AST_BUILDER_KILLER_1_THRESHOLD = 1000
File.open("#{AST_BUILDER_KILLER_1_APP_PATH}/main.cpp", 'w') {|f|
f.puts <<~EOS
#include "../sample-library/infinite.hpp"
EOS
f.puts <<~EOS
int main()
{
typedef infinite<int> expr;
EOS
f.print ' auto ast_builder_killer_1 = expr()'
AST_BUILDER_KILLER_1_THRESHOLD.times do
f.print ' | expr()'
end
f.puts ';'
f.puts <<~EOS
}
EOS
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment