-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFAMIX.js
More file actions
134 lines (114 loc) · 3.35 KB
/
FAMIX.js
File metadata and controls
134 lines (114 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// FAMIX.js
var Generator = function Generator(){
var i = 0;
this.generateID = function(){
return ++i
}
}
var g = new Generator();
var FAMIX = function FAMIX(){
var tab = '\t';
this.id = g.generateID();
// Kind of and abstract method
this.famixPrint = function famixPrint(str, spacing){
return "Not implemented yet";
}
this.toString = function(spacing){
var str = "";
this.makeSpacing = function makeSpacing(str,s){
for(var i = 0; i<s; i++){
str += tab;
}
return str;
}
str = this.makeSpacing(str, spacing);
str += '(FAMIX.' + this.type + ' (id: ' + this.id + ')\n';
str = this.makeSpacing(str, spacing);
str = this.famixPrint(str,spacing);
return str;
}
}
var FAMIX_FUNCTION = function FAMIX_FUNCTION(name){
var tab = '\t';
this.id = g.generateID();
this.type = "Function";
this.name = name;
this.LOC = 1;
this.statements = 1;
this.static_scope_functions = [];
this.static_scope_variables = [];
this.params = [];
this.use_strict = false;
this.use_strict_static_problems = [];
this.famixPrint = function famixPrint(str, spacing){
str += tab + '(name \'' + this.name + '\')\n';
/*makeSpacing(spacing);
str += tab + '(cyclomaticComplexity -1)\n';
makeSpacing(spacing);
str += tab + '(numberOfComments 0)\n';
makeSpacing(spacing);
str += tab + '(numberOfConditionals -1)\n';*/
if(typeof this.context != 'undefined'){
str = this.makeSpacing(str, spacing);
str += tab + '(parentScope (ref: ' + this.context.id + '))\n'
}
str = this.makeSpacing(str, spacing);
if(this.use_strict_static_problems.length != 0){
str += tab + '(staticUseStrictEnabled false)\n';
} else {
str += tab + '(staticUseStrictEnabled true)\n';
}
str = this.makeSpacing(str, spacing);
str += tab + '(numberOfLinesOfCode ' + this.LOC + ')\n';
str = this.makeSpacing(str, spacing);
str += tab + '(numberOfStatements ' + this.statements + '))\n';
/*makeSpacing(spacing);
str += tab + '(numberOfParameters -1))\n';*/
return str;
};
}
var FAMIX_INVOCATION = function FAMIX_INVOCATION(){
var tab = '\t';
this.id = g.generateID();
this.type = "Invocation";
this.sender = null;
this.signature = "";
this.candidates = [];
this.famixPrint = function famixPrint(str, spacing){
// console.log(this.sender)
str += tab + '(sender (ref: ' + this.sender.id + '))\n';
str = this.makeSpacing(str, spacing);
str += tab + '(candidates';
for (var c_index in this.candidates){
var candidate = this.candidates[c_index];
str += ' (ref: ' + candidate.id + ')';
}
str += ')\n';
if(this.receiver != null){
// console.log(this.receiver);
str = this.makeSpacing(str, spacing);
str += tab + '(receiver (ref: ' + this.receiver.id + '))\n';
if( typeof this.receiver.id == 'undefined'){
console.log(this.receiver);
}
}
str = this.makeSpacing(str, spacing);
str += tab + '(signature \'' + this.signature + '\'))\n';
return str;
};
}
var FAMIX_GLOBAL_VAR = function FAMIX_GLOBAL_VAR(name){
var tab = '\t';
this.id = g.generateID();
this.name = name;
this.type = "GlobalVariable";
this.famixPrint = function famixPrint(str, spacing){
str += tab + '(name \'' + this.name + '\'))\n';
return str;
}
}
FAMIX_FUNCTION.prototype = new FAMIX();
FAMIX_INVOCATION.prototype = new FAMIX();
FAMIX_GLOBAL_VAR.prototype = new FAMIX();
// a window context is assumed
var famix_window = new FAMIX_FUNCTION("window");