Skip to content

Commit ea442eb

Browse files
committed
Move TRegex into the graal repository
1 parent 1c4ee0c commit ea442eb

File tree

186 files changed

+29446
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+29446
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
2+
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=do not insert

regex/mx.regex/suite.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
suite = {
2+
"mxversion" : "5.149.0",
3+
4+
"name" : "regex",
5+
6+
"imports" : {
7+
"suites": [
8+
{
9+
"name" : "truffle",
10+
"subdir": True,
11+
"urls" : [
12+
{"url" : "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind" : "binary"},
13+
]
14+
},
15+
]
16+
},
17+
18+
"repositories" : {
19+
"lafo-snapshots" : {
20+
"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots",
21+
"licenses" : ["GPLv2-CPE", "UPL", "BSD-new"]
22+
},
23+
},
24+
25+
"defaultLicense" : "GPLv2-CPE",
26+
27+
"javac.lint.overrides" : "none",
28+
29+
"projects" : {
30+
"com.oracle.truffle.regex" : {
31+
"subDir" : "src",
32+
"sourceDirs" : ["src"],
33+
"dependencies" : [
34+
"truffle:TRUFFLE_API",
35+
],
36+
"annotationProcessors" : ["truffle:TRUFFLE_DSL_PROCESSOR"],
37+
"javaCompliance" : "1.8",
38+
"workingSets" : "Truffle,Regex",
39+
},
40+
},
41+
42+
"distributions" : {
43+
"TREGEX" : {
44+
"subDir" : "src",
45+
"dependencies" : ["com.oracle.truffle.regex"],
46+
"distDependencies" : [
47+
"truffle:TRUFFLE_API",
48+
],
49+
},
50+
}
51+
}
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
3+
4+
<!--
5+
This configuration file was written by the eclipse-cs plugin configuration editor
6+
-->
7+
<!--
8+
Checkstyle-Configuration: Checks
9+
Description: none
10+
-->
11+
<module name="Checker">
12+
<property name="severity" value="error"/>
13+
<module name="TreeWalker">
14+
<property name="tabWidth" value="4"/>
15+
<module name="FileContentsHolder"/>
16+
<module name="JavadocStyle">
17+
<property name="checkHtml" value="false"/>
18+
</module>
19+
<module name="LocalFinalVariableName"/>
20+
<module name="LocalVariableName"/>
21+
<module name="MemberName">
22+
<property name="format" value="^(([a-z][a-zA-Z0-9]*$)|(_[A-Z][a-zA-Z0-9]*_[a-z][a-zA-Z0-9]*$))"/>
23+
</module>
24+
<module name="MethodName">
25+
<property name="format" value="^[a-z][a-z_A-Z0-9]*$"/>
26+
</module>
27+
<module name="PackageName"/>
28+
<module name="ParameterName"/>
29+
<module name="TypeName">
30+
<property name="format" value="^[A-Z][_a-zA-Z0-9]*$"/>
31+
</module>
32+
<module name="RedundantImport"/>
33+
<module name="LineLength">
34+
<property name="max" value="250"/>
35+
</module>
36+
<module name="MethodParamPad"/>
37+
<module name="NoWhitespaceAfter">
38+
<property name="tokens" value="ARRAY_INIT,BNOT,DEC,DOT,INC,LNOT,UNARY_MINUS,UNARY_PLUS"/>
39+
</module>
40+
<module name="NoWhitespaceBefore">
41+
<property name="tokens" value="SEMI,DOT,POST_DEC,POST_INC"/>
42+
</module>
43+
<module name="ParenPad"/>
44+
<module name="TypecastParenPad">
45+
<property name="tokens" value="RPAREN,TYPECAST"/>
46+
</module>
47+
<module name="WhitespaceAfter"/>
48+
<module name="WhitespaceAround">
49+
<property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,EQUAL,GE,GT,LAND,LE,LITERAL_ASSERT,LITERAL_CATCH,LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_FOR,LITERAL_IF,LITERAL_RETURN,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_WHILE,LOR,LT,MINUS,MINUS_ASSIGN,MOD,MOD_ASSIGN,NOT_EQUAL,PLUS,PLUS_ASSIGN,QUESTION,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,LITERAL_ASSERT,TYPE_EXTENSION_AND"/>
50+
</module>
51+
<module name="RedundantModifier"/>
52+
<module name="AvoidNestedBlocks">
53+
<property name="allowInSwitchCase" value="true"/>
54+
</module>
55+
<module name="EmptyBlock">
56+
<property name="option" value="text"/>
57+
<property name="tokens" value="LITERAL_DO,LITERAL_ELSE,LITERAL_FINALLY,LITERAL_IF,LITERAL_TRY,LITERAL_WHILE,STATIC_INIT"/>
58+
</module>
59+
<module name="LeftCurly"/>
60+
<module name="NeedBraces"/>
61+
<module name="RightCurly"/>
62+
<module name="EmptyStatement"/>
63+
<module name="HiddenField">
64+
<property name="severity" value="ignore"/>
65+
<property name="ignoreConstructorParameter" value="true"/>
66+
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
67+
</module>
68+
<module name="FinalClass"/>
69+
<module name="HideUtilityClassConstructor">
70+
<property name="severity" value="ignore"/>
71+
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
72+
</module>
73+
<module name="ArrayTypeStyle"/>
74+
<module name="UpperEll"/>
75+
<module name="FallThrough"/>
76+
<module name="FinalLocalVariable">
77+
<property name="severity" value="ignore"/>
78+
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
79+
</module>
80+
<module name="MultipleVariableDeclarations"/>
81+
<module name="StringLiteralEquality">
82+
<property name="severity" value="error"/>
83+
</module>
84+
<module name="SuperFinalize"/>
85+
<module name="UnnecessaryParentheses">
86+
<property name="severity" value="ignore"/>
87+
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
88+
</module>
89+
<module name="Indentation">
90+
<property name="severity" value="ignore"/>
91+
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
92+
</module>
93+
<module name="StaticVariableName">
94+
<property name="format" value="^[A-Za-z][a-zA-Z0-9]*$"/>
95+
</module>
96+
<module name="EmptyForInitializerPad"/>
97+
<module name="EmptyForIteratorPad"/>
98+
<module name="ModifierOrder"/>
99+
<module name="DefaultComesLast"/>
100+
<module name="InnerAssignment">
101+
<property name="severity" value="ignore"/>
102+
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
103+
</module>
104+
<module name="ModifiedControlVariable"/>
105+
<module name="MutableException">
106+
<property name="severity" value="ignore"/>
107+
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
108+
</module>
109+
<module name="ParameterAssignment">
110+
<property name="severity" value="ignore"/>
111+
<metadata name="net.sf.eclipsecs.core.lastEnabledSeverity" value="inherit"/>
112+
</module>
113+
<module name="RegexpSinglelineJava">
114+
<metadata name="net.sf.eclipsecs.core.comment" value="Illegal trailing whitespace(s) at the end of the line."/>
115+
<property name="format" value="\s$"/>
116+
<property name="message" value="Illegal trailing whitespace(s) at the end of the line."/>
117+
<property name="ignoreComments" value="true"/>
118+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Checks for trailing spaces at the end of a line"/>
119+
</module>
120+
<module name="RegexpSinglelineJava">
121+
<metadata name="net.sf.eclipsecs.core.comment" value="illegal space before a comma"/>
122+
<property name="format" value=" ,"/>
123+
<property name="message" value="illegal space before a comma"/>
124+
<property name="ignoreComments" value="true"/>
125+
<metadata name="com.atlassw.tools.eclipse.checkstyle.customMessage" value="Illegal whitespace before a comma."/>
126+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Checks for whitespace before a comma."/>
127+
</module>
128+
<module name="RegexpSinglelineJava">
129+
<property name="format" value="[^\x00-\x7F]"/>
130+
<property name="message" value="Only use ASCII characters."/>
131+
</module>
132+
</module>
133+
<module name="RegexpHeader">
134+
<property name="header" value="/\*\n \* Copyright \(c\) (20[0-9][0-9], )?20[0-9][0-9], Oracle and/or its affiliates. All rights reserved.\n \* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.\n \*\n \* This code is free software; you can redistribute it and/or modify it\n \* under the terms of the GNU General Public License version 2 only, as\n \* published by the Free Software Foundation. Oracle designates this\n \* particular file as subject to the &quot;Classpath&quot; exception as provided\n \* by Oracle in the LICENSE file that accompanied this code.\n \*\n \* This code is distributed in the hope that it will be useful, but WITHOUT\n \* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\n \* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\n \* version 2 for more details \(a copy is included in the LICENSE file that\n \* accompanied this code\).\n \*\n \* You should have received a copy of the GNU General Public License version\n \* 2 along with this work; if not, write to the Free Software Foundation,\n \* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.\n \*\n \* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA\n \* or visit www.oracle.com if you need additional information or have any\n \* questions.\n \*/\n"/>
135+
<property name="fileExtensions" value="java"/>
136+
</module>
137+
<module name="FileTabCharacter">
138+
<property name="severity" value="error"/>
139+
</module>
140+
<module name="NewlineAtEndOfFile">
141+
<property name="lineSeparator" value="lf"/>
142+
</module>
143+
<module name="Translation"/>
144+
<module name="SuppressionCommentFilter">
145+
<property name="offCommentFormat" value="Checkstyle: stop constant name check"/>
146+
<property name="onCommentFormat" value="Checkstyle: resume constant name check"/>
147+
<property name="checkFormat" value="ConstantNameCheck"/>
148+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Allow non-conforming constant names"/>
149+
</module>
150+
<module name="SuppressionCommentFilter">
151+
<property name="offCommentFormat" value="Checkstyle: stop method name check"/>
152+
<property name="onCommentFormat" value="Checkstyle: resume method name check"/>
153+
<property name="checkFormat" value="MethodName"/>
154+
<property name="checkC" value="false"/>
155+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Disable method name checks"/>
156+
</module>
157+
<module name="SuppressionCommentFilter">
158+
<property name="offCommentFormat" value="CheckStyle: stop parameter assignment check"/>
159+
<property name="onCommentFormat" value="CheckStyle: resume parameter assignment check"/>
160+
<property name="checkFormat" value="ParameterAssignment"/>
161+
<property name="checkC" value="false"/>
162+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Disable Parameter Assignment"/>
163+
</module>
164+
<module name="SuppressionCommentFilter">
165+
<property name="offCommentFormat" value="Checkstyle: stop final variable check"/>
166+
<property name="onCommentFormat" value="Checkstyle: resume final variable check"/>
167+
<property name="checkFormat" value="FinalLocalVariable"/>
168+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Disable final variable checks"/>
169+
</module>
170+
<module name="SuppressionCommentFilter">
171+
<property name="offCommentFormat" value="Checkstyle: stop"/>
172+
<property name="onCommentFormat" value="Checkstyle: resume"/>
173+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Disable all checks"/>
174+
</module>
175+
<module name="SuppressionCommentFilter">
176+
<property name="offCommentFormat" value="CheckStyle: stop inner assignment check"/>
177+
<property name="onCommentFormat" value="CheckStyle: resume inner assignment check"/>
178+
<property name="checkFormat" value="InnerAssignment"/>
179+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Disable inner assignment checks"/>
180+
</module>
181+
<module name="SuppressionCommentFilter">
182+
<property name="offCommentFormat" value="Checkstyle: stop field name check"/>
183+
<property name="onCommentFormat" value="Checkstyle: resume field name check"/>
184+
<property name="checkFormat" value="MemberName"/>
185+
<property name="checkC" value="false"/>
186+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Disable field name checks"/>
187+
</module>
188+
<module name="RegexpMultiline">
189+
<metadata name="net.sf.eclipsecs.core.comment" value="illegal Windows line ending"/>
190+
<property name="format" value="\r\n"/>
191+
<property name="message" value="illegal Windows line ending"/>
192+
</module>
193+
<module name="SuppressionCommentFilter">
194+
<property name="offCommentFormat" value="CheckStyle: stop header check"/>
195+
<property name="onCommentFormat" value="CheckStyle: resume header check"/>
196+
<property name="checkFormat" value=".*Header"/>
197+
<metadata name="com.atlassw.tools.eclipse.checkstyle.comment" value="Disable header checks"/>
198+
</module>
199+
<module name="SuppressionCommentFilter">
200+
<property name="offCommentFormat" value="CheckStyle: start generated"/>
201+
<property name="onCommentFormat" value="CheckStyle: stop generated"/>
202+
<property name="checkFormat" value=".*Name|.*LineLength|.*Header"/>
203+
</module>
204+
</module>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* Copyright (c) 2018, 2018, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.truffle.regex;
26+
27+
import com.oracle.truffle.api.interop.TruffleObject;
28+
import com.oracle.truffle.regex.tregex.TRegexOptions;
29+
import com.oracle.truffle.regex.util.LRUCache;
30+
import java.util.Collections;
31+
import java.util.Map;
32+
33+
public class CachingRegexCompiler extends RegexCompiler {
34+
35+
private final RegexCompiler compiler;
36+
37+
public CachingRegexCompiler(TruffleObject compiler) {
38+
this.compiler = ForeignRegexCompiler.importRegexCompiler(compiler);
39+
}
40+
41+
/**
42+
* Trying to parse and compile a regular expression can produce one of three results. This class
43+
* encodes the sum of these three possibilities.
44+
*
45+
* <ul>
46+
* <li>the regular expression is successfully compiled: compiledRegex is not null</li>
47+
* <li>there is a syntax error in the regular expression: syntaxException is not null</li>
48+
* <li>the regular expression is not supported by the engine: unsupportedRegexException is not
49+
* null</li>
50+
* </ul>
51+
*/
52+
private static final class CompilationResult {
53+
54+
private final TruffleObject compiledRegexObject;
55+
private final RegexSyntaxException syntaxException;
56+
private final UnsupportedRegexException unsupportedRegexException;
57+
58+
private CompilationResult(TruffleObject compiledRegexObject) {
59+
this.compiledRegexObject = compiledRegexObject;
60+
this.syntaxException = null;
61+
this.unsupportedRegexException = null;
62+
}
63+
64+
private CompilationResult(RegexSyntaxException syntaxException) {
65+
this.compiledRegexObject = null;
66+
this.syntaxException = syntaxException;
67+
this.unsupportedRegexException = null;
68+
}
69+
70+
private CompilationResult(UnsupportedRegexException unsupportedRegexException) {
71+
this.compiledRegexObject = null;
72+
this.syntaxException = null;
73+
this.unsupportedRegexException = unsupportedRegexException;
74+
}
75+
}
76+
77+
private final Map<RegexSource, CompilationResult> cache = Collections.synchronizedMap(new LRUCache<>(TRegexOptions.RegexMaxCacheSize));
78+
79+
@Override
80+
public TruffleObject compile(RegexSource source) throws RegexSyntaxException {
81+
CompilationResult result = cache.get(source);
82+
if (result == null) {
83+
result = doCompile(source);
84+
cache.put(source, result);
85+
}
86+
if (result.compiledRegexObject != null) {
87+
assert result.syntaxException == null;
88+
assert result.unsupportedRegexException == null;
89+
return result.compiledRegexObject;
90+
} else if (result.syntaxException != null) {
91+
assert result.compiledRegexObject == null;
92+
assert result.unsupportedRegexException == null;
93+
throw result.syntaxException;
94+
} else {
95+
assert result.compiledRegexObject == null;
96+
assert result.syntaxException == null;
97+
assert result.unsupportedRegexException != null;
98+
throw result.unsupportedRegexException;
99+
}
100+
}
101+
102+
private CompilationResult doCompile(RegexSource regexSource) {
103+
try {
104+
TruffleObject regex = compiler.compile(regexSource);
105+
return new CompilationResult(regex);
106+
} catch (RegexSyntaxException e) {
107+
return new CompilationResult(e);
108+
} catch (UnsupportedRegexException e) {
109+
return new CompilationResult(e);
110+
}
111+
}
112+
}

0 commit comments

Comments
 (0)