Skip to content

Commit b1172d3

Browse files
authored
Add files via upload
1 parent 7a46735 commit b1172d3

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed

Common/CommandLineValues.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
export class CommandLineValues {
2+
public File: string;
3+
public Dir:string;
4+
public MaxPathLength:number;
5+
public MaxPathWidth:number;
6+
public NoHash:boolean;
7+
public NumThreads:number;
8+
public MinCodeLength:number;
9+
public MaxCodeLength:number;
10+
public PrettyPrint:boolean;
11+
public MaxChildId:number;
12+
public debugMode:boolean;
13+
public testSetMode:boolean;
14+
public logDir:string
15+
16+
constructor() {
17+
this.setArgsDeafultValues();
18+
var commandLineArgs = this.getCommandLineArgs();
19+
this.updateCommanLineArgs(commandLineArgs);
20+
}
21+
22+
private setArgsDeafultValues() {
23+
this.File = null;
24+
this.Dir = null;
25+
this.MaxPathLength = 100;
26+
this.MaxPathWidth = 10;
27+
this.NoHash = false;
28+
this.NumThreads = 32;
29+
this.MinCodeLength = 1;
30+
this.MaxCodeLength = 10000;
31+
this.PrettyPrint = false;
32+
this.MaxChildId = Number.MAX_SAFE_INTEGER;
33+
this.debugMode = false;
34+
this.testSetMode = false;
35+
this.logDir = "TSE_log/";
36+
}
37+
38+
private getCommandLineArgs() {
39+
var optionDefinitions = [
40+
{ name: 'dir', type: String},
41+
{ name: 'file', type: String },
42+
{ name: 'max_path_length', type: Number },
43+
{ name: 'max_path_width', type: Number },
44+
{ name: 'no_hash', type: Boolean },
45+
{ name: 'num_threads', type: Number },
46+
{ name: 'min_code_len', type: Number },
47+
{ name: 'max_code_len', type: Number },
48+
{ name: 'pretty_print', type: Boolean },
49+
{ name: 'max_child_id', type: Number },
50+
{ name: 'debug', type: Number },
51+
{ name: 'test_set', type: Number },
52+
{ name: 'log_dir', type: String}
53+
];
54+
const commandLineArgs = require('command-line-args');
55+
const options = commandLineArgs(optionDefinitions);
56+
return options;
57+
}
58+
59+
private updateCommanLineArgs(commandLineArgs : any) : void {
60+
if(commandLineArgs.max_path_length){
61+
this.MaxPathLength=commandLineArgs.max_path_length;
62+
}
63+
if(commandLineArgs.max_path_width){
64+
this.MaxPathWidth=commandLineArgs.max_path_width;
65+
}
66+
if(commandLineArgs.file){
67+
this.File=commandLineArgs.file;
68+
}
69+
if(commandLineArgs.dir){
70+
this.Dir=commandLineArgs.dir;
71+
}
72+
if(commandLineArgs.no_hash){
73+
this.NoHash=commandLineArgs.no_hash;
74+
}
75+
if(commandLineArgs.num_threads){
76+
this.NumThreads=commandLineArgs.num_threads;
77+
}
78+
if(commandLineArgs.min_code_len){
79+
this.MinCodeLength=commandLineArgs.min_code_len;
80+
}
81+
if(commandLineArgs.max_code_len){
82+
this.MaxCodeLength=commandLineArgs.max_code_len;
83+
}
84+
if(commandLineArgs.pretty_print){
85+
this.PrettyPrint=commandLineArgs.pretty_print;
86+
}
87+
if(commandLineArgs.max_child_id){
88+
this.MaxChildId=commandLineArgs.max_child_id;
89+
}
90+
if(commandLineArgs.debug) {
91+
this.debugMode=commandLineArgs.debug;
92+
}
93+
if(commandLineArgs.test_set) {
94+
this.testSetMode=commandLineArgs.test_set;
95+
}
96+
if(commandLineArgs.log_dir) {
97+
let log_dir: string = commandLineArgs.log_dir;
98+
if (!commandLineArgs.log_dir.endsWith("/")) log_dir += "/";
99+
this.logDir=log_dir;
100+
}
101+
}
102+
}

Common/Common.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
export class Common{
3+
4+
public static EmptyString: string="";
5+
public static UTF8:string = "utf-8";
6+
public static internalSeparator:string = "|";
7+
public static EvaluateTempDir:string = "EvalTemp";
8+
public static FieldAccessExpr:string = "FieldAccessExpr";
9+
public static ClassOrInterfaceType:string = "ClassOrInterfaceType";
10+
public static MethodDeclaration:string = "MethodDeclaration";
11+
public static NameExpr:string = "NameExpr";
12+
public static MethodCallExpr:string = "MethodCallExpr";
13+
public static DummyNode:string = "DummyNode";
14+
public static BlankWord:string = "BLANK"
15+
public static c_MaxLabelLength:number = 50;
16+
public static methodName:string = "METHOD_NAME";
17+
18+
public static normalizeName(original: string ,defaultString: string): string {
19+
let carefulStripped = original.toLowerCase()
20+
.replace(/\s/g, "") // whitespaces
21+
.replace(/[\"',]/g, "") // quotes, apostrophies, commas
22+
.replace(/\\P{Print}/g, ""); // unicode weird characters
23+
let stripped: string = original.replace(/[^A-Za-z]/g, "");
24+
if (stripped.length == 0) {
25+
if (carefulStripped.length == 0) {
26+
return defaultString;
27+
} else {
28+
return carefulStripped;
29+
}
30+
} else {
31+
return stripped;
32+
}
33+
}
34+
35+
public static splitToSubtokens(str1: string): Array<string> {
36+
let str2: string = str1.trim();
37+
let strArray = str2.split("(?<=[a-z])(?=[A-Z])|_|[0-9]|(?<=[A-Z])(?=[A-Z][a-z])|\\s+");
38+
return strArray.filter(s => s.length > 0).map(s => Common.normalizeName(s, ""))
39+
.filter(s => s.length > 0);
40+
}
41+
}

Common/utilities.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export function hashCode(str: string) : number{
2+
var hash = 0;
3+
for (let i = 0; i < str.length; i++) {
4+
let chr = str.charCodeAt(i);
5+
hash = ((hash << 5) - hash) + chr;
6+
hash |= 0; // Convert to 32bit integer
7+
}
8+
return hash;
9+
};

0 commit comments

Comments
 (0)