Skip to content
Permalink
Browse files

Callback support in PCTCompile

  • Loading branch information...
lievencardoen authored and gquerret committed Mar 14, 2019
1 parent 67be5bb commit 2523573c2d203575dd425ec53e70772145d1accd
@@ -64,6 +64,7 @@
private boolean flattenDbg = true;
private String ignoredIncludes = null;
private int fileList = 0;
private String callback = null;

// Internal use
private final PCT parent;
@@ -262,6 +263,11 @@ public void setDisplayFiles(int display) {
this.fileList = display;
}

@Override
public void setCallbackClass(String callback) {
this.callback = callback;
}

public List<ResourceCollection> getResources() {
return resources;
}
@@ -402,6 +408,10 @@ public int getFileList() {
return fileList;
}

public String getCallbackClass() {
return callback;
}

protected void writeCompilationProcedure(File f, Charset c) {
boolean bAbove1173 = parent.getVersion().compareTo(new DLCVersion(11, 7, "3")) >= 0;
try (FileOutputStream fos = new FileOutputStream(f);
@@ -79,7 +79,7 @@ public void setNumThreads(int numThreads) {

/**
* Add a nested filenamemapper.
*
*
* @param fileNameMapper the mapper to add.
*/
public void add(FileNameMapper fileNameMapper) {
@@ -88,7 +88,7 @@ public void add(FileNameMapper fileNameMapper) {

/**
* Define the mapper to map source to destination files.
*
*
* @return a mapper to be configured.
* @exception BuildException if more than one mapper is defined.
*/
@@ -115,7 +115,7 @@ public void addPCTRunOption(PCTRunOption option) {

// ******************************
// ICompilationAttributes methods

@Override
public void setMinSize(boolean minSize) {
compAttributes.setMinSize(minSize);
@@ -305,6 +305,11 @@ public void setDisplayFiles(int display) {
compAttributes.setDisplayFiles(display);
}

@Override
public void setCallbackClass(String callback) {
compAttributes.setCallbackClass(callback);
}

// End of ICompilationAttributes methods
// *************************************

@@ -57,7 +57,7 @@

/**
* Switch listing source to PREPROCESS'ed file
*
*
* @param source Can be empty or 'PREPROCESS'
*/
void setListingSource(String source);
@@ -177,7 +177,7 @@

/**
* Specifies progress percentage
*
*
* @param progPerc int (a value from 0 until 100)
*/
void setProgPerc(int progPerc);
@@ -197,7 +197,7 @@

/**
* Immediately stop compiling when a compilation error occurs
*
*
* @param stopOnError Boolean
* @since PCT build #185
*/
@@ -207,4 +207,11 @@
* 1 will display files to be recompiled (and reason). 2 will display all files. 0 doesn't display anything
*/
void setDisplayFiles(int display);
}

/**
* Callback class for compilation procedure. Only under OE 11.3+
*
* @param callback ABL Class
*/
void setCallbackClass(String callback);
}
@@ -327,6 +327,7 @@ private String getOptions() {
sb.append(Boolean.toString(compAttrs.isRequireFullKeywords())).append(';');
sb.append(Boolean.toString(compAttrs.isRequireFullNames())).append(';');
sb.append(Boolean.toString(compAttrs.isRequireFieldQualifiers())).append(';');
sb.append(compAttrs.getCallbackClass() == null ? "" : compAttrs.getCallbackClass()).append(';');

return sb.toString();
}
@@ -238,6 +238,10 @@ private void writeParams() {
bw.newLine();
bw.write("FILELIST=" + compAttrs.getFileList());
bw.newLine();
if (compAttrs.getCallbackClass() != null) {
bw.write("CALLBACKCLASS=" + compAttrs.getCallbackClass());
bw.newLine();
}
} catch (IOException ioe) {
throw new BuildException(Messages.getString("PCTCompile.3"), ioe); //$NON-NLS-1$
}
@@ -15,6 +15,11 @@
*
*/

/* Callbacks are only supported on 11.3+ */
&IF DECIMAL(SUBSTRING(PROVERSION, 1, INDEX(PROVERSION, '.') + 1)) GE 11.3 &THEN
USING Progress.Lang.Class.
&ENDIF

&IF INTEGER(SUBSTRING(PROVERSION, 1, INDEX(PROVERSION, '.'))) GE 11 &THEN
{ pct/v11/xrefd0004.i}
&ELSEIF INTEGER(SUBSTRING(PROVERSION, 1, INDEX(PROVERSION, '.'))) GE 10 &THEN
@@ -114,26 +119,36 @@ DEFINE VARIABLE cDspSteps AS CHARACTER NO-UNDO.
DEFINE VARIABLE cIgnoredIncludes AS CHARACTER NO-UNDO.
DEFINE VARIABLE lIgnoredIncludes AS LOGICAL NO-UNDO.
DEFINE VARIABLE iFileList AS INTEGER NO-UNDO.
DEFINE VARIABLE callbackClass AS CHARACTER NO-UNDO.

/* Handle to calling procedure in order to log messages */
DEFINE VARIABLE hSrcProc AS HANDLE NO-UNDO.
ASSIGN hSrcProc = SOURCE-PROCEDURE.

DEFINE VARIABLE majorMinor AS DECIMAL NO-UNDO.
DEFINE VARIABLE bAbove101 AS LOGICAL NO-UNDO INITIAL TRUE.
DEFINE VARIABLE bAboveEq113 AS LOGICAL NO-UNDO INITIAL TRUE.
DEFINE VARIABLE bAboveEq117 AS LOGICAL NO-UNDO INITIAL FALSE.
DEFINE VARIABLE bAboveEq1173 AS LOGICAL NO-UNDO INITIAL FALSE.
DEFINE VARIABLE bAboveEq12 AS LOGICAL NO-UNDO INITIAL FALSE.

ASSIGN majorMinor = DECIMAL(REPLACE(SUBSTRING(PROVERSION, 1, INDEX(PROVERSION, '.') + 1), '.', SESSION:NUMERIC-DECIMAL-POINT)).
ASSIGN bAbove101 = majorMinor GT 10.1.
ASSIGN bAboveEq113 = (majorMinor GE 11.3).
ASSIGN bAboveEq117 = (majorMinor GE 11.7).
&IF DECIMAL(SUBSTRING(PROVERSION, 1, INDEX(PROVERSION, '.') + 1)) GE 11 &THEN
// PROVERSION(1) available since v11
ASSIGN bAboveEq1173 = (majorMinor GT 11.7) OR ((majorMinor EQ 11.7) AND (INTEGER(ENTRY(3, PROVERSION(1), '.')) GE 3)). /* FIXME Check exact version number */
&ENDIF
ASSIGN bAboveEq12 = (majorMinor GE 12).

/* Callbacks are only supported on 11.3+ */
&IF DECIMAL(SUBSTRING(PROVERSION, 1, INDEX(PROVERSION, '.') + 1)) GE 11.3 &THEN
DEFINE VARIABLE callback AS rssw.pct.ICompileCallback NO-UNDO.
DEFINE VARIABLE compileAction AS rssw.pct.CompileCallbackAction NO-UNDO.
ASSIGN compileAction = rssw.pct.CompileCallbackAction:None.
&ENDIF

PROCEDURE setOption.
DEFINE INPUT PARAMETER ipName AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER ipValue AS CHARACTER NO-UNDO.
@@ -165,6 +180,7 @@ PROCEDURE setOption.
WHEN 'FULLNAMES':U THEN ASSIGN lOptFullNames = (ipValue EQ '1':U).
WHEN 'FILELIST':U THEN ASSIGN iFileList = INTEGER(ipValue).
WHEN 'NUMFILES':U THEN ASSIGN iTotLines = INTEGER(ipValue).
WHEN 'CALLBACKCLASS':U THEN ASSIGN callbackClass = ipValue.

OTHERWISE RUN logError IN hSrcProc (SUBSTITUTE("Unknown parameter '&1' with value '&2'" ,ipName, ipValue)).
END CASE.
@@ -174,6 +190,16 @@ END PROCEDURE.
PROCEDURE initModule:
ASSIGN lIgnoredIncludes = (LENGTH(cignoredIncludes) > 0).

IF (callbackClass > "") AND NOT bAboveEq113 THEN
MESSAGE "Callbacks are only supported on 11.3+".
/* Callbacks are only supported on 11.3+ */
&IF DECIMAL(SUBSTRING(PROVERSION, 1, INDEX(PROVERSION, '.') + 1)) GE 11.3 &THEN
IF (callbackClass > "") THEN DO:
callback = CAST(Class:GetClass(callbackClass):new(), rssw.pct.ICompileCallback).
callback:initialize(hSrcProc).
END.
&ENDIF

/* Gets CRC list */
DEFINE VARIABLE h AS HANDLE NO-UNDO.
h = TEMP-TABLE CRCList:HANDLE.
@@ -366,6 +392,16 @@ PROCEDURE compileXref.
ELSE
ASSIGN debugListingFile = ?.

RUN logVerbose IN hSrcProc (SUBSTITUTE("Compiling &1 in directory &2 TO &3", ipInFile, ipInDir, cSaveDir)).

&IF DECIMAL(SUBSTRING(PROVERSION, 1, INDEX(PROVERSION, '.') + 1)) GE 11.3 &THEN
IF VALID-OBJECT(callback) THEN DO:
compileAction = callback:beforeCompile(hSrcProc, ipInFile, ipInDir).
IF (compileAction EQ rssw.pct.CompileCallbackAction:Skip) THEN
RETURN.
END.
&ENDIF

/* Before 11.7.3, strict mode compiler was throwing errors. 11.7.3 introduced :warning and :error */
&IF DECIMAL(SUBSTRING(PROVERSION, 1, INDEX(PROVERSION, '.') + 1)) GE 11.7 &THEN
IF (cOpts GT "") AND bAboveEq117 AND (NOT bAboveEq1173) THEN DO:
@@ -385,12 +421,15 @@ PROCEDURE compileXref.
END.
&ENDIF

RUN logVerbose IN hSrcProc (SUBSTITUTE("Compiling &1 in directory &2 TO &3", ipInFile, ipInDir, cSaveDir)).
RUN pctcomp.p (IF lRelative THEN ipInFile ELSE ipInDir + '/':U + ipInFile,
cSaveDir, debugListingFile,
IF Lst AND NOT LstPrepro THEN PCTDir + '/':U + ipInFile ELSE ?,
preprocessFile, cStrXrefFile, cXrefFile, IF bAboveEq1173 THEN cOpts ELSE "").

&IF DECIMAL(SUBSTRING(PROVERSION, 1, INDEX(PROVERSION, '.') + 1)) GE 11.3 &THEN
IF VALID-OBJECT(callback) THEN callback:afterCompile(hSrcProc, ipInFile, ipInDir).
&ENDIF

ASSIGN opError = COMPILER:ERROR.
IF NOT opError THEN DO:
/* In order to handle <mapper> element */
@@ -31,7 +31,7 @@ PROCEDURE setOptions:
DEFINE OUTPUT PARAMETER opMsg AS CHARACTER NO-UNDO.

/* Defines compilation option -- This is a ';' separated string containing */
/* runList (LOG), minSize (LOG), md5 (LOG), xcode (LOG), xcodekey (CHAR), forceCompil (LOG), noCompil (LOG), keepXref (LOG), multiComp (LOG), streamIO (LOG), lV6Frame (LOG), outputDir (CHAR), preprocess (LOG), preprocessDir (CHAR), listing (LOG), debugListing (LOG), debugListingDir (CHAR), reqFullKW (LOG), reqFullNames (LOG), reqFldQual (LOG) */
/* runList (LOG), minSize (LOG), md5 (LOG), xcode (LOG), xcodekey (CHAR), forceCompil (LOG), noCompil (LOG), keepXref (LOG), multiComp (LOG), streamIO (LOG), lV6Frame (LOG), outputDir (CHAR), preprocess (LOG), preprocessDir (CHAR), listing (LOG), debugListing (LOG), debugListingDir (CHAR), reqFullKW (LOG), reqFullNames (LOG), reqFldQual (LOG), callbackClass (CHAR) */
RUN setOption IN hComp ('RUNLIST', IF ENTRY(1, ipPrm, ';') EQ 'true' THEN '1' ELSE '0').
RUN setOption IN hComp ('XCODE', IF ENTRY(4, ipPrm, ';') EQ 'true' THEN '1' ELSE '0').
RUN setOption IN hComp ('FORCECOMPILE', IF ENTRY(6, ipPrm, ';') EQ 'true' THEN '1' ELSE '0').
@@ -59,6 +59,7 @@ PROCEDURE setOptions:
RUN setOption IN hComp ('FULLKW', IF ENTRY(32, ipPrm, ';') EQ 'true' THEN '1' ELSE '0').
RUN setOption IN hComp ('FULLNAMES', IF ENTRY(33, ipPrm, ';') EQ 'true' THEN '1' ELSE '0').
RUN setOption IN hComp ('FIELDQLF', IF ENTRY(34, ipPrm, ';') EQ 'true' THEN '1' ELSE '0').
RUN setOption IN hComp ('CALLBACKCLASS', ENTRY(35, ipPrm, ';')).

RUN initModule IN hComp.

@@ -0,0 +1,22 @@
/**
* Copyright 2005-2018 Riverside Software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

CLASS rssw.pct.AbstractCompileCallback IMPLEMENTS rssw.pct.ICompileCallback ABSTRACT:
METHOD PUBLIC VOID initialize(hSrcProc AS HANDLE): END METHOD.
METHOD PUBLIC rssw.pct.CompileCallbackAction beforeCompile(hSrcProc AS HANDLE, ipInFile AS CHARACTER, ipInDir AS CHARACTER): END METHOD.
METHOD PUBLIC VOID afterCompile(hSrcProc AS HANDLE, ipInFile AS CHARACTER, ipInDir AS CHARACTER): END METHOD.
END CLASS.
@@ -0,0 +1,22 @@
/**
* Copyright 2005-2018 Riverside Software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

ENUM rssw.pct.CompileCallbackAction:
DEFINE ENUM None
Skip
/* Implementation will come later */ Stop.
END ENUM.
@@ -0,0 +1,22 @@
/**
* Copyright 2005-2018 Riverside Software
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

INTERFACE rssw.pct.ICompileCallback:
METHOD PUBLIC VOID initialize(hSrcProc AS HANDLE).
METHOD PUBLIC rssw.pct.CompileCallbackAction beforeCompile(hSrcProc AS HANDLE, ipInFile AS CHARACTER, ipInDir AS CHARACTER).
METHOD PUBLIC VOID afterCompile(hSrcProc AS HANDLE, ipInFile AS CHARACTER, ipInDir AS CHARACTER).
END INTERFACE.
Oops, something went wrong.

0 comments on commit 2523573

Please sign in to comment.
You can’t perform that action at this time.