-
Notifications
You must be signed in to change notification settings - Fork 1
/
grid_script.js
executable file
·15087 lines (11290 loc) · 478 KB
/
grid_script.js
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (c) 2014, Intel Corporation
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Purpose: Main script that implements user interface
// Author : Ruchira Sasanka
// Date : Nov 1, 2013
/****************************** Explainations ******************************/
// Titles vs. Indices:
//-------------------
// - Titles are non-editable after configuration. Indices are editable and
// customizable for each usage of the grid. Hence, indices can be different
// for a given step (we need to clone indices but not titles)
// - As per above, we need to have both indices AND titles displayed for
// each dimension.
// - Any dimension can have either titles OR indices displayed.
// ReturnValue convention:
//-----------------------
// If the user returns something explicitly with the return statement,
// that value is returned (and implicityly written to the ReturnValue).
// If the user has a return without any argument, the ReturnValue will
// be returned by default.
/*************************** Global Constants ****************************/
// These are the HTML IDs given to various structures (tables) drawn
//
var AllHtmlGridIds = ['outMenu', 'src1Menu', 'src2Menu', 'src3Menu',
'src4Menu', 'src5Menu', 'src6Menu', 'src7Menu',
'src8Menu', 'src9Menu', 'src10Menu'
];
// Data types supported:
//
// NOTE: These types MUST match the following DataTypes enumeration
//
// NOTE: UniqInd (unique index) type facilitates easy parallelization. It
// means a given row (or column) with that data type has unique
// integer values (keys)
//
// NOTE: TODO: 'func' data type is NOT implemented yet.
// It would allow to specify methods of 'objects'. This
// allows an array of functions (similar to array of function pointers),
// which is useful for implementing event handlers -- e.g., vectored
// interrupt/exception handlers. If 'func' names are not constant, this
// would allow late binding.
//
var TypesArr = ['integer', 'real', 'string', 'boolean', 'char', 'real_sp',
'uniqInd', 'func'
];
//
var DataTypes = {
Integer: 0, // integers
Real: 1, // double precision real numbers by default
String: 2, // character strings
Bool: 3, // boolean
Char: 4, // a single character
Real4: 5, // single precision real numbers
UniqInd: 6, // unique index -- integer type w/ no duplicate values
Func: 7
};
// The following are the keywords (resevered words) of the language
//
var Keywords =
['foreach', 'forever', 'for', 'end',
'let', 'break', 'return', 'continue',
'if', 'else',
'row', 'col', 'ind2', 'ind3', 'ind4', 'ind5'
];
// HTML ID given to the output grid
//
var OutHtmlId = AllHtmlGridIds[0];
// Actual Size Selction drawn at this HTML ID
//
var ActSzSelectHtmlId = AllHtmlGridIds[1];
// Grids are drawn in this HTML ID for 'preview', while they are selected
//
var PreviewHtmlGridId = 'previewDiv';
var INVID = -500; // invalid ID. Must be smaller than -1.
var MININT = -10000; // minimum integer value (for init)
var ROOTPOS = -1; // special id when child is the root expression
// The following MUST be zero. They are used just to make code more readable.
//
var FuncHeaderStepId = 0; // Step ID of Function Header (in a function)
var TemplateFuncId = 0; // Func ID of a template (in module)
/***************************** Default Values ******************************/
// Default show cols/rows. Same are used for default act cols/rows
//
var DefShowCols = 7;
var DefShowRows = 7;
//
// Number of tabs in a dimension by default.
//
var DefNumTabsInDim = 5;
//
var DefDimTitleRoot = "Tab";
var DefDimIndRoot = "dim";
//
// Grid names (captions) given by default to out/copy/return/... grids
//
var DefOutGridName = "Out";
var DefCopyGridName = "Copy";
var DefRetValName = "ReturnValue";
//
// If you change name 'StartUpGrid', you must change the same variable name
// in calcData()
//
var DefStartupGridName = "StartUpGrid"; // Actual startup grid name
var DefGlobalScopeName = "Global";
var DefStartModName = "Module1";
var DefStartupArgsName = "StartUpArgs"; // startup arg name (param)
var DefMainFuncName = "Main";
var DefMainFuncInd = 2;
var DefStepTitle = "Title of Step";
var DefHeaderTitle = "Function Header";
var DefProgName = "prog1.grd";
var DefEndName = "end";
var DefStartNameExt = "startLoc"; //MPI:
var DefEndNameExt = "endLoc"; //MPI:
var DefDeletedName = "DELETED";
var DefNeedUpdateName = "UPDATE";
//
var DefFuncName = "func";
var DefRowIndName = "row";
var DefColIndName = "col";
var DefDimIndNameRoot = "ind";
var DefTitleRoots = ['RowTitle', 'ColTitle'];
// Whether to check the validity of 'output' grid.
// Make this 'true' for actual usage cases
//
var CheckDefOutGridName = false;
// Define the ids for row/col dimensions. These are constants.
// Some algorithms assume Row to the 0th dimension. If these values are
// changed, thorough validation must be done.
//
var RowDimId = 0;
var ColDimId = 1;
// Colors of 2D panes (tabs). These colors are repeated for 'higher' tabs.
//
var TabColors = ["fafafa", "f2f2f2", "dcdcdc", "c3c3c3"];
// Function IDs of functions present by default in a module
//
var FuncID = {
Template: 0,
Global: 1,
Main: 2
};
// Code box Id. We also use this as code box TYPE.
//
var CodeBoxId = {
INVALID: -1,
Index: 0,
BoxStart:1, /* Point where code boxes start */
Range: 1,
Mask: 2,
Formula: 3, /* This is the 1st formula */
};
// To indicate which stage we are in while building a step
//
var StageInStep = {
New: 0,
ConfigStarted: 1, // started configuring new grid
ConfigDone: 2, // finished configuring output (new/exist) grid
SrcSelectStarted: 3, // Started adding sources
GridSelectDone: 4, // Finished adding sources
AllDone: 4, // Same as last valid stage
};
// To indicate the state of an item that is deleted by the user, etc.
//
var DeletedState = {
None: 0,
Deleted: 1, // expr is deleted
NeedUpdate: 2, // expr needs updating
PlaceHolder: 3 // place holder (e.g., a func arg)
};
// File acations enumeration to load/store files
//
var FileActions = {
Read: 0,
Write: 1,
};
// Show data enumeration to capture show data state
//
var ShowDataState = {
None: 0, // not showing data
DataOnly: 1, // Only data is showing
DataAndColor: 2, // Data and color
DataImage: 3, // Data shown as an image
};
// Type (location) of the comment
//
var CommentType = {
//
StepTitle:1, // comment in step title
StepBox:2, // comments in boxes in step
Grid:3, // comment for a grid
// There can be comments in row/col/... titles. DimTitle defines the
// comment type for th *0th* dimension. So, the comment type for 1st
// dimension would be in "DimTitle+1", etc.
//
DimTitle: 10
};
// Enumeration of options in the main menu
//
var MMenu = {
Open: 1,
Save: 2,
SaveAs: 3,
ShowData: 4,
Colorize: 5,
DataImage: 6,
HideData: 7,
ShowCode: 8,
AddModule: 9,
UnusedGrids: 10,
//
// TODO: Delete the following --------------------
//
ShowFortranCode: 20, // Show FORTRAN generated code
ShowFortranCodeParallel: 21, // Show FORTRAN parallel generated code
SaveFortranCode: 22, // Save FORTRAN generated code
SaveFortranCodeParallel: 23, // Save FORTRAN parallel generated code
AnalyzeParallelism: 24, // Analyze parallelism
RunOnCloud0: 25, // Auto-gen serial version and compile
RunOnCloud1: 26, // Auto-gen parallel version and compile
Autotune: 27, // Produce auto-tune script and code implementations
ShowCcode: 28, //Show C generated code
SaveCcode: 29, //Save C generated code
SaveOCLcode: 30, //OCL: Save OpenCL generated code
SaveMPICcode: 31, //MPI: Save MPI (C) code
SaveCcodeParallel: 32 // Save C parallel generated code
};
// Enumeration of options for the grid-config Context Menu
//
var GCMenu = {
//
ShowSizes:1,
Delete:2,
Rename:3,
ShowAllIndices:4, // ?? show indices for all dimensions
Copy:5, // ?? do we allow copy/paste
Paste:6,
}
// Enumeration for types of expressions
//
var ExprType = {
None: 0, // invalid
Grid: 1, // An entire grid (grid name)
GridCell: 2, // Cell in a grid
GridRef:3, // Grid name as a reference (e.g., func arg, global grid)
FuncCall: 4, // function call
Operator: 5, // plus, minus, equal, etc
Index: 6, // an index var as row, col
Title: 7, // a col/row/... title
Number: 8, // number
Range: 9, // an index range like row=(1:end)
String: 10, // a string constant
Literal:11, // predefined (literal) name like start, end, let val, ...
Concat:12, // just a concatenation of expression
ConcatEdit:13, // a concat type while being edited (spaces enabled)
//
ExprStmt: 20, // an Eexpression Statement (as in C) -- e.g.., assignment
//
If:21, // If statement
Else:22, // Else statement
ElseIf:23, // Else if statement
BreakIf:24, // break if
//
Foreach:30, // foreach loop
Forever:31, // forever loop
//
Return:40, // Return expression
Break:41, // Break
Continue:43, // Continue
//
Let:42, // let *definition* for literal substitution
LetName:43, // KK: let *use* (just the let name)
//
LibConst:50, // Constant from a library (e.g., PI)
LibFuncCall:51, // function call from a library
ConstGridRef:52,// constant grid reference (for libraries)
END:60
};
// Types of syntax errors
//
var SynErr = {
None: 0,
MisplacedOp: 1, // misplaced operator
TwoIdents: 2, // two identifies next to each other
TwoOps:3, // two operators next to each other
GridRefMixed:4, // grid reference misplaced
OpAtEnd:5, // operator at the end
};
// Fileds of a range -- used to define a range. They must be in the
// same order (starting at 0) as we expect them to appear -- e.g.,
// row(start:end:step)
//
var RangeFields = {
GridName:0,
Start:1,
End:2,
Step:3
};
// Enumeration for tips for user based on the context
//
var TipId = {
DimInsert: 0,
IndexEdit: 1,
TitleClick: 2,
EditTitles: 3,
NoPeriod: 4,
RootEdit: 5,
SelectGrids: 6,
GridRefClick:7,
NoScalarGrid:8,
SelectKeyword:9,
ScalarGridRefClick:10,
CellIndReplace:11,
ReConfigSizes:12,
AvoidBreak:13,
AvoidReturn:14,
End:15
}
var TipArr = [
// 0
'First click on an index name in Index Range OR an index cell in a grid',
// 1
'Click on Index Name (below the grid) or operator/number to edit',
// 2
'To edit a title, select Configure. To insert a title name into a field ' +
'in Index Range, first select it',
// 3
'To edit the grid name or a title, click on it. ' +
'Use the drop down list to change data type ' +
'of table/rows/columns/etc ',
// 4
'Decimal numbers not accepted for index expressions',
// 5
'Click on a keyword button to replace a keyword. To delete an entire ' +
'mask, press "Delete Mask" button',
// 6
'Please complete grid selection first',
// 7
'A Grid Name can be inserted only into as a function argument or ' +
'a range dimension',
// 8
'No scalar (integer) grids exist yet. You can pick a value only from ' +
'a scalar (integer) grid',
// 9
'Please select a keyword first to replace it',
// 10
'Cannot click on a scalar grid name. Click on the scalar grid cell instead',
// 11
'Directly editing array expression disables cell highlighting. Consider ' +
' editing grid indices instead',
// 12
'Edit sizes of the grid.',
// 13
'Please avoid using break when possible. To improve auto-parallelization' +
', instead, consider using an if-else condition.',
// 14
'Please avoid using return statement to return from the middle of a loop.'+
' Instead, assign to ReturnValue (and use if-else condition if necessary)'
//
];
/*************************** Global Variables ****************************/
var CurHtmlGridId; // HTML Grid name currently operating on (w/ event handlers)
var NewGridObj; // When a *new* grid is created, we keep a reference
// to it here while it is configured (w/ event handlers)
// used only upto a *new* grid is configured
var CommentObj; // comments are edited in this object
// References to current module, function, step that the user is working on.
// These serves as short cut references
//
var CurProgObj; // current program object
var CurModObj; // current module object
var CurFuncObj; // current function object
var CurStepObj; // Current step object
var CurFuncSavId; // while saving, current function id processed
var CurIndObj; // while reconfiguring a grid, to store index obj
// These variables are used only during saving
//
var SavModObj;
var SavFuncObj;
// These variables are used while generating code, to provide information
// about the location of errors
//
var SynErrLoc = null;
// Temporary array used to store valid existing grids that the user
// can select from. This array does not need to be saved.
//
var ExistingGridList;
// Json string for the entire program (to be saved)
//
var ProgJsonStr = "";
// TEMPORARY: This is a temporary solution for demo purposes only
// Program file names. The very first one is a dummy one -- it will be
// displayed but will not be accepted as a file name
//
var ProgFileNames = ["Select", DefProgName, 'code1.txt', 'ex1.grd', 'ex2.grd',
'filter.grd', 'filter2.grd', 'tmp.txt'
];
// File name of the program loaded
//
var ProgFileName;
// Timer to detect double clicks
//
var Timer = null;
/* ********************* SECTION A: Main Objects *************************** */
// ---------------------------------------------------------------------------
// Entire program - to be saved and restored
// ---------------------------------------------------------------------------
function ProgObj(fname) {
// All library modules.
//
this.libModules = new Array();
// All user defined modules in the current program
//
this.allModules = new Array();
// Current module the user is working on
//
this.curModNum = 0;
// File name of the current program
//
this.fileName = fname;
// Whether we are displaying data in grids for the entire program.
// We have this var at the ProgObj level, so that user can see all
// *global* scope data in all *modules* -- this is required for
// 'object orientation' support.
//
this.showData = ShowDataState.None;
}
// ---------------------------------------------------------------------------
// Object to represent an entire moudule
// Current thinking:
// A module is a *stand alone*, a separately compilable unit. It can be made
// into a library module as well, which can be linked with many programs.
// Hence a module can be saved on to disk as a separate unit without being
// part of a larger program. Therefore, if a module refers to grids/funcs of
// other modules, such references must be through copies (or names) -- e.g.,
// a template grid from another module is entirely copied. Similarly, a
// module level variable (grid) cannot be directly referenced by another
// module (but that grid can be an arg to function of another module).
//
// ---------------------------------------------------------------------------
function ModuleObj(myname, skipInit) {
this.name = myname;
this.allFuncs = new Array(); // list of all function is this module
this.curFuncNum = 0; // function number user is working on
// funtions start from this ID -- before this ID, we have global scope
// grids. This is a constant.
//
this.FuncStartID = 2; // Functions start after global scope
this.GlobalScopeID = 1; // global scope just before funcs start
// It is important to create this 'global' seq# at the module level
// because there are function args, module level variables, etc, we
// have to create expressions for. However, we don't have this at the
// ProgramObj level in order to facilitate module portability.
//
this.nextExprSeq = 1; // Seq # given to next ExprObj created
// --------------- initialization --------------------------------
if (!skipInit) {
// Must be done afer initializing this.nextExprSeq
//
this.templateFunc = new FuncObj(); // grid/func templates
this.globalFunc = new FuncObj(); // global (static) scope
}
// If this module is a library, the implementation of the library
// is stored in this variable. This need not be saved. This should be
// initialized when each library is loaded -- which should happen every
// time a prog is loaded
//
this.libObj = null;
}
// --------------------------------------------------------------------------
// Object to represent a function (and function scope)
// --------------------------------------------------------------------------
function FuncObj(skipHeader) {
// NOTE: These are all grids local to a function. All grids created
// within that function has 'function scope'. There is no separate
// 'step scope' to limit grids to a step. At the module level,
// model the module level as a dummy 'global()' function, which
// can cotain grids on its own (plus formula). When a module
// refer to a library, by default, only the grids within this
// global() are visible to the outside.
// NOTE: The incoming args (grids) are added to this array as well.
//
this.allGrids = new Array(); // array that stores all gridObjs in a func
this.allSteps = new Array(); // all step objects in the currrent method
// Does this function represent the global scope. A module level has
// one global level scope (which is modelled as a function because it
// can contain both grids and steps -- e.g., to init global grids)
// TODO: Decide whether this global scope is static or extern
// Currently, we treat it as 'static' to avoid having unintended
// interactions through global variables.
//
this.isGlobal = false;
// Does this function represent the template scope - which is the
// declaration scope for all grids/functions. This scope is especially
// useful for libraries
//
this.isTemplateScope = false;
// Is this function callable (visible) from *other* modules
//
this.isExtern = false;
// The function call expr that respresents this function.
// NOTE: To check arguments to a function, we must use the function
// header Step.
//
// NOTE: The following must be assigned by the caller to create a
// reference.
//
this.funcCallExpr = null;
//
// Return value of the function. This should be of type grid (even when
// the return value is a scalar, it is a scalar grid)
//
this.retExpr = null;
this.curStepNum = 0; // step # the user is working on
// Args are added for selection (select existing grid) and then removed
// later when drop down list is removed.
// -1 : indicates no arg OR return value added
// 0 : indicates return value added but no incoming args
// X : the return value AND X incoming args have been added
//
this.argsAdded = -1;
// ------------------------- Library spcific attribs ------------------
// Whether this is from a library
//
this.isLibFunc = false;
//
// Java script code emulating this library
//
//this.libJSstr = "";
// TODO: Set this variable for each lib func
// Library functions need to have the return data type because there
// is no associated header step to find the data type. Note that
// we always return a scalar from a function (e.g., int, real, etc)
//
this.retDataType = DataTypes.Integer;
//API: The flag below denotes that the user has selected to include
// this library as an entry point, and therefore requires the function
// API to be included in a glaf_api.h auto-generated file.
this.createAPI = false; // Do not include by default.
// ---------------------- Initialization -----------------------------
if (!skipHeader) {
// Create a function heder StepObj (step 0) and add that as the very
// first (0th) step to this FuncObj
//
var sO = new StepObj();
assert((this.allSteps.length == FuncHeaderStepId), "header not step 0");
//
this.allSteps.push( sO );
sO.isHeader = true;
sO.stageInStep = StageInStep.AllDone; // trivially mark complete
}
this.isRegularFunc = function isRegularFunc() {
return (!(this.isGlobal || this.isTemplateScope || this.isLibFunc));
}
}
//----------------------------------------------------------------------------
// Object to represent a 'step' in the program
//
// TODO: arrays to store indices
//
//----------------------------------------------------------------------------
function StepObj() {
// Grid IDs that belong to this step. GriIDs are at the function scopt
// -- i.e., in FuncObj
//
this.allGridIds = new Array();
this.allIndObjs = new Array();
// Code window has multiple 'box'es -- e.g., for range/mask/formula/...
// Each 'box' contains a root expression (which has sub expressions).
// Each root expression is stored in the following array
// Note: First two entries of the array are always range/mask. The third
// entry is a formula. After that, a box can contain either a
// formula or a mask (if/else/elseif)
//
this.boxExprs = new Array(); // box expressions
this.boxAttribs = new Array(); // indentation
//
// These define the index variable names for a step
//
this.dimNameExprs = new Array(); // names given to each index var
// is the output grid in this step a new grid the user created for
// this step? This is used for dynamically allocating a grid. This _could_
// also be useful in deallocating user deleted grids
//
this.isOutGridNew = false;
// Title of this step
//
this.title = null;
// The following two variables MUST be set/changed together. They indicate
// which box has active focus. 'focusBoxExpr' contains the root expression
// of the currently focused box.
//
this.focusBoxId = CodeBoxId.Formula; // by default, formula box active
this.focusBoxExpr = null; // which expr (mask/...) has focus
// for changing an html object like a grid cell (instead of a code box)
//
this.focusHtmlObj = null;
// The following fields are used while a formula is being built. We need
// a mechanism to map an html span drawn in a code box to the an
// exprObj that internally represents an expression.
// We locate the active expression/space using tuple
// <activeParentPath, activeChildPos>. activeParentPath gives a linear
// string of sequence numbers to describe the parent node in an
// ExprObj For this ExprObj, the child
// at postion activChildPos is the active expression/space. A child
// expression or its leading space have the same position. When the
// leading space is active, isSpaceActive is true; otherwise,
// isSpaceActive is false which means that the child ExprObj is active
// NOTE: We need a tuple (rather than a linear path to the expression
// itself) because when we are replacing an expression, we need
// to locate exprArr position with activeChildPos. See function
// replaceOrAppendExpr()
// NOTE: Word 'active' is used to describe the expression where input
// will go to. When an expression is active AND isSpaceActive=false,
// the active expression is *highlighted*. If isSpaceActive=true
// then a space related to the active expression is highligted.
//
this.activeParentPath = null;
this.activeChildPos = INVID; // which child within above ExprObj is active
this.activeParentExpr = null; // active parent expression (ExprObj)
this.isSpaceActive = false; // whether space active (instead of ExprObj)
//
// when the user is entering a number with the keyboard, the digits
// entered so far are kept here
//
this.numberExpr = null;
this.editDimNames = false;
// Comments are stored in the following
// TODO: convert to an array with constant indices
//
this.indexComment = "";
this.ifComment = "";
this.formulaComment = "";
this.stepComment = "";
// Parallelism of the step, indicated by the parallelism meter
//
this.parallelism = 0;
// the stage of the step
//
this.stageInStep = StageInStep.New;
// whether we are displaying data in grids
//
//this.showData = ShowDataState.None;
this.maxDataVal = MININT; // maximum data value
this.isHeader = false; // is this a function header
this.keyboardEnabled = true; // whether keyboard input is enabled
this.potOCLstep = 0; // OCL: Convert to OpenCL if a parallel step.
// If 0, then serial or OpenMP if parallel.
this.showOptions = false; // Whether to show options for step.
// Method to add a source grid
//
this.addGridId = function addGridId(gId) {
this.allGridIds.push(gId); // store grid
}
}
// ---------------------------------------------------------------------------
// Constructor to create a Grid. This creates a basic Grid object.
//
// Create an object as:
// var OutGrid = createGrid(id, "OutGrid", 4, 5, ......);
//
// See: http://www.w3schools.com/js/js_objects.asp
// ---------------------------------------------------------------------------
function GridObj(gridId, caption, actCols, actRows, showCols, showRows,
hasColTitles, hasRowTitles, multiCol, multiRow) {
this.gridId = gridId; // my Id in CurFuncObj.allGrids[]
this.caption = caption;
this.multiCol = multiCol; // whether multiple cols
this.multiRow = multiRow; // whether multiple rows
this.isTemplate = false; // is this a template
// The number of *array* dimensions.
// Note: A scalr is treated as 0-dim since it does not have
// column/row titles/indices. Hence, for a sclar multiCol=multiRow=0
//
this.numDims = 0; // actual number of dimensions
//
if (RowDimId == 0) {
// If there are rows only, then numDims is 1
// (only one dimension present). if there are columns, then row 0
// is also present by default. All columns go to dim 2.
//
if (multiRow) this.numDims = 1; // if row titles/indices are present
if (multiCol) this.numDims = 2; // if col titles/indices are present
} else {
if (multiRow) this.numDims = 2; // if row titles/indices are present
if (multiCol) this.numDims = 1; // if col titles/indices are present
}
// TODO: Consider grouping the following properties of a dim to a new
// class called DimAttribs.
// Each of these is an array of arrays
// See notes in email about multidimensional javascript
// Note: The caller must 'push' items into these arrays
//
this.dimTitles = new Array();
//
this.dimComments = new Array(); // comments for each title in each dim
// Whether a given dimension has titles OR indices
// NOTE: The code has the capbility to display both titles AND indices
// However, we display only Titles OR indices -- not both.
// If a table has titles there is no need for indices -- titles
// can be used as start/end of a range, if a range is inserted.
//
//
this.dimHasTitles = new Array(2);
this.dimHasTitles[ColDimId] = hasColTitles;
this.dimHasTitles[RowDimId] = hasRowTitles;
//
this.dimHasIndices = new Array(2);
this.dimHasIndices[ColDimId] = true; // multiCol && !hasColTitles;
this.dimHasIndices[RowDimId] = multiRow && !hasRowTitles;
//
this.dimShowSize = new Array(2);
this.dimShowSize[RowDimId] = showRows;
this.dimShowSize[ColDimId] = showCols;
//
this.dimActSize = new Array(2);
this.dimActSize[RowDimId] = actRows;
this.dimActSize[ColDimId] = actCols;
//
// It the actual size of a dimension is given by a *scalar* grid,
// its *name* is stored in this array. We store name (rather than a
// gridId, because we should support global variables). At code gen
// time, we will fill dimActSize[d] using the value of dimDynSize[d].
//
this.dimDynSize = new Array(2);
//MPI:
this.dimIsExtended = new Array(2);
this.dimIsExtended[RowDimId] = false;
this.dimIsExtended[ColDimId] = false;
this.isGlobal = false;
this.isDistributed = false;
this.dimSelectTabs = new Array(); // selected tab/index per dim
// Data types. Only one dimension can have data types. So, we need
// only a 1D array. However, the location of the type can be any
// dimension (given by typeInDim).
// If the type is *global*, then the fist entry in the array contains
// that type
//
this.dataTypes = new Array(); // containd type *ind* -- from TypesArr[]
this.typesInDim = -1; // a neagative value indicates global
this.isGridRef = false; // is this grid a ref to another grid
// (Set for incoming func args OR
// global grid -- as a reference )
this.globalRefId = -1; // if this referes to a global grid, its id
this.inArgNum = -1; // input func argument number
this.isRetVal = false; // is this the return value
this.isConst = false; // is this a read-only grid
// Whether there is manully entered init data
//
this.hasInitData = false;
// Data is dynamically allocated as an array of array of .... as
// required by the number of dimensions.
// NOTE: This array MUST be allocated and addressed in the JavaScript
// index order -- i.e., raw major style. This is because we
// pass this array to eval() of JavaScript interpreter. If we
// delcalre RowDimId=0, then our dimension ordering is NOT in
// row-major order. In that case, conversions are necessary. If we
// define ColDimId=0, then no conversion is necessary.
//
this.data = null;
this.dataMax = 1.0;
// If a grid is deleted (e.g., an incoming arg)
//
this.deleted = DeletedState.None;
// If this grid is copy/reference of template/another grid,
// the following contains the name of the original master grid used to
// create this grid. This is required for propagating any updates to
// titles, dimension sizes, etc. The original master can be in the
// current function or a different function (e.g., template/global scope)
// or the template scope of a different module (e.g., for a library)
//
this.masterName = null;
// ********* STEP dependent variables (valid only within a step *********
// (valid only within the current step)
//
// Note: Do NOT clone the following fields
//
// ASSUMPTION: This assumes a gridId is 1:1 associated with an HtmlId in
// a step.
//
// When we draw a grid on the screen, we set its htmlId with the grid.
// This assumes the same grid is NOT drawn on the same screen twice --
// -- i.e., we clone the grid when we want to draw it again.
//
this.htmlId = "";
this.hasSelection = false; // whether this grid has a cell selection
this.selIndDim = -1; // index range highlighted in this dim
//
// An incoming grid cell arg can be represented either as a scalar
// value OR a grid cell reference. When we represent a grid cell as a
// scalar we keep the original reference grid obj here to switch if
// the user requests to do so.
//
this.refgO = null; //
//this.showData = ShowDataState.None;
//this.letClicked = false;
this.curBox = -1; // for passing box number
// This is used only while a new template grid is being 'extended'
// -- i.e., reconfigured
//
this.numDimsOrig = -1;
// When we are displaying data, if the grid sizes are too large, we will
// show only portions of a grid. This array indicates the starting position
// for each dimension for displaying
//
this.dimShowStart = new Array(2);
this.dimShowStart[RowDimId] = 0;
this.dimShowStart[ColDimId] = 0;
// Comment string for this grid
//
this.comment = null;