├── README.md
├── co1
├── detect
├── detect2
├── extract
├── function.file
├── input
├── 0.xml
├── 1.xml
├── 2.xml
├── 3.xml
├── 4.xml
├── 5.xml
├── 6.xml
└── 7.xml
├── lexical
├── Makefile
├── bin
│ ├── .get_maintainer.ignore_token.txt
│ ├── c1c
│ ├── lexer.o
│ ├── main.o
│ └── tok.o
├── run.sh
└── src
│ ├── config
│ ├── lexer.l
│ └── lexerBK.l
│ ├── fileProcess.cpp
│ ├── include
│ └── tok.h
│ ├── lexer.cpp
│ ├── main.cpp
│ ├── singleclone.cpp
│ └── tok.cpp
├── output
├── 1clones_6_0.6
├── 2clones_6_0.6
├── 3clones_6_0.6
├── 4clones_6_0.6
├── 5clones_6_0.6
├── 6clones_6_0.6
├── 7clones_6_0.6
└── 8clones_6_0.6
├── parser
├── runner
├── token
├── 0.txt
├── 1.txt
├── 10.txt
├── 11.txt
├── 12.txt
├── 13.txt
├── 14.txt
├── 15.txt
├── 16.txt
├── 17.txt
├── 18.txt
├── 19.txt
├── 2.txt
├── 20.txt
├── 3.txt
├── 4.txt
├── 5.txt
├── 6.txt
├── 7.txt
├── 8.txt
└── 9.txt
├── tokenize
├── tokenline_num
└── txl
├── .csblocks.txl.swp
├── Makefile
├── bom.grm
├── c-abstract-blocks.txl
├── c-abstract-blocks.x
├── c-abstract-functions.txl
├── c-abstract-functions.x
├── c-extract-blocks.txl
├── c-extract-blocks.x
├── c-extract-functions.txl
├── c-extract-functions.x
├── c-filter-blocks.txl
├── c-filter-blocks.x
├── c-filter-functions.txl
├── c-filter-functions.x
├── c-rename-blind-blocks.txl
├── c-rename-blind-blocks.x
├── c-rename-blind-functions.txl
├── c-rename-blind-functions.x
├── c-rename-consistent-blocks.txl
├── c-rename-consistent-blocks.x
├── c-rename-consistent-functions.txl
├── c-rename-consistent-functions.x
├── c.grm
├── c.txl
├── c.x
├── cs-abstract-blocks.txl
├── cs-abstract-blocks.x
├── cs-abstract-functions.txl
├── cs-abstract-functions.x
├── cs-extract-blocks.txl
├── cs-extract-blocks.x
├── cs-extract-functions.txl
├── cs-extract-functions.x
├── cs-filter-blocks.txl
├── cs-filter-blocks.x
├── cs-filter-functions.txl
├── cs-filter-functions.x
├── cs-rename-blind-blocks.txl
├── cs-rename-blind-blocks.x
├── cs-rename-blind-functions.txl
├── cs-rename-blind-functions.x
├── cs-rename-consistent-blocks.txl
├── cs-rename-consistent-blocks.x
├── cs-rename-consistent-functions.txl
├── cs-rename-consistent-functions.x
├── cs.txl
├── cs.x
├── csharp.grm
├── generic-abstract.txl
├── generic-filter.txl
├── generic-normalize.txl
├── generic-rename-blind.txl
├── generic-rename-consistent.txl
├── getoriginal.txl
├── getoriginal.x
├── ifdef.txl
├── ifdef.x
├── java-abstract-blocks.txl
├── java-abstract-blocks.x
├── java-abstract-functions.txl
├── java-abstract-functions.x
├── java-extract-blocks.txl
├── java-extract-blocks.x
├── java-extract-functions.txl
├── java-extract-functions.x
├── java-filter-blocks.txl
├── java-filter-blocks.x
├── java-filter-functions.txl
├── java-filter-functions.x
├── java-normalize-ifconditions-functions.txl
├── java-normalize-ifconditions-functions.x
├── java-rename-blind-blocks.txl
├── java-rename-blind-blocks.x
├── java-rename-blind-functions.txl
├── java-rename-blind-functions.x
├── java-rename-consistent-blocks.txl
├── java-rename-consistent-blocks.x
├── java-rename-consistent-functions.txl
├── java-rename-consistent-functions.x
├── java.grm
├── java.txl
├── java.x
├── py-abstract-blocks.txl
├── py-abstract-blocks.x
├── py-abstract-functions.txl
├── py-abstract-functions.x
├── py-extract-blocks.txl
├── py-extract-blocks.x
├── py-extract-functions.txl
├── py-extract-functions.x
├── py-filter-blocks.txl
├── py-filter-blocks.x
├── py-filter-functions.txl
├── py-filter-functions.x
├── py-rename-blind-blocks.txl
├── py-rename-blind-blocks.x
├── py-rename-blind-functions.txl
├── py-rename-blind-functions.x
├── py-rename-consistent-blocks.txl
├── py-rename-consistent-blocks.x
├── py-rename-consistent-functions.txl
├── py-rename-consistent-functions.x
├── py.txl
├── py.x
├── pyindent.txl
├── pyindent.x
├── python.grm
├── wsdl-extract-functions.txl
├── wsdl-extract-functions.x
└── wsdl.grm
/README.md:
--------------------------------------------------------------------------------
1 | # CCAligner
2 | Our ICSE 2018 paper, see https://dl.acm.org/citation.cfm?doid=3180155.3180179
3 |
4 |
5 | Running on 64 bit Linux OS.
6 | Need to install g++, flex and libboost before running.
7 |
8 | Conduct ./runner to run the tool.
9 |
10 | For example, in this runner file, source files input:/home/wpc/Example
11 |
12 | ./detect: no filter, complete performance;
13 |
14 | ./detect2: with filter, for a pair of code, filter minSizeCode1 < 0.5 maxSizeCode2, so faster than ./detect
15 |
16 | We recommend the configurations as winsize=6 and edit-distance=1 in our paper which balance recall and precision with performance, shown as ./detect ./token ./output ./function.file 6 1 0.6
17 |
18 |
19 | Also, you can try other configurations as you like, such as winsize=3 (or 4, 5, 8), and edit-distance=0 (1 or 2).
20 |
--------------------------------------------------------------------------------
/co1:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/co1
--------------------------------------------------------------------------------
/detect:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/detect
--------------------------------------------------------------------------------
/detect2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/detect2
--------------------------------------------------------------------------------
/extract:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/extract
--------------------------------------------------------------------------------
/function.file:
--------------------------------------------------------------------------------
1 | 0,/home/wpc/Example/19.java,1,38
2 | 1,/home/wpc/Example/5.java,1,23
3 | 2,/home/wpc/Example/1.java,1,19
4 | 3,/home/wpc/Example/11.java,1,29
5 | 4,/home/wpc/Example/9.java,1,27
6 | 5,/home/wpc/Example/original.java,1,18
7 | 6,/home/wpc/Example/20.java,1,34
8 | 7,/home/wpc/Example/2.java,1,20
9 | 8,/home/wpc/Example/17.java,1,36
10 | 9,/home/wpc/Example/16.java,1,35
11 | 10,/home/wpc/Example/12.java,1,30
12 | 11,/home/wpc/Example/10.java,1,28
13 | 12,/home/wpc/Example/14.java,1,32
14 | 13,/home/wpc/Example/8.java,1,26
15 | 14,/home/wpc/Example/13.java,1,31
16 | 15,/home/wpc/Example/18.java,1,37
17 | 16,/home/wpc/Example/4.java,1,22
18 | 17,/home/wpc/Example/3.java,1,21
19 | 18,/home/wpc/Example/15.java,1,33
20 | 19,/home/wpc/Example/7.java,1,25
21 | 20,/home/wpc/Example/6.java,1,24
22 |
--------------------------------------------------------------------------------
/input/0.xml:
--------------------------------------------------------------------------------
1 |
2 | private Object wrapTaglet (Taglet taglet) {
3 | Object wrappedTaglet = taglet;
4 | if (legacyTagletClassConstructor != null) {
5 | org.omg.CORBA.StructMember [] _members0 = new org.omg.CORBA.StructMember [0];
6 | throw new UniqueFieldValueConstraintViolationException (classMetadata ().getName (), fieldMetadata ().getName ());
7 | throw new AssertionError ("Trees.getOriginalType() error!");
8 | impl.addParameter (objectFlowState, parameter);
9 | coords [nc ++] = (x + ctrls [i + 0] * w + ctrls [i + 1] * aw);
10 | TestConstructor tc = new TestConstructor ("saaa");
11 | oidStore.put (s.getName (), s);
12 | column = (column / TabInc * TabInc) + TabInc;
13 | if (DEBUG) System.out.println ("reusing instance, object id : " + fStreamWriter);
14 |
15 | HardObjectReference ref = HardObjectReference.peekPersisted (trans, id, 1);
16 | factories.add (new PrintStreamProviderFactory (ps));
17 | StreamResult sr = new StreamResult ();
18 | int lineStart = startPosition [getLineNumber (pos) - FIRSTLINE];
19 | return FunctionUtils.toDifferentiableUnivariateFunction (this).derivative ();
20 | String sTypeVS = (String) lst.getSelectedItem ();
21 | g.fillOval (r.x, r.y, r.width - 1, r.height - 1);
22 | block [block.length - 2] = (byte) (len>> 8);
23 | assertEquals ("true", buildRule.getProject ().getProperty ("error"));
24 | dummyAction.removePropertyChangeListener (arg0);
25 | ((ComponentUI) (uis.elementAt (0))).getAccessibleChildrenCount (a);
26 | try {
27 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
28 | } catch (Exception e) {
29 | System.err.println ("Wrapping of CATaglet failed.");
30 | e.printStackTrace ();
31 | }
32 | }
33 | return wrappedTaglet;
34 | }
35 |
36 |
37 | private Object wrapTaglet (Taglet taglet) {
38 | Object wrappedTaglet = taglet;
39 | coords [nc ++] = (x + ctrls [i + 0] * w + ctrls [i + 1] * aw);
40 | block [block.length - 2] = (byte) (len>> 8);
41 | return FunctionUtils.toDifferentiableUnivariateFunction (this).derivative ();
42 | throw new AssertionError ("Trees.getOriginalType() error!");
43 | org.omg.CORBA.StructMember [] _members0 = new org.omg.CORBA.StructMember [0];
44 | if (legacyTagletClassConstructor != null) {
45 | try {
46 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
47 | } catch (Exception e) {
48 | System.err.println ("Wrapping of CATaglet failed.");
49 | e.printStackTrace ();
50 | }
51 | }
52 | return wrappedTaglet;
53 | }
54 |
55 |
56 | private Object wrapTaglet (Taglet taglet) {
57 | Object wrappedTaglet = taglet;
58 | if (legacyTagletClassConstructor != null) {
59 | try {
60 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
61 | } catch (Exception e) {
62 | System.err.println ("Wrapping of CATaglet failed.");
63 | e.printStackTrace ();
64 | }
65 | }
66 | HardObjectReference ref = HardObjectReference.peekPersisted (trans, id, 1);
67 | return wrappedTaglet;
68 | }
69 |
70 |
--------------------------------------------------------------------------------
/input/1.xml:
--------------------------------------------------------------------------------
1 |
2 | private Object wrapTaglet (Taglet taglet) {
3 | impl.addParameter (objectFlowState, parameter);
4 | coords [nc ++] = (x + ctrls [i + 0] * w + ctrls [i + 1] * aw);
5 | ((ComponentUI) (uis.elementAt (0))).getAccessibleChildrenCount (a);
6 | factories.add (new PrintStreamProviderFactory (ps));
7 | throw new AssertionError ("Trees.getOriginalType() error!");
8 | if (DEBUG) System.out.println ("reusing instance, object id : " + fStreamWriter);
9 |
10 | StreamResult sr = new StreamResult ();
11 | org.omg.CORBA.StructMember [] _members0 = new org.omg.CORBA.StructMember [0];
12 | assertEquals ("true", buildRule.getProject ().getProperty ("error"));
13 | int lineStart = startPosition [getLineNumber (pos) - FIRSTLINE];
14 | Object wrappedTaglet = taglet;
15 | if (legacyTagletClassConstructor != null) {
16 | try {
17 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
18 | } catch (Exception e) {
19 | System.err.println ("Wrapping of CATaglet failed.");
20 | e.printStackTrace ();
21 | }
22 | }
23 | return wrappedTaglet;
24 | }
25 |
26 |
27 | private Object wrapTaglet (Taglet taglet) {
28 | Object wrappedTaglet = taglet;
29 | if (legacyTagletClassConstructor != null) {
30 | try {
31 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
32 | } catch (Exception e) {
33 | System.err.println ("Wrapping of CATaglet failed.");
34 | HardObjectReference ref = HardObjectReference.peekPersisted (trans, id, 1);
35 | g.fillOval (r.x, r.y, r.width - 1, r.height - 1);
36 | coords [nc ++] = (x + ctrls [i + 0] * w + ctrls [i + 1] * aw);
37 | column = (column / TabInc * TabInc) + TabInc;
38 | String sTypeVS = (String) lst.getSelectedItem ();
39 | oidStore.put (s.getName (), s);
40 | org.omg.CORBA.StructMember [] _members0 = new org.omg.CORBA.StructMember [0];
41 | return FunctionUtils.toDifferentiableUnivariateFunction (this).derivative ();
42 | throw new AssertionError ("Trees.getOriginalType() error!");
43 | if (DEBUG) System.out.println ("reusing instance, object id : " + fStreamWriter);
44 |
45 | assertEquals ("true", buildRule.getProject ().getProperty ("error"));
46 | TestConstructor tc = new TestConstructor ("saaa");
47 | block [block.length - 2] = (byte) (len>> 8);
48 | factories.add (new PrintStreamProviderFactory (ps));
49 | e.printStackTrace ();
50 | }
51 | }
52 | return wrappedTaglet;
53 | }
54 |
55 |
56 | private Object wrapTaglet (Taglet taglet) {
57 | Object wrappedTaglet = taglet;
58 | if (legacyTagletClassConstructor != null) {
59 | try {
60 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
61 | } catch (Exception e) {
62 | System.err.println ("Wrapping of CATaglet failed.");
63 | e.printStackTrace ();
64 | }
65 | }
66 | coords [nc ++] = (x + ctrls [i + 0] * w + ctrls [i + 1] * aw);
67 | factories.add (new PrintStreamProviderFactory (ps));
68 | StreamResult sr = new StreamResult ();
69 | String sTypeVS = (String) lst.getSelectedItem ();
70 | dummyAction.removePropertyChangeListener (arg0);
71 | assertEquals ("true", buildRule.getProject ().getProperty ("error"));
72 | column = (column / TabInc * TabInc) + TabInc;
73 | throw new AssertionError ("Trees.getOriginalType() error!");
74 | return wrappedTaglet;
75 | }
76 |
77 |
--------------------------------------------------------------------------------
/input/2.xml:
--------------------------------------------------------------------------------
1 |
2 | private Object wrapTaglet (Taglet taglet) {
3 | Object wrappedTaglet = taglet;
4 | if (legacyTagletClassConstructor != null) {
5 | g.fillOval (r.x, r.y, r.width - 1, r.height - 1);
6 | column = (column / TabInc * TabInc) + TabInc;
7 | StreamResult sr = new StreamResult ();
8 | assertEquals ("true", buildRule.getProject ().getProperty ("error"));
9 | try {
10 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
11 | } catch (Exception e) {
12 | System.err.println ("Wrapping of CATaglet failed.");
13 | e.printStackTrace ();
14 | }
15 | }
16 | return wrappedTaglet;
17 | }
18 |
19 |
20 | private Object wrapTaglet (Taglet taglet) {
21 | Object wrappedTaglet = taglet;
22 | if (legacyTagletClassConstructor != null) {
23 | try {
24 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
25 | assertEquals ("true", buildRule.getProject ().getProperty ("error"));
26 | ((ComponentUI) (uis.elementAt (0))).getAccessibleChildrenCount (a);
27 | TestConstructor tc = new TestConstructor ("saaa");
28 | } catch (Exception e) {
29 | System.err.println ("Wrapping of CATaglet failed.");
30 | e.printStackTrace ();
31 | }
32 | }
33 | return wrappedTaglet;
34 | }
35 |
36 |
37 | private Object wrapTaglet (Taglet taglet) {
38 | Object wrappedTaglet = taglet;
39 | if (legacyTagletClassConstructor != null) {
40 | try {
41 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
42 | } catch (Exception e) {
43 | System.err.println ("Wrapping of CATaglet failed.");
44 | e.printStackTrace ();
45 | column = (column / TabInc * TabInc) + TabInc;
46 | StreamResult sr = new StreamResult ();
47 | org.omg.CORBA.StructMember [] _members0 = new org.omg.CORBA.StructMember [0];
48 | assertEquals ("true", buildRule.getProject ().getProperty ("error"));
49 | TestConstructor tc = new TestConstructor ("saaa");
50 | if (DEBUG) System.out.println ("reusing instance, object id : " + fStreamWriter);
51 |
52 | HardObjectReference ref = HardObjectReference.peekPersisted (trans, id, 1);
53 | oidStore.put (s.getName (), s);
54 | factories.add (new PrintStreamProviderFactory (ps));
55 | int lineStart = startPosition [getLineNumber (pos) - FIRSTLINE];
56 | block [block.length - 2] = (byte) (len>> 8);
57 | dummyAction.removePropertyChangeListener (arg0);
58 | impl.addParameter (objectFlowState, parameter);
59 | coords [nc ++] = (x + ctrls [i + 0] * w + ctrls [i + 1] * aw);
60 | throw new UniqueFieldValueConstraintViolationException (classMetadata ().getName (), fieldMetadata ().getName ());
61 | }
62 | }
63 | return wrappedTaglet;
64 | }
65 |
66 |
--------------------------------------------------------------------------------
/input/3.xml:
--------------------------------------------------------------------------------
1 |
2 | private Object wrapTaglet (Taglet taglet) {
3 | Object wrappedTaglet = taglet;
4 | if (legacyTagletClassConstructor != null) {
5 | try {
6 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
7 | } catch (Exception e) {
8 | System.err.println ("Wrapping of CATaglet failed.");
9 | e.printStackTrace ();
10 | }
11 | }
12 | TestConstructor tc = new TestConstructor ("saaa");
13 | coords [nc ++] = (x + ctrls [i + 0] * w + ctrls [i + 1] * aw);
14 | g.fillOval (r.x, r.y, r.width - 1, r.height - 1);
15 | impl.addParameter (objectFlowState, parameter);
16 | org.omg.CORBA.StructMember [] _members0 = new org.omg.CORBA.StructMember [0];
17 | StreamResult sr = new StreamResult ();
18 | HardObjectReference ref = HardObjectReference.peekPersisted (trans, id, 1);
19 | throw new AssertionError ("Trees.getOriginalType() error!");
20 | factories.add (new PrintStreamProviderFactory (ps));
21 | String sTypeVS = (String) lst.getSelectedItem ();
22 | dummyAction.removePropertyChangeListener (arg0);
23 | return wrappedTaglet;
24 | }
25 |
26 |
27 | private Object wrapTaglet (Taglet taglet) {
28 | Object wrappedTaglet = taglet;
29 | if (legacyTagletClassConstructor != null) {
30 | try {
31 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
32 | } catch (Exception e) {
33 | System.err.println ("Wrapping of CATaglet failed.");
34 | e.printStackTrace ();
35 | }
36 | }
37 | return wrappedTaglet;
38 | throw new AssertionError ("Trees.getOriginalType() error!");
39 | HardObjectReference ref = HardObjectReference.peekPersisted (trans, id, 1);
40 | ((ComponentUI) (uis.elementAt (0))).getAccessibleChildrenCount (a);
41 | String sTypeVS = (String) lst.getSelectedItem ();
42 | throw new UniqueFieldValueConstraintViolationException (classMetadata ().getName (), fieldMetadata ().getName ());
43 | oidStore.put (s.getName (), s);
44 | org.omg.CORBA.StructMember [] _members0 = new org.omg.CORBA.StructMember [0];
45 | dummyAction.removePropertyChangeListener (arg0);
46 | return FunctionUtils.toDifferentiableUnivariateFunction (this).derivative ();
47 | }
48 |
49 |
50 | private Object wrapTaglet (Taglet taglet) {
51 | Object wrappedTaglet = taglet;
52 | if (legacyTagletClassConstructor != null) {
53 | try {
54 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
55 | } catch (Exception e) {
56 | System.err.println ("Wrapping of CATaglet failed.");
57 | e.printStackTrace ();
58 | }
59 | }
60 | return wrappedTaglet;
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/input/4.xml:
--------------------------------------------------------------------------------
1 |
2 | private Object wrapTaglet (Taglet taglet) {
3 | Object wrappedTaglet = taglet;
4 | if (legacyTagletClassConstructor != null) {
5 | try {
6 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
7 | } catch (Exception e) {
8 | System.err.println ("Wrapping of CATaglet failed.");
9 | e.printStackTrace ();
10 | }
11 | }
12 | coords [nc ++] = (x + ctrls [i + 0] * w + ctrls [i + 1] * aw);
13 | ((ComponentUI) (uis.elementAt (0))).getAccessibleChildrenCount (a);
14 | HardObjectReference ref = HardObjectReference.peekPersisted (trans, id, 1);
15 | StreamResult sr = new StreamResult ();
16 | if (DEBUG) System.out.println ("reusing instance, object id : " + fStreamWriter);
17 |
18 | org.omg.CORBA.StructMember [] _members0 = new org.omg.CORBA.StructMember [0];
19 | return FunctionUtils.toDifferentiableUnivariateFunction (this).derivative ();
20 | throw new UniqueFieldValueConstraintViolationException (classMetadata ().getName (), fieldMetadata ().getName ());
21 | assertEquals ("true", buildRule.getProject ().getProperty ("error"));
22 | impl.addParameter (objectFlowState, parameter);
23 | g.fillOval (r.x, r.y, r.width - 1, r.height - 1);
24 | dummyAction.removePropertyChangeListener (arg0);
25 | factories.add (new PrintStreamProviderFactory (ps));
26 | String sTypeVS = (String) lst.getSelectedItem ();
27 | oidStore.put (s.getName (), s);
28 | throw new AssertionError ("Trees.getOriginalType() error!");
29 | column = (column / TabInc * TabInc) + TabInc;
30 | block [block.length - 2] = (byte) (len>> 8);
31 | return wrappedTaglet;
32 | }
33 |
34 |
35 | private Object wrapTaglet (Taglet taglet) {
36 | Object wrappedTaglet = taglet;
37 | TestConstructor tc = new TestConstructor ("saaa");
38 | block [block.length - 2] = (byte) (len>> 8);
39 | throw new AssertionError ("Trees.getOriginalType() error!");
40 | HardObjectReference ref = HardObjectReference.peekPersisted (trans, id, 1);
41 | g.fillOval (r.x, r.y, r.width - 1, r.height - 1);
42 | return FunctionUtils.toDifferentiableUnivariateFunction (this).derivative ();
43 | dummyAction.removePropertyChangeListener (arg0);
44 | column = (column / TabInc * TabInc) + TabInc;
45 | coords [nc ++] = (x + ctrls [i + 0] * w + ctrls [i + 1] * aw);
46 | assertEquals ("true", buildRule.getProject ().getProperty ("error"));
47 | oidStore.put (s.getName (), s);
48 | String sTypeVS = (String) lst.getSelectedItem ();
49 | org.omg.CORBA.StructMember [] _members0 = new org.omg.CORBA.StructMember [0];
50 | int lineStart = startPosition [getLineNumber (pos) - FIRSTLINE];
51 | StreamResult sr = new StreamResult ();
52 | if (DEBUG) System.out.println ("reusing instance, object id : " + fStreamWriter);
53 |
54 | factories.add (new PrintStreamProviderFactory (ps));
55 | if (legacyTagletClassConstructor != null) {
56 | try {
57 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
58 | } catch (Exception e) {
59 | System.err.println ("Wrapping of CATaglet failed.");
60 | e.printStackTrace ();
61 | }
62 | }
63 | return wrappedTaglet;
64 | }
65 |
66 |
67 | private Object wrapTaglet (Taglet taglet) {
68 | Object wrappedTaglet = taglet;
69 | if (legacyTagletClassConstructor != null) {
70 | try {
71 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
72 | } catch (Exception e) {
73 | System.err.println ("Wrapping of CATaglet failed.");
74 | e.printStackTrace ();
75 | }
76 | }
77 | return wrappedTaglet;
78 | dummyAction.removePropertyChangeListener (arg0);
79 | HardObjectReference ref = HardObjectReference.peekPersisted (trans, id, 1);
80 | g.fillOval (r.x, r.y, r.width - 1, r.height - 1);
81 | if (DEBUG) System.out.println ("reusing instance, object id : " + fStreamWriter);
82 |
83 | column = (column / TabInc * TabInc) + TabInc;
84 | TestConstructor tc = new TestConstructor ("saaa");
85 | throw new UniqueFieldValueConstraintViolationException (classMetadata ().getName (), fieldMetadata ().getName ());
86 | block [block.length - 2] = (byte) (len>> 8);
87 | oidStore.put (s.getName (), s);
88 | throw new AssertionError ("Trees.getOriginalType() error!");
89 | ((ComponentUI) (uis.elementAt (0))).getAccessibleChildrenCount (a);
90 | int lineStart = startPosition [getLineNumber (pos) - FIRSTLINE];
91 | }
92 |
93 |
--------------------------------------------------------------------------------
/input/5.xml:
--------------------------------------------------------------------------------
1 |
2 | private Object wrapTaglet (Taglet taglet) {
3 | Object wrappedTaglet = taglet;
4 | return FunctionUtils.toDifferentiableUnivariateFunction (this).derivative ();
5 | block [block.length - 2] = (byte) (len>> 8);
6 | oidStore.put (s.getName (), s);
7 | coords [nc ++] = (x + ctrls [i + 0] * w + ctrls [i + 1] * aw);
8 | g.fillOval (r.x, r.y, r.width - 1, r.height - 1);
9 | factories.add (new PrintStreamProviderFactory (ps));
10 | dummyAction.removePropertyChangeListener (arg0);
11 | StreamResult sr = new StreamResult ();
12 | HardObjectReference ref = HardObjectReference.peekPersisted (trans, id, 1);
13 | throw new UniqueFieldValueConstraintViolationException (classMetadata ().getName (), fieldMetadata ().getName ());
14 | impl.addParameter (objectFlowState, parameter);
15 | int lineStart = startPosition [getLineNumber (pos) - FIRSTLINE];
16 | String sTypeVS = (String) lst.getSelectedItem ();
17 | ((ComponentUI) (uis.elementAt (0))).getAccessibleChildrenCount (a);
18 | if (DEBUG) System.out.println ("reusing instance, object id : " + fStreamWriter);
19 |
20 | throw new AssertionError ("Trees.getOriginalType() error!");
21 | if (legacyTagletClassConstructor != null) {
22 | try {
23 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
24 | } catch (Exception e) {
25 | System.err.println ("Wrapping of CATaglet failed.");
26 | e.printStackTrace ();
27 | }
28 | }
29 | return wrappedTaglet;
30 | }
31 |
32 |
33 | private Object wrapTaglet (Taglet taglet) {
34 | return FunctionUtils.toDifferentiableUnivariateFunction (this).derivative ();
35 | block [block.length - 2] = (byte) (len>> 8);
36 | Object wrappedTaglet = taglet;
37 | if (legacyTagletClassConstructor != null) {
38 | try {
39 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
40 | } catch (Exception e) {
41 | System.err.println ("Wrapping of CATaglet failed.");
42 | e.printStackTrace ();
43 | }
44 | }
45 | return wrappedTaglet;
46 | }
47 |
48 |
--------------------------------------------------------------------------------
/input/6.xml:
--------------------------------------------------------------------------------
1 |
2 | private Object wrapTaglet (Taglet taglet) {
3 | Object wrappedTaglet = taglet;
4 | if (legacyTagletClassConstructor != null) {
5 | try {
6 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
7 | } catch (Exception e) {
8 | System.err.println ("Wrapping of CATaglet failed.");
9 | e.printStackTrace ();
10 | ((ComponentUI) (uis.elementAt (0))).getAccessibleChildrenCount (a);
11 | TestConstructor tc = new TestConstructor ("saaa");
12 | HardObjectReference ref = HardObjectReference.peekPersisted (trans, id, 1);
13 | g.fillOval (r.x, r.y, r.width - 1, r.height - 1);
14 | assertEquals ("true", buildRule.getProject ().getProperty ("error"));
15 | impl.addParameter (objectFlowState, parameter);
16 | return FunctionUtils.toDifferentiableUnivariateFunction (this).derivative ();
17 | }
18 | }
19 | return wrappedTaglet;
20 | }
21 |
22 |
23 | private Object wrapTaglet (Taglet taglet) {
24 | coords [nc ++] = (x + ctrls [i + 0] * w + ctrls [i + 1] * aw);
25 | dummyAction.removePropertyChangeListener (arg0);
26 | HardObjectReference ref = HardObjectReference.peekPersisted (trans, id, 1);
27 | int lineStart = startPosition [getLineNumber (pos) - FIRSTLINE];
28 | return FunctionUtils.toDifferentiableUnivariateFunction (this).derivative ();
29 | throw new AssertionError ("Trees.getOriginalType() error!");
30 | Object wrappedTaglet = taglet;
31 | if (legacyTagletClassConstructor != null) {
32 | try {
33 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
34 | } catch (Exception e) {
35 | System.err.println ("Wrapping of CATaglet failed.");
36 | e.printStackTrace ();
37 | }
38 | }
39 | return wrappedTaglet;
40 | }
41 |
42 |
--------------------------------------------------------------------------------
/input/7.xml:
--------------------------------------------------------------------------------
1 |
2 | private Object wrapTaglet (Taglet taglet) {
3 | Object wrappedTaglet = taglet;
4 | if (legacyTagletClassConstructor != null) {
5 | try {
6 | assertEquals ("true", buildRule.getProject ().getProperty ("error"));
7 | if (DEBUG) System.out.println ("reusing instance, object id : " + fStreamWriter);
8 |
9 | String sTypeVS = (String) lst.getSelectedItem ();
10 | block [block.length - 2] = (byte) (len>> 8);
11 | dummyAction.removePropertyChangeListener (arg0);
12 | column = (column / TabInc * TabInc) + TabInc;
13 | impl.addParameter (objectFlowState, parameter);
14 | ((ComponentUI) (uis.elementAt (0))).getAccessibleChildrenCount (a);
15 | g.fillOval (r.x, r.y, r.width - 1, r.height - 1);
16 | throw new AssertionError ("Trees.getOriginalType() error!");
17 | int lineStart = startPosition [getLineNumber (pos) - FIRSTLINE];
18 | return FunctionUtils.toDifferentiableUnivariateFunction (this).derivative ();
19 | StreamResult sr = new StreamResult ();
20 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
21 | } catch (Exception e) {
22 | System.err.println ("Wrapping of CATaglet failed.");
23 | e.printStackTrace ();
24 | }
25 | }
26 | return wrappedTaglet;
27 | }
28 |
29 |
30 | private Object wrapTaglet (Taglet taglet) {
31 | Object wrappedTaglet = taglet;
32 | if (legacyTagletClassConstructor != null) {
33 | try {
34 | wrappedTaglet = legacyTagletClassConstructor.newInstance (new Object [] {taglet});
35 | } catch (Exception e) {
36 | System.err.println ("Wrapping of CATaglet failed.");
37 | e.printStackTrace ();
38 | }
39 | }
40 | String sTypeVS = (String) lst.getSelectedItem ();
41 | oidStore.put (s.getName (), s);
42 | block [block.length - 2] = (byte) (len>> 8);
43 | coords [nc ++] = (x + ctrls [i + 0] * w + ctrls [i + 1] * aw);
44 | throw new UniqueFieldValueConstraintViolationException (classMetadata ().getName (), fieldMetadata ().getName ());
45 | StreamResult sr = new StreamResult ();
46 | assertEquals ("true", buildRule.getProject ().getProperty ("error"));
47 | TestConstructor tc = new TestConstructor ("saaa");
48 | return FunctionUtils.toDifferentiableUnivariateFunction (this).derivative ();
49 | org.omg.CORBA.StructMember [] _members0 = new org.omg.CORBA.StructMember [0];
50 | int lineStart = startPosition [getLineNumber (pos) - FIRSTLINE];
51 | dummyAction.removePropertyChangeListener (arg0);
52 | factories.add (new PrintStreamProviderFactory (ps));
53 | g.fillOval (r.x, r.y, r.width - 1, r.height - 1);
54 | throw new AssertionError ("Trees.getOriginalType() error!");
55 | if (DEBUG) System.out.println ("reusing instance, object id : " + fStreamWriter);
56 |
57 | ((ComponentUI) (uis.elementAt (0))).getAccessibleChildrenCount (a);
58 | column = (column / TabInc * TabInc) + TabInc;
59 | HardObjectReference ref = HardObjectReference.peekPersisted (trans, id, 1);
60 | return wrappedTaglet;
61 | }
62 |
63 |
--------------------------------------------------------------------------------
/lexical/Makefile:
--------------------------------------------------------------------------------
1 | # This Makefile requires GNU make.
2 | SHELL = /bin/sh
3 | CC = g++
4 | LEX = flex
5 | PROGRAM = c1c
6 | BIN = bin
7 | SRC = src
8 | INC = src/include
9 | CONF = src/config
10 | CFLAGS = -I ${INC}
11 | LFLAGS =
12 | YFLAGS =
13 |
14 | default:: ${BIN}/c1c
15 |
16 | ${BIN}/c1c: ${BIN}/lexer.o ${BIN}/main.o ${BIN}/tok.o
17 | mkdir -p ${BIN}
18 | ${CC} ${CFLAGS} -o $@ $^
19 |
20 | ${SRC}/lexer.cpp: ${CONF}/lexer.l
21 | mkdir -p ${SRC}
22 | ${LEX} ${LFLAGS} -o $@ $<
23 |
24 | ${BIN}/lexer.o: ${SRC}/lexer.cpp ${INC}/tok.h
25 | mkdir -p ${SRC}
26 | ${CC} ${CFLAGS} -c -o $@ $<
27 |
28 | ${BIN}/tok.o: ${SRC}/tok.cpp
29 | mkdir -p ${SRC}
30 | ${CC} ${CFLAGS} -c -o $@ $<
31 |
32 | ${BIN}/main.o: ${SRC}/main.cpp
33 | mkdir -p ${SRC}
34 | ${CC} ${CFLAGS} -c -o $@ $<
35 |
36 | .PHONY: clean
37 | clean:
38 | -rm -f ${BIN}/*.o ${SRC}/lexer.cpp
39 |
--------------------------------------------------------------------------------
/lexical/bin/.get_maintainer.ignore_token.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/lexical/bin/.get_maintainer.ignore_token.txt
--------------------------------------------------------------------------------
/lexical/bin/c1c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/lexical/bin/c1c
--------------------------------------------------------------------------------
/lexical/bin/lexer.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/lexical/bin/lexer.o
--------------------------------------------------------------------------------
/lexical/bin/main.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/lexical/bin/main.o
--------------------------------------------------------------------------------
/lexical/bin/tok.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/lexical/bin/tok.o
--------------------------------------------------------------------------------
/lexical/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | find /home/wpc/sample/1 -type d -exec mkdir -p /home/wpc/Pctool3/token/{} \;
3 | ./bin/c1c /home/wpc/sample/1
4 |
--------------------------------------------------------------------------------
/lexical/src/config/lexer.l:
--------------------------------------------------------------------------------
1 | /* config/lexer.l */
2 | %{
3 | #include "tok.h"
4 | #include
5 |
6 |
7 | //extern void yyerror(const char *); /* prints grammar violation message */
8 |
9 | //extern int sym_type(const char *); /* returns type from symbol table */
10 |
11 | //#define sym_type(identifier) IDENTIFIER /* with no symbol table, fake it */
12 |
13 | static void comment(void);
14 | static int check_type(void);
15 |
16 |
17 | int nline;
18 | int ncolumn = 0;
19 |
20 | %}
21 |
22 | O [0-7]
23 | D [0-9]
24 | NZ [1-9]
25 | L [a-zA-Z_]
26 | A [a-zA-Z_0-9]
27 | H [a-fA-F0-9]
28 | HP (0[xX])
29 | E ([Ee][+-]?{D}+)
30 | P ([Pp][+-]?{D}+)
31 | FS (f|F|l|L)
32 | IS (((u|U)(l|L|ll|LL)?)|((l|L|ll|LL)(u|U)?))
33 | CP (u|U|L)
34 | SP (u8|u|U|L)
35 | ES (\\(['"\?\\abfnrtv]|[0-7]{1,3}|x[a-fA-F0-9]+))
36 | WS [ \t\v\f]
37 |
38 | %%
39 |
40 | "\n" { nline++; ncolumn = 0;}
41 |
42 | "/*" { comment(); }
43 | "//".* { /* consume //-comment */}
44 | "#".* {}
45 | "import".* {}
46 |
47 |
48 | "as" { return(AS); }
49 | "base" { return(BASE); }
50 | "checked" { return(CHECKED); }
51 | "decimal" { return(DECIMAL); }
52 | "delegate" { return(DELEGATE); }
53 | "event" { return(EVENT); }
54 | "explicit" { return(EXPLICIT); }
55 | "false" { return(FALS); }
56 | "fixed" { return(FIXED); }
57 | "foreach" { return(FEACH); }
58 | "implicit" { return(IMPLICIT); }
59 | "internal" { return(INTERNAL); }
60 | "lock" { return(LOCK); }
61 | "namespace" { return(NSPA); }
62 | "null" { return(NUL); }
63 | "object" { return(OBJECT); }
64 | "operator" { return(OPRT); }
65 | "override" { return(OVRD); }
66 | "params" { return(PARAMS); }
67 | "readonly" { return(REDY); }
68 | "ref" { return(REF); }
69 | "sbyte" { return(SBYTE); }
70 | "sealed" { return(SEALED); }
71 | "stackalloc" { return(STALLC); }
72 | "string" { return(STRING); }
73 | "true" { return(TRU); }
74 | "typeof" { return(TYPEOF); }
75 | "uint" { return(UINT); }
76 | "ulong" { return(ULONG); }
77 | "unchecked" { return(UCEKD); }
78 | "unsafe" { return(USFE); }
79 | "ushort" { return(USHORT); }
80 | "using" { return(USING); }
81 | "virtual" { return(VIR); }
82 | "auto" { return(AUTO); }
83 | "abstract" { return(ABS); }
84 | "break" { return(BREAK); }
85 | "case" { return(CASE); }
86 | "char" { return(CHAR); }
87 | "const" { return(CONST); }
88 | "new" { return(NEW); }
89 | "assert" { return(ASSERT); }
90 | "continue" { return(CONTINUE); }
91 | "default" { return(DEFAULT); }
92 | "do" { return(DO); }
93 | "double" { return(DOUBLE); }
94 | "byte" { return(BYTE); }
95 | "public" { return(PUBLIC); }
96 | "throws" { return(THROWS); }
97 | "instanceof" { return(INSOF); }
98 | "transient" { return(TRANS); }
99 | "catch" { return(CATCH); }
100 | "extends" { return(EXTENDS); }
101 | "try" { return(TRY); }
102 | "final" { return(FINAL); }
103 | "interface" { return(INTER); }
104 | "class" { return(CLASS); }
105 | "finally" { return(FINALLY); }
106 | "strictfp" { return(STRICT); }
107 | "native" { return(NATIVE); }
108 | "super" { return(SUPER); }
109 | "implements" { return(IMP); }
110 | "protected" { return(PROT); }
111 | "throw" { return(THROW); }
112 | "else" { return(ELSE); }
113 | "enum" { return(ENUM); }
114 | "extern" { return(EXTERN); }
115 | "float" { return(FLOAT); }
116 | "synchronized" { return(SYN); }
117 | "boolean" { return(BOOLEAN); }
118 | "for" { return(FOR); }
119 | "goto" { return(GOTO); }
120 | "private" { return(PRI); }
121 | "this" { return(THIS); }
122 | "if" { return(IF); }
123 | "inline" { return(INLINE); }
124 | "int" { return(INT); }
125 | "long" { return(LONG); }
126 | "register" { return(REGISTER); }
127 | "restrict" { return(RESTRICT); }
128 | "return" { return(RETURN); }
129 | "short" { return(SHORT); }
130 | "signed" { return(SIGNED); }
131 | "sizeof" { return(SIZEOF); }
132 | "static" { return(STATIC); }
133 | "struct" { return(STRUCT); }
134 | "switch" { return(SWITCH); }
135 | "typedef" { return(TYPEDEF); }
136 | "union" { return(UNION); }
137 | "unsigned" { return(UNSIGNED); }
138 | "void" { return(VOID); }
139 | "volatile" { return(VOLATILE); }
140 | "while" { return(WHILE); }
141 | "_Alignas" { return (ALIGNAS); }
142 | "_Alignof" { return (ALIGNOF); }
143 | "_Atomic" { return (ATOMIC); }
144 | "_Bool" { return (BOOL); }
145 | "_Complex" { return (COMPLEX); }
146 | "_Generic" { return (GENERIC); }
147 | "_Imaginary" { return (IMAGINARY); }
148 | "_Noreturn" { return (NORETURN); }
149 | "_Static_assert" { return (STATIC_ASSERT); }
150 | "_Thread_local" { return (THREAD_LOCAL); }
151 | "__func__" { return (FUNC_NAME); }
152 |
153 | {L}{A}* { var_val = yytext; return check_type(); }
154 |
155 | {HP}{H}+{IS}? { return I_CONSTANT; }
156 | {NZ}{D}*{IS}? { return I_CONSTANT; }
157 | "0"{O}*{IS}? { return I_CONSTANT; }
158 | {CP}?"'"([^'\\\n]|{ES})+"'" { return I_CONSTANT; }
159 |
160 | {D}+{E}{FS}? { return F_CONSTANT; }
161 | {D}*"."{D}+{E}?{FS}? { return F_CONSTANT; }
162 | {D}+"."{E}?{FS}? { return F_CONSTANT; }
163 | {HP}{H}+{P}{FS}? { return F_CONSTANT; }
164 | {HP}{H}*"."{H}+{P}{FS}? { return F_CONSTANT; }
165 | {HP}{H}+"."{P}{FS}? { return F_CONSTANT; }
166 |
167 | ({SP}?\"([^"\\\n]|{ES})*\"{WS}*)+ { return STRING_LITERAL; }
168 |
169 | "..." { return ELLIPSIS; }
170 | ">>=" { return RIGHT_ASSIGN; }
171 | "<<=" { return LEFT_ASSIGN; }
172 | "+=" { return ADD_ASSIGN; }
173 | "-=" { return SUB_ASSIGN; }
174 | "*=" { return MUL_ASSIGN; }
175 | "/=" { return DIV_ASSIGN; }
176 | "%=" { return MOD_ASSIGN; }
177 | "&=" { return AND_ASSIGN; }
178 | "^=" { return XOR_ASSIGN; }
179 | "|=" { return OR_ASSIGN; }
180 | ">>" { return RIGHT_OP; }
181 | "<<" { return LEFT_OP; }
182 | "++" { return INC_OP; }
183 | "--" { return DEC_OP; }
184 | "->" { return PTR_OP; }
185 | "&&" { return AND_OP; }
186 | "||" { return OR_OP; }
187 | "<=" { return LE_OP; }
188 | ">=" { return GE_OP; }
189 | "==" { return EQ_OP; }
190 | "!=" { return NE_OP; }
191 | ";" { return ';'; }
192 | ("{"|"<%") { return '{'; }
193 | ("}"|"%>") { return '}'; }
194 | "," { return ','; }
195 | ":" { return ':'; }
196 | "=" { return '='; }
197 | "(" { return '('; }
198 | ")" { return ')'; }
199 | ("["|"<:") { return '['; }
200 | ("]"|":>") { return ']'; }
201 | "." { return '.'; }
202 | "&" { return '&'; }
203 | "!" { return '!'; }
204 | "~" { return '~'; }
205 | "-" { return '-'; }
206 | "+" { return '+'; }
207 | "*" { return '*'; }
208 | "/" { return '/'; }
209 | "%" { return '%'; }
210 | "<" { return '<'; }
211 | ">" { return '>'; }
212 | "^" { return '^'; }
213 | "|" { return '|'; }
214 | "?" { return '?'; }
215 |
216 | {WS}+ { /* whitespace separates tokens */ }
217 | . { /* discard bad characters */ }
218 |
219 | %%
220 |
221 | int yywrap(void) /* called at end of input */
222 | {
223 | return 1; /* terminate now */
224 | }
225 |
226 | static void comment(void)
227 | {
228 | int c;
229 | int flag = 0;
230 |
231 | while ((c = yyinput()) != 0)
232 | {
233 | flag = 0;
234 | if (c == '*')
235 | {
236 | while ((c = yyinput()) == '*')
237 | ;
238 |
239 | if (c == '/')
240 | return;
241 |
242 | if (c == 0)
243 | break;
244 |
245 | if (c == '\n')
246 | {
247 | //printf("cline: %d\n", nline);
248 | nline++;
249 | flag = 1;
250 | }
251 | }
252 | if (flag == 0 && c == '\n')
253 | {
254 | //printf("cline: %d\n", nline);
255 | nline ++;
256 | }
257 | }
258 | //yyerror("unterminated comment");
259 | }
260 |
261 | static int check_type(void)
262 | {
263 |
264 | //switch (sym_type(yytext))
265 | //{
266 | //case TYPEDEF_NAME: /* previously defined */
267 | // return TYPEDEF_NAME;
268 | //case ENUMERATION_CONSTANT: /* previously defined */
269 | // return ENUMERATION_CONSTANT;
270 | //default: /* includes undefined */
271 | return IDENTIFIER;
272 | //}
273 | }
274 |
--------------------------------------------------------------------------------
/lexical/src/config/lexerBK.l:
--------------------------------------------------------------------------------
1 | /* config/lexer.l */
2 | %{
3 | #include "tok.h"
4 | #include
5 | char * readString();
6 | %}
7 |
8 | delim [ \n\t]
9 | ws {delim}+
10 | letter [A-Za-z]
11 | digit [0-9]
12 | /* identifier */
13 | id {letter}({letter}|{digit})*
14 | /* Integer */
15 | number {digit}+
16 |
17 | %%
18 | {ws} {/* No actions */}
19 |
20 | "while" {return(WHILE);}
21 | "const" {return(CONST);}
22 | "int" {return(INT);}
23 | "void" {return(VOID);}
24 | "return" {return(RETURN);}
25 | "else" {return(ELSE);}
26 | "if" {return(IF);}
27 |
28 | {number} {var_val = readString(); return(NUMBER);}
29 | {id} {var_val = readString(); return(ID);}
30 |
31 | "==" {yylval = EQUAL; return(RELOP); }
32 | "!=" {yylval = UNEQUAL; return(RELOP); }
33 | "<" {yylval = LT; return(RELOP);}
34 | ">" {yylval = GT; return(RELOP);}
35 | "<=" {yylval = LE; return(RELOP);}
36 | ">=" {yylval = GE; return(RELOP);}
37 |
38 | "=" {return(ASSIGN);}
39 |
40 | ";" {yylval = ';'; return(PUNCTUATION);}
41 | "(" {yylval = '('; return(PUNCTUATION);}
42 | ")" {yylval = ')'; return(PUNCTUATION);}
43 | "[" {yylval = '['; return(PUNCTUATION);}
44 | "]" {yylval = ']'; return(PUNCTUATION);}
45 | "." {yylval = '.'; return(PUNCTUATION);}
46 | "-" {yylval = '-'; return(BINOP_UNARYOP);}
47 | "+" {yylval = '+'; return(BINOP_UNARYOP);}
48 | "*" {yylval = '*'; return(BINOP);}
49 | "/" {yylval = '/'; return(BINOP);}
50 | "%" {yylval = '%'; return(BINOP);}
51 | . { /* discard bad characters */ }
52 |
53 | %%
54 |
55 | int yywrap()
56 | {
57 | return 1;
58 | }
59 |
60 | char * readString()
61 | {
62 | char * string;
63 | int i;
64 | string = (char *)malloc((yyleng + 1) * sizeof(char));
65 | for(i = 0; i < yyleng; i++)
66 | {
67 | string[i] = yytext[i];
68 | }
69 | string[i] = '\0';
70 | return string;
71 | }
--------------------------------------------------------------------------------
/lexical/src/fileProcess.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #define MAX_PATH_LEN 512
10 |
11 | int count =0;
12 | char dirPath[MAX_PATH_LEN];
13 |
14 | void listAllFiles(char *dirname)
15 | {
16 | assert(dirname != NULL);
17 |
18 | char path[512];
19 | struct dirent *filename;//readdir 的返回类型
20 | DIR *dir;//血的教训阿,不要随便把变量就设成全局变量。。。。
21 |
22 | dir = opendir(dirname);
23 | if(dir == NULL)
24 | {
25 | printf("open dir %s error!\n",dirname);
26 | exit(1);
27 | }
28 |
29 | while((filename = readdir(dir)) != NULL)
30 | {
31 | //目录结构下面问什么会有两个.和..的目录? 跳过着两个目录
32 | if(!strcmp(filename->d_name,".")||!strcmp(filename->d_name,".."))
33 | continue;
34 |
35 | //非常好用的一个函数,比什么字符串拼接什么的来的快的多
36 | sprintf(path,"%s/%s",dirname,filename->d_name);
37 |
38 | struct stat s;
39 | lstat(path,&s);
40 |
41 | if(S_ISDIR(s.st_mode))
42 | {
43 | listAllFiles(path);//递归调用
44 | }
45 | else
46 | {
47 | printf("%d. %s\n",++count,filename->d_name);
48 | }
49 | }
50 | closedir(dir);
51 | }
52 |
53 |
54 | int main(int argc, char **argv)
55 | {
56 |
57 | if(argc != 2)
58 | {
59 | printf("one dir required!(for eample: ./a.out /home/myFolder)\n");
60 | exit(1);
61 | }
62 | strcpy(dirPath,argv[1]);
63 | listAllFiles(dirPath);
64 | printf("total files:%d\n",count);
65 | return 0;
66 | }
--------------------------------------------------------------------------------
/lexical/src/include/tok.h:
--------------------------------------------------------------------------------
1 | #ifndef TOK_H
2 | #define TOK_H
3 |
4 | enum {
5 | AUTO=256,
6 | BREAK,
7 | CASE,
8 | CHAR,
9 | CONST,
10 | CONTINUE,
11 | DEFAULT,
12 | DO,
13 | DOUBLE,
14 | ELSE,
15 | ABS,
16 | NEW,
17 | ASSERT,
18 | BYTE,
19 | //IMPORT,
20 | PUBLIC,
21 | THROWS,
22 | INSOF,
23 | TRANS,
24 | AS,
25 | BASE,
26 | CHECKED,
27 | DECIMAL,
28 | DELEGATE,
29 | EVENT,
30 | EXPLICIT,
31 | FALS,
32 | FIXED,
33 | FEACH,
34 | IMPLICIT,
35 | INTERNAL,
36 | LOCK,
37 | NSPA,
38 | NUL,
39 | OBJECT,
40 | OPRT,
41 | OVRD,
42 | PARAMS,
43 | REDY,
44 | REF,
45 | SBYTE,
46 | SEALED,
47 | STALLC,
48 | STRING,
49 | TRU,
50 | TYPEOF,
51 | UINT,
52 | ULONG,
53 | UCEKD,
54 | USFE,
55 | USHORT,
56 | USING,
57 | VIR,
58 | CATCH,
59 | EXTENDS,
60 | TRY,
61 | FINAL,
62 | INTER,
63 | CLASS,
64 | FINALLY,
65 | STRICT,
66 | NATIVE,
67 | SUPER,
68 | IMP,
69 | PROT,
70 | THROW,
71 | PACK,
72 | SYN,
73 | BOOLEAN,
74 | PRI,
75 | THIS,
76 | ENUM,
77 | EXTERN,
78 | FLOAT,
79 | FOR,
80 | GOTO,
81 | IF,
82 | INLINE,
83 | INT,
84 | LONG,
85 | REGISTER,
86 | RESTRICT,
87 | RETURN,
88 | SHORT,
89 | SIGNED,
90 | SIZEOF,
91 | STATIC,
92 | STRUCT,
93 | SWITCH,
94 | TYPEDEF,
95 | UNION,
96 | UNSIGNED,
97 | VOID,
98 | VOLATILE,
99 | WHILE,
100 | ALIGNAS,
101 | ALIGNOF,
102 | ATOMIC,
103 | BOOL,
104 | COMPLEX,
105 | GENERIC,
106 | IMAGINARY,
107 | NORETURN,
108 | STATIC_ASSERT,
109 | THREAD_LOCAL,
110 | FUNC_NAME,
111 | I_CONSTANT,
112 | F_CONSTANT,
113 | STRING_LITERAL,
114 | ELLIPSIS,
115 | RIGHT_ASSIGN,
116 | LEFT_ASSIGN,
117 | ADD_ASSIGN,
118 | SUB_ASSIGN,
119 | MUL_ASSIGN,
120 | DIV_ASSIGN,
121 | MOD_ASSIGN,
122 | AND_ASSIGN,
123 | XOR_ASSIGN,
124 | OR_ASSIGN,
125 | RIGHT_OP,
126 | LEFT_OP,
127 | INC_OP,
128 | DEC_OP,
129 | PTR_OP,
130 | AND_OP,
131 | OR_OP,
132 | LE_OP,
133 | GE_OP,
134 | EQ_OP,
135 | NE_OP,
136 | TYPEDEF_NAME,
137 | ENUMERATION_CONSTANT,
138 | IDENTIFIER
139 | };
140 |
141 |
142 | //声明语义值如下
143 | extern char* var_val;
144 | extern int yylval;
145 |
146 | #endif
147 |
--------------------------------------------------------------------------------
/lexical/src/singleclone.cpp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/lexical/src/singleclone.cpp
--------------------------------------------------------------------------------
/lexical/src/tok.cpp:
--------------------------------------------------------------------------------
1 | char* var_val;
2 | int yylval;
--------------------------------------------------------------------------------
/output/1clones_6_0.6:
--------------------------------------------------------------------------------
1 | /home/wpc/Example/1.java,1,19,/home/wpc/Example/13.java,1,31
2 | /home/wpc/Example/1.java,1,19,/home/wpc/Example/2.java,1,20
3 | /home/wpc/Example/10.java,1,28,/home/wpc/Example/2.java,1,20
4 | /home/wpc/Example/5.java,1,23,/home/wpc/Example/original.java,1,18
5 | /home/wpc/Example/2.java,1,20,/home/wpc/Example/20.java,1,34
6 | /home/wpc/Example/6.java,1,24,/home/wpc/Example/original.java,1,18
7 | /home/wpc/Example/11.java,1,29,/home/wpc/Example/original.java,1,18
8 |
--------------------------------------------------------------------------------
/output/2clones_6_0.6:
--------------------------------------------------------------------------------
1 | /home/wpc/Example/original.java,1,18,/home/wpc/Example/13.java,1,31
2 | /home/wpc/Example/5.java,1,23,/home/wpc/Example/1.java,1,19
3 | /home/wpc/Example/original.java,1,18,/home/wpc/Example/9.java,1,27
4 | /home/wpc/Example/1.java,1,19,/home/wpc/Example/8.java,1,26
5 | /home/wpc/Example/8.java,1,26,/home/wpc/Example/original.java,1,18
6 | /home/wpc/Example/6.java,1,24,/home/wpc/Example/2.java,1,20
7 | /home/wpc/Example/11.java,1,29,/home/wpc/Example/1.java,1,19
8 |
--------------------------------------------------------------------------------
/output/3clones_6_0.6:
--------------------------------------------------------------------------------
1 | /home/wpc/Example/10.java,1,28,/home/wpc/Example/1.java,1,19
2 | /home/wpc/Example/5.java,1,23,/home/wpc/Example/6.java,1,24
3 | /home/wpc/Example/1.java,1,19,/home/wpc/Example/20.java,1,34
4 | /home/wpc/Example/2.java,1,20,/home/wpc/Example/12.java,1,30
5 |
--------------------------------------------------------------------------------
/output/4clones_6_0.6:
--------------------------------------------------------------------------------
1 | /home/wpc/Example/5.java,1,23,/home/wpc/Example/20.java,1,34
2 |
--------------------------------------------------------------------------------
/output/5clones_6_0.6:
--------------------------------------------------------------------------------
1 | /home/wpc/Example/original.java,1,18,/home/wpc/Example/20.java,1,34
2 | /home/wpc/Example/16.java,1,35,/home/wpc/Example/2.java,1,20
3 | /home/wpc/Example/10.java,1,28,/home/wpc/Example/original.java,1,18
4 | /home/wpc/Example/5.java,1,23,/home/wpc/Example/2.java,1,20
5 | /home/wpc/Example/original.java,1,18,/home/wpc/Example/18.java,1,37
6 | /home/wpc/Example/original.java,1,18,/home/wpc/Example/12.java,1,30
7 | /home/wpc/Example/17.java,1,36,/home/wpc/Example/1.java,1,19
8 | /home/wpc/Example/1.java,1,19,/home/wpc/Example/3.java,1,21
9 | /home/wpc/Example/17.java,1,36,/home/wpc/Example/original.java,1,18
10 |
--------------------------------------------------------------------------------
/output/6clones_6_0.6:
--------------------------------------------------------------------------------
1 | /home/wpc/Example/3.java,1,21,/home/wpc/Example/original.java,1,18
2 | /home/wpc/Example/4.java,1,22,/home/wpc/Example/original.java,1,18
3 | /home/wpc/Example/4.java,1,22,/home/wpc/Example/1.java,1,19
4 | /home/wpc/Example/1.java,1,19,/home/wpc/Example/12.java,1,30
5 | /home/wpc/Example/19.java,1,38,/home/wpc/Example/original.java,1,18
6 |
--------------------------------------------------------------------------------
/output/7clones_6_0.6:
--------------------------------------------------------------------------------
1 | /home/wpc/Example/original.java,1,18,/home/wpc/Example/2.java,1,20
2 | /home/wpc/Example/1.java,1,19,/home/wpc/Example/6.java,1,24
3 | /home/wpc/Example/2.java,1,20,/home/wpc/Example/9.java,1,27
4 | /home/wpc/Example/1.java,1,19,/home/wpc/Example/original.java,1,18
5 |
--------------------------------------------------------------------------------
/output/8clones_6_0.6:
--------------------------------------------------------------------------------
1 | /home/wpc/Example/19.java,1,38,/home/wpc/Example/1.java,1,19
2 | /home/wpc/Example/16.java,1,35,/home/wpc/Example/original.java,1,18
3 | /home/wpc/Example/1.java,1,19,/home/wpc/Example/16.java,1,35
4 | /home/wpc/Example/1.java,1,19,/home/wpc/Example/18.java,1,37
5 | /home/wpc/Example/1.java,1,19,/home/wpc/Example/9.java,1,27
6 |
--------------------------------------------------------------------------------
/parser:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/parser
--------------------------------------------------------------------------------
/runner:
--------------------------------------------------------------------------------
1 | ulimit -s hard
2 |
3 | #! dir of the tool
4 | cd /home/wpc/CCAligner/
5 |
6 | rm -rf input/*
7 | rm -rf output/*
8 | # due to large num of files, 'rm -rf token/*' doesn't work
9 | cd token
10 | find ./ -type f -delete
11 | cd ..
12 | rm function.file > /dev/null 2> /dev/null
13 | rm tokenline_num > /dev/null 2> /dev/null
14 | rm clones > /dev/null 2> /dev/null
15 | # compile
16 | cd txl
17 | chmod +x *.x
18 | cd ..
19 | cd lexical
20 | make clean > /dev/null 2> /dev/null
21 | make > /dev/null 2> /dev/null
22 | cd ..
23 |
24 |
25 | # start timing
26 | date
27 |
28 | #! parser functions: ./extract 'txl' 'language' 'functions' 'source code' 'output' 'thread num'
29 | ./extract ./txl java functions /home/wpc/Example ./input 8 > /dev/null 2> /dev/null
30 | #if c: ./extract ./txl c .. ; if c#:./extract ./txl cs ..
31 |
32 | ./parser ./input ./ 5 > /dev/null 2> /dev/null
33 |
34 | #tokenize: ./tokenize 'function.file' 'token' 'output' 'thread num'
35 | ./tokenize ./function.file ./token ./ 8 > /dev/null 2> /dev/null
36 |
37 | #detect: ./detect 'token files' 'Output' 'function_frag.file' 'window size of token' 'edit-dist' 'similarity'
38 | ./detect ./token ./output ./function.file 6 1 0.6 > /dev/null 2> /dev/null
39 | #or using filter-version by following (more faster):
40 | #./detect2 ./token ./output ./function.file 6 1 0.6 > /dev/null 2> /dev/null
41 | ./co1 ./output ./ > /dev/null 2> /dev/null
42 |
43 | # end timing
44 | date
45 |
--------------------------------------------------------------------------------
/token/0.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | IFLPidNE_OPNULRP
3 | iddotiddotiddotidLKRKidop_assignNEWiddotiddotiddotidLKCONSTANTRKsemi
4 | THROWNEWidLPidLPRPdotidLPRPcommaidLPRPdotidLPRPRPsemi
5 | THROWNEWidLPSTRING_LITERALRPsemi
6 | iddotidLPidcommaidRPsemi
7 | idLKidINC_OPRKop_assignLPidop_plusidLKidop_plusCONSTANTRKop_staridop_plusidLKidop_plusCONSTANTRKop_staridRPsemi
8 | ididop_assignNEWidLPSTRING_LITERALRPsemi
9 | iddotidLPiddotidLPRPcommaidRPsemi
10 | idop_assignLPidop_dividop_staridRPop_plusidsemi
11 | IFLPidRP
12 | iddotiddotidLPSTRING_LITERALop_plusidRPsemi
13 | idREFop_assigniddotidLPidcommaidcommaCONSTANTRPsemi
14 | iddotidLPNEWidLPidRPRPsemi
15 | ididop_assignNEWidLPRPsemi
16 | INTidop_assignidLKidLPidRPop_minusidRKsemi
17 | RETURNiddotidLPTHISRPdotidLPRPsemi
18 | ididop_assignLPidRPiddotidLPRPsemi
19 | iddotidLPiddotidcommaiddotidcommaiddotidop_minusCONSTANTcommaiddotidop_minusCONSTANTRPsemi
20 | idLKiddotidop_minusCONSTANTRKop_assignLPBYTERPLPidRIGHT_OPCONSTANTRPsemi
21 | idLPSTRING_LITERALcommaiddotidLPRPdotidLPSTRING_LITERALRPRPsemi
22 | iddotidLPidRPsemi
23 | LPLPidRPLPiddotidLPCONSTANTRPRPRPdotidLPidRPsemi
24 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
25 | RB
26 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
27 | iddotidLPRPsemi
28 | RB
29 | RB
30 | RETURNidsemi
31 | RB
32 |
--------------------------------------------------------------------------------
/token/1.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | idLKidINC_OPRKop_assignLPidop_plusidLKidop_plusCONSTANTRKop_staridop_plusidLKidop_plusCONSTANTRKop_staridRPsemi
3 | idLKiddotidop_minusCONSTANTRKop_assignLPBYTERPLPidRIGHT_OPCONSTANTRPsemi
4 | RETURNiddotidLPTHISRPdotidLPRPsemi
5 | THROWNEWidLPSTRING_LITERALRPsemi
6 | iddotiddotiddotidLKRKidop_assignNEWiddotiddotiddotidLKCONSTANTRKsemi
7 | IFLPidNE_OPNULRP
8 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
9 | RB
10 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
11 | iddotidLPRPsemi
12 | RB
13 | RB
14 | RETURNidsemi
15 | RB
16 |
--------------------------------------------------------------------------------
/token/10.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | IFLPidNE_OPNULRP
3 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
4 | RB
5 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
6 | iddotidLPRPsemi
7 | RB
8 | RB
9 | RETURNidsemi
10 | iddotidLPidRPsemi
11 | idREFop_assigniddotidLPidcommaidcommaCONSTANTRPsemi
12 | iddotidLPiddotidcommaiddotidcommaiddotidop_minusCONSTANTcommaiddotidop_minusCONSTANTRPsemi
13 | IFLPidRP
14 | iddotiddotidLPSTRING_LITERALop_plusidRPsemi
15 | idop_assignLPidop_dividop_staridRPop_plusidsemi
16 | ididop_assignNEWidLPSTRING_LITERALRPsemi
17 | THROWNEWidLPidLPRPdotidLPRPcommaidLPRPdotidLPRPRPsemi
18 | idLKiddotidop_minusCONSTANTRKop_assignLPBYTERPLPidRIGHT_OPCONSTANTRPsemi
19 | iddotidLPiddotidLPRPcommaidRPsemi
20 | THROWNEWidLPSTRING_LITERALRPsemi
21 | LPLPidRPLPiddotidLPCONSTANTRPRPRPdotidLPidRPsemi
22 | INTidop_assignidLKidLPidRPop_minusidRKsemi
23 | RB
24 |
--------------------------------------------------------------------------------
/token/11.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPiddotidLPidcommaidRPsemi
2 | idLKidINC_OPRKop_assignLPidop_plusidLKidop_plusCONSTANTRKop_staridop_plusidLKidop_plusCONSTANTRKop_staridRPsemi
3 | LPLPidRPLPiddotidLPCONSTANTRPRPRPdotidLPidRPsemi
4 | iddotidLPNEWidLPidRPRPsemi
5 | THROWNEWidLPSTRING_LITERALRPsemi
6 | IFLPidRP
7 | iddotiddotidLPSTRING_LITERALop_plusidRPsemi
8 | ididop_assignNEWidLPRPsemi
9 | iddotiddotiddotidLKRKidop_assignNEWiddotiddotiddotidLKCONSTANTRKsemi
10 | idLPSTRING_LITERALcommaiddotidLPRPdotidLPSTRING_LITERALRPRPsemi
11 | INTidop_assignidLKidLPidRPop_minusidRKsemi
12 | ididop_assignidsemi
13 | IFLPidNE_OPNULRP
14 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
15 | RB
16 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
17 | iddotidLPRPsemi
18 | RB
19 | RB
20 | RETURNidsemi
21 | RB
22 |
--------------------------------------------------------------------------------
/token/12.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | IFLPidNE_OPNULRP
3 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
4 | RB
5 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
6 | idREFop_assigniddotidLPidcommaidcommaCONSTANTRPsemi
7 | iddotidLPiddotidcommaiddotidcommaiddotidop_minusCONSTANTcommaiddotidop_minusCONSTANTRPsemi
8 | idLKidINC_OPRKop_assignLPidop_plusidLKidop_plusCONSTANTRKop_staridop_plusidLKidop_plusCONSTANTRKop_staridRPsemi
9 | idop_assignLPidop_dividop_staridRPop_plusidsemi
10 | ididop_assignLPidRPiddotidLPRPsemi
11 | iddotidLPiddotidLPRPcommaidRPsemi
12 | iddotiddotiddotidLKRKidop_assignNEWiddotiddotiddotidLKCONSTANTRKsemi
13 | RETURNiddotidLPTHISRPdotidLPRPsemi
14 | THROWNEWidLPSTRING_LITERALRPsemi
15 | IFLPidRP
16 | iddotiddotidLPSTRING_LITERALop_plusidRPsemi
17 | idLPSTRING_LITERALcommaiddotidLPRPdotidLPSTRING_LITERALRPRPsemi
18 | ididop_assignNEWidLPSTRING_LITERALRPsemi
19 | idLKiddotidop_minusCONSTANTRKop_assignLPBYTERPLPidRIGHT_OPCONSTANTRPsemi
20 | iddotidLPNEWidLPidRPRPsemi
21 | iddotidLPRPsemi
22 | RB
23 | RB
24 | RETURNidsemi
25 | RB
26 |
--------------------------------------------------------------------------------
/token/13.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | IFLPidNE_OPNULRP
3 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
4 | RB
5 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
6 | iddotidLPRPsemi
7 | RB
8 | RB
9 | idLKidINC_OPRKop_assignLPidop_plusidLKidop_plusCONSTANTRKop_staridop_plusidLKidop_plusCONSTANTRKop_staridRPsemi
10 | iddotidLPNEWidLPidRPRPsemi
11 | ididop_assignNEWidLPRPsemi
12 | ididop_assignLPidRPiddotidLPRPsemi
13 | iddotidLPidRPsemi
14 | idLPSTRING_LITERALcommaiddotidLPRPdotidLPSTRING_LITERALRPRPsemi
15 | idop_assignLPidop_dividop_staridRPop_plusidsemi
16 | THROWNEWidLPSTRING_LITERALRPsemi
17 | RETURNidsemi
18 | RB
19 |
--------------------------------------------------------------------------------
/token/14.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | IFLPidNE_OPNULRP
3 | TRYidLPSTRING_LITERALcommaiddotidLPRPdotidLPSTRING_LITERALRPRPsemi
4 | IFLPidRP
5 | iddotiddotidLPSTRING_LITERALop_plusidRPsemi
6 | ididop_assignLPidRPiddotidLPRPsemi
7 | idLKiddotidop_minusCONSTANTRKop_assignLPBYTERPLPidRIGHT_OPCONSTANTRPsemi
8 | iddotidLPidRPsemi
9 | idop_assignLPidop_dividop_staridRPop_plusidsemi
10 | iddotidLPidcommaidRPsemi
11 | LPLPidRPLPiddotidLPCONSTANTRPRPRPdotidLPidRPsemi
12 | iddotidLPiddotidcommaiddotidcommaiddotidop_minusCONSTANTcommaiddotidop_minusCONSTANTRPsemi
13 | THROWNEWidLPSTRING_LITERALRPsemi
14 | INTidop_assignidLKidLPidRPop_minusidRKsemi
15 | RETURNiddotidLPTHISRPdotidLPRPsemi
16 | ididop_assignNEWidLPRPsemi
17 | idop_assigniddotidLPNEWidLKRKidRBRPsemi
18 | RB
19 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
20 | iddotidLPRPsemi
21 | RB
22 | RB
23 | RETURNidsemi
24 | RB
25 |
--------------------------------------------------------------------------------
/token/15.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | IFLPidNE_OPNULRP
3 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
4 | RB
5 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
6 | iddotidLPRPsemi
7 | RB
8 | RB
9 | ididop_assignLPidRPiddotidLPRPsemi
10 | iddotidLPiddotidLPRPcommaidRPsemi
11 | idLKiddotidop_minusCONSTANTRKop_assignLPBYTERPLPidRIGHT_OPCONSTANTRPsemi
12 | idLKidINC_OPRKop_assignLPidop_plusidLKidop_plusCONSTANTRKop_staridop_plusidLKidop_plusCONSTANTRKop_staridRPsemi
13 | THROWNEWidLPidLPRPdotidLPRPcommaidLPRPdotidLPRPRPsemi
14 | ididop_assignNEWidLPRPsemi
15 | idLPSTRING_LITERALcommaiddotidLPRPdotidLPSTRING_LITERALRPRPsemi
16 | ididop_assignNEWidLPSTRING_LITERALRPsemi
17 | RETURNiddotidLPTHISRPdotidLPRPsemi
18 | iddotiddotiddotidLKRKidop_assignNEWiddotiddotiddotidLKCONSTANTRKsemi
19 | INTidop_assignidLKidLPidRPop_minusidRKsemi
20 | iddotidLPidRPsemi
21 | iddotidLPNEWidLPidRPRPsemi
22 | iddotidLPiddotidcommaiddotidcommaiddotidop_minusCONSTANTcommaiddotidop_minusCONSTANTRPsemi
23 | THROWNEWidLPSTRING_LITERALRPsemi
24 | IFLPidRP
25 | iddotiddotidLPSTRING_LITERALop_plusidRPsemi
26 | LPLPidRPLPiddotidLPCONSTANTRPRPRPdotidLPidRPsemi
27 | idop_assignLPidop_dividop_staridRPop_plusidsemi
28 | idREFop_assigniddotidLPidcommaidcommaCONSTANTRPsemi
29 | RETURNidsemi
30 | RB
31 |
--------------------------------------------------------------------------------
/token/16.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | IFLPidNE_OPNULRP
3 | iddotidLPiddotidcommaiddotidcommaiddotidop_minusCONSTANTcommaiddotidop_minusCONSTANTRPsemi
4 | idop_assignLPidop_dividop_staridRPop_plusidsemi
5 | ididop_assignNEWidLPRPsemi
6 | idLPSTRING_LITERALcommaiddotidLPRPdotidLPSTRING_LITERALRPRPsemi
7 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
8 | RB
9 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
10 | iddotidLPRPsemi
11 | RB
12 | RB
13 | RETURNidsemi
14 | RB
15 |
--------------------------------------------------------------------------------
/token/17.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | IFLPidNE_OPNULRP
3 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
4 | idLPSTRING_LITERALcommaiddotidLPRPdotidLPSTRING_LITERALRPRPsemi
5 | LPLPidRPLPiddotidLPCONSTANTRPRPRPdotidLPidRPsemi
6 | ididop_assignNEWidLPSTRING_LITERALRPsemi
7 | RB
8 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
9 | iddotidLPRPsemi
10 | RB
11 | RB
12 | RETURNidsemi
13 | RB
14 |
--------------------------------------------------------------------------------
/token/18.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | IFLPidNE_OPNULRP
3 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
4 | RB
5 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
6 | iddotidLPRPsemi
7 | idop_assignLPidop_dividop_staridRPop_plusidsemi
8 | ididop_assignNEWidLPRPsemi
9 | iddotiddotiddotidLKRKidop_assignNEWiddotiddotiddotidLKCONSTANTRKsemi
10 | idLPSTRING_LITERALcommaiddotidLPRPdotidLPSTRING_LITERALRPRPsemi
11 | ididop_assignNEWidLPSTRING_LITERALRPsemi
12 | IFLPidRP
13 | iddotiddotidLPSTRING_LITERALop_plusidRPsemi
14 | idREFop_assigniddotidLPidcommaidcommaCONSTANTRPsemi
15 | iddotidLPiddotidLPRPcommaidRPsemi
16 | iddotidLPNEWidLPidRPRPsemi
17 | INTidop_assignidLKidLPidRPop_minusidRKsemi
18 | idLKiddotidop_minusCONSTANTRKop_assignLPBYTERPLPidRIGHT_OPCONSTANTRPsemi
19 | iddotidLPidRPsemi
20 | iddotidLPidcommaidRPsemi
21 | idLKidINC_OPRKop_assignLPidop_plusidLKidop_plusCONSTANTRKop_staridop_plusidLKidop_plusCONSTANTRKop_staridRPsemi
22 | THROWNEWidLPidLPRPdotidLPRPcommaidLPRPdotidLPRPRPsemi
23 | RB
24 | RB
25 | RETURNidsemi
26 | RB
27 |
--------------------------------------------------------------------------------
/token/19.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | IFLPidNE_OPNULRP
3 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
4 | RB
5 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
6 | iddotidLPRPsemi
7 | LPLPidRPLPiddotidLPCONSTANTRPRPRPdotidLPidRPsemi
8 | ididop_assignNEWidLPSTRING_LITERALRPsemi
9 | idREFop_assigniddotidLPidcommaidcommaCONSTANTRPsemi
10 | iddotidLPiddotidcommaiddotidcommaiddotidop_minusCONSTANTcommaiddotidop_minusCONSTANTRPsemi
11 | idLPSTRING_LITERALcommaiddotidLPRPdotidLPSTRING_LITERALRPRPsemi
12 | iddotidLPidcommaidRPsemi
13 | RETURNiddotidLPTHISRPdotidLPRPsemi
14 | RB
15 | RB
16 | RETURNidsemi
17 | RB
18 |
--------------------------------------------------------------------------------
/token/2.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | IFLPidNE_OPNULRP
3 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
4 | RB
5 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
6 | iddotidLPRPsemi
7 | RB
8 | RB
9 | idREFop_assigniddotidLPidcommaidcommaCONSTANTRPsemi
10 | RETURNidsemi
11 | RB
12 |
--------------------------------------------------------------------------------
/token/20.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPidLKidINC_OPRKop_assignLPidop_plusidLKidop_plusCONSTANTRKop_staridop_plusidLKidop_plusCONSTANTRKop_staridRPsemi
2 | iddotidLPidRPsemi
3 | idREFop_assigniddotidLPidcommaidcommaCONSTANTRPsemi
4 | INTidop_assignidLKidLPidRPop_minusidRKsemi
5 | RETURNiddotidLPTHISRPdotidLPRPsemi
6 | THROWNEWidLPSTRING_LITERALRPsemi
7 | ididop_assignidsemi
8 | IFLPidNE_OPNULRP
9 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
10 | RB
11 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
12 | iddotidLPRPsemi
13 | RB
14 | RB
15 | RETURNidsemi
16 | RB
17 |
--------------------------------------------------------------------------------
/token/3.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | IFLPidNE_OPNULRP
3 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
4 | RB
5 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
6 | iddotidLPRPsemi
7 | RB
8 | RB
9 | ididop_assignNEWidLPSTRING_LITERALRPsemi
10 | idLKidINC_OPRKop_assignLPidop_plusidLKidop_plusCONSTANTRKop_staridop_plusidLKidop_plusCONSTANTRKop_staridRPsemi
11 | iddotidLPiddotidcommaiddotidcommaiddotidop_minusCONSTANTcommaiddotidop_minusCONSTANTRPsemi
12 | iddotidLPidcommaidRPsemi
13 | iddotiddotiddotidLKRKidop_assignNEWiddotiddotiddotidLKCONSTANTRKsemi
14 | ididop_assignNEWidLPRPsemi
15 | idREFop_assigniddotidLPidcommaidcommaCONSTANTRPsemi
16 | THROWNEWidLPSTRING_LITERALRPsemi
17 | iddotidLPNEWidLPidRPRPsemi
18 | ididop_assignLPidRPiddotidLPRPsemi
19 | iddotidLPidRPsemi
20 | RETURNidsemi
21 | RB
22 |
--------------------------------------------------------------------------------
/token/4.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | IFLPidNE_OPNULRP
3 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
4 | RB
5 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
6 | iddotidLPRPsemi
7 | RB
8 | RB
9 | RETURNidsemi
10 | THROWNEWidLPSTRING_LITERALRPsemi
11 | idREFop_assigniddotidLPidcommaidcommaCONSTANTRPsemi
12 | LPLPidRPLPiddotidLPCONSTANTRPRPRPdotidLPidRPsemi
13 | ididop_assignLPidRPiddotidLPRPsemi
14 | THROWNEWidLPidLPRPdotidLPRPcommaidLPRPdotidLPRPRPsemi
15 | iddotidLPiddotidLPRPcommaidRPsemi
16 | iddotiddotiddotidLKRKidop_assignNEWiddotiddotiddotidLKCONSTANTRKsemi
17 | iddotidLPidRPsemi
18 | RETURNiddotidLPTHISRPdotidLPRPsemi
19 | RB
20 |
--------------------------------------------------------------------------------
/token/5.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | IFLPidNE_OPNULRP
3 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
4 | RB
5 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
6 | iddotidLPRPsemi
7 | RB
8 | RB
9 | RETURNidsemi
10 | RB
11 |
--------------------------------------------------------------------------------
/token/6.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | RETURNiddotidLPTHISRPdotidLPRPsemi
3 | idLKiddotidop_minusCONSTANTRKop_assignLPBYTERPLPidRIGHT_OPCONSTANTRPsemi
4 | iddotidLPiddotidLPRPcommaidRPsemi
5 | idLKidINC_OPRKop_assignLPidop_plusidLKidop_plusCONSTANTRKop_staridop_plusidLKidop_plusCONSTANTRKop_staridRPsemi
6 | iddotidLPiddotidcommaiddotidcommaiddotidop_minusCONSTANTcommaiddotidop_minusCONSTANTRPsemi
7 | iddotidLPNEWidLPidRPRPsemi
8 | iddotidLPidRPsemi
9 | ididop_assignNEWidLPRPsemi
10 | idREFop_assigniddotidLPidcommaidcommaCONSTANTRPsemi
11 | THROWNEWidLPidLPRPdotidLPRPcommaidLPRPdotidLPRPRPsemi
12 | iddotidLPidcommaidRPsemi
13 | INTidop_assignidLKidLPidRPop_minusidRKsemi
14 | ididop_assignLPidRPiddotidLPRPsemi
15 | LPLPidRPLPiddotidLPCONSTANTRPRPRPdotidLPidRPsemi
16 | IFLPidRP
17 | iddotiddotidLPSTRING_LITERALop_plusidRPsemi
18 | THROWNEWidLPSTRING_LITERALRPsemi
19 | IFLPidNE_OPNULRP
20 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
21 | RB
22 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
23 | iddotidLPRPsemi
24 | RB
25 | RB
26 | RETURNidsemi
27 | RB
28 |
--------------------------------------------------------------------------------
/token/7.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPRETURNiddotidLPTHISRPdotidLPRPsemi
2 | idLKiddotidop_minusCONSTANTRKop_assignLPBYTERPLPidRIGHT_OPCONSTANTRPsemi
3 | ididop_assignidsemi
4 | IFLPidNE_OPNULRP
5 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
6 | RB
7 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
8 | iddotidLPRPsemi
9 | RB
10 | RB
11 | RETURNidsemi
12 | RB
13 |
--------------------------------------------------------------------------------
/token/8.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | IFLPidNE_OPNULRP
3 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
4 | RB
5 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
6 | iddotidLPRPsemi
7 | RB
8 | RB
9 | idLKidINC_OPRKop_assignLPidop_plusidLKidop_plusCONSTANTRKop_staridop_plusidLKidop_plusCONSTANTRKop_staridRPsemi
10 | LPLPidRPLPiddotidLPCONSTANTRPRPRPdotidLPidRPsemi
11 | idREFop_assigniddotidLPidcommaidcommaCONSTANTRPsemi
12 | ididop_assignNEWidLPRPsemi
13 | IFLPidRP
14 | iddotiddotidLPSTRING_LITERALop_plusidRPsemi
15 | iddotiddotiddotidLKRKidop_assignNEWiddotiddotiddotidLKCONSTANTRKsemi
16 | RETURNiddotidLPTHISRPdotidLPRPsemi
17 | THROWNEWidLPidLPRPdotidLPRPcommaidLPRPdotidLPRPRPsemi
18 | idLPSTRING_LITERALcommaiddotidLPRPdotidLPSTRING_LITERALRPRPsemi
19 | iddotidLPidcommaidRPsemi
20 | iddotidLPiddotidcommaiddotidcommaiddotidop_minusCONSTANTcommaiddotidop_minusCONSTANTRPsemi
21 | iddotidLPidRPsemi
22 | iddotidLPNEWidLPidRPRPsemi
23 | ididop_assignLPidRPiddotidLPRPsemi
24 | iddotidLPiddotidLPRPcommaidRPsemi
25 | THROWNEWidLPSTRING_LITERALRPsemi
26 | idop_assignLPidop_dividop_staridRPop_plusidsemi
27 | idLKiddotidop_minusCONSTANTRKop_assignLPBYTERPLPidRIGHT_OPCONSTANTRPsemi
28 | RETURNidsemi
29 | RB
30 |
--------------------------------------------------------------------------------
/token/9.txt:
--------------------------------------------------------------------------------
1 | PRIididLPididRPididop_assignidsemi
2 | ididop_assignNEWidLPSTRING_LITERALRPsemi
3 | idLKiddotidop_minusCONSTANTRKop_assignLPBYTERPLPidRIGHT_OPCONSTANTRPsemi
4 | THROWNEWidLPSTRING_LITERALRPsemi
5 | idREFop_assigniddotidLPidcommaidcommaCONSTANTRPsemi
6 | iddotidLPiddotidcommaiddotidcommaiddotidop_minusCONSTANTcommaiddotidop_minusCONSTANTRPsemi
7 | RETURNiddotidLPTHISRPdotidLPRPsemi
8 | iddotidLPidRPsemi
9 | idop_assignLPidop_dividop_staridRPop_plusidsemi
10 | idLKidINC_OPRKop_assignLPidop_plusidLKidop_plusCONSTANTRKop_staridop_plusidLKidop_plusCONSTANTRKop_staridRPsemi
11 | idLPSTRING_LITERALcommaiddotidLPRPdotidLPSTRING_LITERALRPRPsemi
12 | iddotidLPiddotidLPRPcommaidRPsemi
13 | ididop_assignLPidRPiddotidLPRPsemi
14 | iddotiddotiddotidLKRKidop_assignNEWiddotiddotiddotidLKCONSTANTRKsemi
15 | INTidop_assignidLKidLPidRPop_minusidRKsemi
16 | ididop_assignNEWidLPRPsemi
17 | IFLPidRP
18 | iddotiddotidLPSTRING_LITERALop_plusidRPsemi
19 | iddotidLPNEWidLPidRPRPsemi
20 | IFLPidNE_OPNULRP
21 | TRYidop_assigniddotidLPNEWidLKRKidRBRPsemi
22 | RB
23 | CATCHLPididRPiddotiddotidLPSTRING_LITERALRPsemi
24 | iddotidLPRPsemi
25 | RB
26 | RB
27 | RETURNidsemi
28 | RB
29 |
--------------------------------------------------------------------------------
/tokenize:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/tokenize
--------------------------------------------------------------------------------
/tokenline_num:
--------------------------------------------------------------------------------
1 | 31
2 | 15
3 | 11
4 | 21
5 | 19
6 | 10
7 | 27
8 | 12
9 | 29
10 | 28
11 | 23
12 | 21
13 | 25
14 | 18
15 | 24
16 | 30
17 | 14
18 | 13
19 | 26
20 | 17
21 | 16
22 |
--------------------------------------------------------------------------------
/txl/.csblocks.txl.swp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/.csblocks.txl.swp
--------------------------------------------------------------------------------
/txl/Makefile:
--------------------------------------------------------------------------------
1 | # Makefile to compile all TXL tools used in NiCad
2 |
3 | # TXL tool size - recommended default 400
4 | # On 32-bit platoforms, max 1000
5 | # On 64-bit platformss, max 4000
6 |
7 | SIZE=400
8 |
9 | # *** WARNING: larger sizes make parsing significantly slower
10 | # in the presence of syntax errors.
11 |
12 | .SUFFIXES:
13 | .SUFFIXES:.txl .x
14 |
15 | SRCS = $(wildcard *.txl)
16 | FILTEREDSRCS = $(filter-out generic-%.txl,$(SRCS))
17 | OBJS = $(patsubst %.txl,%.x,$(FILTEREDSRCS))
18 |
19 | all: $(OBJS)
20 |
21 | %.x: %.txl
22 | txlc -s $(SIZE) $<
23 |
24 | clean:
25 | /bin/rm -f *.x
26 |
27 |
--------------------------------------------------------------------------------
/txl/bom.grm:
--------------------------------------------------------------------------------
1 | % TXL BOM handling plugin
2 | % A. Malton & J.R. Cordy, April 2011
3 |
4 | % DO NOT EDIT THIS FILE.
5 | % Your editor may convert it and destroy the critical characters
6 | % in the token pattern.
7 |
8 | % Include this file in your TXL program using the command
9 | % include "bom.grm"
10 | % to ignore UTF-8 BOM headers in input files, which otherwise can
11 | % cause parsing problems.
12 |
13 | tokens
14 | ignore ""
15 | end tokens
--------------------------------------------------------------------------------
/txl/c-abstract-blocks.txl:
--------------------------------------------------------------------------------
1 | % Abstract given nonterminals from potential clones - C block version
2 |
3 | % Jim Cordy, May 2010
4 |
5 | % Using Gnu C grammar
6 | include "c.grm"
7 |
8 | % Redefinition for potential clones
9 |
10 | redefine compound_statement
11 | { [IN] [NL]
12 | [compound_statement_body] [EX]
13 | } [NL]
14 | end redefine
15 |
16 | define potential_clone
17 | [compound_statement]
18 | end define
19 |
20 | % Generic abstraction
21 | include "generic-abstract.txl"
22 |
--------------------------------------------------------------------------------
/txl/c-abstract-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/c-abstract-blocks.x
--------------------------------------------------------------------------------
/txl/c-abstract-functions.txl:
--------------------------------------------------------------------------------
1 | % Abstract given nonterminals from potential clones - C function version
2 |
3 | % Jim Cordy, May 2010
4 |
5 | % Using Gnu C grammar
6 | include "c.grm"
7 |
8 | % Redefinition for potential clones
9 | redefine function_definition
10 | [function_header]
11 | [opt KR_parameter_decls]
12 | '{ [IN][NL]
13 | [compound_statement_body] [EX]
14 | '}
15 | end redefine
16 |
17 | define potential_clone
18 | [function_definition]
19 | end define
20 |
21 | % Generic abstract
22 | include "generic-abstract.txl"
23 |
24 |
--------------------------------------------------------------------------------
/txl/c-abstract-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/c-abstract-functions.x
--------------------------------------------------------------------------------
/txl/c-extract-blocks.txl:
--------------------------------------------------------------------------------
1 | % Example using TXL 10.5a source coordinate extensions to extract
2 | % a table of all compound statements with source coordinates
3 |
4 | % Jim Cordy, October 2009
5 |
6 | % Revised Aug 2012 - disallow output forms in input parse - JRC
7 | % Revised July 2011 - ignore BOM headers in source
8 |
9 | % Using Gnu C grammar
10 | include "c.grm"
11 |
12 | % Ignore BOM headers from Windows
13 | include "bom.grm"
14 |
15 | % Redefinitions to collect source coordinates for function definitions as parsed input,
16 | % and to allow for XML markup of function definitions as output
17 |
18 | redefine compound_statement
19 | % Input form
20 | [srcfilename] [srclinenumber] % Keep track of starting file and line number
21 | { [IN] [NL]
22 | [compound_statement_body] [EX]
23 | [srcfilename] [srclinenumber] % Keep track of ending file and line number
24 | } [opt ';] [NL]
25 | |
26 | % Output form
27 | [not token] % disallow input parse of this form
28 | [opt xml_source_coordinate]
29 | { [IN] [NL]
30 | [compound_statement_body] [EX]
31 | } [opt ';] [NL]
32 | [opt end_xml_source_coordinate]
33 | end redefine
34 |
35 | define xml_source_coordinate
36 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [NL]
37 | end define
38 |
39 | define end_xml_source_coordinate
40 | '< [SPOFF] '/ 'source '> [SPON] [NL]
41 | end define
42 |
43 | redefine program
44 | ...
45 | | [repeat compound_statement]
46 | end redefine
47 |
48 |
49 | % Main function - extract and mark up compound statements from parsed input program
50 | function main
51 | replace [program]
52 | P [program]
53 | construct Compounds [repeat compound_statement]
54 | _ [^ P] % Extract all compound statements from program
55 | [convertCompoundStatements]
56 | by
57 | Compounds [removeOptSemis]
58 | [removeEmptyStatements]
59 | end function
60 |
61 | rule convertCompoundStatements
62 | % Find each compound statement and match its input source coordinates
63 | skipping [compound_statement]
64 | replace [compound_statement]
65 | FileName [srcfilename] LineNumber [srclinenumber]
66 | '{
67 | CompoundBody [compound_statement_body]
68 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
69 | '} Semi [opt ';]
70 |
71 | % Convert file name and line numbers to strings for XML
72 | construct FileNameString [stringlit]
73 | _ [quote FileName]
74 | construct LineNumberString [stringlit]
75 | _ [quote LineNumber]
76 | construct EndLineNumberString [stringlit]
77 | _ [quote EndLineNumber]
78 |
79 | % Output is XML form with attributes indicating input source coordinates
80 | construct XmlHeader [xml_source_coordinate]
81 |
82 | by
83 | XmlHeader
84 | {
85 | CompoundBody [unmarkEmbeddedCompoundStatements]
86 | '}
87 |
88 | end rule
89 |
90 | rule unmarkEmbeddedCompoundStatements
91 | replace [compound_statement]
92 | FileName [srcfilename] LineNumber [srclinenumber]
93 | '{
94 | CompoundBody [compound_statement_body]
95 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
96 | '} Semi [opt ';]
97 | construct Empty [opt xml_source_coordinate]
98 | % none, to force output form
99 | by
100 | Empty
101 | '{
102 | CompoundBody
103 | '}
104 | end rule
105 |
106 | rule removeOptSemis
107 | replace [opt ';]
108 | ';
109 | by
110 | % none
111 | end rule
112 |
113 | rule removeEmptyStatements
114 | replace [repeat declaration_or_statement]
115 | ';
116 | More [repeat declaration_or_statement]
117 | by
118 | More
119 | end rule
120 |
--------------------------------------------------------------------------------
/txl/c-extract-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/c-extract-blocks.x
--------------------------------------------------------------------------------
/txl/c-extract-functions.txl:
--------------------------------------------------------------------------------
1 | % Example using TXL 10.5a source coordinate extensions to extract
2 | % a table of all function definitions with source coordinates
3 |
4 | % Jim Cordy, January 2008
5 |
6 | % Revised Aug 2012 - disallow ouput forms in input parse - JRC
7 | % Revised July 2011 - ignore BOM headers in source
8 | % Revised 30.04.08 - unmark embedded functions - JRC
9 |
10 | % Using Gnu C grammar
11 | include "c.grm"
12 |
13 | % Ignore BOM headers from Windows
14 | include "bom.grm"
15 |
16 | % Redefinitions to collect source coordinates for function definitions as parsed input,
17 | % and to allow for XML markup of function definitions as output
18 |
19 | redefine function_definition
20 | % Input form
21 | [srcfilename] [srclinenumber] % Keep track of starting file and line number
22 | [function_header]
23 | [opt KR_parameter_decls]
24 | '{ [IN][NL]
25 | [compound_statement_body] [EX]
26 | [srcfilename] [srclinenumber] % Keep track of ending file and line number
27 | '}
28 | |
29 | % Output form
30 | [not token] % disallow output form in input parse
31 | [opt xml_source_coordinate]
32 | [function_header]
33 | [opt KR_parameter_decls]
34 | '{ [IN][NL]
35 | [compound_statement_body] [EX]
36 | '}
37 | [opt end_xml_source_coordinate]
38 | end redefine
39 |
40 | define xml_source_coordinate
41 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [NL]
42 | end define
43 |
44 | define end_xml_source_coordinate
45 | [NL] '< [SPOFF] '/ 'source '> [SPON] [NL]
46 | end define
47 |
48 | redefine program
49 | ...
50 | | [repeat function_definition]
51 | end redefine
52 |
53 |
54 | % Main function - extract and mark up function definitions from parsed input program
55 | function main
56 | replace [program]
57 | P [program]
58 | construct Functions [repeat function_definition]
59 | _ [^ P] % Extract all functions from program
60 | [convertFunctionDefinitions] % Mark up with XML
61 | by
62 | Functions [removeOptSemis]
63 | [removeEmptyStatements]
64 | end function
65 |
66 | rule convertFunctionDefinitions
67 | % Find each function definition and match its input source coordinates
68 | replace [function_definition]
69 | FileName [srcfilename] LineNumber [srclinenumber]
70 | FunctionHeader [function_header]
71 | KR_Parms [opt KR_parameter_decls]
72 | '{
73 | FunctionBody [compound_statement_body]
74 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
75 | '}
76 |
77 | % Convert file name and line numbers to strings for XML
78 | construct FileNameString [stringlit]
79 | _ [quote FileName]
80 | construct LineNumberString [stringlit]
81 | _ [quote LineNumber]
82 | construct EndLineNumberString [stringlit]
83 | _ [quote EndLineNumber]
84 |
85 | % Output is XML form with attributes indicating input source coordinates
86 | construct XmlHeader [xml_source_coordinate]
87 |
88 | by
89 | XmlHeader
90 | FunctionHeader
91 | KR_Parms
92 | '{
93 | FunctionBody [unmarkEmbeddedFunctionDefinitions]
94 | '}
95 |
96 | end rule
97 |
98 | rule unmarkEmbeddedFunctionDefinitions
99 | replace [function_definition]
100 | FileName [srcfilename] LineNumber [srclinenumber]
101 | FunctionHeader [function_header]
102 | KR_Parms [opt KR_parameter_decls]
103 | '{
104 | FunctionBody [compound_statement_body]
105 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
106 | '}
107 | by
108 | FunctionHeader
109 | KR_Parms
110 | '{
111 | FunctionBody
112 | '}
113 | end rule
114 |
115 | rule removeOptSemis
116 | replace [opt ';]
117 | ';
118 | by
119 | % none
120 | end rule
121 |
122 | rule removeEmptyStatements
123 | replace [repeat declaration_or_statement]
124 | ';
125 | More [repeat declaration_or_statement]
126 | by
127 | More
128 | end rule
129 |
--------------------------------------------------------------------------------
/txl/c-extract-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/c-extract-functions.x
--------------------------------------------------------------------------------
/txl/c-filter-blocks.txl:
--------------------------------------------------------------------------------
1 | % Filter given nonterminals from potential clones - C block version
2 |
3 | % Jim Cordy, May 2010
4 |
5 | % Using Gnu C grammar
6 | include "c.grm"
7 |
8 | % Redefinition for potential clones
9 |
10 | redefine compound_statement
11 | { [IN] [NL]
12 | [compound_statement_body] [EX]
13 | } [NL]
14 | end redefine
15 |
16 | define potential_clone
17 | [compound_statement]
18 | end define
19 |
20 | % Generic filter
21 | include "generic-filter.txl"
22 |
--------------------------------------------------------------------------------
/txl/c-filter-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/c-filter-blocks.x
--------------------------------------------------------------------------------
/txl/c-filter-functions.txl:
--------------------------------------------------------------------------------
1 | % Filter given nonterminals from potential clones - C function version
2 |
3 | % Jim Cordy, May 2010
4 |
5 | % Using Gnu C grammar
6 | include "c.grm"
7 |
8 | % Redefinition for potential clones
9 | redefine function_definition
10 | [function_header]
11 | [opt KR_parameter_decls]
12 | '{ [IN][NL]
13 | [compound_statement_body] [EX]
14 | '}
15 | end redefine
16 |
17 | define potential_clone
18 | [function_definition]
19 | end define
20 |
21 | % Generic filter
22 | include "generic-filter.txl"
23 |
24 |
--------------------------------------------------------------------------------
/txl/c-filter-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/c-filter-functions.x
--------------------------------------------------------------------------------
/txl/c-rename-blind-blocks.txl:
--------------------------------------------------------------------------------
1 | % Blind renaming - C blocks
2 | % Jim Cordy, May 2010
3 |
4 | % Using Gnu C grammar
5 | include "c.grm"
6 |
7 | redefine compound_statement
8 | { [IN] [NL]
9 | [compound_statement_body] [EX]
10 | } [NL]
11 | end redefine
12 |
13 | define potential_clone
14 | [compound_statement]
15 | end define
16 |
17 | % Generic blind renaming
18 | include "generic-rename-blind.txl"
19 |
20 |
--------------------------------------------------------------------------------
/txl/c-rename-blind-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/c-rename-blind-blocks.x
--------------------------------------------------------------------------------
/txl/c-rename-blind-functions.txl:
--------------------------------------------------------------------------------
1 | % Blind renaming - C functions
2 | % Jim Cordy, May 2010
3 |
4 | % Using Gnu C grammar
5 | include "c.grm"
6 |
7 | redefine function_definition
8 | [function_header]
9 | [opt KR_parameter_decls]
10 | '{ [IN][NL]
11 | [compound_statement_body] [EX]
12 | '}
13 | end redefine
14 |
15 | define potential_clone
16 | [function_definition]
17 | end define
18 |
19 | % Generic blind renaming
20 | include "generic-rename-blind.txl"
21 |
22 |
--------------------------------------------------------------------------------
/txl/c-rename-blind-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/c-rename-blind-functions.x
--------------------------------------------------------------------------------
/txl/c-rename-consistent-blocks.txl:
--------------------------------------------------------------------------------
1 | % Consistent renaming - C blocks
2 | % Jim Cordy, May 2010
3 |
4 | % Using Gnu C grammmar
5 | include "c.grm"
6 |
7 | redefine compound_statement
8 | { [IN] [NL]
9 | [compound_statement_body] [EX]
10 | } [NL]
11 | end redefine
12 |
13 | define potential_clone
14 | [compound_statement]
15 | end define
16 |
17 | % Generic consistent renaming
18 | include "generic-rename-consistent.txl"
19 |
20 |
--------------------------------------------------------------------------------
/txl/c-rename-consistent-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/c-rename-consistent-blocks.x
--------------------------------------------------------------------------------
/txl/c-rename-consistent-functions.txl:
--------------------------------------------------------------------------------
1 | % Consistent renaming - C functions
2 | % Jim Cordy, May 2010
3 |
4 | % Using Gnu C grammar
5 | include "c.grm"
6 |
7 | redefine function_definition
8 | [function_header]
9 | [opt KR_parameter_decls]
10 | '{ [IN][NL]
11 | [compound_statement_body] [EX]
12 | '}
13 | end redefine
14 |
15 | define potential_clone
16 | [function_definition]
17 | end define
18 |
19 | % Generic consistent renaming
20 | include "generic-rename-consistent.txl"
21 |
22 |
--------------------------------------------------------------------------------
/txl/c-rename-consistent-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/c-rename-consistent-functions.x
--------------------------------------------------------------------------------
/txl/c.txl:
--------------------------------------------------------------------------------
1 | % Example using TXL 10.5a source coordinate extensions to extract
2 | % a table of all function definitions with source coordinates
3 |
4 | % Jim Cordy, January 2008
5 |
6 | % Revised 30.04.08 - unmark embedded functions - JRC
7 |
8 | % Using Gnu C grammar
9 | include "c.grm"
10 |
11 | % Redefinitions to collect source coordinates for function definitions as parsed input,
12 | % and to allow for XML markup of function definitions as output
13 |
14 | redefine function_definition
15 | % Input form
16 | [srcfilename] [srclinenumber] % Keep track of starting file and line number
17 | [function_header]
18 | [opt KR_parameter_decls]
19 | '{ [IN][NL]
20 | [compound_statement_body] [EX]
21 | [srcfilename] [srclinenumber] % Keep track of ending file and line number
22 | '}
23 | |
24 | % Output form
25 | [opt xml_source_coordinate]
26 | [function_header]
27 | [opt KR_parameter_decls]
28 | '{ [IN][NL]
29 | [compound_statement_body] [EX]
30 | '}
31 | [opt end_xml_source_coordinate]
32 | end redefine
33 |
34 | define xml_source_coordinate
35 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [NL]
36 | end define
37 |
38 | define end_xml_source_coordinate
39 | [NL] '< [SPOFF] '/ 'source '> [SPON] [NL]
40 | end define
41 |
42 | redefine program
43 | ...
44 | | [repeat function_definition]
45 | end redefine
46 |
47 |
48 | % Main function - extract and mark up function definitions from parsed input program
49 | function main
50 | replace [program]
51 | P [program]
52 | construct Functions [repeat function_definition]
53 | _ [^ P] % Extract all functions from program
54 | [convertFunctionDefinitions] % Mark up with XML
55 | by
56 | Functions
57 | end function
58 |
59 | rule convertFunctionDefinitions
60 | % Find each function definition and match its input source coordinates
61 | replace [function_definition]
62 | FileName [srcfilename] LineNumber [srclinenumber]
63 | FunctionHeader [function_header]
64 | KR_Parms [opt KR_parameter_decls]
65 | '{
66 | FunctionBody [compound_statement_body]
67 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
68 | '}
69 |
70 | % Convert file name and line numbers to strings for XML
71 | construct FileNameString [stringlit]
72 | _ [quote FileName]
73 | construct LineNumberString [stringlit]
74 | _ [quote LineNumber]
75 | construct EndLineNumberString [stringlit]
76 | _ [quote EndLineNumber]
77 |
78 | % Output is XML form with attributes indicating input source coordinates
79 | by
80 |
81 | FunctionHeader
82 | KR_Parms
83 | '{
84 | FunctionBody [unmarkEmbeddedFunctionDefinitions]
85 | '}
86 |
87 | end rule
88 |
89 | rule unmarkEmbeddedFunctionDefinitions
90 | replace [function_definition]
91 | FileName [srcfilename] LineNumber [srclinenumber]
92 | FunctionHeader [function_header]
93 | KR_Parms [opt KR_parameter_decls]
94 | '{
95 | FunctionBody [compound_statement_body]
96 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
97 | '}
98 | by
99 | FunctionHeader
100 | KR_Parms
101 | '{
102 | FunctionBody
103 | '}
104 | end rule
105 |
--------------------------------------------------------------------------------
/txl/c.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/c.x
--------------------------------------------------------------------------------
/txl/cs-abstract-blocks.txl:
--------------------------------------------------------------------------------
1 | % Abstract given nonterminals from potential clones - C# block version
2 |
3 | % Jim Cordy, May 2010
4 |
5 | % Using C# grammar
6 | include "csharp.grm"
7 |
8 | % Redefinition for potential clones
9 | redefine block
10 | { [IN] [NL]
11 | [opt statement_list] [EX]
12 | } [NL]
13 | end redefine
14 |
15 | define potential_clone
16 | [block]
17 | end define
18 |
19 | % Generic abstract
20 | include "generic-abstract.txl"
21 |
22 |
--------------------------------------------------------------------------------
/txl/cs-abstract-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/cs-abstract-blocks.x
--------------------------------------------------------------------------------
/txl/cs-abstract-functions.txl:
--------------------------------------------------------------------------------
1 | % Abstract given nonterminals from potential clones - C# function version
2 |
3 | % Jim Cordy, May 2010
4 |
5 | % Using C# grammar
6 | include "csharp.grm"
7 |
8 | % Redefinition for potential clones
9 |
10 | % Temporary handling of designated Linq extensions
11 | redefine invocation_operator
12 | ...
13 | | '(( [repeat argument_list_or_key] '))
14 | end redefine
15 |
16 | define argument_list_or_key
17 | [argument_list]
18 | | 'in
19 | end define
20 |
21 | define method_definition
22 | [method_header]
23 | '{ [NL][IN]
24 | [opt statement_list] [EX]
25 | '}
26 | end define
27 |
28 | define potential_clone
29 | [method_definition]
30 | end define
31 |
32 | % Generic abstract
33 | include "generic-abstract.txl"
34 |
35 |
--------------------------------------------------------------------------------
/txl/cs-abstract-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/cs-abstract-functions.x
--------------------------------------------------------------------------------
/txl/cs-extract-blocks.txl:
--------------------------------------------------------------------------------
1 | % Example using TXL 10.5a source coordinate extensions to extract
2 | % a table of all blocks with source coordinates
3 |
4 | % Jim Cordy, October 2009
5 |
6 | % Revised Aug 2012 - disallow ouput forms in input parse - JRC
7 | % Revised July 2011 - ignore BOM headers in source
8 |
9 | % Using C# grammar
10 | include "csharp.grm"
11 |
12 | % Ignore BOM headers from Windows
13 | include "bom.grm"
14 |
15 | % Redefinitions to collect source coordinates for blocks as parsed input,
16 | % and to allow for XML markup of blocks as output
17 |
18 | redefine block
19 | % Input form
20 | [srcfilename] [srclinenumber] % Keep track of starting file and line number
21 | { [IN] [NL]
22 | [opt statement_list] [EX]
23 | [srcfilename] [srclinenumber] % Keep track of ending file and line number
24 | } [opt ';] [NL]
25 | |
26 | % Output form
27 | [not token] % disallow output form in input parse
28 | [opt xml_source_coordinate]
29 | { [IN] [NL]
30 | [opt statement_list] [EX]
31 | } [opt ';] [NL]
32 | [opt end_xml_source_coordinate]
33 | end redefine
34 |
35 | define xml_source_coordinate
36 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [NL]
37 | end define
38 |
39 | define end_xml_source_coordinate
40 | '< [SPOFF] '/ 'source '> [SPON] [NL]
41 | end define
42 |
43 | redefine program
44 | ...
45 | | [repeat block]
46 | end redefine
47 |
48 |
49 | % Main function - extract and mark up blocks from parsed input program
50 | function main
51 | replace [program]
52 | P [program]
53 | construct Compounds [repeat block]
54 | _ [^ P] % Extract all blocks from program
55 | [convertCompoundStatements]
56 | by
57 | Compounds [removeOptSemis]
58 | [removeEmptyStatements]
59 | end function
60 |
61 | rule convertCompoundStatements
62 | % Find each block and match its input source coordinates
63 | skipping [block]
64 | replace [block]
65 | FileName [srcfilename] LineNumber [srclinenumber]
66 | '{
67 | CompoundBody [opt statement_list]
68 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
69 | '} Semi [opt ';]
70 |
71 | % Convert file name and line numbers to strings for XML
72 | construct FileNameString [stringlit]
73 | _ [quote FileName]
74 | construct LineNumberString [stringlit]
75 | _ [quote LineNumber]
76 | construct EndLineNumberString [stringlit]
77 | _ [quote EndLineNumber]
78 |
79 | % Output is XML form with attributes indicating input source coordinates
80 | construct XmlHeader [xml_source_coordinate]
81 |
82 | by
83 | XmlHeader
84 | {
85 | CompoundBody [unmarkEmbeddedCompoundStatements]
86 | '}
87 |
88 | end rule
89 |
90 | rule unmarkEmbeddedCompoundStatements
91 | replace [block]
92 | FileName [srcfilename] LineNumber [srclinenumber]
93 | '{
94 | CompoundBody [opt statement_list]
95 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
96 | '} Semi [opt ';]
97 | construct Empty [opt xml_source_coordinate]
98 | % none, to force output form
99 | by
100 | Empty
101 | '{
102 | CompoundBody
103 | '}
104 | end rule
105 |
106 | rule removeOptSemis
107 | replace [opt ';]
108 | ';
109 | by
110 | % none
111 | end rule
112 |
113 | rule removeEmptyStatements
114 | replace [repeat declaration_or_statement+]
115 | ';
116 | More [repeat declaration_or_statement+]
117 | by
118 | More
119 | end rule
120 |
--------------------------------------------------------------------------------
/txl/cs-extract-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/cs-extract-blocks.x
--------------------------------------------------------------------------------
/txl/cs-extract-functions.txl:
--------------------------------------------------------------------------------
1 | % Example using TXL 10.5a source coordinate extensions to extract
2 | % a table of all method definitions with source coordinates
3 |
4 | % Jim Cordy, January 2008
5 |
6 | % Revised Aug 2012 - disallow ouput forms in input parse - JRC
7 | % Revised July 2011 - ignore BOM headers in source
8 | % Revised 30.04.08 - unmark embedded functions - JRC
9 |
10 | % Using C# grammar
11 | include "csharp.grm"
12 |
13 | % Ignore BOM headers from Windows
14 | include "bom.grm"
15 |
16 | % Temporary handling of designated Linq extensions
17 | redefine invocation_operator
18 | ...
19 | | '(( [repeat argument_list_or_key] '))
20 | end redefine
21 |
22 | define argument_list_or_key
23 | [argument_list]
24 | | 'in
25 | end define
26 |
27 | % Redefinitions to collect source coordinates for function definitions as parsed input,
28 | % and to allow for XML markup of function definitions as output
29 |
30 | redefine method_declaration
31 | [method_definition]
32 | |
33 | % Uninteresting interface form
34 | [method_header] '; [NL]
35 | end redefine
36 |
37 | define method_definition
38 | % Input form
39 | [srcfilename] [srclinenumber] % Keep track of starting file and line number
40 | [method_header]
41 | '{ [NL][IN]
42 | [opt statement_list] [EX]
43 | [srcfilename] [srclinenumber] % Keep track of ending file and line number
44 | '} [opt ';]
45 | |
46 | % Output form
47 | [not token] % disallow output form in input parse
48 | [opt xml_source_coordinate]
49 | [method_header]
50 | '{ [NL][IN]
51 | [opt statement_list] [EX]
52 | '} [opt ';]
53 | [opt end_xml_source_coordinate]
54 | end define
55 |
56 | define xml_source_coordinate
57 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [NL]
58 | end define
59 |
60 | define end_xml_source_coordinate
61 | [NL] '< [SPOFF] '/ 'source '> [SPON] [NL]
62 | end define
63 |
64 | redefine program
65 | ...
66 | | [repeat method_definition]
67 | end redefine
68 |
69 |
70 | % Main function - extract and mark up function definitions from parsed input program
71 | function main
72 | replace [program]
73 | P [program]
74 | construct Functions [repeat method_definition]
75 | _ [^ P] % Extract all functions from program
76 | [convertFunctionDefinitions] % Mark up with XML
77 | by
78 | Functions [removeOptSemis]
79 | [removeEmptyStatements]
80 | end function
81 |
82 | rule convertFunctionDefinitions
83 | % Find each function definition and match its input source coordinates
84 | replace [method_definition]
85 | FileName [srcfilename] LineNumber [srclinenumber]
86 | FunctionHeader [method_header]
87 | '{
88 | FunctionBody [opt statement_list]
89 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
90 | '} Semi [opt ';]
91 |
92 | % Convert file name and line numbers to strings for XML
93 | construct FileNameString [stringlit]
94 | _ [quote FileName]
95 | construct LineNumberString [stringlit]
96 | _ [quote LineNumber]
97 | construct EndLineNumberString [stringlit]
98 | _ [quote EndLineNumber]
99 |
100 | % Output is XML form with attributes indicating input source coordinates
101 | construct XmlHeader [xml_source_coordinate]
102 |
103 | by
104 | XmlHeader
105 | FunctionHeader
106 | '{
107 | FunctionBody % [unmarkEmbeddedFunctionDefinitions]
108 | '}
109 |
110 | end rule
111 |
112 | rule unmarkEmbeddedFunctionDefinitions
113 | replace [method_definition]
114 | FileName [srcfilename] LineNumber [srclinenumber]
115 | FunctionHeader [method_header]
116 | '{
117 | FunctionBody [opt statement_list]
118 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
119 | '}
120 | by
121 | FunctionHeader
122 | '{
123 | FunctionBody
124 | '}
125 | end rule
126 |
127 | rule removeOptSemis
128 | replace [opt ';]
129 | ';
130 | by
131 | % none
132 | end rule
133 |
134 | rule removeEmptyStatements
135 | replace [repeat declaration_or_statement+]
136 | ';
137 | More [repeat declaration_or_statement+]
138 | by
139 | More
140 | end rule
141 |
--------------------------------------------------------------------------------
/txl/cs-extract-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/cs-extract-functions.x
--------------------------------------------------------------------------------
/txl/cs-filter-blocks.txl:
--------------------------------------------------------------------------------
1 | % Filter given nonterminals from potential clones - C# block version
2 |
3 | % Jim Cordy, May 2010
4 |
5 | % Using C# grammar
6 | include "csharp.grm"
7 |
8 | % Redefinition for potential clones
9 | redefine block
10 | { [IN] [NL]
11 | [opt statement_list] [EX]
12 | } [NL]
13 | end redefine
14 |
15 | define potential_clone
16 | [block]
17 | end define
18 |
19 | % Generic filter
20 | include "generic-filter.txl"
21 |
22 |
--------------------------------------------------------------------------------
/txl/cs-filter-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/cs-filter-blocks.x
--------------------------------------------------------------------------------
/txl/cs-filter-functions.txl:
--------------------------------------------------------------------------------
1 | % Filter given nonterminals from potential clones - C# function version
2 |
3 | % Jim Cordy, May 2010
4 |
5 | % Using C# grammar
6 | include "csharp.grm"
7 |
8 | % Redefinition for potential clones
9 |
10 | % Temporary handling of designated Linq extensions
11 | redefine invocation_operator
12 | ...
13 | | '(( [repeat argument_list_or_key] '))
14 | end redefine
15 |
16 | define argument_list_or_key
17 | [argument_list]
18 | | 'in
19 | end define
20 |
21 | define method_definition
22 | [method_header]
23 | '{ [NL][IN]
24 | [opt statement_list] [EX]
25 | '}
26 | end define
27 |
28 | define potential_clone
29 | [method_definition]
30 | end define
31 |
32 | % Generic filter
33 | include "generic-filter.txl"
34 |
35 |
--------------------------------------------------------------------------------
/txl/cs-filter-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/cs-filter-functions.x
--------------------------------------------------------------------------------
/txl/cs-rename-blind-blocks.txl:
--------------------------------------------------------------------------------
1 | % Blind renaming - C# blocks
2 | % Jim Cordy, May 2010
3 |
4 | % Using C# grammar
5 | include "csharp.grm"
6 |
7 | % Redefinition for potential clones
8 | redefine block
9 | { [IN] [NL]
10 | [opt statement_list] [EX]
11 | } [NL]
12 | end redefine
13 |
14 | define potential_clone
15 | [block]
16 | end define
17 |
18 | % Generic blind renaming
19 | include "generic-rename-blind.txl"
20 |
21 |
--------------------------------------------------------------------------------
/txl/cs-rename-blind-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/cs-rename-blind-blocks.x
--------------------------------------------------------------------------------
/txl/cs-rename-blind-functions.txl:
--------------------------------------------------------------------------------
1 | % Blind renaming - C# functions
2 | % Jim Cordy, May 2010
3 |
4 | % Using C# grammar
5 | include "csharp.grm"
6 |
7 | % Redefinition for potential clones
8 |
9 | % Temporary handling of designated Linq extensions
10 | redefine invocation_operator
11 | ...
12 | | '(( [repeat argument_list_or_key] '))
13 | end redefine
14 |
15 | define argument_list_or_key
16 | [argument_list]
17 | | 'in
18 | end define
19 |
20 | define method_definition
21 | [method_header]
22 | '{ [NL][IN]
23 | [opt statement_list] [EX]
24 | '}
25 | end define
26 |
27 | define potential_clone
28 | [method_definition]
29 | end define
30 |
31 | % Generic blind renaming
32 | include "generic-rename-blind.txl"
33 |
34 |
--------------------------------------------------------------------------------
/txl/cs-rename-blind-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/cs-rename-blind-functions.x
--------------------------------------------------------------------------------
/txl/cs-rename-consistent-blocks.txl:
--------------------------------------------------------------------------------
1 | % Consistent renaming - C# blocks
2 | % Jim Cordy, May 2010
3 |
4 | % Using C# grammar
5 | include "csharp.grm"
6 |
7 | % Redefinition for potential clones
8 | redefine block
9 | { [IN] [NL]
10 | [opt statement_list] [EX]
11 | } [NL]
12 | end redefine
13 |
14 | define potential_clone
15 | [block]
16 | end define
17 |
18 | % Generic consistent renaming
19 | include "generic-rename-consistent.txl"
20 |
21 |
--------------------------------------------------------------------------------
/txl/cs-rename-consistent-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/cs-rename-consistent-blocks.x
--------------------------------------------------------------------------------
/txl/cs-rename-consistent-functions.txl:
--------------------------------------------------------------------------------
1 | % Consistent renaming - C# functions
2 | % Jim Cordy, May 2010
3 |
4 | % Using C# grammar
5 | include "csharp.grm"
6 |
7 | % Redefinition for potential clones
8 |
9 | % Temporary handling of designated Linq extensions
10 | redefine invocation_operator
11 | ...
12 | | '(( [repeat argument_list_or_key] '))
13 | end redefine
14 |
15 | define argument_list_or_key
16 | [argument_list]
17 | | 'in
18 | end define
19 |
20 | define method_definition
21 | [method_header]
22 | '{ [NL][IN]
23 | [opt statement_list] [EX]
24 | '}
25 | end define
26 |
27 | define potential_clone
28 | [method_definition]
29 | end define
30 |
31 | % Generic consistent renaming
32 | include "generic-rename-consistent.txl"
33 |
34 |
--------------------------------------------------------------------------------
/txl/cs-rename-consistent-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/cs-rename-consistent-functions.x
--------------------------------------------------------------------------------
/txl/cs.txl:
--------------------------------------------------------------------------------
1 | % ECMA-334 Edition 3 (June 2005) Standard C# Grammar
2 | % Adapted directly from ECMA-334 (June 2005) Appendix A by Jim Cordy (cordy@cs.queensu.ca)
3 | % March 2006 (Revised August 2006)
4 |
5 | % Simple null program to test the C# grammar
6 |
7 | % TXL ECMA-334 C# Grammar
8 | include "csharp.grm"
9 |
10 | % Comment out this line to use grammar without preserving comments
11 | % #define COMMENTS
12 |
13 | % Experimental overrides to allow for comment preservation
14 | #ifdef COMMENTS
15 | include "Csharp_ECMA_334_CommentOverrides.Grm"
16 | #endif
17 |
18 | % Comment out this line to use grammar without preserving intentional extra newlines
19 | % #define NEWLINES
20 |
21 | % Experimental overrides to allow for preservation of intentional extra newlines
22 | #ifdef NEWLINES
23 | include "Csharp_PreserveNewlines.Grm"
24 | #endif
25 |
26 | % Some of our examples are method fragments, not whole programs
27 | redefine namespace_member_declaration
28 | ...
29 | | [method_declaration]
30 | end redefine
31 |
32 | % Temporary handling of designated Linq extensions
33 | redefine invocation_operator
34 | ...
35 | | '(( [repeat argument_list_or_key] '))
36 | end redefine
37 |
38 | define argument_list_or_key
39 | [argument_list]
40 | | 'in
41 | end define
42 |
43 | % Just parse
44 | function main
45 | replace [program]
46 | P [program]
47 | by
48 | P
49 | #ifdef NEWLINES
50 | [preserveNewlines]
51 | #endif
52 | end function
53 |
54 |
--------------------------------------------------------------------------------
/txl/cs.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/cs.x
--------------------------------------------------------------------------------
/txl/generic-abstract.txl:
--------------------------------------------------------------------------------
1 | % Generic abstraction of nonterminals
2 | % Jim Cordy, May 2010
3 |
4 | define xml_source_coordinate
5 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [NL]
6 | end define
7 |
8 | define end_xml_source_coordinate
9 | [NL] '< [SPOFF] '/ 'source '> [SPON] [NL]
10 | end define
11 |
12 | define source_unit
13 | [xml_source_coordinate]
14 | [potential_clone]
15 | [end_xml_source_coordinate]
16 | end define
17 |
18 | redefine program
19 | [repeat source_unit]
20 | end redefine
21 |
22 | % Main program
23 |
24 | rule main
25 | % Get the list of nonterminals to be abstracted
26 | import TXLargs [stringlit*]
27 | AbstractedNTs [stringlit*]
28 |
29 | % Abstract them in each potential clone
30 | skipping [source_unit]
31 | replace $ [source_unit]
32 | BeginXML [xml_source_coordinate]
33 | PC [potential_clone]
34 | EndXML [end_xml_source_coordinate]
35 | by
36 | BeginXML
37 | PC [abstract each AbstractedNTs]
38 | EndXML
39 | end rule
40 |
41 | rule abstract AbstractedNTstring [stringlit]
42 | construct AbstractedNT [id]
43 | _ [unquote AbstractedNTstring]
44 | % Replace all the given NTs by their nonterminal name
45 | deconstruct * [any] AbstractedNT
46 | AbstractedNTname [any]
47 | replace $ [any]
48 | Any [any]
49 | where
50 | Any [istype AbstractedNT]
51 | by
52 | AbstractedNTname
53 | end rule
54 |
--------------------------------------------------------------------------------
/txl/generic-filter.txl:
--------------------------------------------------------------------------------
1 | % Generic filtering of nonterminals
2 | % Jim Cordy, May 2010
3 |
4 | define xml_source_coordinate
5 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [NL]
6 | end define
7 |
8 | define end_xml_source_coordinate
9 | [NL] '< [SPOFF] '/ 'source '> [SPON] [NL]
10 | end define
11 |
12 | define source_unit
13 | [xml_source_coordinate]
14 | [potential_clone]
15 | [end_xml_source_coordinate]
16 | end define
17 |
18 | redefine program
19 | [repeat source_unit]
20 | end redefine
21 |
22 | % Main program
23 |
24 | rule main
25 | % Get the list of nonterminals to be filtered
26 | import TXLargs [stringlit*]
27 | FilteredNTs [stringlit*]
28 |
29 | % Make a global nothing
30 | construct Empty [empty]
31 | deconstruct * [any] Empty
32 | Nothing [any]
33 | export Nothing
34 |
35 | skipping [source_unit]
36 | replace $ [source_unit]
37 | BeginXML [xml_source_coordinate]
38 | PC [potential_clone]
39 | EndXML [end_xml_source_coordinate]
40 | by
41 | BeginXML
42 | PC [filter each FilteredNTs]
43 | EndXML
44 | end rule
45 |
46 | rule filter FilteredNTstring [stringlit]
47 | construct FilteredNT [id]
48 | _ [unquote FilteredNTstring]
49 | % Replace all the given NTs by nothing
50 | import Nothing [any]
51 | replace $ [any]
52 | Any [any]
53 | where
54 | Any [istype FilteredNT]
55 | by
56 | Nothing
57 | end rule
58 |
--------------------------------------------------------------------------------
/txl/generic-normalize.txl:
--------------------------------------------------------------------------------
1 | % Generic application of custom normalization rule
2 | % Jim Cordy, May 2010
3 |
4 | define xml_source_coordinate
5 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [NL]
6 | end define
7 |
8 | define end_xml_source_coordinate
9 | [NL] '< [SPOFF] '/ 'source '> [SPON] [NL]
10 | end define
11 |
12 | define source_unit
13 | [xml_source_coordinate]
14 | [potential_clone]
15 | [end_xml_source_coordinate]
16 | end define
17 |
18 | redefine program
19 | [repeat source_unit]
20 | end redefine
21 |
22 | % Main program
23 |
24 | rule main
25 | % Abstract them in each potential clone
26 | skipping [source_unit]
27 | replace $ [source_unit]
28 | BeginXML [xml_source_coordinate]
29 | PC [potential_clone]
30 | EndXML [end_xml_source_coordinate]
31 | by
32 | BeginXML
33 | PC [normalize]
34 | EndXML
35 | end rule
36 |
--------------------------------------------------------------------------------
/txl/generic-rename-blind.txl:
--------------------------------------------------------------------------------
1 | % Generic blind renaming for potential clones
2 | % Jim Cordy, May 2010
3 |
4 | define xml_source_coordinate
5 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [NL]
6 | end define
7 |
8 | define end_xml_source_coordinate
9 | [NL] '< [SPOFF] '/ 'source '> [SPON] [NL]
10 | end define
11 |
12 | define source_unit
13 | [xml_source_coordinate]
14 | [potential_clone]
15 | [end_xml_source_coordinate]
16 | end define
17 |
18 | redefine program
19 | [repeat source_unit]
20 | end redefine
21 |
22 | % Main program
23 |
24 | rule main
25 | skipping [source_unit]
26 | replace $ [source_unit]
27 | BeginXML [xml_source_coordinate]
28 | PC [potential_clone]
29 | EndXML [end_xml_source_coordinate]
30 | by
31 | BeginXML
32 | PC [renameIds]
33 | EndXML
34 | end rule
35 |
36 | rule renameIds
37 | replace $ [id]
38 | _ [id]
39 | by
40 | 'x
41 | end rule
42 |
--------------------------------------------------------------------------------
/txl/generic-rename-consistent.txl:
--------------------------------------------------------------------------------
1 | % Generic consistent renaming for potential clones
2 | % Jim Cordy, May 2010
3 |
4 | define xml_source_coordinate
5 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [NL]
6 | end define
7 |
8 | define end_xml_source_coordinate
9 | [NL] '< [SPOFF] '/ 'source '> [SPON] [NL]
10 | end define
11 |
12 | define source_unit
13 | [xml_source_coordinate]
14 | [potential_clone]
15 | [end_xml_source_coordinate]
16 | end define
17 |
18 | redefine program
19 | [repeat source_unit]
20 | end redefine
21 |
22 | % Main program
23 |
24 | rule main
25 | skipping [source_unit]
26 | replace $ [source_unit]
27 | BeginXML [xml_source_coordinate]
28 | PC [potential_clone]
29 | EndXML [end_xml_source_coordinate]
30 | by
31 | BeginXML
32 | PC [renameIds]
33 | EndXML
34 | end rule
35 |
36 | % Rule to normalize using consistent renaming of identifiers
37 | % to normal form (x1, x2, x3, ...)
38 |
39 | function renameIds
40 | replace [potential_clone]
41 | PC [potential_clone]
42 |
43 | % Make a list of all of the unique identifiers
44 | construct Ids [repeat id]
45 | _ [^ PC] [removeDuplicateIds]
46 |
47 | % Make normalized new names of the form xN for each of them
48 | construct GenIds [repeat id]
49 | Ids [genIds 0]
50 |
51 | % Consistently replace each instance of each one by its normalized form
52 | by
53 | PC [$ each Ids GenIds]
54 | end function
55 |
56 | % Utility rule - remove duplicate ids from a list
57 |
58 | function removeDuplicateIds
59 | replace [repeat id]
60 | Id [id]
61 | Rest [repeat id]
62 | by
63 | Id
64 | Rest [removeIds Id]
65 | [removeDuplicateIds]
66 | end function
67 |
68 | rule removeIds Id [id]
69 | replace [repeat id]
70 | Id
71 | More [repeat id]
72 | by
73 | More
74 | end rule
75 |
76 | % Utility rule - make a normalized id of the form xN for each unique id in a list
77 |
78 | function genIds NM1 [number]
79 | % For each id in the list
80 | replace [repeat id]
81 | _ [id]
82 | Rest [repeat id]
83 |
84 | % Generate the next xN id
85 | construct N [number]
86 | NM1 [+ 1]
87 | construct GenId [id]
88 | _ [+ 'x] [+ N]
89 |
90 | % Replace the id with the generated one
91 | % and recursively do the next one
92 | by
93 | GenId
94 | Rest [genIds N]
95 | end function
96 |
97 |
--------------------------------------------------------------------------------
/txl/getoriginal.txl:
--------------------------------------------------------------------------------
1 | % Program to fetch original source given the XML source coordinates
2 | % Jim Cordy, April 2008
3 |
4 | tokens
5 | charlit ""
6 | end tokens
7 |
8 | define program
9 | [xml_source_coordinate]
10 | | [source_lines]
11 | end define
12 |
13 | define xml_source_coordinate
14 | '< 'source 'file=[stringlit] 'startline=[stringlit] 'endline=[stringlit] '>
15 | end define
16 |
17 | define source_lines
18 | [repeat source_line]
19 | end define
20 |
21 | define source_line
22 | [repeat not_newline] [newline]
23 | end define
24 |
25 | define not_newline
26 | [not newline] [token]
27 | end define
28 |
29 | function main
30 | replace [program]
31 | '< source 'file=File[stringlit] 'startline=Start[stringlit] 'endline=End[stringlit] '>
32 | construct Source [repeat source_line]
33 | _ [pragma "-char -nomultiline"] [read File]
34 | construct StartLine [number]
35 | _ [unquote Start]
36 | construct EndLine [number]
37 | _ [unquote End]
38 | by
39 | Source [select StartLine EndLine]
40 | end function
41 |
--------------------------------------------------------------------------------
/txl/getoriginal.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/getoriginal.x
--------------------------------------------------------------------------------
/txl/ifdef.txl:
--------------------------------------------------------------------------------
1 | % Antoniol et al heuristic to resolve all #ifs in C programs
2 | % Jim Cordy, Feb 2008
3 | % Version 2.0, November 2010
4 |
5 | % Comments out all preprocessor statements, and all #if and #elsif parts
6 | % to leave the body of the #else part of all #ifs only
7 |
8 | % Change Log:
9 | % v2.0
10 | % Inverted to keep #else instead of #if part - JRC 16.11.10
11 | % v1.0
12 | % Refined patterns for commenting out #if 0 - JRC 19.10.09
13 | % Refined token patterns for #if and preprocessor lines - JRC 6.5.08
14 | % Corrected token pattern for #elif - JRC 29.1.10
15 | % Corrected commenting out #elif - JRC 12.11.10
16 |
17 | #pragma -char -comment -esc '\\' -width 32767
18 |
19 | comments
20 | //
21 | end comments
22 |
23 | tokens
24 | % Long comments need to be handled specially
25 | comment "/\*#[(\*/)]*\*/"
26 | end tokens
27 |
28 | compounds
29 | //
30 | end compounds
31 |
32 | tokens
33 | % A preprocessor line is one beginning with a # and then anything to end of line (\n#n*)
34 | % If the line ends in backslash, then it continues on the next line (\\\n)
35 | % Comments are assumed to be part of the preprocessor line (/\*#[(\*/)]*\*/)
36 | ifdef_line "[ \t]*\# *ifn?(def)?[ \t\(][(\\\n)(/\*#[(\*/)]*\*/)#n]*"
37 | elsedef_line "[ \t]*\# *else[(\\\n)(/\*#[(\*/)]*\*/)#n]*"
38 | elsifdef_line "[ \t]*\# *els?ifn?(def)?[ \t][(\\\n)(/\*#[(\*/)]*\*/)#n]*"
39 | endifdef_line "[ \t]*\# *endif[(\\\n)(/\*#[(\*/)]*\*/)#n]*"
40 | other_preprocessor_line "[ \t]*\#[(\\\n)(\"#[\"\n]*\")(/\*#[(\*/)]*\*/)#n]*"
41 | % Anything else, including line comments, is just a text line to us
42 | other_line "#[(/\*)\n]+"
43 | end tokens
44 |
45 | define program
46 | [repeat line]
47 | end define
48 |
49 | define line
50 | [ifdef]
51 | | [opt //] [other_preprocessor_line] [newline]
52 | | [opt //] [any_other_line] [newline]
53 | end define
54 |
55 | define ifdef
56 | [opt //] [ifdef_line] [newline]
57 | [repeat line]
58 | [repeat elsif_part]
59 | [opt else_part]
60 | [opt //] [endifdef_line] [newline]
61 | end define
62 |
63 | define elsif_part
64 | [opt //] [elsifdef_line] [newline]
65 | [repeat line]
66 | end define
67 |
68 | define else_part
69 | [opt //] [elsedef_line] [newline]
70 | [repeat line]
71 | end define
72 |
73 | define any_other_line
74 | [repeat not_newline]
75 | end define
76 |
77 | define not_newline
78 | [long_comment]
79 | | [not ifdef_token] [not newline] [token]
80 | end define
81 |
82 | define long_comment
83 | [repeat comment+]
84 | end define
85 |
86 | define ifdef_token
87 | [ifdef_line]
88 | | [elsedef_line]
89 | | [elsifdef_line]
90 | | [endifdef_line]
91 | end define
92 |
93 | function main
94 | replace [program]
95 | P [program]
96 | deconstruct * [newline] P
97 | NewlineToken [newline]
98 | construct Newline [stringlit]
99 | _ [quote NewlineToken]
100 | export Newline
101 | by
102 | P [commentOutPreprocessors]
103 | [resolveIfdefs]
104 | [resolveIfndefs]
105 | [fixStrangeComments]
106 | end function
107 |
108 | rule resolveIfdefs
109 | replace [ifdef]
110 | IfDef [ifdef_line] NL [newline]
111 | ThenLines [repeat line]
112 | Elsifs [repeat elsif_part]
113 | Else [opt else_part]
114 | EndIf [endifdef_line] _ [newline]
115 | where not
116 | IfDef [grep "ifndef "]
117 | by
118 | // IfDef [commentContinuationsIfDef] NL
119 | ThenLines [commentOutLines]
120 | Elsifs [commentOutElsifs]
121 | [commentOutLines]
122 | Else [commentOutFirst] [commentContinuationsElseDef]
123 | % Leave these lines in
124 | // EndIf [commentContinuationsEndIfDef] NL
125 | end rule
126 |
127 | rule resolveIfndefs
128 | replace [ifdef]
129 | IfDef [ifdef_line] NL [newline]
130 | ThenLines [repeat line]
131 | Elsifs [repeat elsif_part]
132 | Else [opt else_part]
133 | EndIf [endifdef_line] _ [newline]
134 | where
135 | IfDef [grep "ifndef "]
136 | by
137 | // IfDef [commentContinuationsIfDef] NL
138 | % Leave these lines in
139 | ThenLines
140 | Elsifs
141 | [commentOutLines]
142 | Else [commentOutFirst] [commentContinuationsElseDef]
143 | [commentOutLines]
144 | // EndIf [commentContinuationsEndIfDef] NL
145 | end rule
146 |
147 | function commentOutFirst
148 | replace * [opt //]
149 | by
150 | //
151 | end function
152 |
153 | rule commentOutPreprocessors
154 | replace [line]
155 | PrepLine [other_preprocessor_line] NL [newline]
156 | by
157 | // PrepLine [commentContinuationsPrepLine] NL
158 | end rule
159 |
160 | rule commentOutElsifs
161 | replace [elsif_part]
162 | ElsifLine [elsifdef_line] NL [newline]
163 | Lines [repeat line]
164 | by
165 | // ElsifLine NL
166 | Lines
167 | end rule
168 |
169 | rule commentOutLines
170 | replace $ [line]
171 | Line [line]
172 | by
173 | Line [commentOut]
174 | [commentContinuationsIfDef]
175 | [commentContinuationsElseDef]
176 | [commentContinuationsEndIfDef]
177 | [commentContinuationsPrepLine]
178 | [commentContinuationsCommentLine]
179 | end rule
180 |
181 | rule commentOut
182 | replace [opt //]
183 | by
184 | //
185 | end rule
186 |
187 | rule commentContinuationsIfDef
188 | import Newline [stringlit]
189 | replace $ [ifdef_line]
190 | IfDef [ifdef_line]
191 | construct NewlineIndex [number]
192 | _ [index IfDef Newline]
193 | deconstruct not NewlineIndex
194 | 0
195 | construct PreNewline [ifdef_line]
196 | IfDef [: 1 NewlineIndex]
197 | construct NewlinePlus1 [number]
198 | NewlineIndex [+1]
199 | construct PostNewline [ifdef_line]
200 | IfDef [: NewlinePlus1 9999] [commentContinuationsIfDef]
201 | by
202 | PreNewline [+ "//"] [+ PostNewline]
203 | end rule
204 |
205 | rule commentContinuationsElseDef
206 | import Newline [stringlit]
207 | replace $ [elsedef_line]
208 | ElseDef [elsedef_line]
209 | construct NewlineIndex [number]
210 | _ [index ElseDef Newline]
211 | deconstruct not NewlineIndex
212 | 0
213 | construct PreNewline [elsedef_line]
214 | ElseDef [: 1 NewlineIndex]
215 | construct NewlinePlus1 [number]
216 | NewlineIndex [+1]
217 | construct PostNewline [elsedef_line]
218 | ElseDef [: NewlinePlus1 9999] [commentContinuationsElseDef]
219 | by
220 | PreNewline [+ "//"] [+ PostNewline]
221 | end rule
222 |
223 | rule commentContinuationsEndIfDef
224 | import Newline [stringlit]
225 | replace $ [endifdef_line]
226 | EndIfDef [endifdef_line]
227 | construct NewlineIndex [number]
228 | _ [index EndIfDef Newline]
229 | deconstruct not NewlineIndex
230 | 0
231 | construct PreNewline [endifdef_line]
232 | EndIfDef [: 1 NewlineIndex]
233 | construct NewlinePlus1 [number]
234 | NewlineIndex [+1]
235 | construct PostNewline [endifdef_line]
236 | EndIfDef [: NewlinePlus1 9999] [commentContinuationsEndIfDef]
237 | by
238 | PreNewline [+ "//"] [+ PostNewline]
239 | end rule
240 |
241 | rule commentContinuationsPrepLine
242 | import Newline [stringlit]
243 | replace $ [other_preprocessor_line]
244 | PrepLine [other_preprocessor_line]
245 | construct NewlineIndex [number]
246 | _ [index PrepLine Newline]
247 | deconstruct not NewlineIndex
248 | 0
249 | construct PreNewline [other_preprocessor_line]
250 | PrepLine [: 1 NewlineIndex]
251 | construct NewlinePlus1 [number]
252 | NewlineIndex [+1]
253 | construct PostNewline [other_preprocessor_line]
254 | PrepLine [: NewlinePlus1 9999] [commentContinuationsPrepLine]
255 | by
256 | PreNewline [+ "//"] [+ PostNewline]
257 | end rule
258 |
259 | rule commentContinuationsCommentLine
260 | import Newline [stringlit]
261 | replace $ [comment]
262 | Comment [comment]
263 | construct NewlineIndex [number]
264 | _ [index Comment Newline]
265 | deconstruct not NewlineIndex
266 | 0
267 | construct PreNewline [comment]
268 | Comment [: 1 NewlineIndex]
269 | construct NewlinePlus1 [number]
270 | NewlineIndex [+1]
271 | construct PostNewline [comment]
272 | Comment [: NewlinePlus1 9999] [commentContinuationsCommentLine]
273 | by
274 | PreNewline [+ "//"] [+ PostNewline]
275 | end rule
276 |
277 | rule fixStrangeComments
278 | replace $ [other_line]
279 | Line [other_line]
280 | construct StrangeIndex [number]
281 | _ [index Line "/*/"]
282 | deconstruct not StrangeIndex
283 | 0
284 | construct PreStrange [other_line]
285 | Line [: 1 StrangeIndex]
286 | construct StrangePlus1 [number]
287 | StrangeIndex [+1]
288 | construct PostStrange [other_line]
289 | Line [: StrangePlus1 9999]
290 | by
291 | PreStrange [+ "//"] [+ PostStrange]
292 | end rule
293 |
--------------------------------------------------------------------------------
/txl/ifdef.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/ifdef.x
--------------------------------------------------------------------------------
/txl/java-abstract-blocks.txl:
--------------------------------------------------------------------------------
1 | % Abstract given nonterminals from potential clones - Java block version
2 |
3 | % Jim Cordy, May 2010
4 |
5 | % Using Java grammar
6 | include "java.grm"
7 |
8 | % Redefinition for potential clones
9 | redefine block
10 | { [IN] [NL]
11 | [repeat declaration_or_statement] [EX]
12 | } [NL]
13 | end redefine
14 |
15 | define potential_clone
16 | [block]
17 | end define
18 |
19 | % Generic nonterminal abstraction
20 | include "generic-abstract.txl"
21 |
--------------------------------------------------------------------------------
/txl/java-abstract-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/java-abstract-blocks.x
--------------------------------------------------------------------------------
/txl/java-abstract-functions.txl:
--------------------------------------------------------------------------------
1 | % Abstract given nonterminals from potential clones - Java functions version
2 |
3 | % Jim Cordy, May 2010
4 |
5 | % Using Java grammar
6 | include "java.grm"
7 |
8 | define method_definition
9 | [method_header]
10 | '{ [NL][IN]
11 | [repeat declaration_or_statement] [EX]
12 | '}
13 | end define
14 |
15 | define method_header
16 | [repeat modifier] [opt generic_parameter] [opt type_specifier] [method_declarator] [opt throws]
17 | end define
18 |
19 | define potential_clone
20 | [method_definition]
21 | end define
22 |
23 | % Generic nonterminal abstraction
24 | include "generic-abstract.txl"
25 |
--------------------------------------------------------------------------------
/txl/java-abstract-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/java-abstract-functions.x
--------------------------------------------------------------------------------
/txl/java-extract-blocks.txl:
--------------------------------------------------------------------------------
1 | % Example using TXL 10.5a source coordinate extensions to extract
2 | % a table of all blocks with source coordinates
3 |
4 | % Jim Cordy, October 2009
5 |
6 | % Revised Aug 2012 - disallow output forms in input parse - JRC
7 | % Revised July 2011 - ignore BOM headers in source
8 |
9 | % Using Java grammar
10 | include "java.grm"
11 |
12 | % Ignore BOM headers from Windows
13 | include "bom.grm"
14 |
15 | % Redefinitions to collect source coordinates for blocks as parsed input,
16 | % and to allow for XML markup of blocks as output
17 |
18 | redefine block
19 | % Input form
20 | [srcfilename] [srclinenumber] % Keep track of starting file and line number
21 | { [IN] [NL]
22 | [repeat declaration_or_statement] [EX]
23 | [srcfilename] [srclinenumber] % Keep track of ending file and line number
24 | } [opt ';] [NL]
25 | |
26 | % Output form
27 | [not token] % disallow input parse of this form
28 | [opt xml_source_coordinate]
29 | { [IN] [NL]
30 | [repeat declaration_or_statement] [EX]
31 | } [opt ';] [NL]
32 | [opt end_xml_source_coordinate]
33 | end redefine
34 |
35 | define xml_source_coordinate
36 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [NL]
37 | end define
38 |
39 | define end_xml_source_coordinate
40 | '< [SPOFF] '/ 'source '> [SPON] [NL]
41 | end define
42 |
43 | redefine program
44 | ...
45 | | [repeat block]
46 | end redefine
47 |
48 |
49 | % Main function - extract and mark up blocks from parsed input program
50 | function main
51 | replace [program]
52 | P [program]
53 | construct Compounds [repeat block]
54 | _ [^ P] % Extract all blocks from program
55 | [convertCompoundStatements]
56 | by
57 | Compounds [removeOptSemis]
58 | [removeEmptyStatements]
59 | end function
60 |
61 | rule convertCompoundStatements
62 | % Find each block and match its input source coordinates
63 | skipping [block]
64 | replace [block]
65 | FileName [srcfilename] LineNumber [srclinenumber]
66 | '{
67 | CompoundBody [repeat declaration_or_statement]
68 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
69 | '} Semi [opt ';]
70 |
71 | % Convert file name and line numbers to strings for XML
72 | construct FileNameString [stringlit]
73 | _ [quote FileName]
74 | construct LineNumberString [stringlit]
75 | _ [quote LineNumber]
76 | construct EndLineNumberString [stringlit]
77 | _ [quote EndLineNumber]
78 |
79 | % Output is XML form with attributes indicating input source coordinates
80 | construct XmlHeader [xml_source_coordinate]
81 |
82 | by
83 | XmlHeader
84 | {
85 | CompoundBody [unmarkEmbeddedCompoundStatements]
86 | '}
87 |
88 | end rule
89 |
90 | rule unmarkEmbeddedCompoundStatements
91 | replace [block]
92 | FileName [srcfilename] LineNumber [srclinenumber]
93 | '{
94 | CompoundBody [repeat declaration_or_statement]
95 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
96 | '} Semi [opt ';]
97 | construct Empty [opt xml_source_coordinate]
98 | % none, to force output form
99 | by
100 | Empty
101 | '{
102 | CompoundBody
103 | '}
104 | end rule
105 |
106 | rule removeOptSemis
107 | replace [opt ';]
108 | ';
109 | by
110 | % none
111 | end rule
112 |
113 | rule removeEmptyStatements
114 | replace [repeat declaration_or_statement]
115 | ';
116 | More [repeat declaration_or_statement]
117 | by
118 | More
119 | end rule
120 |
--------------------------------------------------------------------------------
/txl/java-extract-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/java-extract-blocks.x
--------------------------------------------------------------------------------
/txl/java-extract-functions.txl:
--------------------------------------------------------------------------------
1 | % Example using TXL 10.5a source coordinate extensions to extract
2 | % a table of all method definitions with source coordinates
3 |
4 | % Jim Cordy, January 2008
5 |
6 | % Revised Nov 2012 - remove @Override annotations from clone comparison - JRC
7 | % Revised Aug 2012 - disallow ouput forms in input parse - JRC
8 | % Revised July 2011 - ignore BOM headers in source
9 | % Revised 25.03.11 - match constructors as methods - JRC
10 | % Revised 30.04.08 - unmark embedded functions - JRC
11 |
12 | % Using Java 5 grammar
13 | include "java.grm"
14 |
15 | % Ignore BOM headers from Windows
16 | include "bom.grm"
17 |
18 | % Redefinitions to collect source coordinates for function definitions as parsed input,
19 | % and to allow for XML markup of function definitions as output
20 |
21 | % Modified to match constructors as well. Even though the grammar still
22 | % has constructor_declaration in it, this one will match first. - JRC 25mar11
23 |
24 | redefine method_declaration
25 | [repeat annotation] % Remove @Override annotations from clone comparison
26 | [method_definition]
27 | |
28 | [method_header]
29 | [opt annotation_default] '; [NL][NL]
30 | end redefine
31 |
32 | define method_definition
33 | % Input form
34 | [srcfilename] [srclinenumber] % Keep track of starting file and line number
35 | [method_header]
36 | '{ [NL][IN]
37 | [repeat declaration_or_statement] [EX]
38 | [srcfilename] [srclinenumber] % Keep track of ending file and line number
39 | '}
40 | |
41 | % Output form
42 | [not token] % disallow output form in input parse
43 | [opt xml_source_coordinate]
44 | [method_header]
45 | '{ [NL][IN]
46 | [repeat declaration_or_statement] [EX]
47 | '}
48 | [opt end_xml_source_coordinate]
49 | end define
50 |
51 | define method_header
52 | [repeat modifier] [opt generic_parameter] [opt type_specifier] [method_declarator] [opt throws]
53 | end define
54 |
55 | define xml_source_coordinate
56 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [NL]
57 | end define
58 |
59 | define end_xml_source_coordinate
60 | [NL] '< [SPOFF] '/ 'source '> [SPON] [NL]
61 | end define
62 |
63 | redefine program
64 | ...
65 | | [repeat method_definition]
66 | end redefine
67 |
68 |
69 | % Main function - extract and mark up function definitions from parsed input program
70 | function main
71 | replace [program]
72 | P [program]
73 | construct Functions [repeat method_definition]
74 | _ [^ P] % Extract all functions from program
75 | [convertFunctionDefinitions] % Mark up with XML
76 | by
77 | Functions [removeOptSemis]
78 | [removeEmptyStatements]
79 | end function
80 |
81 | rule convertFunctionDefinitions
82 | % Find each function definition and match its input source coordinates
83 | replace [method_definition]
84 | FileName [srcfilename] LineNumber [srclinenumber]
85 | FunctionHeader [method_header]
86 | '{
87 | FunctionBody [repeat declaration_or_statement]
88 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
89 | '}
90 |
91 | % Convert file name and line numbers to strings for XML
92 | construct FileNameString [stringlit]
93 | _ [quote FileName]
94 | construct LineNumberString [stringlit]
95 | _ [quote LineNumber]
96 | construct EndLineNumberString [stringlit]
97 | _ [quote EndLineNumber]
98 |
99 | % Output is XML form with attributes indicating input source coordinates
100 | construct XmlHeader [xml_source_coordinate]
101 |
102 | by
103 | XmlHeader
104 | FunctionHeader
105 | '{
106 | FunctionBody [unmarkEmbeddedFunctionDefinitions]
107 | '}
108 |
109 | end rule
110 |
111 | rule unmarkEmbeddedFunctionDefinitions
112 | replace [method_definition]
113 | FileName [srcfilename] LineNumber [srclinenumber]
114 | FunctionHeader [method_header]
115 | '{
116 | FunctionBody [repeat declaration_or_statement]
117 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
118 | '}
119 | by
120 | FunctionHeader
121 | '{
122 | FunctionBody
123 | '}
124 | end rule
125 |
126 | rule removeOptSemis
127 | replace [opt ';]
128 | ';
129 | by
130 | % none
131 | end rule
132 |
133 | rule removeEmptyStatements
134 | replace [repeat declaration_or_statement]
135 | ';
136 | More [repeat declaration_or_statement]
137 | by
138 | More
139 | end rule
140 |
--------------------------------------------------------------------------------
/txl/java-extract-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/java-extract-functions.x
--------------------------------------------------------------------------------
/txl/java-filter-blocks.txl:
--------------------------------------------------------------------------------
1 | % Filter given nonterminals from potential clones - Java block version
2 |
3 | % Jim Cordy, May 2010
4 |
5 | % Using Java grammar
6 | include "java.grm"
7 |
8 | % Redefinition for potential clones
9 | redefine block
10 | { [IN] [NL]
11 | [repeat declaration_or_statement] [EX]
12 | } [NL]
13 | end redefine
14 |
15 | define potential_clone
16 | [block]
17 | end define
18 |
19 | % Generic nonterminal filtering
20 | include "generic-filter.txl"
21 |
--------------------------------------------------------------------------------
/txl/java-filter-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/java-filter-blocks.x
--------------------------------------------------------------------------------
/txl/java-filter-functions.txl:
--------------------------------------------------------------------------------
1 | % Filter given nonterminals from potential clones - Java functions version
2 |
3 | % Jim Cordy, May 2010
4 |
5 | % Using Java grammar
6 | include "java.grm"
7 |
8 | define method_definition
9 | [method_header]
10 | '{ [NL][IN]
11 | [repeat declaration_or_statement] [EX]
12 | '}
13 | end define
14 |
15 | define method_header
16 | [repeat modifier] [opt generic_parameter] [opt type_specifier] [method_declarator] [opt throws]
17 | end define
18 |
19 | define potential_clone
20 | [method_definition]
21 | end define
22 |
23 | % Generic nonterminal filtering
24 | include "generic-filter.txl"
25 |
--------------------------------------------------------------------------------
/txl/java-filter-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/java-filter-functions.x
--------------------------------------------------------------------------------
/txl/java-normalize-ifconditions-functions.txl:
--------------------------------------------------------------------------------
1 | % Example custom context-dependent normalization:
2 | % abstract only if-condition expressions in Java
3 | % Jim Cordy, May 2010
4 |
5 | % Using Java grammar
6 | include "java.grm"
7 |
8 | define method_definition
9 | [method_header]
10 | '{ [NL][IN]
11 | [repeat declaration_or_statement] [EX]
12 | '}
13 | end define
14 |
15 | define method_header
16 | [repeat modifier] [opt generic_parameter] [opt type_specifier] [method_declarator] [opt throws]
17 | end define
18 |
19 | define potential_clone
20 | [method_definition]
21 | end define
22 |
23 | % Generic normalization
24 | include "generic-normalize.txl"
25 |
26 |
27 | % The custom context-dependent normalizing rule you want applied
28 |
29 | rule normalize
30 | replace $ [if_statement]
31 | 'if '( Condition [expression] ')
32 | ThenPart [statement]
33 | ElsePart [opt else_clause]
34 | by
35 | 'if '( 'expression ')
36 | ThenPart
37 | ElsePart
38 | end rule
39 |
--------------------------------------------------------------------------------
/txl/java-normalize-ifconditions-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/java-normalize-ifconditions-functions.x
--------------------------------------------------------------------------------
/txl/java-rename-blind-blocks.txl:
--------------------------------------------------------------------------------
1 | % Blind renaming - Java blocks
2 | % Jim Cordy, May 2010
3 |
4 | % Using Java 5 grammar
5 | include "java.grm"
6 |
7 | redefine block
8 | { [IN] [NL]
9 | [repeat declaration_or_statement] [EX]
10 | } [NL]
11 | end redefine
12 |
13 | define potential_clone
14 | [block]
15 | end define
16 |
17 | % Generic blind renaming
18 | include "generic-rename-blind.txl"
19 |
20 |
--------------------------------------------------------------------------------
/txl/java-rename-blind-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/java-rename-blind-blocks.x
--------------------------------------------------------------------------------
/txl/java-rename-blind-functions.txl:
--------------------------------------------------------------------------------
1 | % Blind renaming - Java functions
2 | % Jim Cordy, May 2010
3 |
4 | % Using Java 5 grammar
5 | include "java.grm"
6 |
7 | define method_definition
8 | [method_header]
9 | '{ [NL][IN]
10 | [repeat declaration_or_statement] [EX]
11 | '}
12 | end define
13 |
14 | define method_header
15 | [repeat modifier] [opt generic_parameter] [opt type_specifier] [method_declarator] [opt throws]
16 | end define
17 |
18 | define potential_clone
19 | [method_definition]
20 | end define
21 |
22 | % Generic blind renaming
23 | include "generic-rename-blind.txl"
24 |
25 |
--------------------------------------------------------------------------------
/txl/java-rename-blind-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/java-rename-blind-functions.x
--------------------------------------------------------------------------------
/txl/java-rename-consistent-blocks.txl:
--------------------------------------------------------------------------------
1 | % Consistent renaming - Java blocks
2 | % Jim Cordy, May 2010
3 |
4 | % Using Java 5 grammar
5 | include "java.grm"
6 |
7 | redefine block
8 | { [IN] [NL]
9 | [repeat declaration_or_statement] [EX]
10 | } [NL]
11 | end redefine
12 |
13 | define potential_clone
14 | [block]
15 | end define
16 |
17 | % Generic consistent renaming
18 | include "generic-rename-consistent.txl"
19 |
20 |
--------------------------------------------------------------------------------
/txl/java-rename-consistent-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/java-rename-consistent-blocks.x
--------------------------------------------------------------------------------
/txl/java-rename-consistent-functions.txl:
--------------------------------------------------------------------------------
1 | % Consistent renaming - Java functions
2 | % Jim Cordy, May 2010
3 |
4 | % Using Java 5 grammar
5 | include "java.grm"
6 |
7 | define method_definition
8 | [method_header]
9 | '{ [NL][IN]
10 | [repeat declaration_or_statement] [EX]
11 | '}
12 | end define
13 |
14 | define method_header
15 | [repeat modifier] [opt generic_parameter] [opt type_specifier] [method_declarator] [opt throws]
16 | end define
17 |
18 | define potential_clone
19 | [method_definition]
20 | end define
21 |
22 | % Generic consistent renaming
23 | include "generic-rename-consistent.txl"
24 |
25 |
--------------------------------------------------------------------------------
/txl/java-rename-consistent-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/java-rename-consistent-functions.x
--------------------------------------------------------------------------------
/txl/java.txl:
--------------------------------------------------------------------------------
1 | % Example using TXL 10.5a source coordinate extensions to extract
2 | % a table of all method definitions with source coordinates
3 |
4 | % Jim Cordy, January 2008
5 |
6 | % Requires TXL 10.5a or later
7 |
8 | % Using Java 5 grammar
9 | include "java.grm"
10 |
11 | % Main function - extract and mark up function definitions from parsed input program
12 | function main
13 | match [program]
14 | P [program]
15 | end function
16 |
--------------------------------------------------------------------------------
/txl/java.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/java.x
--------------------------------------------------------------------------------
/txl/py-abstract-blocks.txl:
--------------------------------------------------------------------------------
1 | % Abstract given nonterminals from potential clones - Python block version
2 |
3 | % Jim Cordy, May 2010
4 |
5 | % Using Python grammar
6 | include "python.grm"
7 |
8 | % Redefinition for potential clones
9 | define potential_clone
10 | [block]
11 | end define
12 |
13 | redefine indent
14 | [opt newline] 'INDENT [IN]
15 | end redefine
16 |
17 | redefine dedent
18 | [EX] 'DEDENT [newline]
19 | end redefine
20 |
21 | % Generic abstract
22 | include "generic-abstract.txl"
23 |
24 | % Specialize for Python
25 | redefine xml_source_coordinate
26 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [newline]
27 | end redefine
28 |
29 | redefine end_xml_source_coordinate
30 | '< [SPOFF] '/ 'source '> [SPON] [newline]
31 | end redefine
32 |
--------------------------------------------------------------------------------
/txl/py-abstract-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/py-abstract-blocks.x
--------------------------------------------------------------------------------
/txl/py-abstract-functions.txl:
--------------------------------------------------------------------------------
1 | % Abstract given nonterminals from potential clones - Python function version
2 |
3 | % Jim Cordy, May 2010
4 |
5 | % Using Python grammar
6 | include "python.grm"
7 |
8 | % Redefinition for potential clones
9 | define block_funcdef
10 | 'def [id] [parameters] ':
11 | [indent] [endofline]
12 | [repeat fstatement+]
13 | [dedent]
14 | end define
15 |
16 | define fstatement
17 | [repeat newline] [statement]
18 | end define
19 |
20 | define potential_clone
21 | [block_funcdef]
22 | end define
23 |
24 | redefine indent
25 | [newline] 'INDENT [IN]
26 | end redefine
27 |
28 | redefine dedent
29 | [EX] 'DEDENT [newline]
30 | end redefine
31 |
32 | % Generic abstract
33 | include "generic-abstract.txl"
34 |
35 | % Specialize for Python
36 | redefine xml_source_coordinate
37 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [newline]
38 | end redefine
39 |
40 | redefine end_xml_source_coordinate
41 | '< [SPOFF] '/ 'source '> [SPON] [newline]
42 | end redefine
43 |
--------------------------------------------------------------------------------
/txl/py-abstract-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/py-abstract-functions.x
--------------------------------------------------------------------------------
/txl/py-extract-blocks.txl:
--------------------------------------------------------------------------------
1 | % Example using TXL 10.5a source coordinate extensions to extract
2 | % a table of all method definitions with source coordinates
3 |
4 | % Jim Cordy, January 2008
5 |
6 | % Revised Aug 2012 - disallow ouput forms in input parse - JRC
7 | % Revised July 2011 - ignore BOM headers in source
8 | % Revised 30.04.08 - unmark embedded blocks - JRC
9 |
10 | % Using Python grammar
11 | include "python.grm"
12 |
13 | % Ignore BOM headers from Windows
14 | include "bom.grm"
15 |
16 | % Redefinitions to collect source coordinates for block definitions as parsed input,
17 | % and to allow for XML markup of block definitions as output
18 |
19 | redefine block
20 | % input form
21 | [srcfilename] [srclinenumber] % Keep track of starting file and line number
22 | [indent] [endofline]
23 | [opt doccomment]
24 | [repeat statement_or_newline+]
25 | [srcfilename] [srclinenumber] % Keep track of ending file and line number
26 | [dedent]
27 | |
28 | % output form
29 | [not token] % disallow output form in input parse
30 | [opt xml_source_coordinate]
31 | [indent] [endofline]
32 | [repeat statement_or_newline+]
33 | [dedent]
34 | [opt end_xml_source_coordinate]
35 | end redefine
36 |
37 | define doccomment
38 | [longstringlit] [endofline]
39 | | [longcharlit] [endofline]
40 | end define
41 |
42 | redefine indent
43 | [NL] 'INDENT [IN]
44 | | [firstindent]
45 | end redefine
46 |
47 | define firstindent
48 | 'INDENT [IN]
49 | end define
50 |
51 | redefine dedent
52 | [EX] 'DEDENT [NL]
53 | end redefine
54 |
55 | define xml_source_coordinate
56 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [NL]
57 | end define
58 |
59 | define end_xml_source_coordinate
60 | '< [SPOFF] '/ 'source '> [SPON] [NL]
61 | end define
62 |
63 | redefine program
64 | ...
65 | | [repeat block]
66 | end redefine
67 |
68 |
69 | % Main function - extract and mark up block definitions from parsed input program
70 | function main
71 | replace [program]
72 | P [program]
73 | construct Blocks [repeat block]
74 | _ [^ P] % Extract all blocks from program
75 | [removeEmptyBlocks] % Get rid of empty ones
76 | [convertBlockDefinitions] % Mark up with XML
77 | by
78 | Blocks
79 | end function
80 |
81 | rule convertBlockDefinitions
82 | % Find each block definition and match its input source coordinates
83 | replace [block]
84 | FileName [srcfilename] LineNumber [srclinenumber]
85 | Indent [indent] EOL [endofline]
86 | DocComment [opt doccomment]
87 | BlockBody [repeat statement_or_newline+]
88 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
89 | Dedent [dedent]
90 |
91 | % Convert file name and line numbers to strings for XML
92 | construct FileNameString [stringlit]
93 | _ [quote FileName]
94 | construct LineNumberString [stringlit]
95 | _ [quote LineNumber]
96 | construct LineNumberPlus1 [number]
97 | _ [unquote LineNumberString] [+ 1]
98 | construct LineNumberPlus1String [stringlit]
99 | _ [quote LineNumberPlus1]
100 | construct EndLineNumberString [stringlit]
101 | _ [quote EndLineNumber]
102 | construct EndLineNumberMinus1 [number]
103 | _ [unquote EndLineNumberString] [- 1]
104 | construct EndLineNumberMinus1String [stringlit]
105 | _ [quote EndLineNumberMinus1]
106 | construct FirstIndent [firstindent]
107 | 'INDENT
108 |
109 | % Output is XML form with attributes indicating input source coordinates
110 | construct XmlHeader [xml_source_coordinate]
111 |
112 | by
113 | XmlHeader
114 | FirstIndent EOL
115 | BlockBody [unmarkEmbeddedBlockDefinitions]
116 | [reduceEndOfLines]
117 | [reduceEndOfLines2]
118 | [reduceEmptyStmts]
119 | Dedent
120 |
121 | end rule
122 |
123 | rule unmarkEmbeddedBlockDefinitions
124 | replace [block]
125 | FileName [srcfilename] LineNumber [srclinenumber]
126 | Indent [indent] EOL [endofline]
127 | DocComment [opt doccomment]
128 | BlockBody [repeat statement_or_newline+]
129 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
130 | Dedent [dedent]
131 | by
132 | Indent EOL
133 | BlockBody
134 | Dedent
135 | end rule
136 |
137 | rule reduceEndOfLines
138 | replace [repeat endofline]
139 | EOL [endofline]
140 | _ [endofline]
141 | _ [repeat endofline]
142 | by
143 | EOL
144 | end rule
145 |
146 | rule reduceEndOfLines2
147 | replace [opt endofline]
148 | EOL [endofline]
149 | by
150 | end rule
151 |
152 | rule reduceEmptyStmts
153 | replace [repeat statement_or_newline]
154 | EOL [endofline]
155 | Stmts [repeat statement_or_newline]
156 | by
157 | Stmts
158 | end rule
159 |
160 | rule removeEmptyBlocks
161 | replace [repeat block]
162 | FileName [srcfilename] LineNumber [srclinenumber]
163 | Indent [indent] EOL [endofline]
164 | DocComment [opt doccomment]
165 | BlockBody [repeat statement_or_newline+]
166 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
167 | Dedent [dedent]
168 | More [repeat block]
169 | deconstruct not * [statement] BlockBody
170 | Stmt [statement]
171 | by
172 | More
173 | end rule
174 |
--------------------------------------------------------------------------------
/txl/py-extract-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/py-extract-blocks.x
--------------------------------------------------------------------------------
/txl/py-extract-functions.txl:
--------------------------------------------------------------------------------
1 | % Extract function defintions from Python code
2 |
3 | % Jim Cordy, January 2010
4 |
5 | % Revised Aug 2012 - disallow ouput forms in input parse - JRC
6 | % Revised July 2011 - ignore BOM headers in source
7 |
8 | % Using Python grammar
9 | include "python.grm"
10 |
11 | % Ignore BOM headers from Windows
12 | include "bom.grm"
13 |
14 | % Redefinitions to collect source coordinates for function definitions as parsed input,
15 | % and to allow for XML markup of function definitions as output
16 |
17 | redefine funcdef
18 | [block_funcdef]
19 | | [simple_funcdef] % Remove one liners from potential clone output
20 | end redefine
21 |
22 | define simple_funcdef
23 | 'def [id] [parameters] ': [simple_statement] [endofline]
24 | end define
25 |
26 | define block_funcdef
27 | % input form
28 | [srcfilename] [srclinenumber] % Keep track of starting file and line number
29 | 'def [id] [parameters] ':
30 | [indent] [endofline]
31 | [opt doccomment] % Remove doc comments from potential clone output
32 | [repeat fstatement+]
33 | [srcfilename] [srclinenumber]
34 | [repeat newline]
35 | [dedent]
36 | |
37 | % output form
38 | [not token] % disallow output form in input parse
39 | [opt xml_source_coordinate]
40 | 'def [id] [parameters] ':
41 | [indent] [endofline]
42 | [repeat fstatement+]
43 | [dedent]
44 | [opt end_xml_source_coordinate]
45 | end define
46 |
47 | define doccomment
48 | [longstringlit] [endofline]
49 | | [longcharlit] [endofline]
50 | end define
51 |
52 | define fstatement
53 | [repeat newline] [statement]
54 | end define
55 |
56 | redefine indent
57 | [NL] 'INDENT [IN]
58 | end redefine
59 |
60 | redefine dedent
61 | [EX] 'DEDENT [NL]
62 | end redefine
63 |
64 | define xml_source_coordinate
65 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [NL]
66 | end define
67 |
68 | define end_xml_source_coordinate
69 | '< [SPOFF] '/ 'source '> [SPON] [NL]
70 | end define
71 |
72 | redefine program
73 | ...
74 | | [repeat block_funcdef]
75 | end redefine
76 |
77 |
78 | % Main function - extract and mark up function definitions from parsed input program
79 | function main
80 | replace [program]
81 | P [program]
82 | construct Functions [repeat block_funcdef]
83 | _ [^ P] % Extract all functions from program
84 | [removeEmptyFunctions] % Any left over didn't have a statement in them
85 | [convertFunctionDefinitions] % Mark up with XML
86 | by
87 | Functions
88 | end function
89 |
90 | rule convertFunctionDefinitions
91 | % Find each function definition and match its input source coordinates
92 | skipping [block_funcdef]
93 | replace [block_funcdef]
94 | FileName [srcfilename] LineNumber [srclinenumber]
95 | 'def FunctionId [id] Parameters [parameters] ': Indent [indent] EOL [endofline]
96 | DocComment [opt doccomment]
97 | FunctionBody [repeat fstatement+]
98 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
99 | _ [repeat newline]
100 | Dedent [dedent]
101 |
102 | % Convert file name and line numbers to strings for XML
103 | construct FileNameString [stringlit]
104 | _ [quote FileName]
105 | construct LineNumberString [stringlit]
106 | _ [quote LineNumber]
107 | construct EndLineNumberMinus2 [number]
108 | _ [pragma "--newline"] [parse EndLineNumber] [- 1] % correct for DEDENT lines
109 | construct EndLineNumberString [stringlit]
110 | _ [quote EndLineNumberMinus2]
111 |
112 | % Output is XML form with attributes indicating input source coordinates
113 | construct XmlHeader [xml_source_coordinate]
114 |
115 | by
116 | XmlHeader
117 | 'def FunctionId Parameters ':
118 | Indent EOL
119 | FunctionBody [unmarkEmbeddedFunctionDefinitions]
120 | [reduceEndOfLines] [reduceEndOfLines2]
121 | [reduceNewlines] [reduceEmptyStmts]
122 | Dedent
123 |
124 | end rule
125 |
126 | rule unmarkEmbeddedFunctionDefinitions
127 | replace [block_funcdef]
128 | FileName [srcfilename] LineNumber [srclinenumber]
129 | 'def FunctionId [id] Parameters [parameters] ': Indent [indent] EOL [endofline]
130 | DocComment [opt doccomment]
131 | FunctionBody [repeat fstatement+]
132 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
133 | _ [repeat newline]
134 | Dedent [dedent]
135 | by
136 | 'def FunctionId Parameters ':
137 | Indent EOL
138 | FunctionBody
139 | Dedent
140 | end rule
141 |
142 | rule reduceEndOfLines
143 | replace [repeat endofline]
144 | EOL [endofline]
145 | _ [endofline]
146 | _ [repeat endofline]
147 | by
148 | EOL
149 | end rule
150 |
151 | rule reduceEndOfLines2
152 | replace [opt endofline]
153 | EOL [endofline]
154 | by
155 | end rule
156 |
157 | rule reduceNewlines
158 | replace [repeat newline]
159 | Newlne [newline]
160 | _ [repeat newline]
161 | by
162 | end rule
163 |
164 | rule reduceEmptyStmts
165 | replace [repeat statement_or_newline]
166 | EOL [endofline]
167 | Stmts [repeat statement_or_newline]
168 | by
169 | Stmts
170 | end rule
171 |
172 | rule removeEmptyFunctions
173 | replace [repeat block_funcdef]
174 | FileName [srcfilename] LineNumber [srclinenumber]
175 | 'def FunctionId [id] Parameters [parameters] ':
176 | Indent [indent] EOL [endofline]
177 | DocComment [opt doccomment]
178 | FunctionBody [repeat fstatement+]
179 | EndFileName [srcfilename] EndLineNumber [srclinenumber]
180 | _ [repeat newline]
181 | Dedent [dedent]
182 | More [repeat block_funcdef]
183 | deconstruct not * [statement] FunctionBody
184 | Stmt [statement]
185 | by
186 | More
187 | end rule
188 |
--------------------------------------------------------------------------------
/txl/py-extract-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/py-extract-functions.x
--------------------------------------------------------------------------------
/txl/py-filter-blocks.txl:
--------------------------------------------------------------------------------
1 | % Filter given nonterminals from potential clones - Python block version
2 |
3 | % Jim Cordy, May 2010
4 |
5 | % Using Python grammar
6 | include "python.grm"
7 |
8 | % Redefinition for potential clones
9 | define potential_clone
10 | [block]
11 | end define
12 |
13 | redefine indent
14 | [opt newline] 'INDENT [IN]
15 | end redefine
16 |
17 | redefine dedent
18 | [EX] 'DEDENT [newline]
19 | end redefine
20 |
21 | % Generic filter
22 | include "generic-filter.txl"
23 |
24 | % Specialize for Python
25 | redefine xml_source_coordinate
26 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [newline]
27 | end redefine
28 |
29 | redefine end_xml_source_coordinate
30 | '< [SPOFF] '/ 'source '> [SPON] [newline]
31 | end redefine
32 |
--------------------------------------------------------------------------------
/txl/py-filter-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/py-filter-blocks.x
--------------------------------------------------------------------------------
/txl/py-filter-functions.txl:
--------------------------------------------------------------------------------
1 | % Filter given nonterminals from potential clones - Python function version
2 |
3 | % Jim Cordy, May 2010
4 |
5 | % Using Python grammar
6 | include "python.grm"
7 |
8 | % Redefinition for potential clones
9 | define block_funcdef
10 | 'def [id] [parameters] ':
11 | [indent] [endofline]
12 | [repeat fstatement+]
13 | [dedent]
14 | end define
15 |
16 | define fstatement
17 | [repeat newline] [statement]
18 | end define
19 |
20 | define potential_clone
21 | [block_funcdef]
22 | end define
23 |
24 | redefine indent
25 | [newline] 'INDENT [IN]
26 | end redefine
27 |
28 | redefine dedent
29 | [EX] 'DEDENT [newline]
30 | end redefine
31 |
32 | % Generic filter
33 | include "generic-filter.txl"
34 |
35 | % Specialize for Python
36 | redefine xml_source_coordinate
37 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [newline]
38 | end redefine
39 |
40 | redefine end_xml_source_coordinate
41 | '< [SPOFF] '/ 'source '> [SPON] [newline]
42 | end redefine
43 |
--------------------------------------------------------------------------------
/txl/py-filter-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/py-filter-functions.x
--------------------------------------------------------------------------------
/txl/py-rename-blind-blocks.txl:
--------------------------------------------------------------------------------
1 | % Blind renaming - Python blocks
2 | % Jim Cordy, May 2010
3 |
4 | % Using Python grammar
5 | include "python.grm"
6 |
7 | % Redefinition for potential clones
8 | define potential_clone
9 | [block]
10 | end define
11 |
12 | redefine indent
13 | [opt newline] 'INDENT [IN]
14 | end redefine
15 |
16 | redefine dedent
17 | [EX] 'DEDENT [newline]
18 | end redefine
19 |
20 | % Generic blind renaming
21 | include "generic-rename-blind.txl"
22 |
23 | % Specialize for Python
24 | redefine xml_source_coordinate
25 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [newline]
26 | end redefine
27 |
28 | redefine end_xml_source_coordinate
29 | '< [SPOFF] '/ 'source '> [SPON] [newline]
30 | end redefine
31 |
--------------------------------------------------------------------------------
/txl/py-rename-blind-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/py-rename-blind-blocks.x
--------------------------------------------------------------------------------
/txl/py-rename-blind-functions.txl:
--------------------------------------------------------------------------------
1 | % Blind renaming - Python functions
2 | % Jim Cordy, May 2010
3 |
4 | % Using Python grammar
5 | include "python.grm"
6 |
7 | % Redefinition for potential clones
8 | define block_funcdef
9 | 'def [id] [parameters] ':
10 | [indent] [endofline]
11 | [repeat fstatement+]
12 | [dedent]
13 | end define
14 |
15 | define fstatement
16 | [repeat newline] [statement]
17 | end define
18 |
19 | define potential_clone
20 | [block_funcdef]
21 | end define
22 |
23 | redefine indent
24 | [newline] 'INDENT [IN]
25 | end redefine
26 |
27 | redefine dedent
28 | [EX] 'DEDENT [newline]
29 | end redefine
30 |
31 | % Generic blind renaming
32 | include "generic-rename-blind.txl"
33 |
34 | % Specialize for Python
35 | redefine xml_source_coordinate
36 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [newline]
37 | end redefine
38 |
39 | redefine end_xml_source_coordinate
40 | '< [SPOFF] '/ 'source '> [SPON] [newline]
41 | end redefine
42 |
--------------------------------------------------------------------------------
/txl/py-rename-blind-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/py-rename-blind-functions.x
--------------------------------------------------------------------------------
/txl/py-rename-consistent-blocks.txl:
--------------------------------------------------------------------------------
1 | % Consistent renaming - Python blocks
2 | % Jim Cordy, May 2010
3 |
4 | % Using Python grammar
5 | include "python.grm"
6 |
7 | % Redefinition for potential clones
8 | define potential_clone
9 | [block]
10 | end define
11 |
12 | redefine indent
13 | [opt newline] 'INDENT [IN]
14 | end redefine
15 |
16 | redefine dedent
17 | [EX] 'DEDENT [newline]
18 | end redefine
19 |
20 | % Generic consistent renaming
21 | include "generic-rename-consistent.txl"
22 |
23 | % Specialize for Python
24 | redefine xml_source_coordinate
25 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [newline]
26 | end redefine
27 |
28 | redefine end_xml_source_coordinate
29 | '< [SPOFF] '/ 'source '> [SPON] [newline]
30 | end redefine
31 |
--------------------------------------------------------------------------------
/txl/py-rename-consistent-blocks.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/py-rename-consistent-blocks.x
--------------------------------------------------------------------------------
/txl/py-rename-consistent-functions.txl:
--------------------------------------------------------------------------------
1 | % Consistent renaming - Python functions
2 | % Jim Cordy, May 2010
3 |
4 | % Using Python grammar
5 | include "python.grm"
6 |
7 | % Redefinition for potential clones
8 | define block_funcdef
9 | 'def [id] [parameters] ':
10 | [indent] [endofline]
11 | [repeat fstatement+]
12 | [dedent]
13 | end define
14 |
15 | define fstatement
16 | [repeat newline] [statement]
17 | end define
18 |
19 | define potential_clone
20 | [block_funcdef]
21 | end define
22 |
23 | redefine indent
24 | [newline] 'INDENT [IN]
25 | end redefine
26 |
27 | redefine dedent
28 | [EX] 'DEDENT [newline]
29 | end redefine
30 |
31 | % Generic consistent renaming
32 | include "generic-rename-consistent.txl"
33 |
34 | % Specialize for Python
35 | redefine xml_source_coordinate
36 | '< [SPOFF] 'source [SP] 'file=[stringlit] [SP] 'startline=[stringlit] [SP] 'endline=[stringlit] '> [SPON] [newline]
37 | end redefine
38 |
39 | redefine end_xml_source_coordinate
40 | '< [SPOFF] '/ 'source '> [SPON] [newline]
41 | end redefine
42 |
--------------------------------------------------------------------------------
/txl/py-rename-consistent-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/py-rename-consistent-functions.x
--------------------------------------------------------------------------------
/txl/py.txl:
--------------------------------------------------------------------------------
1 | include "python.grm"
2 |
3 | function main
4 | match [program]
5 | P [program]
6 | end function
7 |
8 |
--------------------------------------------------------------------------------
/txl/py.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/py.x
--------------------------------------------------------------------------------
/txl/pyindent.txl:
--------------------------------------------------------------------------------
1 | % Program to explicate standard Python INDENT/DEDENT symbols
2 | % J.R. Cordy, Queen's University, November 2008
3 |
4 | % Copyright 2008 James R. Cordy
5 |
6 | % Redistribution and use in source and binary forms, with or without
7 | % modification, are permitted provided that the following conditions are met:
8 | %
9 | % Redistributions of source code must retain the above copyright notice,
10 | % this list of conditions and the following disclaimer.
11 | % Redistributions in binary form must reproduce the above copyright notice,
12 | % this list of conditions and the following disclaimer in the documentation
13 | % and/or other materials provided with the distribution.
14 | %
15 | % THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
16 | % INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
17 | % AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
18 | % AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
19 | % OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 | % SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 | % INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 | % CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 | % ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 | % POSSIBILITY OF SUCH DAMAGE.
25 |
26 | % Modification Log:
27 |
28 | % v1.3, Jim Cordy, 13 November 2008.
29 | % Validated against 1,500 random Python programs,
30 | % including the entire Python demo set
31 | %
32 | % v1.2, Jim Cordy, 12 November 2008.
33 | % Changed to Python INDENT / DEDENT syntax rather than { }
34 | % Added proper handling of long strings
35 | % Added proper handling of Python { }, [ ] and ( ) compound structures
36 | % Added proper handling of comments and blank lines
37 | %
38 | % v1.1, Jim Cordy, November 2008.
39 | % Fixed problem caused by empty lines.
40 | %
41 | % v1.0, Jim Cordy, November 2008.
42 | % Initial revision.
43 |
44 | % This is a character-level transformation
45 | #pragma -char -comment -w 32000
46 |
47 | % We need to expand tabs and count spaces, so override [space] to be a single blank
48 | % and define a [tab] token for a single tab character
49 | tokens
50 | space " "
51 | tab " " % ASCII TAB (ctrl-i) character
52 | end tokens
53 |
54 | % Python long tokens
55 | tokens
56 | longstringlit "\"\"\"#[(\"\"\")]*\"\"\""
57 | longcharlit "'''#[(''')]*'''"
58 | end tokens
59 |
60 | % Python comemnts
61 | comments
62 | '#
63 | end comments
64 |
65 | tokens
66 | ignore "\\\n"
67 | end tokens
68 |
69 | % For this transformation, the input is a sequence of lines
70 | define program
71 | [repeat line]
72 | end define
73 |
74 | % Each input line consists of spacing indentation followed by the contents of the line
75 | % the [opt indent] and [repeat dedent] allow us to insert { } as needed
76 | define line
77 | [repeat tab_space] [not tab_space] [repeat linetoken] [opt indent] [repeat endofline+] [repeat dedent]
78 | end define
79 |
80 | % End of line handles trailing comments and trailing blank and comment lines
81 | define endofline
82 | [repeat tab_space] [opt comment] [newline]
83 | end define
84 |
85 | % We infer the standard Python implcit INDENT / DEDENT symbols from
86 | % the indentation in the program using the Python offside rules
87 | define indent
88 | [SP] 'INDENT
89 | end define
90 |
91 | define dedent
92 | 'DEDENT [SP]
93 | end define
94 |
95 | define tab_space
96 | [tab] | [space]
97 | end define
98 |
99 | define linetoken
100 | [repeat tab_space+]
101 | | [nonblank_token]
102 | end define
103 |
104 | define nonblank_token
105 | [compound]
106 | | [not newline] [not comment] [token]
107 | end define
108 |
109 | % We need to be careful to treat Python atomic structures specially,
110 | % so that we don't mistake the newlines and indentations in them as
111 | % meaningful
112 | define compound
113 | '{ [repeat compoundtoken] '}
114 | | '[ [repeat compoundtokensquare] ']
115 | | '( [repeat compoundtokenround] ')
116 | end define
117 |
118 | define compoundtoken
119 | [repeat tab_space+]
120 | | [not tab_space] [not '}] [linetoken]
121 | | [newline]
122 | | [comment]
123 | end define
124 |
125 | define compoundtokensquare
126 | [repeat tab_space+]
127 | | [not tab_space] [not ']] [linetoken]
128 | | [newline]
129 | | [comment]
130 | end define
131 |
132 | define compoundtokenround
133 | [repeat tab_space+]
134 | | [not tab_space] [not ')] [linetoken]
135 | | [newline]
136 | | [comment]
137 | end define
138 |
139 | % The main program - expands tabs to spaces, then infers where INDENT / DEDENT
140 | % go using Python offside rules
141 | function main
142 | replace [program]
143 | Lines [repeat line]
144 | by
145 | Lines [markEOF]
146 | [deleteRedundantSpaces]
147 | [expandTabs]
148 | [insertIndents]
149 | [unmarkEOF]
150 | end function
151 |
152 | % Leading spaces before a tab are assumed meaningless
153 | rule deleteRedundantSpaces
154 | replace [repeat tab_space]
155 | _ [space] Tab [tab] More [repeat tab_space]
156 | by
157 | Tab More
158 | end rule
159 |
160 | % According to the Python spec, each leading tab expands to exactly 8 spaces
161 | rule expandTabs
162 | construct Space [space]
163 | _ [unquote " "]
164 | replace [repeat tab_space]
165 | Tab [tab] Rest [repeat tab_space]
166 | by
167 | Space Space Space Space Space Space Space Space Rest
168 | end rule
169 |
170 | % Insert a { before each new indentation level ...
171 | rule insertIndents
172 | replace [repeat line]
173 | Space1 [repeat tab_space] Content1 [repeat linetoken] NL [repeat endofline+] Dedents1 [repeat dedent]
174 | Rest [repeat line]
175 | deconstruct * [nonblank_token] Content1
176 | _ [nonblank_token]
177 | %% deconstruct not * [nonblank_token] Content1
178 | %% '\
179 | deconstruct Rest
180 | Space2 [repeat tab_space] Content2 [repeat linetoken] _ [opt indent] _ [repeat endofline+] _ [repeat dedent]
181 | _ [repeat line]
182 | deconstruct * [nonblank_token] Content2
183 | _ [nonblank_token]
184 | construct LengthSpace1 [number]
185 | _ [length Space1]
186 | construct LengthSpace2 [number]
187 | _ [length Space2]
188 | where
189 | LengthSpace2 [> LengthSpace1]
190 | by
191 | Space1 Content1 'INDENT NL Dedents1
192 | Rest [insertDedent Space1]
193 | end rule
194 |
195 | % ... and a } before the corresponding dedent from that level
196 | function insertDedent Space [repeat tab_space]
197 | replace * [repeat line]
198 | Space1 [repeat tab_space] Content1 [repeat linetoken] Indent1 [opt indent] NL [repeat
199 | endofline+] Dedents1 [repeat dedent]
200 | Space2 [repeat tab_space] Content2 [repeat linetoken] Indent2 [opt indent] NL2 [repeat
201 | endofline+] Dedents2 [repeat dedent]
202 | Rest [repeat line]
203 | deconstruct * [nonblank_token] Content2
204 | _ [nonblank_token]
205 | construct LengthSpace [number]
206 | _ [length Space]
207 | construct LengthSpace2 [number]
208 | _ [length Space2]
209 | where
210 | LengthSpace2 [<= LengthSpace]
211 | by
212 | Space1 Content1 Indent1 NL 'DEDENT Dedents1
213 | Space2 Content2 Indent2 NL2 Dedents2
214 | Rest
215 | end function
216 |
217 | function markEOF
218 | construct OptNL [opt newline]
219 | _ [parse ""]
220 | deconstruct OptNL
221 | NL [newline]
222 | replace [repeat line]
223 | Lines [repeat line]
224 | construct EOFline [line]
225 | 'EOF NL
226 | by
227 | Lines [. EOFline]
228 | end function
229 |
230 | function unmarkEOF
231 | replace * [repeat line]
232 | 'EOF NL [newline]
233 | by
234 | end function
235 |
--------------------------------------------------------------------------------
/txl/pyindent.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/pyindent.x
--------------------------------------------------------------------------------
/txl/python.grm:
--------------------------------------------------------------------------------
1 | % TXL Python grammar
2 | % Mykhaylo Sorochan and Jim Cordy, November 2008
3 | % Version 1.5, June 2015
4 |
5 | % Copyright 2008 Mykhaylo Sorochan and James R. Cordy,
6 | % after the standard Python 2.5 reference grammar,
7 | % Copyright 1990-2008 Python Software Foundation
8 |
9 | % Redistribution and use in source and binary forms, with or without
10 | % modification, are permitted provided that the following conditions are met:
11 | %
12 | % Redistributions of source code must retain the above copyright notice,
13 | % this list of conditions and the following disclaimer.
14 | % Redistributions in binary form must reproduce the above copyright notice,
15 | % this list of conditions and the following disclaimer in the documentation
16 | % and/or other materials provided with the distribution.
17 | %
18 | % THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 | % INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20 | % AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21 | % AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22 | % OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 | % SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 | % INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 | % CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 | % ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 | % POSSIBILITY OF SUCH DAMAGE.
28 |
29 | % Modification Log:
30 |
31 | % v1.5, Jim Cordy, June 2015.
32 | % Fixed bug with missing comma in [startest]
33 | % Modifed [statement_or_newline] to avoid deep long backtracks
34 | % Added Python 3 syntax for [print_statement]
35 | % Fixed yield statement to allow no value
36 | % Added explicit octal tokens (e.g., 0o600)
37 | %
38 | % v1.4, Jim Cordy, March 2012.
39 | % Refactored to expose [condition] for if/while conditions, [expression], [block]
40 | %
41 | % v1.3, Jim Cordy, 13 November 2008.
42 | % Validated against a library of 1,500 random Python programs including the
43 | % entire Python demo set.
44 | %
45 | % v1.2, Jim Cordy and Mykhaylo Sorochan, 12 November 2008.
46 | % Fixed the [literal] definition and all token patterns to correspond to the Python 2.5 standard.
47 | % Corrected [return_statement] and [comp_op].
48 | % Changed to standard INDENT / DEDENT tokens rather than C-style brackets to avoid confusion
49 | % with Python { } compound structures.
50 | %
51 | % v1.1, Jim Cordy, November 2008.
52 | % Tuned and reprogrammed for TXL. Added newline sensitivity.
53 | % Added use of bracketing preprocessor pyindent.txl to handle Python INDENT/DEDENT rules.
54 | %
55 | % v1.0, Mykhaylo Sorochan, October 2008.
56 | % Initial revision.
57 |
58 | % This grammar expects that Python INDENTs and DEDENTs have been made explicit using
59 | % C-style { and } bracketing as output by pyindent.txl. It parses and removes { }
60 | % as INDENT/DEDENT symbols.
61 |
62 | % Comment out this line to process without preserving comments
63 | %% #define COMMENTS
64 |
65 | % Python is always newline-sensitive and can have long tokens
66 | #pragma -newline -w 32000
67 |
68 | #ifdef COMMENTS
69 | % Comment out this line to throw away comments
70 | #pragma -comment
71 | #endif
72 |
73 | % Python tokens
74 | tokens
75 | % Python string forms - shortstrings are already captured by [stringlit] and [charlit]
76 | % All may be preceded by a stringprefix, see [stringliteral] below
77 | longstringlit "\"\"\"#[(\"\"\")]*\"\"\""
78 | longcharlit "'''#[(''')]*'''"
79 |
80 | % Python number forms - decimal integers and floating point forms are already captured by [number]
81 | hexinteger "0[Xx][\dABCDEFabcdef]+"
82 | octinteger "0o?[01234567]+"
83 | pointfloat "\d*.\d+([Ee][+-]?\d+)?" % other forms covered by [floatnumber]
84 | | "\d+.\d*([Ee][+-]?\d+)?"
85 | end tokens
86 |
87 | % Python keywords
88 | keys
89 | and del from 'not while
90 | elif global or
91 | 'assert else if pass yield
92 | break except 'import 'print
93 | class exec in raise
94 | continue finally is return
95 | def for lambda try @
96 | % Not keywords in Python 2.5, but may be in future
97 | % as with
98 | end keys
99 |
100 | % Compound operators
101 | compounds
102 | == += -= *= /= '%= &= |= ^= <<= >>= **= //= ** >>
103 | end compounds
104 |
105 | % Python comments are # to end-of-line
106 | comments
107 | '#
108 | '\
109 | end comments
110 |
111 | % The standard Python grammar, optimized for TXL
112 | define program
113 | [file_input]
114 | end define
115 |
116 | define file_input
117 | [repeat statement_or_newline]
118 | end define
119 |
120 | define statement_or_newline
121 | [statement]
122 | | [endofline+] % avoid deep long backtracks - JRC 30jun15
123 | end define
124 |
125 | define decorator
126 | '@ [dotted_name] [opt decorator_arglist] [endofline] [repeat endofline]
127 | end define
128 |
129 | % The [SPOFF] '( [SPON] suppresses TXL default output spacing before (
130 | define decorator_arglist
131 | [SPOFF] '( [SPON] [IN] [opt arglist] [repeat endofline] ') [EX]
132 | end define
133 |
134 | define decorators
135 | [repeat decorator+]
136 | end define
137 |
138 | define decorated
139 | [decorators] [classdef]
140 | | [decorators] [funcdef]
141 | end define
142 |
143 | define funcdef
144 | 'def [id] [parameters] ': [suite]
145 | end define
146 |
147 | define parameters
148 | [SPOFF] '( [SPON] [opt varargslist] [repeat endofline] ')
149 | end define
150 |
151 | define varargslist
152 | [repeat fpdef_test_comma] [repeat endofline] '* [id]
153 | | [repeat fpdef_test_comma] [repeat endofline] '* [id] [opt endofline] ', [repeat endofline] '** [id]
154 | | [repeat fpdef_test_comma] [repeat endofline] '** [id]
155 | | [list fpdef_test+] [opt ',]
156 | end define
157 |
158 | define fpdef_test
159 | [repeat endofline] [fpdef] [opt is_test] [opt endofline]
160 | end define
161 |
162 | define fpdef_test_comma
163 | [fpdef_test] ',
164 | end define
165 |
166 | define is_test
167 | '= [repeat endofline] [test]
168 | end define
169 |
170 | define fpdef
171 | [id] [opt endofline]
172 | | [SPOFF] '( [SPON] [fplist] [repeat endofline] ') [opt endofline]
173 | end define
174 |
175 | define fplist
176 | [list fpdef+] [opt ',]
177 | end define
178 |
179 | define statement
180 | [simple_statement] [endofline]
181 | | [compound_statement]
182 | end define
183 |
184 | define simple_statement
185 | [small_statement] [repeat semicolon_small_statement] [opt ';]
186 | | [comment]
187 | end define
188 |
189 | define semicolon_small_statement
190 | '; [small_statement]
191 | end define
192 |
193 | define small_statement
194 | [expr_statement]
195 | | [print_statement]
196 | | [del_statement]
197 | | [pass_statement]
198 | | [flow_statement]
199 | | [import_statement]
200 | | [global_statement]
201 | | [exec_statement]
202 | | [assert_statement]
203 | end define
204 |
205 | define expr_statement
206 | [testlist] [repeat is_expr]
207 | | [testlist] [augassign] [assign_value]
208 | end define
209 |
210 | define is_expr
211 | '= [repeat endofline] [assign_value]
212 | end define
213 |
214 | define augassign
215 | '+= | '-= | '*= | '/= | '%= | '&= | '|=
216 | | '^= | '<<= | '>>= | '**= | '//=
217 | end define
218 |
219 | define assign_value
220 | [yield_expr]
221 | | [testlist]
222 | end define
223 |
224 | % For normal assignments, additional restrictions enforced by the interpreter
225 | define print_statement
226 | 'print [opt '>>] [list test] [opt ',]
227 | | 'print [SPOFF] '( [SPON] [IN] [arglist] [repeat endofline] ') [EX] % Python 3 - JRC 30jun15
228 | end define
229 |
230 | define del_statement
231 | 'del [exprlist]
232 | end define
233 |
234 | define pass_statement
235 | 'pass
236 | end define
237 |
238 | define flow_statement
239 | [break_statement]
240 | | [continue_statement]
241 | | [return_statement]
242 | | [raise_statement]
243 | | [yield_statement]
244 | end define
245 |
246 | define break_statement
247 | 'break
248 | end define
249 |
250 | define continue_statement
251 | 'continue
252 | end define
253 |
254 | define return_statement
255 | 'return [opt testlist]
256 | end define
257 |
258 | define yield_statement
259 | [yield_expr]
260 | end define
261 |
262 | define raise_statement
263 | 'raise [opt test_list]
264 | end define
265 |
266 | define test_list
267 | [test] [opt comma_test] [opt comma_test]
268 | end define
269 |
270 | define comma_test
271 | [opt endofline] ', [test]
272 | end define
273 |
274 | define import_statement
275 | [import_name]
276 | | [import_from]
277 | end define
278 |
279 | define import_name
280 | 'import [dotted_as_names]
281 | end define
282 |
283 | define import_from
284 | 'from [repeat '.] [opt dotted_name] [repeat endofline] 'import [import_items]
285 | end define
286 |
287 | define import_items
288 | '*
289 | | [repeat endofline] [SPOFF] '( [SPON] [import_as_names] [repeat endofline] ')
290 | | [repeat endofline] [import_as_names]
291 | end define
292 |
293 | define import_as_name
294 | [repeat endofline] [id] [opt as_name]
295 | end define
296 |
297 | define as_name
298 | 'as [id]
299 | end define
300 |
301 | define dotted_as_name
302 | [dotted_name] [opt as_id]
303 | end define
304 |
305 | define as_id
306 | 'as [id]
307 | end define
308 |
309 | define import_as_names
310 | [list import_as_name+] [opt ',]
311 | end define
312 |
313 | define dotted_as_names
314 | [list dotted_as_name+]
315 | end define
316 |
317 | define dotted_name
318 | [id] [opt dot_dotted_name]
319 | end define
320 |
321 | define dot_dotted_name
322 | [repeat endofline] '. [repeat endofline] [dotted_name]
323 | end define
324 |
325 | define global_statement
326 | 'global [list id+]
327 | end define
328 |
329 | define exec_statement
330 | 'exec [expression] [opt in_test] [opt comma_test]
331 | end define
332 |
333 | define in_test
334 | 'in [test]
335 | end define
336 |
337 | define assert_statement
338 | 'assert [test] [opt comma_test]
339 | end define
340 |
341 | define compound_statement
342 | [if_statement]
343 | | [while_statement]
344 | | [for_statement]
345 | | [try_statement]
346 | | [with_statement]
347 | | [funcdef]
348 | | [classdef]
349 | | [decorated]
350 | end define
351 |
352 | define if_statement
353 | 'if [condition] ':
354 | [suite]
355 | [repeat elif_clause]
356 | [opt else_clause]
357 | end define
358 |
359 | define elif_clause
360 | 'elif [condition] ':
361 | [suite]
362 | end define
363 |
364 | define else_clause
365 | 'else ':
366 | [suite]
367 | end define
368 |
369 | define while_statement
370 | 'while [condition] ':
371 | [suite]
372 | [opt else_clause]
373 | end define
374 |
375 | define for_statement
376 | 'for [exprlist] 'in [testlist] ':
377 | [suite]
378 | [opt else_clause]
379 | end define
380 |
381 | define try_statement
382 | 'try ':
383 | [suite]
384 | [repeat except_clause_suite]
385 | [opt else_clause]
386 | [opt finally_clause]
387 | end define
388 |
389 | define finally_clause
390 | 'finally ':
391 | [suite]
392 | end define
393 |
394 | define except_clause_suite
395 | [except_clause] ':
396 | [suite]
397 | end define
398 |
399 | define with_statement
400 | 'with [test] [opt with_var] ':
401 | [suite]
402 | end define
403 |
404 | define with_var
405 | 'as [expression]
406 | end define
407 |
408 | % NB compile.c makes sure that the default except clause is last
409 | define except_clause
410 | 'except [opt except_test]
411 | end define
412 |
413 | define except_test
414 | [test] [opt as_or_comma_test]
415 | end define
416 |
417 | define as_or_comma_test
418 | 'as [test]
419 | | ', [test]
420 | end define
421 |
422 | define suite
423 | [block]
424 | | [simple_statement] [endofline]
425 | end define
426 |
427 | define block
428 | [indent] [endofline]
429 | [repeat statement_or_newline+]
430 | [dedent]
431 | end define
432 |
433 | % Every end of line may have an optional trailing comment
434 | define endofline
435 | [opt comment] [newline]
436 | end define
437 |
438 | % Assumes that the input program doesn't have identifiers named INDENT or DEDENT
439 | keys
440 | INDENT DEDENT
441 | end keys
442 |
443 | define indent
444 | % By using [attr], the INDENT does not appear in output
445 | [attr 'INDENT] [IN]
446 | end define
447 |
448 | define dedent
449 | % By using [attr], the DEDENT does not appear in output
450 | [attr 'DEDENT] [EX]
451 | end define
452 |
453 | % Backward compatibility cruft to support:
454 | % [ x for x in lambda: True, lambda: False if x() ]
455 | % even while also allowing:
456 | % lambda x: 5 if x else 2
457 | % (But not a mix of the two)
458 |
459 | define testplist_safe
460 | [list old_test+] [opt ',]
461 | end define
462 |
463 | define old_test
464 | [or_test]
465 | | [old_lambdef]
466 | end define
467 |
468 | define old_lambdef
469 | 'lambda [opt varargslist] ':
470 | [old_test]
471 | end define
472 |
473 | define condition
474 | [test]
475 | end define
476 |
477 | define test
478 | [repeat endofline] [or_test] [opt if_test] [opt endofline]
479 | | [repeat endofline] [lambdef] [opt endofline]
480 | end define
481 |
482 | define if_test
483 | [repeat endofline] 'if [or_test] [opt endofline] 'else [test]
484 | end define
485 |
486 | define or_test
487 | [and_test] [opt orop_or_test]
488 | end define
489 |
490 | define orop_or_test
491 | [repeat endofline] 'or [repeat endofline] [or_test]
492 | end define
493 |
494 | define and_test
495 | [not_test] [opt andop_and_test]
496 | end define
497 |
498 | define andop_and_test
499 | [repeat endofline] 'and [repeat endofline] [and_test]
500 | end define
501 |
502 | define not_test
503 | [repeat 'not] [repeat endofline] [comparison]
504 | end define
505 |
506 | define comparison
507 | [expression] [opt comp_op_comparison]
508 | end define
509 |
510 | define comp_op_comparison
511 | [repeat endofline] [comp_op] [repeat endofline] [comparison]
512 | end define
513 |
514 | define comp_op
515 | '< | '> | '== | '>= | '<= | '<> | '!= | 'in | 'not 'in | 'is | 'is 'not
516 | end define
517 |
518 | define expression
519 | [xor_expr] [opt orop_expr]
520 | end define
521 |
522 | define orop_expr
523 | [repeat endofline] '| [repeat endofline] [expression]
524 | end define
525 |
526 | define xor_expr
527 | [and_expr] [opt xorop_expr]
528 | end define
529 |
530 | define xorop_expr
531 | [repeat endofline] '^ [repeat endofline] [xor_expr]
532 | end define
533 |
534 | define and_expr
535 | [shift_expr] [opt andop_and_expr]
536 | end define
537 |
538 | define andop_and_expr
539 | [repeat endofline] '& [repeat endofline] [and_expr]
540 | end define
541 |
542 | define shift_expr
543 | [arith_expr] [repeat shiftop_shift_expr]
544 | end define
545 |
546 | define shiftop_shift_expr
547 | [opt endofline] [shift_op] [opt endofline] [shift_expr]
548 | end define
549 |
550 | define shift_op
551 | '<< | '>>
552 | end define
553 |
554 | define arith_expr
555 | [term] [repeat op_arith_expr]
556 | end define
557 |
558 | define op_arith_expr
559 | [repeat endofline] [arith_op] [repeat endofline] [arith_expr]
560 | end define
561 |
562 | define arith_op
563 | '+ | '-
564 | end define
565 |
566 | define term
567 | [factor] [repeat op_term]
568 | end define
569 |
570 | define op_term
571 | [repeat endofline] [term_op] [repeat endofline] [term]
572 | end define
573 |
574 | define term_op
575 | '* | '/ | '% | '//
576 | end define
577 |
578 | define factor
579 | [repeat unary_op] [power]
580 | end define
581 |
582 | define unary_op
583 | '+ | '- | '~
584 | end define
585 |
586 | define power
587 | [atom] [repeat trailer] [opt exp_factor]
588 | end define
589 |
590 | define exp_factor
591 | '** [factor]
592 | end define
593 |
594 | define atom
595 | [id]
596 | | [literal]
597 | | '( [IN] [repeat endofline] [opt yield_expr] [repeat endofline] ') [EX]
598 | | '( [IN] [repeat endofline] [testplist_gexp] [repeat endofline] ') [EX]
599 | | '[ [IN] [repeat endofline] [opt listmaker] '] [EX]
600 | | '{ [IN] [repeat endofline] [opt dictmaker] [repeat endofline] '} [EX]
601 | | '` [testlist1] '`
602 | end define
603 |
604 | define listmaker
605 | [repeat endofline] [test] [repeat endofline] [plist_for] [repeat endofline]
606 | | [repeat endofline] [list test] [opt ',] [repeat endofline]
607 | end define
608 |
609 | define testplist_gexp
610 | [list test+] [opt endofline] [opt ',]
611 | | [test] [opt endofline] [gen_for]
612 | end define
613 |
614 | define lambdef
615 | 'lambda [opt varargslist] ':
616 | [test]
617 | end define
618 |
619 | define trailer
620 | [SPOFF] '( [SPON] [IN] [arglist] [repeat endofline] ') [EX]
621 | | '[ [IN] [subscriptlist] '] [EX]
622 | | [repeat endofline] '. [repeat endofline] [id]
623 | end define
624 |
625 | define subscriptlist
626 | [list subscript+] [',] [repeat endofline]
627 | end define
628 |
629 | define subscript
630 | [repeat endofline] '. '. '. [opt endofline]
631 | | [repeat endofline] [test] [opt endofline]
632 | | [repeat endofline] [opt test] ': [opt test] [opt sliceop] [opt endofline]
633 | end define
634 |
635 | define sliceop
636 | ': [opt test]
637 | end define
638 |
639 | define exprlist
640 | [list expression+] [repeat endofline] [opt ',]
641 | end define
642 |
643 | define testlist
644 | [list test+] [repeat endofline] [opt ',]
645 | end define
646 |
647 | define dictmaker
648 | [list dict_entry] [repeat endofline] [opt ',] [repeat endofline]
649 | end define
650 |
651 | define dict_entry
652 | [repeat endofline]
653 | [test] ':
654 | [repeat endofline] % jrc
655 | [test]
656 | end define
657 |
658 | define classdef
659 | 'class [opt id] ': [suite]
660 | | 'class [opt id] [SPOFF] '( [SPON] [opt testlist] [repeat endofline] ') ': [suite]
661 | end define
662 |
663 | define arglist
664 | [opt star_test] [list argument] [opt comma_opt_star_test]
665 | end define
666 |
667 | define star_test
668 | [repeat endofline] '* [test] [opt ',] % added comma - JRC 30jun15
669 | | [repeat endofline] '** [test] [opt ',]
670 | end define
671 |
672 | define comma_opt_star_test
673 | ', [opt star_test] [opt comma_opt_star_test]
674 | end define
675 |
676 | define argument
677 | [repeat endofline] [test] [opt argument_value] [repeat endofline]
678 | end define
679 |
680 | define argument_value
681 | [repeat endofline] [opt gen_for]
682 | | '= [repeat endofline] [test]
683 | end define
684 |
685 | define plist_iter
686 | [repeat endofline] [plist_for]
687 | | [repeat endofline] [plist_if]
688 | end define
689 |
690 | define plist_for
691 | 'for [repeat endofline] [exprlist] 'in [testplist_safe] [opt plist_iter]
692 | end define
693 |
694 | define plist_if
695 | 'if [old_test] [opt plist_iter]
696 | end define
697 |
698 | define gen_iter
699 | [repeat endofline] [gen_for]
700 | | [repeat endofline] [gen_if]
701 | end define
702 |
703 | define gen_for
704 | 'for [exprlist] 'in [or_test] [opt gen_iter]
705 | end define
706 |
707 | define gen_if
708 | 'if [old_test] [opt gen_iter]
709 | end define
710 |
711 | define testlist1
712 | [list test]
713 | end define
714 |
715 | % not used in grammar, but may appear in "node" passed from Parser to Compiler
716 | define encoding_decl
717 | [id]
718 | end define
719 |
720 | define yield_expr
721 | 'yield [opt testlist]
722 | end define
723 |
724 | % Python literals
725 | define literal
726 | [stringliteral] [repeat more_stringliteral]
727 | | [integerliteral]
728 | | [floatliteral]
729 | end define
730 |
731 | define more_stringliteral
732 | [repeat endofline] [stringliteral]
733 | end define
734 |
735 | define stringliteral
736 | [stringprefix] [SPOFF] [string] [SPON]
737 | | [string]
738 | end define
739 |
740 | define stringprefix
741 | 'r | 'u | 'ur | 'R | 'U | 'UR | 'Ur | 'uR
742 | | 'b | 'br
743 | end define
744 |
745 | define string
746 | [stringlit]
747 | | [charlit]
748 | | [longstringlit]
749 | | [longcharlit]
750 | end define
751 |
752 | define integerliteral
753 | [integer] [opt long] [opt imag]
754 | end define
755 |
756 | define integer
757 | [integernumber]
758 | | [hexinteger]
759 | | [octinteger]
760 | end define
761 |
762 | define long
763 | [SPOFF] 'l [SPON]
764 | | [SPOFF] 'L [SPON]
765 | end define
766 |
767 | define floatliteral
768 | [number] [opt imag]
769 | | [pointfloat] [opt imag]
770 | end define
771 |
772 | define imag
773 | [SPOFF] 'j [SPON]
774 | | [SPOFF] 'J [SPON]
775 | end define
776 |
777 |
--------------------------------------------------------------------------------
/txl/wsdl-extract-functions.x:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/PCWcn/CCAligner/f27622d6f1500536c45862c4d49bd5f5d6802ace/txl/wsdl-extract-functions.x
--------------------------------------------------------------------------------
/txl/wsdl.grm:
--------------------------------------------------------------------------------
1 | %% WSDL Grammar v0.7
2 | %% Douglas Martin
3 | %% Queen's University
4 | %% June 2009
5 |
6 | %% Changelog
7 | %% Deconstructed Schemas into complexTypes and simpleTypes
8 |
9 | #pragma -case -w 32000
10 |
11 | tokens
12 | id | "\a[-\i]*"
13 | end tokens
14 |
15 | comments
16 |
17 |
18 |
19 |
20 |
21 |
22 | end comments
23 |
24 | define program
25 | [opt xml_def]
26 | [definitions_or_description]
27 | end define
28 |
29 | define xml_def
30 | [SPOFF] ' [SPON] [NL]
31 | end define
32 |
33 | define definitions_or_description
34 | [definitions] %% for WSDL 1.1
35 | | [description] %% for WSDL 2.0
36 | end define
37 |
38 | define prefix
39 | 'soap:
40 | | 'xs:
41 | | 'xmlns:
42 | | 'wsdl:
43 | | 'mime:
44 | | 'http:
45 | | [id] ': %% others?
46 | end define
47 |
48 | define attribute_list
49 | [repeat attribute]
50 | end define
51 |
52 | define attribute
53 | [name_attr]
54 | | [target_namespace_attr]
55 | | [type_attr]
56 | | [element_attr]
57 | | [message_attr]
58 | | [xmlns_attr]
59 | | [basic_attr]
60 | end define
61 |
62 | define name_attr
63 | [SP] [opt prefix] 'name = [stringlit]
64 | end define
65 |
66 | define target_namespace_attr
67 | [SP] [opt prefix] 'targetNamespace = [stringlit]
68 | end define
69 |
70 | define element_attr
71 | [SP] [opt prefix] 'element = [stringlit]
72 | end define
73 |
74 | define type_attr
75 | [SP] [opt prefix] 'type = [stringlit]
76 | end define
77 |
78 | define message_attr
79 | [SP] [opt prefix] 'message = [stringlit]
80 | end define
81 |
82 | define xmlns_attr
83 | [SP] 'xmlns: [id] = [stringlit]
84 | end define
85 |
86 | define basic_attr
87 | [SP] [opt prefix] [id] = [stringlit]
88 | end define
89 |
90 | % WSDL 1.1
91 | define definitions
92 | [SPOFF] '< [opt prefix] 'definitions [opt attribute_list] '> [SPON] [NL][IN]
93 | [repeat top_level_elements] [EX]
94 | [SPOFF] ' [opt prefix] 'definitions> [SPON] [NL]
95 | end define
96 |
97 | % WSDL 2.0
98 | define description
99 | [SPOFF] '< [opt prefix] 'description [opt attribute_list] '> [SPON] [NL][IN]
100 | [repeat top_level_elements] [EX]
101 | [SPOFF] ' [opt prefix] 'description> [SPON] [NL]
102 | end define
103 |
104 | define import_or_include
105 | [import_element]
106 | | [include_element]
107 | end define
108 |
109 | define import_element
110 | [SPOFF] '< [opt prefix] 'import [opt attribute_list] '/> [SPON] [NL]
111 | | [SPOFF] '< [opt prefix] 'import [opt attribute_list] '> ''import> [SPON] [NL]
112 | end define
113 |
114 | define include_element
115 | [SPOFF] '< [opt prefix] 'include [opt attribute_list] '/> [SPON] [NL]
116 | | [SPOFF] '< [opt prefix] 'include [opt attribute_list] '> ''include> [SPON] [NL]
117 | end define
118 |
119 | define types
120 | [SPOFF] '< [opt prefix] 'types [opt attribute_list] '> [SPON] [NL][IN]
121 | [repeat types_scope] [EX]
122 | [SPOFF] ' [opt prefix] 'types> [SPON] [NL]
123 | end define
124 |
125 | define schema
126 | [SPOFF] '< [opt prefix] 'schema [opt attribute_list] '> [SPON] [NL][IN]
127 | [repeat schema_scope] [EX]
128 | [SPOFF] ' [opt prefix] 'schema> [SPON] [NL]
129 | | [SPOFF] '< [opt prefix] 'schema [opt attribute_list] '/> [SPON] [NL]
130 | end define
131 |
132 | define complex_type
133 | [SPOFF] '< [opt prefix] 'complexType [opt attribute_list] '> [SPON] [NL][IN]
134 | [repeat schema_scope] [EX]
135 | [SPOFF] ' [opt prefix] 'complexType> [SPON] [NL]
136 | end define
137 |
138 | define simple_type
139 | [SPOFF] '< [opt prefix] 'simpleType [opt attribute_list] '> [SPON] [NL][IN]
140 | [repeat schema_scope] [EX]
141 | [SPOFF] ' [opt prefix] 'simpleType> [SPON] [NL]
142 | end define
143 |
144 | define schema_element
145 | [SPOFF] '< [opt prefix] 'element [opt attribute_list] '/> [SPON] [NL]
146 | | [SPOFF] '< [opt prefix] 'element [opt attribute_list] '> [SPON] [NL][IN]
147 | [repeat schema_scope] [EX]
148 | [SPOFF] ' [opt prefix] 'element> [SPON] [NL]
149 | end define
150 |
151 | define sequence
152 | [SPOFF] '<'sequence> [SPON] [NL][IN]
153 | [repeat schema_scope] [EX]
154 | [SPOFF] ''sequence> [SPON] [NL]
155 | | [SPOFF] ''sequence> [SPON] [NL]
156 | end define
157 |
158 | define message
159 | [SPOFF] '< [opt prefix] 'message [opt attribute_list] [SPON] '> [NL][IN]
160 | [repeat message_scope] [EX]
161 | [SPOFF] ' [opt prefix] 'message> [SPON] [NL]
162 | end define
163 |
164 | define part
165 | [SPOFF] '< [opt prefix] 'part [opt attribute_list] '/> [SPON] [NL]
166 | | [SPOFF] '< [opt prefix] 'part [opt attribute_list] '> [SPON] [NL][IN]
167 | [repeat element] [EX]
168 | [SPOFF] ' [opt prefix] 'part> [SPON] [NL]
169 | end define
170 |
171 | define binding
172 | [SPOFF] '< [opt prefix] 'binding [opt attribute_list] [SPON] '> [NL][IN]
173 | [repeat binding_scope] [EX]
174 | [SPOFF] ' [opt prefix] 'binding> [SPON] [NL]
175 | | [SPOFF] '< [opt prefix] 'binding [opt attribute_list] '/> [SPON] [NL]
176 | end define
177 |
178 | define service
179 | [SPOFF] '< [opt prefix] 'service [opt attribute_list] [SPON] '> [NL][IN]
180 | [repeat service_scope] [EX]
181 | [SPOFF] ' [opt prefix] 'service> [SPON] [NL]
182 | end define
183 |
184 | define port
185 | [SPOFF] '< [opt prefix] 'port [opt attribute_list] [SPON] '> [NL][IN]
186 | [repeat element] [EX]
187 | [SPOFF] ' [opt prefix] 'port> [SPON] [NL]
188 | | [SPOFF] '< [opt prefix] 'port [opt attribute_list] '/> [SPON] [NL]
189 | end define
190 |
191 | define port_type
192 | [SPOFF] '< [opt prefix] 'portType [opt attribute_list] [SPON] '> [NL][IN]
193 | [repeat operation] [EX]
194 | [SPOFF] ' [opt prefix] 'portType> [SPON] [NL]
195 | end define
196 |
197 | define operation
198 | [SPOFF] '< [opt prefix] 'operation [opt attribute_list] [SPON] '> [NL][IN]
199 | [repeat operation_scope] [EX]
200 | [SPOFF] ' [opt prefix] 'operation> [SPON] [NL]
201 | | [SPOFF] '< [opt prefix] 'operation [opt attribute_list] '/> [SPON] [NL]
202 | end define
203 |
204 | define input
205 | [SPOFF] '< [opt prefix] 'input [opt attribute_list] '> [SPON] [NL][IN]
206 | [repeat element] [EX]
207 | [SPOFF] ' [opt prefix] 'input> [SPON] [NL]
208 | | [SPOFF] '< [opt prefix] 'input [opt attribute_list] '/> [SPON] [NL]
209 | end define
210 |
211 | define output
212 | [SPOFF] '< [opt prefix] 'output [opt attribute_list] '> [SPON] [NL][IN]
213 | [repeat element] [EX]
214 | [SPOFF] ' [opt prefix] 'output> [SPON] [NL]
215 | | [SPOFF] '< [opt prefix] 'output [opt attribute_list] '/> [SPON] [NL]
216 | end define
217 |
218 | define infault
219 | [SPOFF] '< [opt prefix] 'infault [opt attribute_list] '> [SPON] [NL][IN]
220 | [repeat element] [EX]
221 | [SPOFF] ' [opt prefix] 'infault> [SPON] [NL]
222 | | [SPOFF] '< [opt prefix] 'infault [opt attribute_list] '/> [SPON] [NL]
223 | end define
224 |
225 | define outfault
226 | [SPOFF] '< [opt prefix] 'outfault [opt attribute_list] '> [SPON] [NL][IN]
227 | [repeat element] [EX]
228 | [SPOFF] ' [opt prefix] 'outfault> [SPON] [NL]
229 | | [SPOFF] '< [opt prefix] 'outfault [opt attribute_list] '/> [SPON] [NL]
230 | end define
231 |
232 | define fault
233 | [SPOFF] '< [opt prefix] 'fault [opt attribute_list] '> [SPON] [NL][IN]
234 | [repeat element] [EX]
235 | [SPOFF] ' [opt prefix] 'fault> [SPON] [NL]
236 | | [SPOFF] '< [opt prefix] 'fault [opt attribute_list] '/> [SPON] [NL]
237 | end define
238 |
239 | define interface
240 | [SPOFF] '< [opt prefix] 'interface [opt attribute_list] '> [SPON] [NL][IN]
241 | [repeat interface_scope] [EX]
242 | [SPOFF] ' [opt prefix] 'interface> [SPON] [NL]
243 | | [SPOFF] '< [opt prefix] 'interface [opt attribute_list] '/> [SPON] [NL]
244 | end define
245 |
246 | define top_level_elements
247 | [import_or_include]
248 | | [types]
249 | | [service]
250 | | [message]
251 | | [port_type]
252 | | [binding]
253 | | [interface]
254 | | [element]
255 | end define
256 |
257 | define types_scope
258 | [schema]
259 | | [element]
260 | end define
261 |
262 | define schema_scope
263 | [schema_element]
264 | | [sequence]
265 | | [complex_type]
266 | | [simple_type]
267 | | [element]
268 | end define
269 |
270 | define message_scope
271 | [part]
272 | | [element]
273 | end define
274 |
275 | define operation_scope
276 | [operation]
277 | | [input]
278 | | [output]
279 | | [infault]
280 | | [outfault]
281 | | [fault]
282 | | [element]
283 | end define
284 |
285 | define binding_scope
286 | [operation]
287 | | [element]
288 | end define
289 |
290 | define service_scope
291 | [port]
292 | | [element]
293 | end define
294 |
295 | define interface_scope
296 | [operation]
297 | | [fault]
298 | | [element]
299 | end define
300 |
301 | define element
302 | [definitions]
303 | | [import_or_include]
304 | | [types]
305 | | [schema]
306 | | [schema_element]
307 | | [complex_type]
308 | | [simple_type]
309 | | [service]
310 | | [interface]
311 | | [message]
312 | | [port_type]
313 | | [binding]
314 | | [operation]
315 | | [input]
316 | | [output]
317 | | [infault]
318 | | [outfault]
319 | | [fault]
320 | | [port]
321 | | [part]
322 | | [singleton_tag]
323 | | [tag]
324 | end define
325 |
326 | define singleton_tag
327 | [SPOFF] '< [opt prefix] [id] [attribute_list] '/> [SPON] [NL]
328 | end define
329 |
330 | define tag
331 | [begin_tag] [NL][IN]
332 | [repeat element] [EX]
333 | [end_tag] [NL]
334 | end define
335 |
336 | define begin_tag
337 | [SPOFF] '< [opt prefix] [push id] [attribute_list] '> [SPON]
338 | end define
339 |
340 | define end_tag
341 | [SPOFF] ' [opt prefix] [pop id] '> [SPON]
342 | end define
343 |
344 |
--------------------------------------------------------------------------------