Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 83-dead-rules
  • 87-transition-conflict
  • 90-h_literal-produces-pointer-signedness-warnings
  • ASThexviewer
  • arena-allocator
  • c++
  • cxx
  • flatten-null
  • java-bindings
  • jpeg_parser
  • llvm-backend
  • luajit
  • master
  • mpeg4_parser
  • nitf_parser
  • old-llvm-backend
  • old-valgrind-cleanup
  • php-bindings
  • python-bindings
  • refactor-build
  • regex
  • static-analysis
  • valgrind-cleanup
  • windows-vs2013
  • 1.1.0
  • nightly_20191026
  • nightly_20191027
  • nightly_20191201
  • nightly_20191202
  • nightly_20191203
  • nightly_20191204
  • nightly_20191205
  • nightly_20191206
  • nightly_20191207
  • nightly_20191208
  • nightly_20191209
  • nightly_20191210
  • nightly_20191211
  • nightly_20191212
  • nightly_20191213
  • nightly_20191214
  • nightly_20191215
  • nightly_20191216
  • nightly_20191217
  • nightly_20191218
  • nightly_20191219
  • nightly_20191220
  • nightly_20191221
  • nightly_20191222
  • nightly_20191223
  • nightly_20191224
  • nightly_20191225
  • nightly_20191226
  • nightly_20191227
  • nightly_20191228
  • nightly_20191229
  • nightly_20191230
  • nightly_20191231
  • nightly_20200101
  • nightly_20200102
  • nightly_20200103
  • nightly_20200104
  • nightly_20200105
  • nightly_20200106
  • nightly_20200107
  • nightly_20200108
  • nightly_20200109
  • nightly_20200110
  • nightly_20200111
  • nightly_20200112
  • nightly_20200113
  • nightly_20200114
  • nightly_20200115
  • nightly_20200116
  • nightly_20200117
  • nightly_20200118
  • nightly_20200119
  • nightly_20200120
  • nightly_20200121
  • nightly_20200122
  • nightly_20200123
  • nightly_20200124
  • nightly_20200125
  • nightly_20200126
  • nightly_20200127
  • nightly_20200128
  • nightly_20200129
  • nightly_20200130
  • nightly_20200131
  • nightly_20200201
  • nightly_20200202
  • nightly_20200203
  • nightly_20200204
  • nightly_20200205
  • nightly_20200206
  • nightly_20200207
  • nightly_20200208
  • nightly_20200209
  • nightly_20200210
  • nightly_20200211
  • nightly_20200212
  • nightly_20200213
  • nightly_20200214
  • nightly_20200215
  • nightly_20200216
  • nightly_20200217
  • nightly_20200218
  • nightly_20200219
  • nightly_20200220
  • nightly_20200221
  • nightly_20200222
  • nightly_20200223
  • nightly_20200413
  • nightly_20200414
  • nightly_20200415
  • nightly_20200416
  • nightly_20200417
  • nightly_20200418
  • nightly_20200419
  • nightly_20200420
  • nightly_20200421
  • nightly_20200422
  • nightly_20200423
  • nightly_20200423bis
124 results

Target

Select target project
  • hammer/hammer
  • mlp/hammer
  • xentrac/hammer
  • pesco/hammer
  • denleylam/hammer
  • nobody/hammer
  • letitiali/hammer
  • kia/hammer-sandbox
  • vyrus001/hammer
9 results
Select Git revision
Show changes
Commits on Source (9)
Showing
with 354 additions and 6 deletions
[submodule "src/bindings/haskell"]
path = src/bindings/haskell
url = git://gitorious.org/hhammer/hhammer.git
# from http://www.scons.org/wiki/JavaNativeInterface
import os
import sys
def walkDirs(path):
"""helper function to get a list of all subdirectories"""
def addDirs(pathlist, dirname, names):
"""internal function to pass to os.path.walk"""
for n in names:
f = os.path.join(dirname, n)
if os.path.isdir(f):
pathlist.append(f)
pathlist = [path]
os.path.walk(path, addDirs, pathlist)
return pathlist
def ConfigureJNI(env):
"""Configure the given environment for compiling Java Native Interface
c or c++ language files."""
if not env.get('JAVAC'):
print "The Java compiler must be installed and in the current path."
return 0
# first look for a shell variable called JAVA_HOME
java_base = os.environ.get('JAVA_HOME')
if not java_base:
if sys.platform == 'darwin':
# Apple's OS X has its own special java base directory
java_base = '/System/Library/Frameworks/JavaVM.framework'
else:
# Search for the java compiler
print "JAVA_HOME environment variable is not set. Searching for java... ",
jcdir = os.path.dirname(env.WhereIs('javac'))
if not jcdir:
print "not found."
return 0
# assuming the compiler found is in some directory like
# /usr/jdkX.X/bin/javac, java's home directory is /usr/jdkX.X
java_base = os.path.join(jcdir, "..")
print "found at " + java_base
if sys.platform == 'cygwin':
# Cygwin and Sun Java have different ideas of how path names
# are defined. Use cygpath to convert the windows path to
# a cygwin path. i.e. C:\jdkX.X to /cygdrive/c/jdkX.X
java_base = os.popen("cygpath -up '"+java_base+"'").read().replace( \
'\n', '')
if sys.platform == 'darwin':
# Apple does not use Sun's naming convention
java_headers = [os.path.join(java_base, 'Headers')]
java_libs = [os.path.join(java_base, 'Libraries')]
else:
# windows and linux
java_headers = [os.path.join(java_base, 'include')]
java_libs = [os.path.join(java_base, 'lib')]
# Sun's windows and linux JDKs keep system-specific header
# files in a sub-directory of include
if java_base == '/usr' or java_base == '/usr/local':
# too many possible subdirectories. Just use defaults
java_headers.append(os.path.join(java_headers[0], 'win32'))
java_headers.append(os.path.join(java_headers[0], 'linux'))
java_headers.append(os.path.join(java_headers[0], 'solaris'))
else:
# add all subdirs of 'include'. The system specific headers
# should be in there somewhere
java_headers = walkDirs(java_headers[0])
# add Java's include and lib directory to the environment
env.Append(CPPPATH = java_headers)
env.Append(LIBPATH = java_libs)
# add any special platform-specific compilation or linking flags
if sys.platform == 'darwin':
env.Append(SHLINKFLAGS = '-dynamiclib -framework JavaVM')
env['SHLIBSUFFIX'] = '.jnilib'
elif sys.platform == 'cygwin':
env.Append(CCFLAGS = '-mno-cygwin')
env.Append(SHLINKFLAGS = '-mno-cygwin -Wl,--kill-at')
# Add extra potentially useful environment variables
env['JAVA_HOME'] = java_base
env['JNI_CPPPATH'] = java_headers
env['JNI_LIBPATH'] = java_libs
return 1
......@@ -7,7 +7,7 @@ import sys
vars = Variables(None, ARGUMENTS)
vars.Add(PathVariable('DESTDIR', "Root directory to install in (useful for packaging scripts)", None, PathVariable.PathIsDirCreate))
vars.Add(PathVariable('prefix', "Where to install in the FHS", "/usr/local", PathVariable.PathAccept))
vars.Add(ListVariable('bindings', 'Language bindings to build', 'none', ['dotnet', 'perl', 'php', 'python']))
vars.Add(ListVariable('bindings', 'Language bindings to build', 'none', ['dotnet', 'java', 'perl', 'php', 'python']))
env = Environment(ENV = {'PATH' : os.environ['PATH']},
variables = vars,
......@@ -17,6 +17,12 @@ env = Environment(ENV = {'PATH' : os.environ['PATH']},
if not 'bindings' in env:
env['bindings'] = []
if 'java' in env['bindings']:
from ConfigureJNI import ConfigureJNI
if not ConfigureJNI(env):
print "Java Native Interface is required for Java bindings. Exiting."
Exit(0)
def calcInstallPath(*elements):
path = os.path.abspath(os.path.join(*map(env.subst, elements)))
if 'DESTDIR' in env:
......
% -*- prolog -*-
% Run with:
% $ swipl -q -t halt -g tsgenjava:prolog tsgenjava.pl >output-file
% Note: this needs to be run from the lib/ directory.
% So,
% swipl -q -t halt -g tsgenjava:prolog tsgenjava.pl >../src/bindings/java/test/hammer_tests.java
:- module(tsgenjava,
[gen_ts/2]).
:- expects_dialect(swi).
:- use_module(tsparser).
% TODO: build a Box-like pretty-printer
% ch_range should become chRange
underscore_to_camel([0'_, X|Xs], [Xp|Xsp]) :- !,
code_type(Xp, to_upper(X)),
underscore_to_camel(Xs,Xsp).
underscore_to_camel([X|Xs],[X|Xsp]) :- !,
underscore_to_camel(Xs,Xsp).
underscore_to_camel([],[]) :- !.
format_parser_name(Name, Result) :-
atom_codes(Name, CName),
( member(0'_, CName) ->
underscore_to_camel(CName, Result0);
CName = Result0),
append("Hammer.", Result0, Result), !.
format_test_name(Name, Result) :-
atom_codes(Name, [CInit|CName]),
code_type(RInit, to_upper(CInit)),
append("Test", [RInit|CName], Result), !.
indent(0) --> "", !.
indent(N) -->
{N > 0},
" ",
{Np is N - 1},
indent(Np).
pp_char_guts(0x22) -->
"\\\"", !.
pp_char_guts(0x27) -->
"\\'", !.
pp_char_guts(A) -->
{ A >= 0x20, A < 0x7F } ->
[A];
"\\x",
{ H is A >> 4, L is A /\ 0xF,
code_type(Hc, xdigit(H)),
code_type(Lc, xdigit(L)) },
[Hc,Lc].
pp_hexnum_guts(0) --> !.
pp_hexnum_guts(A) -->
{ L is A /\ 0xF,
H is A >> 4,
code_type(Lc, xdigit(L)) },
pp_hexnum_guts(H),
[Lc], !.
pp_string_guts([]) --> !.
pp_string_guts([X|Xs]) -->
pp_char_guts(X),
pp_string_guts(Xs), !.
pp_parser_args([]) --> !.
pp_parser_args([X|Rest]) -->
pp_parser(X),
pp_parser_args_rest(Rest).
pp_parser_args_rest([]) --> !.
pp_parser_args_rest([X|Xs]) -->
", ",
pp_parser(X),
pp_parser_args_rest(Xs).
pp_parser(parser(Name, Args)) -->
!,
{format_parser_name(Name,Fname)},
Fname,
"(",
pp_parser_args(Args),
")".
pp_parser(string(Str)) --> !,
"\"",
pp_string_guts(Str),
"\"", !.
pp_parser(num(0)) --> "0", !.
pp_parser(num(Num)) --> !,
( {Num < 0} ->
"-0x", {RNum is -Num}; "0x", {RNum = Num} ),
pp_hexnum_guts(RNum).
pp_parser(char(C)) --> !,
"'", pp_char_guts(C), "'", !.
pp_parser(ref(Name)) -->
{atom_codes(Name,CName)},
"sp_", CName, !.
pp_parser(A) -->
{ writef("WTF is a %w?\n", [A]),
!, fail
}.
pp_test_elem(decl, parser(_)) --> !.
pp_test_elem(init, parser(_)) --> !.
pp_test_elem(exec, parser(P)) -->
!, indent(2),
"parser = ",
pp_parser(P),
";\n".
pp_test_elem(decl, subparser(Name,_)) -->
!, indent(2),
"IndirectParser ", pp_parser(ref(Name)),
" = Hammer.Indirect();\n".
pp_test_elem(init, subparser(Name, Parser)) -->
!, indent(2),
pp_parser(ref(Name)), ".Bind(",
pp_parser(Parser),
");\n".
pp_test_elem(exec, subparser(_,_)) --> !.
pp_test_elem(decl, test(_,_)) --> !.
pp_test_elem(init, test(_,_)) --> !.
pp_test_elem(decl, testFail(_)) --> !.
pp_test_elem(init, testFail(_)) --> !.
pp_test_elem(exec, test(Str, Result)) -->
!, indent(2),
"Assert.assertEquals(parser.parse(", pp_parser(string(Str)),
"), ",
pp_parse_result(Result),
");\n".
pp_test_elem(exec, testFail(Str)) -->
!, indent(2),
"Assert.assertNull(parser.parse(", pp_parser(string(Str)),
"));\n".
% pp_test_elem(_, _) --> !.
pp_result_seq([]) --> !.
pp_result_seq([X|Xs]) --> !,
pp_parse_result(X),
pp_result_seq_r(Xs).
pp_result_seq_r([]) --> !.
pp_result_seq_r([X|Xs]) --> !,
", ",
pp_parse_result(X),
pp_result_seq_r(Xs).
pp_byte_seq([]) --> !.
pp_byte_seq([X|Xs]) --> !,
pp_parser(num(X)),
pp_byte_seq_r(Xs).
pp_byte_seq_r([]) --> !.
pp_byte_seq_r([X|Xs]) --> !,
", ",
pp_parser(num(X)),
pp_byte_seq_r(Xs).
pp_parse_result(char(C)) --> !,
"(byte)",
pp_parser(char(C)).
pp_parse_result(seq(Args)) --> !,
"new object[]{ ", pp_result_seq(Args), "}".
pp_parse_result(none) --> !,
"null".
pp_parse_result(uint(V)) --> !,
"(System.UInt64)", pp_parser(num(V)).
pp_parse_result(sint(V)) --> !,
"(System.Int64)(", pp_parser(num(V)), ")".
pp_parse_result(string(A)) --> !,
"new byte[]{ ", pp_byte_seq(A), "}".
%pp_parse_result(A) -->
% "\x1b[1;31m",
% {with_output_to(codes(C), write(A))},
% C,
% "\x1b[0m".
pp_test_elems(_, []) --> !.
pp_test_elems(Phase, [X|Xs]) -->
!,
pp_test_elem(Phase,X),
pp_test_elems(Phase,Xs).
pp_test_case(testcase(Name, Elems)) -->
!,
indent(1), "@Test\n",
{ format_test_name(Name, TName) },
indent(1), "public void ", TName, "() {\n",
indent(2), "Parser parser;\n",
pp_test_elems(decl, Elems),
pp_test_elems(init, Elems),
pp_test_elems(exec, Elems),
indent(1), "}\n".
pp_test_cases([]) --> !.
pp_test_cases([A|As]) -->
pp_test_case(A),
pp_test_cases(As).
pp_test_suite(Suite) -->
"package com.upstandinghackers.hammer; \n\n",
"import org.testng.annotations.*;\n\n",
"public class HammerTest {\n",
pp_test_cases(Suite),
"}\n".
gen_ts(Foo,Str) :-
phrase(pp_test_suite(Foo),Str).
prolog :-
read_tc(A),
gen_ts(A, Res),
writef("%s", [Res]).
File moved
haskell @ 332e242d
Subproject commit 332e242d6314d1a5b8aee7bde47dd4c080f9b4e6
File moved
File moved
File moved
# -*- python -*-
import os, sys
Import('env libhammer_shared testruns targets')
javaenv = env.Clone()
javaenv['ENV']['LD_LIBRARY_PATH'] = os.path.dirname(str(libhammer_shared[0]))
def PrependDir(dir, filelist):
return [os.path.join(dir,x) for x in filelist]
csources = [
"com_upstandinghackers_hammer_Hammer.c",
"com_upstandinghackers_hammer_ParsedToken.c",
"com_upstandinghackers_hammer_Parser.c",
"com_upstandinghackers_hammer_ParseResult.c"
]
classes = javaenv.Java(target = 'classes', source = '#src/bindings/java/jsrc')
jni_headers = javaenv.JavaH(target = 'csrc', source = classes)
native_src = PrependDir('csrc', csources)
libhammer_java = javaenv.SharedLibrary('libjhammer', native_src, LIBS=['hammer'], LIBPATH='../../')
hammer_jar = javaenv.Jar('hammer.jar', 'classes')
Default(libhammer_java, hammer_jar)
javatestenv = javaenv.Clone()
javatestenv['ENV']['LD_LIBRARY_PATH'] = os.path.dirname(str(libhammer_shared[0]))
#ifndef JHAMMER_H
#define JHAMMER_H
#include <jni.h>
#include "internal.h"
#include "../../../internal.h"
#include <assert.h>
// Unsafe (non-asserting) helpers
......
......@@ -43,10 +43,10 @@ public class Hammer
public static native Parser int32();
public static native Parser int16();
public static native Parser int8();
public static native Parser uInt64();
public static native Parser uInt32();
public static native Parser uInt16();
public static native Parser uInt8();
public static native Parser uint64();
public static native Parser uint32();
public static native Parser uint16();
public static native Parser uint8();
public static native Parser whitespace(Parser p);
public static native Parser left(Parser p, Parser q);
public static native Parser right(Parser p, Parser q);
......
......@@ -5,6 +5,12 @@ public class Parser
public native void bindIndirect(Parser inner);
public native void free();
public long getInner() {return this.inner;}
public ParseResult parse(String input) {
return Hammer.parse(this, input.getBytes(), input.length());
}
public ParseResult parse(byte[] input, int length) {
return Hammer.parse(this, input, length);
}
private long inner;
Parser(long inner) {this.inner=inner;}
......