@abaplint/cli 2.120.81 → 2.120.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cli.js +1463 -100
- package/package.json +2 -2
package/build/cli.js
CHANGED
|
@@ -24712,6 +24712,7 @@ class ABAPFileInformationParser {
|
|
|
24712
24712
|
return results;
|
|
24713
24713
|
}
|
|
24714
24714
|
parseAttributes(node, visibility) {
|
|
24715
|
+
var _a;
|
|
24715
24716
|
if (node === undefined) {
|
|
24716
24717
|
return [];
|
|
24717
24718
|
}
|
|
@@ -24720,23 +24721,34 @@ class ABAPFileInformationParser {
|
|
|
24720
24721
|
return [];
|
|
24721
24722
|
}
|
|
24722
24723
|
const ret = [];
|
|
24723
|
-
|
|
24724
|
+
const data = contents.findDirectStatements(Statements.Data);
|
|
24725
|
+
for (const structure of contents.findDirectStructures(Structures.Data)) {
|
|
24726
|
+
const begin = structure.findDirectStatement(Statements.DataBegin);
|
|
24727
|
+
if (begin.findDirectExpression(Expressions.DefinitionName)) {
|
|
24728
|
+
data.push(begin);
|
|
24729
|
+
}
|
|
24730
|
+
}
|
|
24731
|
+
for (const d of data) {
|
|
24724
24732
|
const name = d.findFirstExpression(Expressions.DefinitionName).getFirstToken();
|
|
24725
24733
|
ret.push({
|
|
24726
24734
|
name: name.getStr(),
|
|
24727
24735
|
identifier: new _identifier_1.Identifier(name, this.filename),
|
|
24728
24736
|
level: _abap_file_information_1.AttributeLevel.Instance,
|
|
24729
|
-
readOnly:
|
|
24737
|
+
readOnly: this.isReadOnly(d),
|
|
24730
24738
|
visibility,
|
|
24731
24739
|
});
|
|
24732
24740
|
}
|
|
24733
|
-
|
|
24734
|
-
|
|
24741
|
+
const classData = contents.findDirectStatements(Statements.ClassData);
|
|
24742
|
+
for (const structure of contents.findDirectStructures(Structures.ClassData)) {
|
|
24743
|
+
classData.push(structure.findDirectStatement(Statements.ClassDataBegin));
|
|
24744
|
+
}
|
|
24745
|
+
for (const d of classData) {
|
|
24746
|
+
const name = ((_a = d.findFirstExpression(Expressions.DefinitionName)) !== null && _a !== void 0 ? _a : d.findDirectExpression(Expressions.NamespaceSimpleName)).getFirstToken();
|
|
24735
24747
|
ret.push({
|
|
24736
24748
|
name: name.getStr(),
|
|
24737
24749
|
identifier: new _identifier_1.Identifier(name, this.filename),
|
|
24738
24750
|
level: _abap_file_information_1.AttributeLevel.Static,
|
|
24739
|
-
readOnly:
|
|
24751
|
+
readOnly: this.isReadOnly(d),
|
|
24740
24752
|
visibility,
|
|
24741
24753
|
});
|
|
24742
24754
|
}
|
|
@@ -24752,6 +24764,12 @@ class ABAPFileInformationParser {
|
|
|
24752
24764
|
}
|
|
24753
24765
|
return ret;
|
|
24754
24766
|
}
|
|
24767
|
+
isReadOnly(statement) {
|
|
24768
|
+
const definition = statement.findDirectExpression(Expressions.DataDefinition);
|
|
24769
|
+
const nodes = definition ? [definition, ...definition.findAllExpressions(Expressions.TypeTableKey)] : [statement];
|
|
24770
|
+
// In these grammar nodes, a direct READ token only occurs in the READ-ONLY modifier.
|
|
24771
|
+
return nodes.some(node => node.findDirectTokenByText("READ") !== undefined);
|
|
24772
|
+
}
|
|
24755
24773
|
parseMethodDefinition(node, visibility) {
|
|
24756
24774
|
var _a;
|
|
24757
24775
|
if (node === undefined) {
|
|
@@ -27553,7 +27571,9 @@ class Procedural {
|
|
|
27553
27571
|
}
|
|
27554
27572
|
}
|
|
27555
27573
|
if (found === undefined) {
|
|
27556
|
-
|
|
27574
|
+
const lookup = ddic.lookup(param.type);
|
|
27575
|
+
this.addDDICUsing(lookup.object, nameToken, filename);
|
|
27576
|
+
found = lookup.type;
|
|
27557
27577
|
}
|
|
27558
27578
|
if (param.direction === types_1.FunctionModuleParameterDirection.tables) {
|
|
27559
27579
|
if (found instanceof basic_1.TableType) {
|
|
@@ -27565,10 +27585,12 @@ class Procedural {
|
|
|
27565
27585
|
}
|
|
27566
27586
|
if ((found instanceof basic_1.UnknownType || found instanceof basic_1.VoidType) && ((_a = param.type) === null || _a === void 0 ? void 0 : _a.includes("-"))) {
|
|
27567
27587
|
const [name, field] = param.type.split("-");
|
|
27568
|
-
const
|
|
27588
|
+
const lookup = ddic.lookupTableOrView(name);
|
|
27589
|
+
const f = lookup.type;
|
|
27569
27590
|
if (f && f instanceof basic_1.StructureType) {
|
|
27570
27591
|
const c = f.getComponentByName(field);
|
|
27571
27592
|
if (c) {
|
|
27593
|
+
this.addDDICUsing(lookup.object, nameToken, filename);
|
|
27572
27594
|
found = c;
|
|
27573
27595
|
}
|
|
27574
27596
|
}
|
|
@@ -27632,6 +27654,12 @@ class Procedural {
|
|
|
27632
27654
|
}
|
|
27633
27655
|
}
|
|
27634
27656
|
}
|
|
27657
|
+
addDDICUsing(object, token, filename) {
|
|
27658
|
+
if (object === undefined) {
|
|
27659
|
+
return;
|
|
27660
|
+
}
|
|
27661
|
+
this.scope.getDDICReferences().addUsing(this.scope.getParentObj(), { object, token, filename });
|
|
27662
|
+
}
|
|
27635
27663
|
functionModuleParameterMeta(param) {
|
|
27636
27664
|
const ret = [];
|
|
27637
27665
|
if (param.direction === types_1.FunctionModuleParameterDirection.importing) {
|
|
@@ -49871,7 +49899,7 @@ class SyntaxLogic {
|
|
|
49871
49899
|
this.reg.getMSAGReferences().clear(this.object);
|
|
49872
49900
|
if (this.object instanceof objects_1.Program && this.object.isInclude()) {
|
|
49873
49901
|
// todo, show some kind of error?
|
|
49874
|
-
return { issues: [], spaghetti: this.scope.pop(new position_1.Position(
|
|
49902
|
+
return { issues: [], spaghetti: this.scope.pop(new position_1.Position(position_1.MAX_POSITION_VALUE, position_1.MAX_POSITION_VALUE)) };
|
|
49875
49903
|
}
|
|
49876
49904
|
this.traverseObject();
|
|
49877
49905
|
// the FORM definitions are now all traversed, ie. their parameters are typed
|
|
@@ -49880,7 +49908,7 @@ class SyntaxLogic {
|
|
|
49880
49908
|
}
|
|
49881
49909
|
this.deferred = [];
|
|
49882
49910
|
for (;;) {
|
|
49883
|
-
const spaghetti = this.scope.pop(new position_1.Position(
|
|
49911
|
+
const spaghetti = this.scope.pop(new position_1.Position(position_1.MAX_POSITION_VALUE, position_1.MAX_POSITION_VALUE)); // pop built-in scopes
|
|
49884
49912
|
if (spaghetti.getTop().getIdentifier().stype === _scope_type_1.ScopeType.BuiltIn) {
|
|
49885
49913
|
const result = { issues: this.issues, spaghetti };
|
|
49886
49914
|
this.object.syntaxResult = result;
|
|
@@ -60587,6 +60615,7 @@ exports.Diagnostics = Diagnostics;
|
|
|
60587
60615
|
|
|
60588
60616
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
60589
60617
|
exports.DumpScope = void 0;
|
|
60618
|
+
const position_1 = __webpack_require__(/*! ../position */ "../core/build/src/position.js");
|
|
60590
60619
|
const _scope_type_1 = __webpack_require__(/*! ../abap/5_syntax/_scope_type */ "../core/build/src/abap/5_syntax/_scope_type.js");
|
|
60591
60620
|
class DumpScope {
|
|
60592
60621
|
static dump(spaghetti) {
|
|
@@ -60600,8 +60629,8 @@ class DumpScope {
|
|
|
60600
60629
|
const sident = " ".repeat(indent * 2);
|
|
60601
60630
|
let ret = sident + "<u>" + identifier.stype + ", <tt>" + identifier.sname + "</tt>";
|
|
60602
60631
|
ret += ", (" + coverage.start.getRow() + ", " + coverage.start.getCol() + ")";
|
|
60603
|
-
if (coverage.end.getRow() ===
|
|
60604
|
-
&& coverage.end.getCol() ===
|
|
60632
|
+
if (coverage.end.getRow() === position_1.MAX_POSITION_VALUE
|
|
60633
|
+
&& coverage.end.getCol() === position_1.MAX_POSITION_VALUE) {
|
|
60605
60634
|
ret += ", (max, max)";
|
|
60606
60635
|
}
|
|
60607
60636
|
else {
|
|
@@ -70971,7 +71000,10 @@ exports.WebReportingTemplate = WebReportingTemplate;
|
|
|
70971
71000
|
"use strict";
|
|
70972
71001
|
|
|
70973
71002
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
70974
|
-
exports.Position = void 0;
|
|
71003
|
+
exports.Position = exports.MAX_POSITION_VALUE = void 0;
|
|
71004
|
+
// largest value that is a Smi on all V8 builds, larger values (eg. Number.MAX_SAFE_INTEGER) make V8
|
|
71005
|
+
// store row/col of every Position as boxed heap numbers, costing ~32 bytes per Position
|
|
71006
|
+
exports.MAX_POSITION_VALUE = 2 ** 30 - 1;
|
|
70975
71007
|
// first position is (1,1)
|
|
70976
71008
|
class Position {
|
|
70977
71009
|
constructor(row, col) {
|
|
@@ -71522,7 +71554,7 @@ class Registry {
|
|
|
71522
71554
|
}
|
|
71523
71555
|
static abaplintVersion() {
|
|
71524
71556
|
// magic, see build script "version.js"
|
|
71525
|
-
return "2.120.
|
|
71557
|
+
return "2.120.83";
|
|
71526
71558
|
}
|
|
71527
71559
|
getDDICReferences() {
|
|
71528
71560
|
return this.ddicReferences;
|
|
@@ -72078,14 +72110,18 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
72078
72110
|
};
|
|
72079
72111
|
})();
|
|
72080
72112
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
72081
|
-
exports.SourceKind = exports.PredicateKind = exports.Procedure = exports.ObjectAnalysis = exports.Variable = exports.OccurrenceKind = void 0;
|
|
72113
|
+
exports.Hierarchy = exports.NUMERIC_FUNCTIONS = exports.SourceKind = exports.PredicateKind = exports.InitialDeclaration = exports.Procedure = exports.ObjectAnalysis = exports.Variable = exports.OccurrenceKind = void 0;
|
|
72082
72114
|
exports.findStructures = findStructures;
|
|
72083
72115
|
exports.expressionPath = expressionPath;
|
|
72084
72116
|
exports.plainMove = plainMove;
|
|
72117
|
+
exports.plainCreateObject = plainCreateObject;
|
|
72085
72118
|
exports.singleField = singleField;
|
|
72086
72119
|
exports.singleTarget = singleTarget;
|
|
72087
72120
|
exports.plainClear = plainClear;
|
|
72088
72121
|
exports.plainData = plainData;
|
|
72122
|
+
exports.initialValue = initialValue;
|
|
72123
|
+
exports.initialDeclaration = initialDeclaration;
|
|
72124
|
+
exports.initialAtFirstReference = initialAtFirstReference;
|
|
72089
72125
|
exports.isImmutable = isImmutable;
|
|
72090
72126
|
exports.isReferenceType = isReferenceType;
|
|
72091
72127
|
exports.identicalTypes = identicalTypes;
|
|
@@ -72096,6 +72132,10 @@ exports.isCondition = isCondition;
|
|
|
72096
72132
|
exports.dataSource = dataSource;
|
|
72097
72133
|
exports.targetType = targetType;
|
|
72098
72134
|
exports.unchangedBetween = unchangedBetween;
|
|
72135
|
+
exports.formalParameter = formalParameter;
|
|
72136
|
+
exports.passedByValue = passedByValue;
|
|
72137
|
+
exports.literalType = literalType;
|
|
72138
|
+
exports.expressionType = expressionType;
|
|
72099
72139
|
exports.mergeEdits = mergeEdits;
|
|
72100
72140
|
exports.deleteRegion = deleteRegion;
|
|
72101
72141
|
exports.deleteStatement = deleteStatement;
|
|
@@ -72115,6 +72155,10 @@ const syntax_1 = __webpack_require__(/*! ../abap/5_syntax/syntax */ "../core/bui
|
|
|
72115
72155
|
const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
|
|
72116
72156
|
const _typed_identifier_1 = __webpack_require__(/*! ../abap/types/_typed_identifier */ "../core/build/src/abap/types/_typed_identifier.js");
|
|
72117
72157
|
const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
|
|
72158
|
+
const class_definition_1 = __webpack_require__(/*! ../abap/types/class_definition */ "../core/build/src/abap/types/class_definition.js");
|
|
72159
|
+
const interface_definition_1 = __webpack_require__(/*! ../abap/types/interface_definition */ "../core/build/src/abap/types/interface_definition.js");
|
|
72160
|
+
const class_1 = __webpack_require__(/*! ../objects/class */ "../core/build/src/objects/class.js");
|
|
72161
|
+
const interface_1 = __webpack_require__(/*! ../objects/interface */ "../core/build/src/objects/interface.js");
|
|
72118
72162
|
const _abap_object_1 = __webpack_require__(/*! ../objects/_abap_object */ "../core/build/src/objects/_abap_object.js");
|
|
72119
72163
|
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
72120
72164
|
const position_1 = __webpack_require__(/*! ../position */ "../core/build/src/position.js");
|
|
@@ -72387,6 +72431,23 @@ class Procedure {
|
|
|
72387
72431
|
}
|
|
72388
72432
|
return between;
|
|
72389
72433
|
}
|
|
72434
|
+
/** the next statement executed after a direct statement of a block, skipping declarations, which have no effect
|
|
72435
|
+
* where they are written; undefined if there is none in the block */
|
|
72436
|
+
nextExecuted(statement) {
|
|
72437
|
+
const block = this.block(statement);
|
|
72438
|
+
for (let index = this.index(statement) + 1; index < this.statements.length; index++) {
|
|
72439
|
+
const next = this.statements[index];
|
|
72440
|
+
const type = next.get();
|
|
72441
|
+
if (this.block(next) !== block) {
|
|
72442
|
+
return undefined;
|
|
72443
|
+
}
|
|
72444
|
+
else if (!(this.isSimple(next) && (type instanceof Statements.Data || type instanceof Statements.Type
|
|
72445
|
+
|| type instanceof Statements.Constant || type instanceof Statements.FieldSymbol || type instanceof _statement_1.Comment))) {
|
|
72446
|
+
return next;
|
|
72447
|
+
}
|
|
72448
|
+
}
|
|
72449
|
+
return undefined;
|
|
72450
|
+
}
|
|
72390
72451
|
/** a comment line or end of line comment between the two positions */
|
|
72391
72452
|
hasComment(start, end) {
|
|
72392
72453
|
if (this.comments === undefined) {
|
|
@@ -72397,6 +72458,18 @@ class Procedure {
|
|
|
72397
72458
|
}
|
|
72398
72459
|
return this.comments.some(c => !c.isBefore(start) && c.isBefore(end));
|
|
72399
72460
|
}
|
|
72461
|
+
/** a structure of one of the types contains the statement */
|
|
72462
|
+
enclosedBy(statement, types) {
|
|
72463
|
+
let parent = this.parents.get(statement);
|
|
72464
|
+
while (parent !== undefined && parent !== this.structure) {
|
|
72465
|
+
const type = parent.get();
|
|
72466
|
+
if (types.some(t => type instanceof t)) {
|
|
72467
|
+
return true;
|
|
72468
|
+
}
|
|
72469
|
+
parent = this.parents.get(parent);
|
|
72470
|
+
}
|
|
72471
|
+
return false;
|
|
72472
|
+
}
|
|
72400
72473
|
/** the IF structure of an IF or ELSEIF statement */
|
|
72401
72474
|
ifStructure(statement) {
|
|
72402
72475
|
let parent = this.parents.get(statement);
|
|
@@ -72469,6 +72542,23 @@ class Procedure {
|
|
|
72469
72542
|
}
|
|
72470
72543
|
return variable;
|
|
72471
72544
|
}
|
|
72545
|
+
/** memory that only this procedure can reach: a local variable, or a pass-by-value or RETURNING parameter of
|
|
72546
|
+
* a method or form, with all references understood and its address never taken */
|
|
72547
|
+
private(identifier) {
|
|
72548
|
+
const variable = this.variable(identifier);
|
|
72549
|
+
if (variable === undefined || variable.complete === false || variable.escapes()
|
|
72550
|
+
|| variable.identifier.getMeta().includes("static" /* IdentifierMeta.Static */)) {
|
|
72551
|
+
return undefined;
|
|
72552
|
+
}
|
|
72553
|
+
const meta = variable.identifier.getMeta();
|
|
72554
|
+
if (variable.isLocal()) {
|
|
72555
|
+
return variable;
|
|
72556
|
+
}
|
|
72557
|
+
// function module parameters can be global parameters of the function group
|
|
72558
|
+
const parameter = !(this.structure.get() instanceof Structures.FunctionModule)
|
|
72559
|
+
&& (meta.includes("pass_by_value" /* IdentifierMeta.PassByValue */) || meta.includes("returning" /* IdentifierMeta.MethodReturning */));
|
|
72560
|
+
return parameter ? variable : undefined;
|
|
72561
|
+
}
|
|
72472
72562
|
/** all local variables declared in the procedure */
|
|
72473
72563
|
locals() {
|
|
72474
72564
|
var _a;
|
|
@@ -72560,6 +72650,17 @@ class Procedure {
|
|
|
72560
72650
|
}
|
|
72561
72651
|
return statement.findFirstExpression(Expressions.NewObject) === undefined;
|
|
72562
72652
|
}
|
|
72653
|
+
/** the method or builtin function called at the method name token */
|
|
72654
|
+
methodAt(token) {
|
|
72655
|
+
for (const reference of this.analysis.referencesAt(this.file.getFilename(), token)) {
|
|
72656
|
+
if ((reference.referenceType === _reference_1.ReferenceType.MethodReference
|
|
72657
|
+
|| reference.referenceType === _reference_1.ReferenceType.BuiltinMethodReference)
|
|
72658
|
+
&& reference.resolved !== undefined && "getParameters" in reference.resolved) {
|
|
72659
|
+
return reference.resolved;
|
|
72660
|
+
}
|
|
72661
|
+
}
|
|
72662
|
+
return undefined;
|
|
72663
|
+
}
|
|
72563
72664
|
/** every data write in the statement goes to a local variable, a pass-by-value parameter or the
|
|
72564
72665
|
* RETURNING parameter, ie. memory that no other data object, field symbol or reference can share */
|
|
72565
72666
|
writesOnlyPrivate(statement) {
|
|
@@ -72730,6 +72831,31 @@ function plainMove(statement) {
|
|
|
72730
72831
|
}
|
|
72731
72832
|
return { target, source, operator };
|
|
72732
72833
|
}
|
|
72834
|
+
/** CREATE OBJECT target [TYPE class] [EXPORTING parameters]. without chaining, pragmas, EXCEPTIONS or dynamic parts */
|
|
72835
|
+
function plainCreateObject(statement) {
|
|
72836
|
+
if (!(statement.get() instanceof Statements.CreateObject) || statement.getColon() !== undefined
|
|
72837
|
+
|| statement.getPragmas().length > 0) {
|
|
72838
|
+
return undefined;
|
|
72839
|
+
}
|
|
72840
|
+
const children = statement.getChildren();
|
|
72841
|
+
const target = children[2];
|
|
72842
|
+
if (!(target instanceof nodes_1.ExpressionNode) || !(target.get() instanceof Expressions.Target)) {
|
|
72843
|
+
return undefined;
|
|
72844
|
+
}
|
|
72845
|
+
let type;
|
|
72846
|
+
// the last child is the period
|
|
72847
|
+
for (let i = 3; i < children.length - 1; i += 2) {
|
|
72848
|
+
const word = children[i] instanceof nodes_1.TokenNode ? children[i].getFirstToken().getStr().toUpperCase() : "";
|
|
72849
|
+
const value = children[i + 1];
|
|
72850
|
+
if (word === "TYPE" && value instanceof nodes_1.ExpressionNode && value.get() instanceof Expressions.ClassName) {
|
|
72851
|
+
type = value;
|
|
72852
|
+
}
|
|
72853
|
+
else if (!(word === "EXPORTING" && (value === null || value === void 0 ? void 0 : value.get()) instanceof Expressions.ParameterListS)) {
|
|
72854
|
+
return undefined;
|
|
72855
|
+
}
|
|
72856
|
+
}
|
|
72857
|
+
return { target, type };
|
|
72858
|
+
}
|
|
72733
72859
|
/** the source is a single field, ie. one token */
|
|
72734
72860
|
function singleField(source) {
|
|
72735
72861
|
var _a;
|
|
@@ -72764,6 +72890,49 @@ function plainData(statement) {
|
|
|
72764
72890
|
return statement.get() instanceof Statements.Data
|
|
72765
72891
|
&& ((_a = statement.findDirectExpression(Expressions.DataDefinition)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.Value)) === undefined;
|
|
72766
72892
|
}
|
|
72893
|
+
/** VALUE type( ) with an explicit type and an empty body, ie. the initial value of the type */
|
|
72894
|
+
function initialValue(source) {
|
|
72895
|
+
const tokens = source.getTokens();
|
|
72896
|
+
return tokens.length === 4 && tokens[0].getStr().toUpperCase() === "VALUE"
|
|
72897
|
+
&& source.findDirectExpression(Expressions.TypeNameOrInfer) !== undefined
|
|
72898
|
+
&& tokens[1].getStr() !== "#" && tokens[2].getStr() === "(" && tokens[3].getStr() === ")";
|
|
72899
|
+
}
|
|
72900
|
+
var InitialDeclaration;
|
|
72901
|
+
(function (InitialDeclaration) {
|
|
72902
|
+
/** DATA v TYPE ... without VALUE: v is initial when the procedure starts, the statement is not executed */
|
|
72903
|
+
InitialDeclaration["Data"] = "data";
|
|
72904
|
+
/** DATA(v) = VALUE t( ).: sets v to the initial value of t every time it is executed, also in each loop iteration */
|
|
72905
|
+
InitialDeclaration["Value"] = "value";
|
|
72906
|
+
})(InitialDeclaration || (exports.InitialDeclaration = InitialDeclaration = {}));
|
|
72907
|
+
/** how the declaration of a local variable makes it initial, undefined if it does not */
|
|
72908
|
+
function initialDeclaration(variable) {
|
|
72909
|
+
const declaration = variable.declaration;
|
|
72910
|
+
if (declaration === undefined) {
|
|
72911
|
+
return undefined;
|
|
72912
|
+
}
|
|
72913
|
+
else if (variable.inline === false) {
|
|
72914
|
+
return plainData(declaration) ? InitialDeclaration.Data : undefined;
|
|
72915
|
+
}
|
|
72916
|
+
const move = plainMove(declaration);
|
|
72917
|
+
return move !== undefined && move.operator === "=" && move.target.getChildren().length === 1
|
|
72918
|
+
&& move.target.findDirectExpression(Expressions.InlineData) !== undefined && initialValue(move.source)
|
|
72919
|
+
? InitialDeclaration.Value : undefined;
|
|
72920
|
+
}
|
|
72921
|
+
/** the variable is initial at the statement, which is its first reference after the declaration */
|
|
72922
|
+
function initialAtFirstReference(procedure, variable, statement) {
|
|
72923
|
+
const declaration = variable.declaration;
|
|
72924
|
+
const kind = initialDeclaration(variable);
|
|
72925
|
+
// neither the declaration nor the statement in a loop: nothing can change the variable before the statement
|
|
72926
|
+
const noLoop = procedure.loop(declaration) === undefined && procedure.loop(statement) === undefined;
|
|
72927
|
+
if (kind === InitialDeclaration.Data) {
|
|
72928
|
+
return noLoop;
|
|
72929
|
+
}
|
|
72930
|
+
else if (kind === InitialDeclaration.Value) {
|
|
72931
|
+
// executed before the statement in the same iteration
|
|
72932
|
+
return noLoop || (procedure.dominates(declaration, statement) && procedure.sameLoop(declaration, statement));
|
|
72933
|
+
}
|
|
72934
|
+
return false;
|
|
72935
|
+
}
|
|
72767
72936
|
/** constants of the class or program, builtin constants like abap_true, and me: never change */
|
|
72768
72937
|
function isImmutable(identifier) {
|
|
72769
72938
|
if (!(identifier instanceof _typed_identifier_1.TypedIdentifier)) {
|
|
@@ -72891,7 +73060,7 @@ var SourceKind;
|
|
|
72891
73060
|
(function (SourceKind) {
|
|
72892
73061
|
/** constants and me, never change */
|
|
72893
73062
|
SourceKind["Immutable"] = "immutable";
|
|
72894
|
-
/** a local variable, or a component of it, changes only by references to the variable */
|
|
73063
|
+
/** a local variable or a pass-by-value parameter, or a component of it, changes only by references to the variable */
|
|
72895
73064
|
SourceKind["Local"] = "local";
|
|
72896
73065
|
/** attributes, parameters, globals, anything reached via a reference: may change by other code */
|
|
72897
73066
|
SourceKind["Volatile"] = "volatile";
|
|
@@ -72900,6 +73069,7 @@ var SourceKind;
|
|
|
72900
73069
|
* expressions, field symbols or dereferencing with ->* */
|
|
72901
73070
|
function dataSource(procedure, source) {
|
|
72902
73071
|
var _a;
|
|
73072
|
+
var _b;
|
|
72903
73073
|
if (source.getChildren().length !== 1) {
|
|
72904
73074
|
return undefined;
|
|
72905
73075
|
}
|
|
@@ -72955,7 +73125,7 @@ function dataSource(procedure, source) {
|
|
|
72955
73125
|
if (type === undefined || type.isGeneric() || (type instanceof basic_1.TableType && type.isWithHeader())) {
|
|
72956
73126
|
return undefined;
|
|
72957
73127
|
}
|
|
72958
|
-
const local = next === 1 ? procedure.local(first) : undefined;
|
|
73128
|
+
const local = next === 1 ? (_b = procedure.local(first)) !== null && _b !== void 0 ? _b : procedure.private(first) : undefined;
|
|
72959
73129
|
let kind = SourceKind.Volatile;
|
|
72960
73130
|
if (deref === false && isImmutable(first)) {
|
|
72961
73131
|
kind = SourceKind.Immutable;
|
|
@@ -73036,7 +73206,8 @@ function unchangedBetween(procedure, source, from, to, read) {
|
|
|
73036
73206
|
const statement = procedure.statements[index];
|
|
73037
73207
|
if (index === end && read !== undefined) {
|
|
73038
73208
|
if (isReceiver(statement, read)
|
|
73039
|
-
|| (statement.get() instanceof Statements.Move && procedure.isCallFree(statement))
|
|
73209
|
+
|| (statement.get() instanceof Statements.Move && procedure.isCallFree(statement))
|
|
73210
|
+
|| passedByValue(procedure, statement, read)) {
|
|
73040
73211
|
continue;
|
|
73041
73212
|
}
|
|
73042
73213
|
}
|
|
@@ -73062,6 +73233,229 @@ function isReceiver(statement, token) {
|
|
|
73062
73233
|
&& receiver.countTokens() === 1 && receiver.getFirstToken().getStart().equals(token.getStart())
|
|
73063
73234
|
&& ((_b = chain === null || chain === void 0 ? void 0 : chain.getChildren()[1]) === null || _b === void 0 ? void 0 : _b.getFirstToken().getStr()) === "->";
|
|
73064
73235
|
}
|
|
73236
|
+
/** the token is the complete actual parameter for an importing parameter: m( v ), m( p = v ),
|
|
73237
|
+
* CALL METHOD m EXPORTING p = v, NEW c( p = v ) or CREATE OBJECT o EXPORTING p = v */
|
|
73238
|
+
function formalParameter(procedure, statement, token) {
|
|
73239
|
+
var _a, _b, _c;
|
|
73240
|
+
const path = expressionPath(statement, token);
|
|
73241
|
+
const index = path.findIndex(e => e.get() instanceof Expressions.Source && e.countTokens() === 1);
|
|
73242
|
+
const source = path[index];
|
|
73243
|
+
if (source === undefined || source.findDirectExpression(Expressions.FieldChain) === undefined
|
|
73244
|
+
|| !source.getFirstToken().getStart().equals(token.getStart())) {
|
|
73245
|
+
return undefined;
|
|
73246
|
+
}
|
|
73247
|
+
const parent = index > 0 ? path[index - 1] : undefined;
|
|
73248
|
+
let name;
|
|
73249
|
+
let call;
|
|
73250
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.get()) instanceof Expressions.MethodCallParam) {
|
|
73251
|
+
call = path[index - 2];
|
|
73252
|
+
}
|
|
73253
|
+
else if ((parent === null || parent === void 0 ? void 0 : parent.get()) instanceof Expressions.NewObject) {
|
|
73254
|
+
call = parent;
|
|
73255
|
+
}
|
|
73256
|
+
else if ((parent === null || parent === void 0 ? void 0 : parent.get()) instanceof Expressions.ParameterS && ((_a = path[index - 2]) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.ParameterListS) {
|
|
73257
|
+
name = (_b = parent.findDirectExpression(Expressions.ParameterName)) === null || _b === void 0 ? void 0 : _b.getFirstToken().getStr();
|
|
73258
|
+
const list = path[index - 3];
|
|
73259
|
+
const above = path[index - 4];
|
|
73260
|
+
if (list === undefined && statement.get() instanceof Statements.CreateObject) {
|
|
73261
|
+
call = statement;
|
|
73262
|
+
}
|
|
73263
|
+
else if ((list === null || list === void 0 ? void 0 : list.get()) instanceof Expressions.MethodCallParam) {
|
|
73264
|
+
call = above;
|
|
73265
|
+
}
|
|
73266
|
+
else if ((list === null || list === void 0 ? void 0 : list.get()) instanceof Expressions.NewObject) {
|
|
73267
|
+
call = list;
|
|
73268
|
+
}
|
|
73269
|
+
else if ((list === null || list === void 0 ? void 0 : list.get()) instanceof Expressions.MethodParameters && (above === null || above === void 0 ? void 0 : above.get()) instanceof Expressions.MethodCallParam) {
|
|
73270
|
+
call = path[index - 5];
|
|
73271
|
+
}
|
|
73272
|
+
else if ((list === null || list === void 0 ? void 0 : list.get()) instanceof Expressions.MethodParameters && (above === null || above === void 0 ? void 0 : above.get()) instanceof Expressions.MethodCallBody
|
|
73273
|
+
&& index === 4 && statement.get() instanceof Statements.Call) {
|
|
73274
|
+
call = statement;
|
|
73275
|
+
}
|
|
73276
|
+
}
|
|
73277
|
+
if (call === undefined) {
|
|
73278
|
+
return undefined;
|
|
73279
|
+
}
|
|
73280
|
+
let method;
|
|
73281
|
+
if (call instanceof nodes_1.ExpressionNode && call.get() instanceof Expressions.MethodCall) {
|
|
73282
|
+
const methodName = (_c = call.findDirectExpression(Expressions.MethodName)) === null || _c === void 0 ? void 0 : _c.getFirstToken();
|
|
73283
|
+
method = methodName === undefined ? undefined : procedure.methodAt(methodName);
|
|
73284
|
+
}
|
|
73285
|
+
else if (call instanceof nodes_1.StatementNode && call.get() instanceof Statements.Call) {
|
|
73286
|
+
const methodSource = call.findDirectExpression(Expressions.MethodSource);
|
|
73287
|
+
method = methodSource === undefined ? undefined : procedure.methodAt(methodSource.getLastToken());
|
|
73288
|
+
}
|
|
73289
|
+
else if (!(call.get() instanceof Expressions.NewObject) && !(call.get() instanceof Statements.CreateObject)) {
|
|
73290
|
+
return undefined;
|
|
73291
|
+
}
|
|
73292
|
+
const parameters = method === null || method === void 0 ? void 0 : method.getParameters();
|
|
73293
|
+
const formal = name !== null && name !== void 0 ? name : parameters === null || parameters === void 0 ? void 0 : parameters.getDefaultImporting();
|
|
73294
|
+
const parameter = formal === undefined ? undefined
|
|
73295
|
+
: parameters === null || parameters === void 0 ? void 0 : parameters.getImporting().find(p => p.getName().toUpperCase() === formal.toUpperCase());
|
|
73296
|
+
return { call, method, parameter };
|
|
73297
|
+
}
|
|
73298
|
+
/** the token is the complete actual parameter for a pass-by-value importing parameter of the only call in the
|
|
73299
|
+
* statement, so the method gets a copy of the value when it is called, and nothing else runs before */
|
|
73300
|
+
function passedByValue(procedure, statement, token) {
|
|
73301
|
+
var _a, _b;
|
|
73302
|
+
if (!(statement.get() instanceof Statements.Call) && plainMove(statement) === undefined) {
|
|
73303
|
+
return false;
|
|
73304
|
+
}
|
|
73305
|
+
const formal = formalParameter(procedure, statement, token);
|
|
73306
|
+
if ((formal === null || formal === void 0 ? void 0 : formal.method) === undefined || ((_a = formal.parameter) === null || _a === void 0 ? void 0 : _a.getMeta().includes("pass_by_value" /* IdentifierMeta.PassByValue */)) !== true
|
|
73307
|
+
|| statement.findFirstExpression(Expressions.NewObject) !== undefined) {
|
|
73308
|
+
return false;
|
|
73309
|
+
}
|
|
73310
|
+
for (const call of statement.findAllExpressionsRecursive(Expressions.MethodCall)) {
|
|
73311
|
+
const name = (_b = call.findDirectExpression(Expressions.MethodName)) === null || _b === void 0 ? void 0 : _b.getFirstToken();
|
|
73312
|
+
const builtin = name === undefined ? false : procedure.analysis.referencesAt(procedure.file.getFilename(), name)
|
|
73313
|
+
.some(r => r.referenceType === _reference_1.ReferenceType.BuiltinMethodReference);
|
|
73314
|
+
if (call !== formal.call && builtin === false) {
|
|
73315
|
+
return false;
|
|
73316
|
+
}
|
|
73317
|
+
}
|
|
73318
|
+
return true;
|
|
73319
|
+
}
|
|
73320
|
+
/** builtin functions whose result type follows the type of the argument */
|
|
73321
|
+
exports.NUMERIC_FUNCTIONS = new Set(["abs", "sign", "ceil", "floor", "trunc", "frac", "ipow", "nmax", "nmin",
|
|
73322
|
+
"round", "rescale"]);
|
|
73323
|
+
/** type of a literal: 'abc' is c LENGTH 3, `abc` is string, 12 is i */
|
|
73324
|
+
function literalType(constant) {
|
|
73325
|
+
var _a;
|
|
73326
|
+
var _b;
|
|
73327
|
+
if (constant.countTokens() !== 1) {
|
|
73328
|
+
return undefined;
|
|
73329
|
+
}
|
|
73330
|
+
const text = constant.getFirstToken().getStr();
|
|
73331
|
+
if (constant.findDirectExpression(Expressions.Integer) !== undefined) {
|
|
73332
|
+
const value = Number(text);
|
|
73333
|
+
return Number.isInteger(value) && Math.abs(value) <= 2147483647 ? basic_1.IntegerType.get() : undefined;
|
|
73334
|
+
}
|
|
73335
|
+
else if (text.startsWith("'") && text.endsWith("'") && text.length >= 2) {
|
|
73336
|
+
return new basic_1.CharacterType(Math.max(1, text.length - 2 - ((_b = (_a = text.match(/''/g)) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0)));
|
|
73337
|
+
}
|
|
73338
|
+
else if (text.startsWith("`") && text.endsWith("`")) {
|
|
73339
|
+
return basic_1.StringType.get();
|
|
73340
|
+
}
|
|
73341
|
+
return undefined;
|
|
73342
|
+
}
|
|
73343
|
+
/** Static type of an expression whose type does not depend on where it is used: literals, string templates,
|
|
73344
|
+
* concatenations, xsdbool( ), boolc( ), data objects, method calls and attributes after method calls.
|
|
73345
|
+
* Undefined if not known, e.g. for constructor expressions, arithmetic or builtin functions typed by their argument */
|
|
73346
|
+
function expressionType(procedure, source) {
|
|
73347
|
+
var _a, _b, _c;
|
|
73348
|
+
const children = source.getChildren();
|
|
73349
|
+
const first = children[0];
|
|
73350
|
+
const keyword = first instanceof nodes_1.TokenNode ? first.getFirstToken().getStr().toUpperCase() : "";
|
|
73351
|
+
if (children.length === 4 && keyword === "XSDBOOL" && source.findDirectExpression(Expressions.Cond) !== undefined) {
|
|
73352
|
+
return new basic_1.CharacterType(1);
|
|
73353
|
+
}
|
|
73354
|
+
else if (children.length === 4 && keyword === "BOOLC" && source.findDirectExpression(Expressions.Cond) !== undefined) {
|
|
73355
|
+
return basic_1.StringType.get();
|
|
73356
|
+
}
|
|
73357
|
+
else if (children.length === 3 && children[1] instanceof nodes_1.TokenNode && children[1].getFirstToken().getStr() === "&&") {
|
|
73358
|
+
return basic_1.StringType.get();
|
|
73359
|
+
}
|
|
73360
|
+
else if (!(first instanceof nodes_1.ExpressionNode)) {
|
|
73361
|
+
return undefined;
|
|
73362
|
+
}
|
|
73363
|
+
if (children.length === 1 && first.get() instanceof Expressions.Constant) {
|
|
73364
|
+
return literalType(first);
|
|
73365
|
+
}
|
|
73366
|
+
else if (children.length === 1 && first.get() instanceof Expressions.StringTemplate) {
|
|
73367
|
+
return basic_1.StringType.get();
|
|
73368
|
+
}
|
|
73369
|
+
else if (children.length === 1 && first.get() instanceof Expressions.FieldChain) {
|
|
73370
|
+
return (_a = dataSource(procedure, source)) === null || _a === void 0 ? void 0 : _a.type;
|
|
73371
|
+
}
|
|
73372
|
+
else if (!(first.get() instanceof Expressions.MethodCallChain)) {
|
|
73373
|
+
return undefined;
|
|
73374
|
+
}
|
|
73375
|
+
// the last call of the chain, optionally followed by ->attribute
|
|
73376
|
+
let type;
|
|
73377
|
+
const last = first.getChildren()[first.getChildren().length - 1];
|
|
73378
|
+
if (last instanceof nodes_1.ExpressionNode && last.get() instanceof Expressions.MethodCall) {
|
|
73379
|
+
const name = (_b = last.findDirectExpression(Expressions.MethodName)) === null || _b === void 0 ? void 0 : _b.getFirstToken();
|
|
73380
|
+
const method = name === undefined ? undefined : procedure.methodAt(name);
|
|
73381
|
+
if (name === undefined || method === undefined || exports.NUMERIC_FUNCTIONS.has(name.getStr().toLowerCase())) {
|
|
73382
|
+
return undefined;
|
|
73383
|
+
}
|
|
73384
|
+
type = (_c = method.getParameters().getReturning()) === null || _c === void 0 ? void 0 : _c.getType();
|
|
73385
|
+
}
|
|
73386
|
+
else {
|
|
73387
|
+
return undefined;
|
|
73388
|
+
}
|
|
73389
|
+
if (children.length === 1) {
|
|
73390
|
+
return type;
|
|
73391
|
+
}
|
|
73392
|
+
const attribute = children[2];
|
|
73393
|
+
if (children.length === 3 && children[1].get() instanceof Expressions.Arrow && attribute instanceof nodes_1.ExpressionNode
|
|
73394
|
+
&& attribute.get() instanceof Expressions.AttributeChain && attribute.getChildren().length === 1) {
|
|
73395
|
+
const identifier = procedure.identifierAt(attribute.getFirstToken());
|
|
73396
|
+
return identifier instanceof _typed_identifier_1.TypedIdentifier ? identifier.getType() : undefined;
|
|
73397
|
+
}
|
|
73398
|
+
return undefined;
|
|
73399
|
+
}
|
|
73400
|
+
////////////////////////////////////////
|
|
73401
|
+
// classes and interfaces
|
|
73402
|
+
/** classes and interfaces by name: local ones in the scope of the procedure, global ones in the registry */
|
|
73403
|
+
class Hierarchy {
|
|
73404
|
+
constructor(reg, procedure) {
|
|
73405
|
+
this.reg = reg;
|
|
73406
|
+
this.procedure = procedure;
|
|
73407
|
+
}
|
|
73408
|
+
find(name) {
|
|
73409
|
+
var _a;
|
|
73410
|
+
const scope = this.procedure.analysis.spaghetti.lookupPosition(this.procedure.getStart(), this.procedure.file.getFilename());
|
|
73411
|
+
const local = (_a = scope === null || scope === void 0 ? void 0 : scope.findClassDefinition(name)) !== null && _a !== void 0 ? _a : scope === null || scope === void 0 ? void 0 : scope.findInterfaceDefinition(name);
|
|
73412
|
+
if (local !== undefined) {
|
|
73413
|
+
return local;
|
|
73414
|
+
}
|
|
73415
|
+
const clas = this.reg.getObject("CLAS", name);
|
|
73416
|
+
if (clas instanceof class_1.Class) {
|
|
73417
|
+
return clas.getDefinition();
|
|
73418
|
+
}
|
|
73419
|
+
const intf = this.reg.getObject("INTF", name);
|
|
73420
|
+
return intf instanceof interface_1.Interface ? intf.getDefinition() : undefined;
|
|
73421
|
+
}
|
|
73422
|
+
/** the class or interface definition of an object reference type, undefined if it is not known */
|
|
73423
|
+
definition(type) {
|
|
73424
|
+
if (!(type instanceof basic_1.ObjectReferenceType)) {
|
|
73425
|
+
return undefined;
|
|
73426
|
+
}
|
|
73427
|
+
const identifier = type.getIdentifier();
|
|
73428
|
+
const found = identifier instanceof class_definition_1.ClassDefinition || identifier instanceof interface_definition_1.InterfaceDefinition
|
|
73429
|
+
? identifier : this.find(identifier.getName());
|
|
73430
|
+
return found instanceof class_definition_1.ClassDefinition || found instanceof interface_definition_1.InterfaceDefinition ? found : undefined;
|
|
73431
|
+
}
|
|
73432
|
+
/** sub is sup, or inherits from it or implements it; false if a definition on the way is not known */
|
|
73433
|
+
isSubtype(sub, sup) {
|
|
73434
|
+
const target = sup.toUpperCase();
|
|
73435
|
+
const visited = new Set();
|
|
73436
|
+
const stack = [sub.toUpperCase()];
|
|
73437
|
+
while (stack.length > 0) {
|
|
73438
|
+
const name = stack.pop();
|
|
73439
|
+
if (name === target) {
|
|
73440
|
+
return true;
|
|
73441
|
+
}
|
|
73442
|
+
else if (visited.has(name)) {
|
|
73443
|
+
continue;
|
|
73444
|
+
}
|
|
73445
|
+
visited.add(name);
|
|
73446
|
+
const definition = this.find(name);
|
|
73447
|
+
const superClass = definition === null || definition === void 0 ? void 0 : definition.getSuperClass();
|
|
73448
|
+
if (superClass !== undefined) {
|
|
73449
|
+
stack.push(superClass.toUpperCase());
|
|
73450
|
+
}
|
|
73451
|
+
for (const implementing of (definition === null || definition === void 0 ? void 0 : definition.getImplementing()) || []) {
|
|
73452
|
+
stack.push(implementing.name.toUpperCase());
|
|
73453
|
+
}
|
|
73454
|
+
}
|
|
73455
|
+
return false;
|
|
73456
|
+
}
|
|
73457
|
+
}
|
|
73458
|
+
exports.Hierarchy = Hierarchy;
|
|
73065
73459
|
////////////////////////////////////////
|
|
73066
73460
|
// edits
|
|
73067
73461
|
const rowCache = new WeakMap();
|
|
@@ -75817,14 +76211,7 @@ ENDIF.`,
|
|
|
75817
76211
|
return false;
|
|
75818
76212
|
}
|
|
75819
76213
|
const constant = (0, _procedure_analysis_1.characterConstant)(procedure, move.source);
|
|
75820
|
-
return (constant !== undefined && (0, _procedure_analysis_1.sameCharacters)(constant, "")) ||
|
|
75821
|
-
}
|
|
75822
|
-
/** VALUE type( ) */
|
|
75823
|
-
initialValue(source) {
|
|
75824
|
-
const tokens = source.getTokens();
|
|
75825
|
-
return tokens.length === 4 && tokens[0].getStr().toUpperCase() === "VALUE"
|
|
75826
|
-
&& source.findDirectExpression(Expressions.TypeNameOrInfer) !== undefined
|
|
75827
|
-
&& tokens[1].getStr() !== "#" && tokens[2].getStr() === "(" && tokens[3].getStr() === ")";
|
|
76214
|
+
return (constant !== undefined && (0, _procedure_analysis_1.sameCharacters)(constant, "")) || (0, _procedure_analysis_1.initialValue)(move.source);
|
|
75828
76215
|
}
|
|
75829
76216
|
}
|
|
75830
76217
|
exports.BooleanFlagViaIf = BooleanFlagViaIf;
|
|
@@ -76209,6 +76596,205 @@ exports.CallTransactionAuthorityCheck = CallTransactionAuthorityCheck;
|
|
|
76209
76596
|
|
|
76210
76597
|
/***/ },
|
|
76211
76598
|
|
|
76599
|
+
/***/ "../core/build/src/rules/cast_via_generic_reference.js"
|
|
76600
|
+
/*!*************************************************************!*\
|
|
76601
|
+
!*** ../core/build/src/rules/cast_via_generic_reference.js ***!
|
|
76602
|
+
\*************************************************************/
|
|
76603
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
76604
|
+
|
|
76605
|
+
"use strict";
|
|
76606
|
+
|
|
76607
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
76608
|
+
if (k2 === undefined) k2 = k;
|
|
76609
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
76610
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
76611
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
76612
|
+
}
|
|
76613
|
+
Object.defineProperty(o, k2, desc);
|
|
76614
|
+
}) : (function(o, m, k, k2) {
|
|
76615
|
+
if (k2 === undefined) k2 = k;
|
|
76616
|
+
o[k2] = m[k];
|
|
76617
|
+
}));
|
|
76618
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
76619
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
76620
|
+
}) : function(o, v) {
|
|
76621
|
+
o["default"] = v;
|
|
76622
|
+
});
|
|
76623
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
76624
|
+
var ownKeys = function(o) {
|
|
76625
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
76626
|
+
var ar = [];
|
|
76627
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
76628
|
+
return ar;
|
|
76629
|
+
};
|
|
76630
|
+
return ownKeys(o);
|
|
76631
|
+
};
|
|
76632
|
+
return function (mod) {
|
|
76633
|
+
if (mod && mod.__esModule) return mod;
|
|
76634
|
+
var result = {};
|
|
76635
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
76636
|
+
__setModuleDefault(result, mod);
|
|
76637
|
+
return result;
|
|
76638
|
+
};
|
|
76639
|
+
})();
|
|
76640
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
76641
|
+
exports.CastViaGenericReference = exports.CastViaGenericReferenceConf = void 0;
|
|
76642
|
+
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
76643
|
+
const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
|
|
76644
|
+
const interface_definition_1 = __webpack_require__(/*! ../abap/types/interface_definition */ "../core/build/src/abap/types/interface_definition.js");
|
|
76645
|
+
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
76646
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
76647
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
76648
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
76649
|
+
const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
|
|
76650
|
+
class CastViaGenericReferenceConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
76651
|
+
}
|
|
76652
|
+
exports.CastViaGenericReferenceConf = CastViaGenericReferenceConf;
|
|
76653
|
+
class CastViaGenericReference {
|
|
76654
|
+
constructor() {
|
|
76655
|
+
this.conf = new CastViaGenericReferenceConf();
|
|
76656
|
+
}
|
|
76657
|
+
getMetadata() {
|
|
76658
|
+
return {
|
|
76659
|
+
key: "cast_via_generic_reference",
|
|
76660
|
+
title: "Cast via generic reference",
|
|
76661
|
+
shortDescription: `Finds a down cast from a local reference variable that only holds a copy of another reference`,
|
|
76662
|
+
extendedInformation: `Reports DATA o TYPE REF TO object. o = r. ... x ?= o. when all of the following hold:
|
|
76663
|
+
|
|
76664
|
+
* o is a local variable of a METHOD, FORM or FUNCTION, declared with DATA without VALUE and not chained,
|
|
76665
|
+
typed REF TO object, or REF TO a class or interface that is the static type of r or a supertype of it
|
|
76666
|
+
* o has exactly one write, o = r., exactly one read, the complete source of x ?= o., and its address is never
|
|
76667
|
+
taken. x is not an inline declaration
|
|
76668
|
+
* r is a plain object reference: a variable, or a chain of attributes and components without calls,
|
|
76669
|
+
offsets, table expressions, field symbols or ->*
|
|
76670
|
+
* r keeps its value from o = r. until the read, as in unnecessary_copy: for a local r, no write to it and its
|
|
76671
|
+
address is never taken; for other r, in addition no method, function or form call and no write except to
|
|
76672
|
+
local variables, by value parameters and RETURNING in between
|
|
76673
|
+
* o = r. is executed before x ?= o. on every path: the read is in the same block or a nested block, and both
|
|
76674
|
+
are in the same loop
|
|
76675
|
+
* x ?= r. is valid: x or r is typed REF TO object or an interface, or the class of x and the class of r
|
|
76676
|
+
are in the same inheritance line
|
|
76677
|
+
|
|
76678
|
+
The object is the same, so the cast succeeds or raises cx_sy_move_cast_error the same way.
|
|
76679
|
+
try_cast_empty_catch can then replace a TRY around the cast.
|
|
76680
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
76681
|
+
INCLUDE, test seams, enhancements or native SQL.
|
|
76682
|
+
|
|
76683
|
+
The quick fix deletes the declaration and o = r., and casts r directly. No release requirement.`,
|
|
76684
|
+
tags: [_irule_1.RuleTag.Quickfix],
|
|
76685
|
+
badExample: `DATA lo_object TYPE REF TO object.
|
|
76686
|
+
lo_object = io_node.
|
|
76687
|
+
TRY.
|
|
76688
|
+
lo_leaf ?= lo_object.
|
|
76689
|
+
CATCH cx_sy_move_cast_error.
|
|
76690
|
+
ENDTRY.`,
|
|
76691
|
+
goodExample: `TRY.
|
|
76692
|
+
lo_leaf ?= io_node.
|
|
76693
|
+
CATCH cx_sy_move_cast_error.
|
|
76694
|
+
ENDTRY.`,
|
|
76695
|
+
};
|
|
76696
|
+
}
|
|
76697
|
+
getConfig() {
|
|
76698
|
+
return this.conf;
|
|
76699
|
+
}
|
|
76700
|
+
setConfig(conf) {
|
|
76701
|
+
this.conf = conf;
|
|
76702
|
+
}
|
|
76703
|
+
initialize(reg) {
|
|
76704
|
+
this.reg = reg;
|
|
76705
|
+
return this;
|
|
76706
|
+
}
|
|
76707
|
+
run(obj) {
|
|
76708
|
+
var _a, _b;
|
|
76709
|
+
const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
|
|
76710
|
+
if (analysis === undefined) {
|
|
76711
|
+
return [];
|
|
76712
|
+
}
|
|
76713
|
+
const issues = [];
|
|
76714
|
+
for (const procedure of analysis.procedures) {
|
|
76715
|
+
if (procedure.supported === false) {
|
|
76716
|
+
continue;
|
|
76717
|
+
}
|
|
76718
|
+
const hierarchy = new _procedure_analysis_1.Hierarchy(this.reg, procedure);
|
|
76719
|
+
for (const variable of procedure.locals()) {
|
|
76720
|
+
const declaration = variable.declaration;
|
|
76721
|
+
const type = variable.identifier.getType();
|
|
76722
|
+
const writes = variable.writes();
|
|
76723
|
+
const reads = variable.reads();
|
|
76724
|
+
if (variable.inline || !(0, _procedure_analysis_1.plainData)(declaration) || declaration.getColon() !== undefined || variable.escapes()
|
|
76725
|
+
|| !this.isObjectReference(type) || writes.length !== 1 || reads.length !== 1) {
|
|
76726
|
+
continue;
|
|
76727
|
+
}
|
|
76728
|
+
const write = writes[0];
|
|
76729
|
+
const read = reads[0];
|
|
76730
|
+
const assign = (0, _procedure_analysis_1.plainMove)(write.statement);
|
|
76731
|
+
const cast = (0, _procedure_analysis_1.plainMove)(read.statement);
|
|
76732
|
+
if (assign === undefined || cast === undefined || assign.operator !== "=" || cast.operator !== "?="
|
|
76733
|
+
|| ((_a = (0, _procedure_analysis_1.singleTarget)(assign.target)) === null || _a === void 0 ? void 0 : _a.getStart().equals(write.token.getStart())) !== true
|
|
76734
|
+
|| ((_b = (0, _procedure_analysis_1.singleField)(cast.source)) === null || _b === void 0 ? void 0 : _b.getStart().equals(read.token.getStart())) !== true
|
|
76735
|
+
|| cast.target.findFirstExpression(Expressions.InlineData) !== undefined
|
|
76736
|
+
|| !procedure.dominates(write.statement, read.statement)
|
|
76737
|
+
|| !procedure.sameLoop(write.statement, read.statement)) {
|
|
76738
|
+
continue;
|
|
76739
|
+
}
|
|
76740
|
+
const source = (0, _procedure_analysis_1.dataSource)(procedure, assign.source);
|
|
76741
|
+
const target = (0, _procedure_analysis_1.targetType)(procedure, cast.target);
|
|
76742
|
+
if (source === undefined || source.base === variable || target === undefined
|
|
76743
|
+
|| !this.isObjectReference(source.type)
|
|
76744
|
+
|| !this.isSupertype(hierarchy, type, source.type)
|
|
76745
|
+
|| !this.castable(hierarchy, source.type, target)
|
|
76746
|
+
|| !(0, _procedure_analysis_1.unchangedBetween)(procedure, source, write.statement, read.statement, read.token)) {
|
|
76747
|
+
continue;
|
|
76748
|
+
}
|
|
76749
|
+
const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, [
|
|
76750
|
+
(0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration),
|
|
76751
|
+
(0, _procedure_analysis_1.deleteStatement)(procedure.file, write.statement),
|
|
76752
|
+
edit_helper_1.EditHelper.replaceToken(procedure.file, read.token, source.text)
|
|
76753
|
+
]);
|
|
76754
|
+
const message = "Cast " + source.text + " directly instead of via " + variable.identifier.getName();
|
|
76755
|
+
issues.push(issue_1.Issue.atStatement(procedure.file, read.statement, message, this.getMetadata().key, this.conf.severity, fix));
|
|
76756
|
+
}
|
|
76757
|
+
}
|
|
76758
|
+
return issues;
|
|
76759
|
+
}
|
|
76760
|
+
isObjectReference(type) {
|
|
76761
|
+
return type instanceof basic_1.GenericObjectReferenceType || type instanceof basic_1.ObjectReferenceType;
|
|
76762
|
+
}
|
|
76763
|
+
/** every reference of type sub can be assigned to type sup without a cast */
|
|
76764
|
+
isSupertype(hierarchy, sup, sub) {
|
|
76765
|
+
if (sup instanceof basic_1.GenericObjectReferenceType) {
|
|
76766
|
+
return true;
|
|
76767
|
+
}
|
|
76768
|
+
else if (!(sup instanceof basic_1.ObjectReferenceType) || !(sub instanceof basic_1.ObjectReferenceType)) {
|
|
76769
|
+
return false;
|
|
76770
|
+
}
|
|
76771
|
+
return hierarchy.isSubtype(sub.getIdentifierName(), sup.getIdentifierName());
|
|
76772
|
+
}
|
|
76773
|
+
/** target ?= source. is statically valid */
|
|
76774
|
+
castable(hierarchy, source, target) {
|
|
76775
|
+
if (source instanceof basic_1.GenericObjectReferenceType || target instanceof basic_1.GenericObjectReferenceType) {
|
|
76776
|
+
return true;
|
|
76777
|
+
}
|
|
76778
|
+
else if (!(source instanceof basic_1.ObjectReferenceType) || !(target instanceof basic_1.ObjectReferenceType)) {
|
|
76779
|
+
return false;
|
|
76780
|
+
}
|
|
76781
|
+
const sourceDefinition = hierarchy.definition(source);
|
|
76782
|
+
const targetDefinition = hierarchy.definition(target);
|
|
76783
|
+
if (sourceDefinition === undefined || targetDefinition === undefined) {
|
|
76784
|
+
return false;
|
|
76785
|
+
}
|
|
76786
|
+
else if (sourceDefinition instanceof interface_definition_1.InterfaceDefinition || targetDefinition instanceof interface_definition_1.InterfaceDefinition) {
|
|
76787
|
+
return true;
|
|
76788
|
+
}
|
|
76789
|
+
return hierarchy.isSubtype(source.getIdentifierName(), target.getIdentifierName())
|
|
76790
|
+
|| hierarchy.isSubtype(target.getIdentifierName(), source.getIdentifierName());
|
|
76791
|
+
}
|
|
76792
|
+
}
|
|
76793
|
+
exports.CastViaGenericReference = CastViaGenericReference;
|
|
76794
|
+
//# sourceMappingURL=cast_via_generic_reference.js.map
|
|
76795
|
+
|
|
76796
|
+
/***/ },
|
|
76797
|
+
|
|
76212
76798
|
/***/ "../core/build/src/rules/catch_and_raise.js"
|
|
76213
76799
|
/*!**************************************************!*\
|
|
76214
76800
|
!*** ../core/build/src/rules/catch_and_raise.js ***!
|
|
@@ -79130,10 +79716,13 @@ class ClearAfterDeclaration {
|
|
|
79130
79716
|
shortDescription: `Finds CLEAR of a local variable that is still initial since its declaration`,
|
|
79131
79717
|
extendedInformation: `Reports CLEAR x. when all of the following hold:
|
|
79132
79718
|
|
|
79133
|
-
* x is a local variable of a METHOD, FORM or FUNCTION, declared with DATA x TYPE/LIKE ... without VALUE
|
|
79719
|
+
* x is a local variable of a METHOD, FORM or FUNCTION, declared with DATA x TYPE/LIKE ... without VALUE,
|
|
79720
|
+
or with DATA(x) = VALUE t( ). with an explicit type and nothing in the parentheses
|
|
79134
79721
|
* the CLEAR is the first reference to x after the declaration, it has no WITH addition
|
|
79135
|
-
* neither the
|
|
79136
|
-
RETRY, RESUME or CATCH BEFORE UNWIND. DATA is not executed per iteration, so a CLEAR in a loop can be needed
|
|
79722
|
+
* neither the declaration nor the CLEAR is inside a LOOP, DO, WHILE, SELECT loop, PROVIDE, or a TRY block with
|
|
79723
|
+
RETRY, RESUME or CATCH BEFORE UNWIND. DATA is not executed per iteration, so a CLEAR in a loop can be needed.
|
|
79724
|
+
DATA(x) = VALUE t( ). is executed per iteration, it may also be in the same loop as the CLEAR, if the CLEAR is
|
|
79725
|
+
in the block of the declaration or a nested block
|
|
79137
79726
|
|
|
79138
79727
|
Any later use of x does not matter, the CLEAR can only be reached with x still initial.
|
|
79139
79728
|
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
@@ -79168,13 +79757,11 @@ CLEAR lv_count.`,
|
|
|
79168
79757
|
continue;
|
|
79169
79758
|
}
|
|
79170
79759
|
for (const variable of procedure.locals()) {
|
|
79171
|
-
const declaration = variable.declaration;
|
|
79172
79760
|
const first = variable.occurrences[0];
|
|
79173
|
-
if (
|
|
79761
|
+
if (first === undefined
|
|
79174
79762
|
|| first.kind !== _procedure_analysis_1.OccurrenceKind.Write
|
|
79175
79763
|
|| ((_a = (0, _procedure_analysis_1.plainClear)(first.statement)) === null || _a === void 0 ? void 0 : _a.getStart().equals(first.token.getStart())) !== true
|
|
79176
|
-
|| procedure.
|
|
79177
|
-
|| procedure.loop(first.statement) !== undefined) {
|
|
79764
|
+
|| !(0, _procedure_analysis_1.initialAtFirstReference)(procedure, variable, first.statement)) {
|
|
79178
79765
|
continue;
|
|
79179
79766
|
}
|
|
79180
79767
|
const fix = (0, _procedure_analysis_1.deleteStatement)(procedure.file, first.statement);
|
|
@@ -79189,6 +79776,195 @@ exports.ClearAfterDeclaration = ClearAfterDeclaration;
|
|
|
79189
79776
|
|
|
79190
79777
|
/***/ },
|
|
79191
79778
|
|
|
79779
|
+
/***/ "../core/build/src/rules/clear_before_overwrite.js"
|
|
79780
|
+
/*!*********************************************************!*\
|
|
79781
|
+
!*** ../core/build/src/rules/clear_before_overwrite.js ***!
|
|
79782
|
+
\*********************************************************/
|
|
79783
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
79784
|
+
|
|
79785
|
+
"use strict";
|
|
79786
|
+
|
|
79787
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
79788
|
+
if (k2 === undefined) k2 = k;
|
|
79789
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
79790
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
79791
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
79792
|
+
}
|
|
79793
|
+
Object.defineProperty(o, k2, desc);
|
|
79794
|
+
}) : (function(o, m, k, k2) {
|
|
79795
|
+
if (k2 === undefined) k2 = k;
|
|
79796
|
+
o[k2] = m[k];
|
|
79797
|
+
}));
|
|
79798
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
79799
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
79800
|
+
}) : function(o, v) {
|
|
79801
|
+
o["default"] = v;
|
|
79802
|
+
});
|
|
79803
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
79804
|
+
var ownKeys = function(o) {
|
|
79805
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
79806
|
+
var ar = [];
|
|
79807
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
79808
|
+
return ar;
|
|
79809
|
+
};
|
|
79810
|
+
return ownKeys(o);
|
|
79811
|
+
};
|
|
79812
|
+
return function (mod) {
|
|
79813
|
+
if (mod && mod.__esModule) return mod;
|
|
79814
|
+
var result = {};
|
|
79815
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
79816
|
+
__setModuleDefault(result, mod);
|
|
79817
|
+
return result;
|
|
79818
|
+
};
|
|
79819
|
+
})();
|
|
79820
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
79821
|
+
exports.ClearBeforeOverwrite = exports.ClearBeforeOverwriteConf = void 0;
|
|
79822
|
+
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
79823
|
+
const Structures = __importStar(__webpack_require__(/*! ../abap/3_structures/structures */ "../core/build/src/abap/3_structures/structures/index.js"));
|
|
79824
|
+
const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
|
|
79825
|
+
const _typed_identifier_1 = __webpack_require__(/*! ../abap/types/_typed_identifier */ "../core/build/src/abap/types/_typed_identifier.js");
|
|
79826
|
+
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
79827
|
+
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
79828
|
+
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
79829
|
+
const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
|
|
79830
|
+
class ClearBeforeOverwriteConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
79831
|
+
}
|
|
79832
|
+
exports.ClearBeforeOverwriteConf = ClearBeforeOverwriteConf;
|
|
79833
|
+
class ClearBeforeOverwrite {
|
|
79834
|
+
constructor() {
|
|
79835
|
+
this.conf = new ClearBeforeOverwriteConf();
|
|
79836
|
+
}
|
|
79837
|
+
getMetadata() {
|
|
79838
|
+
return {
|
|
79839
|
+
key: "clear_before_overwrite",
|
|
79840
|
+
title: "CLEAR before overwrite",
|
|
79841
|
+
shortDescription: `Finds CLEAR of a local variable whose next use overwrites it completely`,
|
|
79842
|
+
extendedInformation: `Reports CLEAR v. when all of the following hold:
|
|
79843
|
+
|
|
79844
|
+
* v is a local variable of a METHOD, FORM or FUNCTION, its address is never taken: no field symbol,
|
|
79845
|
+
REF #( ), GET REFERENCE, and it is not passed to a parameter by reference
|
|
79846
|
+
* the CLEAR is not chained and has no WITH addition
|
|
79847
|
+
* the next reference to v is a full overwrite in the same block: v = <expression>., including v = NEW ...,
|
|
79848
|
+
or CREATE OBJECT v. with optional TYPE and EXPORTING, where nothing else in the statement references v.
|
|
79849
|
+
Not ?=, READ TABLE INTO, offset/length or component writes, CREATE OBJECT with EXCEPTIONS, or other
|
|
79850
|
+
statements that can leave v unchanged
|
|
79851
|
+
* every statement between the CLEAR and the overwrite is a direct statement of the block, not a nested structure,
|
|
79852
|
+
and does not reference v
|
|
79853
|
+
* v is not a table with header line
|
|
79854
|
+
* if a TRY or CATCH SYSTEM-EXCEPTIONS encloses the CLEAR, nothing from the CLEAR to the overwrite can raise
|
|
79855
|
+
an exception, a CATCH could see the old value: the overwrite directly follows the CLEAR and assigns a variable
|
|
79856
|
+
or a literal of identical type, or a reference variable
|
|
79857
|
+
|
|
79858
|
+
Unlike clear_after_declaration, the CLEAR can be in a loop.
|
|
79859
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
79860
|
+
INCLUDE, test seams, enhancements or native SQL.
|
|
79861
|
+
|
|
79862
|
+
The quick fix deletes the CLEAR. No release requirement.`,
|
|
79863
|
+
tags: [_irule_1.RuleTag.Quickfix],
|
|
79864
|
+
badExample: `CLEAR lv_name.
|
|
79865
|
+
lv_name = iv_name.`,
|
|
79866
|
+
goodExample: `lv_name = iv_name.`,
|
|
79867
|
+
};
|
|
79868
|
+
}
|
|
79869
|
+
getConfig() {
|
|
79870
|
+
return this.conf;
|
|
79871
|
+
}
|
|
79872
|
+
setConfig(conf) {
|
|
79873
|
+
this.conf = conf;
|
|
79874
|
+
}
|
|
79875
|
+
initialize(reg) {
|
|
79876
|
+
this.reg = reg;
|
|
79877
|
+
return this;
|
|
79878
|
+
}
|
|
79879
|
+
run(obj) {
|
|
79880
|
+
var _a;
|
|
79881
|
+
const analysis = _procedure_analysis_1.ObjectAnalysis.run(this.reg, obj);
|
|
79882
|
+
if (analysis === undefined) {
|
|
79883
|
+
return [];
|
|
79884
|
+
}
|
|
79885
|
+
const issues = [];
|
|
79886
|
+
for (const procedure of analysis.procedures) {
|
|
79887
|
+
if (procedure.supported === false) {
|
|
79888
|
+
continue;
|
|
79889
|
+
}
|
|
79890
|
+
for (const variable of procedure.locals()) {
|
|
79891
|
+
const type = variable.identifier.getType();
|
|
79892
|
+
if (variable.escapes() || (type instanceof basic_1.TableType && type.isWithHeader())
|
|
79893
|
+
|| this.passedByReference(procedure, variable)) {
|
|
79894
|
+
continue;
|
|
79895
|
+
}
|
|
79896
|
+
const occurrences = variable.occurrences;
|
|
79897
|
+
for (let i = 0; i < occurrences.length - 1; i++) {
|
|
79898
|
+
const clear = occurrences[i];
|
|
79899
|
+
const next = occurrences[i + 1];
|
|
79900
|
+
if (((_a = (0, _procedure_analysis_1.plainClear)(clear.statement)) === null || _a === void 0 ? void 0 : _a.getStart().equals(clear.token.getStart())) !== true
|
|
79901
|
+
|| clear.statement.getColon() !== undefined
|
|
79902
|
+
|| occurrences.some(o => o !== next && o.statement === next.statement)
|
|
79903
|
+
|| !this.overwrites(next)) {
|
|
79904
|
+
continue;
|
|
79905
|
+
}
|
|
79906
|
+
const between = procedure.straightBetween(clear.statement, next.statement);
|
|
79907
|
+
if (between === undefined
|
|
79908
|
+
|| (procedure.enclosedBy(clear.statement, [Structures.Try, Structures.CatchSystemExceptions])
|
|
79909
|
+
&& (between.length > 0 || !this.cannotRaise(procedure, variable, next.statement)))) {
|
|
79910
|
+
continue;
|
|
79911
|
+
}
|
|
79912
|
+
const message = "CLEAR of " + variable.identifier.getName() + ", which is overwritten before it is read";
|
|
79913
|
+
issues.push(issue_1.Issue.atStatement(procedure.file, clear.statement, message, this.getMetadata().key, this.conf.severity, (0, _procedure_analysis_1.deleteStatement)(procedure.file, clear.statement)));
|
|
79914
|
+
}
|
|
79915
|
+
}
|
|
79916
|
+
}
|
|
79917
|
+
return issues;
|
|
79918
|
+
}
|
|
79919
|
+
/** passed to a method, NEW, CREATE OBJECT or RAISE EXCEPTION, other than to a pass-by-value parameter;
|
|
79920
|
+
* the called code could keep a reference to the parameter */
|
|
79921
|
+
passedByReference(procedure, variable) {
|
|
79922
|
+
var _a;
|
|
79923
|
+
for (const read of variable.reads()) {
|
|
79924
|
+
const path = (0, _procedure_analysis_1.expressionPath)(read.statement, read.token);
|
|
79925
|
+
if (!path.some(e => e.get() instanceof Expressions.MethodCallParam || e.get() instanceof Expressions.ParameterListS
|
|
79926
|
+
|| e.get() instanceof Expressions.MethodParameters)) {
|
|
79927
|
+
continue;
|
|
79928
|
+
}
|
|
79929
|
+
const formal = (0, _procedure_analysis_1.formalParameter)(procedure, read.statement, read.token);
|
|
79930
|
+
if (((_a = formal === null || formal === void 0 ? void 0 : formal.parameter) === null || _a === void 0 ? void 0 : _a.getMeta().includes("pass_by_value" /* IdentifierMeta.PassByValue */)) !== true) {
|
|
79931
|
+
return true;
|
|
79932
|
+
}
|
|
79933
|
+
}
|
|
79934
|
+
return false;
|
|
79935
|
+
}
|
|
79936
|
+
/** v = <expression>. or CREATE OBJECT v [TYPE c] [EXPORTING ...]. */
|
|
79937
|
+
overwrites(occurrence) {
|
|
79938
|
+
var _a, _b;
|
|
79939
|
+
const statement = occurrence.statement;
|
|
79940
|
+
const move = (0, _procedure_analysis_1.plainMove)(statement);
|
|
79941
|
+
if (move !== undefined) {
|
|
79942
|
+
return move.operator === "=" && ((_a = (0, _procedure_analysis_1.singleTarget)(move.target)) === null || _a === void 0 ? void 0 : _a.getStart().equals(occurrence.token.getStart())) === true;
|
|
79943
|
+
}
|
|
79944
|
+
const create = (0, _procedure_analysis_1.plainCreateObject)(statement);
|
|
79945
|
+
return create !== undefined && ((_b = (0, _procedure_analysis_1.singleTarget)(create.target)) === null || _b === void 0 ? void 0 : _b.getStart().equals(occurrence.token.getStart())) === true;
|
|
79946
|
+
}
|
|
79947
|
+
/** v = w. or v = literal. without conversion */
|
|
79948
|
+
cannotRaise(procedure, variable, statement) {
|
|
79949
|
+
const move = (0, _procedure_analysis_1.plainMove)(statement);
|
|
79950
|
+
if (move === undefined) {
|
|
79951
|
+
return false;
|
|
79952
|
+
}
|
|
79953
|
+
const type = variable.identifier.getType();
|
|
79954
|
+
const field = (0, _procedure_analysis_1.singleField)(move.source);
|
|
79955
|
+
const constant = move.source.getChildren().length === 1 ? move.source.findDirectExpression(Expressions.Constant) : undefined;
|
|
79956
|
+
const identifier = field === undefined ? undefined : procedure.identifierAt(field);
|
|
79957
|
+
const source = identifier instanceof _typed_identifier_1.TypedIdentifier ? identifier.getType()
|
|
79958
|
+
: constant === undefined ? undefined : (0, _procedure_analysis_1.literalType)(constant);
|
|
79959
|
+
return source !== undefined
|
|
79960
|
+
&& ((0, _procedure_analysis_1.identicalTypes)(source, type) || ((0, _procedure_analysis_1.isReferenceType)(source) && (0, _procedure_analysis_1.isReferenceType)(type) && field !== undefined));
|
|
79961
|
+
}
|
|
79962
|
+
}
|
|
79963
|
+
exports.ClearBeforeOverwrite = ClearBeforeOverwrite;
|
|
79964
|
+
//# sourceMappingURL=clear_before_overwrite.js.map
|
|
79965
|
+
|
|
79966
|
+
/***/ },
|
|
79967
|
+
|
|
79192
79968
|
/***/ "../core/build/src/rules/clear_exporting_parameters.js"
|
|
79193
79969
|
/*!*************************************************************!*\
|
|
79194
79970
|
!*** ../core/build/src/rules/clear_exporting_parameters.js ***!
|
|
@@ -80028,8 +80804,9 @@ c = <constant>, c <> <constant>, EQ, NE, c IS INITIAL, c IS NOT INITIAL, optiona
|
|
|
80028
80804
|
The declaration must be executed before the condition on every path: the IF is in the block of the
|
|
80029
80805
|
declaration or a nested block. The quick fix deletes the declaration.
|
|
80030
80806
|
|
|
80031
|
-
2. DATA v TYPE ... without VALUE,
|
|
80032
|
-
|
|
80807
|
+
2. DATA v TYPE ... without VALUE, or DATA(v) = VALUE t( ). with an explicit type and nothing in the parentheses,
|
|
80808
|
+
where v is never changed, except by CLEAR v., and its address is never taken, in a condition v IS [NOT] INITIAL
|
|
80809
|
+
or v IS [NOT] BOUND. The declaration is kept.
|
|
80033
80810
|
|
|
80034
80811
|
The quick fix removes the IF branch that is never taken, or keeps the branch that is always taken and
|
|
80035
80812
|
removes the rest, also in ELSEIF chains: a first IF branch that is never taken turns the next ELSEIF into IF,
|
|
@@ -80070,12 +80847,12 @@ ENDIF.`,
|
|
|
80070
80847
|
}
|
|
80071
80848
|
const candidates = [];
|
|
80072
80849
|
for (const variable of procedure.locals()) {
|
|
80073
|
-
if (
|
|
80074
|
-
this.constantVariable(procedure, variable, candidates);
|
|
80075
|
-
}
|
|
80076
|
-
else {
|
|
80850
|
+
if ((0, _procedure_analysis_1.initialDeclaration)(variable) !== undefined) {
|
|
80077
80851
|
this.initialVariable(procedure, variable, candidates);
|
|
80078
80852
|
}
|
|
80853
|
+
else if (variable.inline) {
|
|
80854
|
+
this.constantVariable(procedure, variable, candidates);
|
|
80855
|
+
}
|
|
80079
80856
|
}
|
|
80080
80857
|
issues.push(...(0, _procedure_analysis_1.foldIssues)(procedure.file, candidates, this.getMetadata().key, this.conf.severity));
|
|
80081
80858
|
}
|
|
@@ -80111,9 +80888,9 @@ ENDIF.`,
|
|
|
80111
80888
|
fix: (0, _procedure_analysis_1.mergeEdits)(procedure.file, [fold, (0, _procedure_analysis_1.deleteStatement)(procedure.file, declaration)]),
|
|
80112
80889
|
});
|
|
80113
80890
|
}
|
|
80114
|
-
/** DATA v TYPE ... never changed: IF v IS INITIAL / IS BOUND */
|
|
80891
|
+
/** DATA v TYPE ... or DATA(v) = VALUE t( ). never changed: IF v IS INITIAL / IS BOUND */
|
|
80115
80892
|
initialVariable(procedure, variable, candidates) {
|
|
80116
|
-
if (
|
|
80893
|
+
if (variable.escapes()
|
|
80117
80894
|
|| variable.writes().some(w => { var _a; return ((_a = (0, _procedure_analysis_1.plainClear)(w.statement)) === null || _a === void 0 ? void 0 : _a.getStart().equals(w.token.getStart())) !== true; })) {
|
|
80118
80895
|
return;
|
|
80119
80896
|
}
|
|
@@ -80376,6 +81153,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
80376
81153
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
80377
81154
|
exports.CopyChain = exports.CopyChainConf = void 0;
|
|
80378
81155
|
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
81156
|
+
const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
|
|
81157
|
+
const basic_1 = __webpack_require__(/*! ../abap/types/basic */ "../core/build/src/abap/types/basic/index.js");
|
|
80379
81158
|
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
80380
81159
|
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
80381
81160
|
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
@@ -80393,28 +81172,49 @@ class CopyChain {
|
|
|
80393
81172
|
key: "copy_chain",
|
|
80394
81173
|
title: "Copy chain",
|
|
80395
81174
|
shortDescription: `Finds a local variable that only passes a value on from one variable to another`,
|
|
80396
|
-
extendedInformation: `Reports
|
|
81175
|
+
extendedInformation: `Reports a local variable that only passes a value on, in two cases.
|
|
81176
|
+
|
|
81177
|
+
1. DATA v TYPE ... [CLEAR v.] v = src. ... y = v. when all of the following hold:
|
|
80397
81178
|
|
|
80398
|
-
* v is a local variable of a METHOD, FORM or FUNCTION, declared with DATA without VALUE
|
|
81179
|
+
* v is a local variable of a METHOD, FORM or FUNCTION, declared with DATA without VALUE, or with
|
|
81180
|
+
DATA(v) = VALUE t( ). with an explicit type and nothing in the parentheses
|
|
80399
81181
|
* v has exactly one write besides CLEAR: v = src., and all CLEARs are before it
|
|
80400
81182
|
* v has exactly one read, the complete source of y = v.
|
|
80401
|
-
* src is a local variable,
|
|
81183
|
+
* src is a local variable, or a pass-by-value or RETURNING parameter of a method or form, its address is never
|
|
81184
|
+
taken, and it is not written from v = src. until y = v.
|
|
80402
81185
|
* v = src. is executed before y = v. on every path: y = v. is in the same block or a nested block,
|
|
80403
81186
|
and both are in the same loop
|
|
80404
81187
|
* v and src are both reference types, or have identical types; for other types the copy into v can convert,
|
|
80405
81188
|
e.g. truncate a string into a c field. For DATA(y) = v. the types must be identical, else y changes its type
|
|
80406
81189
|
* the declaration, the CLEARs and v = src. are not chained
|
|
80407
81190
|
|
|
80408
|
-
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
80409
|
-
INCLUDE, test seams, enhancements or native SQL.
|
|
80410
|
-
|
|
80411
81191
|
The quick fix deletes the declaration, the CLEARs and v = src., and changes the read to y = src.
|
|
80412
|
-
|
|
81192
|
+
|
|
81193
|
+
2. DATA a TYPE REF TO c. CREATE OBJECT a. b = a. when all of the following hold:
|
|
81194
|
+
|
|
81195
|
+
* a is a local variable, declared with DATA without VALUE and not chained, its address is never taken
|
|
81196
|
+
* the only other references to a are CREATE OBJECT a. and the complete source of b = a., which is the next
|
|
81197
|
+
statement in the same block, apart from declarations like DATA in between
|
|
81198
|
+
* CREATE OBJECT has at most TYPE and EXPORTING, it is not chained. With EXCEPTIONS, a classic exception in the
|
|
81199
|
+
constructor would leave b unchanged instead of initial
|
|
81200
|
+
* b is a local variable, or a pass-by-value or RETURNING parameter, whose address is never taken, it is
|
|
81201
|
+
declared before the CREATE OBJECT and not used in its parameters, so the constructor cannot see b
|
|
81202
|
+
* b = a. passes the syntax check, so the static type of b accepts the class of a
|
|
81203
|
+
|
|
81204
|
+
The quick fix deletes the declaration of a and b = a., and creates the object in b, keeping TYPE and EXPORTING.
|
|
81205
|
+
If the static types of a and b differ, it adds TYPE with the class of a.
|
|
81206
|
+
|
|
81207
|
+
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
81208
|
+
INCLUDE, test seams, enhancements or native SQL. No release requirement.`,
|
|
80413
81209
|
tags: [_irule_1.RuleTag.Quickfix],
|
|
80414
81210
|
badExample: `DATA lo_copy TYPE REF TO zcl_node.
|
|
80415
81211
|
lo_copy = lo_node.
|
|
80416
|
-
ro_result = lo_copy
|
|
80417
|
-
|
|
81212
|
+
ro_result = lo_copy.
|
|
81213
|
+
DATA lo_new TYPE REF TO zcl_node.
|
|
81214
|
+
CREATE OBJECT lo_new.
|
|
81215
|
+
ro_other = lo_new.`,
|
|
81216
|
+
goodExample: `ro_result = lo_node.
|
|
81217
|
+
CREATE OBJECT ro_other.`,
|
|
80418
81218
|
};
|
|
80419
81219
|
}
|
|
80420
81220
|
getConfig() {
|
|
@@ -80440,7 +81240,7 @@ ro_result = lo_copy.`,
|
|
|
80440
81240
|
}
|
|
80441
81241
|
for (const variable of procedure.locals()) {
|
|
80442
81242
|
const declaration = variable.declaration;
|
|
80443
|
-
if (
|
|
81243
|
+
if ((0, _procedure_analysis_1.initialDeclaration)(variable) === undefined || declaration.getColon() !== undefined
|
|
80444
81244
|
|| variable.escapes()) {
|
|
80445
81245
|
continue;
|
|
80446
81246
|
}
|
|
@@ -80461,6 +81261,13 @@ ro_result = lo_copy.`,
|
|
|
80461
81261
|
}
|
|
80462
81262
|
const write = writes[0];
|
|
80463
81263
|
const read = reads[0];
|
|
81264
|
+
if (write.statement.get() instanceof Statements.CreateObject) {
|
|
81265
|
+
const issue = clears.length === 0 ? this.createObject(procedure, variable, write, read) : undefined;
|
|
81266
|
+
if (issue !== undefined) {
|
|
81267
|
+
issues.push(issue);
|
|
81268
|
+
}
|
|
81269
|
+
continue;
|
|
81270
|
+
}
|
|
80464
81271
|
const assign = (0, _procedure_analysis_1.plainMove)(write.statement);
|
|
80465
81272
|
const use = (0, _procedure_analysis_1.plainMove)(read.statement);
|
|
80466
81273
|
if (assign === undefined || use === undefined || assign.operator !== "=" || use.operator !== "="
|
|
@@ -80498,6 +81305,46 @@ ro_result = lo_copy.`,
|
|
|
80498
81305
|
}
|
|
80499
81306
|
return issues;
|
|
80500
81307
|
}
|
|
81308
|
+
/** DATA a TYPE REF TO c. CREATE OBJECT a. b = a. */
|
|
81309
|
+
createObject(procedure, variable, write, read) {
|
|
81310
|
+
var _a, _b, _c;
|
|
81311
|
+
const create = (0, _procedure_analysis_1.plainCreateObject)(write.statement);
|
|
81312
|
+
const use = (0, _procedure_analysis_1.plainMove)(read.statement);
|
|
81313
|
+
const token = use === undefined ? undefined : (0, _procedure_analysis_1.singleTarget)(use.target);
|
|
81314
|
+
const target = token === undefined ? undefined : procedure.private(procedure.identifierAt(token));
|
|
81315
|
+
if (create === undefined || use === undefined || use.operator !== "=" || target === undefined
|
|
81316
|
+
|| ((_a = (0, _procedure_analysis_1.singleTarget)(create.target)) === null || _a === void 0 ? void 0 : _a.getStart().equals(write.token.getStart())) !== true
|
|
81317
|
+
|| ((_b = (0, _procedure_analysis_1.singleField)(use.source)) === null || _b === void 0 ? void 0 : _b.getStart().equals(read.token.getStart())) !== true
|
|
81318
|
+
|| read.statement !== procedure.nextExecuted(write.statement) || !procedure.isSimple(read.statement)
|
|
81319
|
+
|| target.occurrences.some(o => o.statement === write.statement)
|
|
81320
|
+
|| (target.declaration !== undefined && procedure.index(target.declaration) > write.index)) {
|
|
81321
|
+
return undefined;
|
|
81322
|
+
}
|
|
81323
|
+
const type = variable.identifier.getType();
|
|
81324
|
+
const targetType = target.identifier.getType();
|
|
81325
|
+
let text = (0, _procedure_analysis_1.nodeText)(procedure.file, use.target);
|
|
81326
|
+
if (!(type instanceof basic_1.ObjectReferenceType)
|
|
81327
|
+
|| !(targetType instanceof basic_1.ObjectReferenceType || targetType instanceof basic_1.GenericObjectReferenceType)) {
|
|
81328
|
+
return undefined;
|
|
81329
|
+
}
|
|
81330
|
+
else if (create.type === undefined && !(0, _procedure_analysis_1.identicalTypes)(type, targetType)) {
|
|
81331
|
+
// the class of a, as written in its declaration
|
|
81332
|
+
const declared = (_c = variable.declaration.findDirectExpression(Expressions.DataDefinition)) === null || _c === void 0 ? void 0 : _c.findDirectExpression(Expressions.Type);
|
|
81333
|
+
const name = declared === null || declared === void 0 ? void 0 : declared.findDirectExpression(Expressions.TypeName);
|
|
81334
|
+
if (name === undefined || (declared === null || declared === void 0 ? void 0 : declared.getTokens().length) !== 4) {
|
|
81335
|
+
return undefined;
|
|
81336
|
+
}
|
|
81337
|
+
text = text + " TYPE " + (0, _procedure_analysis_1.nodeText)(procedure.file, name);
|
|
81338
|
+
}
|
|
81339
|
+
const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, [
|
|
81340
|
+
(0, _procedure_analysis_1.deleteStatement)(procedure.file, variable.declaration),
|
|
81341
|
+
edit_helper_1.EditHelper.replaceToken(procedure.file, write.token, text),
|
|
81342
|
+
(0, _procedure_analysis_1.deleteStatement)(procedure.file, read.statement)
|
|
81343
|
+
]);
|
|
81344
|
+
const message = "Copy chain via " + variable.identifier.getName() + ", create the object in "
|
|
81345
|
+
+ (0, _procedure_analysis_1.nodeText)(procedure.file, use.target) + " directly";
|
|
81346
|
+
return issue_1.Issue.atStatement(procedure.file, read.statement, message, this.getMetadata().key, this.conf.severity, fix);
|
|
81347
|
+
}
|
|
80501
81348
|
}
|
|
80502
81349
|
exports.CopyChain = CopyChain;
|
|
80503
81350
|
//# sourceMappingURL=copy_chain.js.map
|
|
@@ -80567,7 +81414,9 @@ class CopyOfInitialVariable {
|
|
|
80567
81414
|
shortDescription: `Finds assignments from a local variable that is always initial`,
|
|
80568
81415
|
extendedInformation: `Reports DATA v TYPE ... [CLEAR v.] x = v. when all of the following hold:
|
|
80569
81416
|
|
|
80570
|
-
* v is a local variable of a METHOD, FORM or FUNCTION, declared with DATA without VALUE
|
|
81417
|
+
* v is a local variable of a METHOD, FORM or FUNCTION, declared with DATA without VALUE, or with
|
|
81418
|
+
DATA(v) = VALUE t( ). with an explicit type and nothing in the parentheses. Both make v initial, the latter
|
|
81419
|
+
every time it is executed, so v is initial wherever it is read, also in loops
|
|
80571
81420
|
* v is never changed, except by CLEAR v., and its address is never taken
|
|
80572
81421
|
* v has exactly one read, the complete source of x = v., where x is not an inline declaration
|
|
80573
81422
|
* x and v are both reference types, or have identical types. Initial values convert differently between
|
|
@@ -80610,7 +81459,7 @@ ro_result = lo_empty.`,
|
|
|
80610
81459
|
const declaration = variable.declaration;
|
|
80611
81460
|
const reads = variable.reads();
|
|
80612
81461
|
const writes = variable.writes();
|
|
80613
|
-
if (
|
|
81462
|
+
if ((0, _procedure_analysis_1.initialDeclaration)(variable) === undefined || declaration.getColon() !== undefined
|
|
80614
81463
|
|| variable.escapes() || reads.length !== 1
|
|
80615
81464
|
|| writes.some(w => { var _a; return ((_a = (0, _procedure_analysis_1.plainClear)(w.statement)) === null || _a === void 0 ? void 0 : _a.getStart().equals(w.token.getStart())) !== true
|
|
80616
81465
|
|| w.statement.getColon() !== undefined; })) {
|
|
@@ -89629,6 +90478,7 @@ __exportStar(__webpack_require__(/*! ./begin_single_include */ "../core/build/sr
|
|
|
89629
90478
|
__exportStar(__webpack_require__(/*! ./boolean_flag_via_if */ "../core/build/src/rules/boolean_flag_via_if.js"), exports);
|
|
89630
90479
|
__exportStar(__webpack_require__(/*! ./bound_check_after_create */ "../core/build/src/rules/bound_check_after_create.js"), exports);
|
|
89631
90480
|
__exportStar(__webpack_require__(/*! ./call_transaction_authority_check */ "../core/build/src/rules/call_transaction_authority_check.js"), exports);
|
|
90481
|
+
__exportStar(__webpack_require__(/*! ./cast_via_generic_reference */ "../core/build/src/rules/cast_via_generic_reference.js"), exports);
|
|
89632
90482
|
__exportStar(__webpack_require__(/*! ./catch_and_raise */ "../core/build/src/rules/catch_and_raise.js"), exports);
|
|
89633
90483
|
__exportStar(__webpack_require__(/*! ./cds_association_name */ "../core/build/src/rules/cds_association_name.js"), exports);
|
|
89634
90484
|
__exportStar(__webpack_require__(/*! ./cds_check_syntax */ "../core/build/src/rules/cds_check_syntax.js"), exports);
|
|
@@ -89649,6 +90499,7 @@ __exportStar(__webpack_require__(/*! ./check_syntax */ "../core/build/src/rules/
|
|
|
89649
90499
|
__exportStar(__webpack_require__(/*! ./check_text_elements */ "../core/build/src/rules/check_text_elements.js"), exports);
|
|
89650
90500
|
__exportStar(__webpack_require__(/*! ./check_transformation_exists */ "../core/build/src/rules/check_transformation_exists.js"), exports);
|
|
89651
90501
|
__exportStar(__webpack_require__(/*! ./clear_after_declaration */ "../core/build/src/rules/clear_after_declaration.js"), exports);
|
|
90502
|
+
__exportStar(__webpack_require__(/*! ./clear_before_overwrite */ "../core/build/src/rules/clear_before_overwrite.js"), exports);
|
|
89652
90503
|
__exportStar(__webpack_require__(/*! ./clear_exporting_parameters */ "../core/build/src/rules/clear_exporting_parameters.js"), exports);
|
|
89653
90504
|
__exportStar(__webpack_require__(/*! ./class_attribute_names */ "../core/build/src/rules/class_attribute_names.js"), exports);
|
|
89654
90505
|
__exportStar(__webpack_require__(/*! ./classic_exceptions_overlap */ "../core/build/src/rules/classic_exceptions_overlap.js"), exports);
|
|
@@ -101871,10 +102722,14 @@ If the statement contains a JOIN it is not checked`,
|
|
|
101871
102722
|
setConfig(conf) {
|
|
101872
102723
|
this.conf = conf;
|
|
101873
102724
|
}
|
|
101874
|
-
buildFix(file, statement) {
|
|
102725
|
+
buildFix(file, statement, rows) {
|
|
102726
|
+
const end = statement.getLastToken().getEnd();
|
|
102727
|
+
const suffix = rows[end.getRow() - 1].slice(end.getCol() - 1).trimStart();
|
|
102728
|
+
// Keep chained '*' continuations out of the full-line comment column.
|
|
102729
|
+
const newline = suffix !== "" && suffix.startsWith('"') === false ? "\n " : "";
|
|
101875
102730
|
return {
|
|
101876
102731
|
description: `Add "#EC CI_NOORDER`,
|
|
101877
|
-
edit: edit_helper_1.EditHelper.insertAt(file,
|
|
102732
|
+
edit: edit_helper_1.EditHelper.insertAt(file, end, ` "#EC CI_NOORDER${newline}`),
|
|
101878
102733
|
};
|
|
101879
102734
|
}
|
|
101880
102735
|
run(obj) {
|
|
@@ -101890,6 +102745,7 @@ If the statement contains a JOIN it is not checked`,
|
|
|
101890
102745
|
const message = "SELECT SINGLE possibily not unique";
|
|
101891
102746
|
for (const file of obj.getABAPFiles()) {
|
|
101892
102747
|
const statements = file.getStatements();
|
|
102748
|
+
const rows = file.getRawRows();
|
|
101893
102749
|
for (let i = 0; i < statements.length; i++) {
|
|
101894
102750
|
const s = statements[i];
|
|
101895
102751
|
if (!(s.get() instanceof Statements.Select)) {
|
|
@@ -101936,7 +102792,7 @@ If the statement contains a JOIN it is not checked`,
|
|
|
101936
102792
|
}
|
|
101937
102793
|
}
|
|
101938
102794
|
if (set.size > 0) {
|
|
101939
|
-
const fix = this.buildFix(file, s);
|
|
102795
|
+
const fix = this.buildFix(file, s, rows);
|
|
101940
102796
|
issues.push(issue_1.Issue.atStatement(file, s, message, this.getMetadata().key, this.getConfig().severity, undefined, [fix]));
|
|
101941
102797
|
}
|
|
101942
102798
|
}
|
|
@@ -102562,21 +103418,51 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
102562
103418
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
102563
103419
|
exports.SingleUseExpressionTemp = exports.SingleUseExpressionTempConf = void 0;
|
|
102564
103420
|
const Expressions = __importStar(__webpack_require__(/*! ../abap/2_statements/expressions */ "../core/build/src/abap/2_statements/expressions/index.js"));
|
|
103421
|
+
const Statements = __importStar(__webpack_require__(/*! ../abap/2_statements/statements */ "../core/build/src/abap/2_statements/statements/index.js"));
|
|
102565
103422
|
const nodes_1 = __webpack_require__(/*! ../abap/nodes */ "../core/build/src/abap/nodes/index.js");
|
|
102566
103423
|
const _reference_1 = __webpack_require__(/*! ../abap/5_syntax/_reference */ "../core/build/src/abap/5_syntax/_reference.js");
|
|
102567
103424
|
const edit_helper_1 = __webpack_require__(/*! ../edit_helper */ "../core/build/src/edit_helper.js");
|
|
102568
103425
|
const issue_1 = __webpack_require__(/*! ../issue */ "../core/build/src/issue.js");
|
|
103426
|
+
const version_1 = __webpack_require__(/*! ../version */ "../core/build/src/version.js");
|
|
102569
103427
|
const _basic_rule_config_1 = __webpack_require__(/*! ./_basic_rule_config */ "../core/build/src/rules/_basic_rule_config.js");
|
|
102570
103428
|
const _irule_1 = __webpack_require__(/*! ./_irule */ "../core/build/src/rules/_irule.js");
|
|
102571
103429
|
const _procedure_analysis_1 = __webpack_require__(/*! ./_procedure_analysis */ "../core/build/src/rules/_procedure_analysis.js");
|
|
102572
103430
|
class SingleUseExpressionTempConf extends _basic_rule_config_1.BasicRuleConfig {
|
|
102573
103431
|
}
|
|
102574
103432
|
exports.SingleUseExpressionTempConf = SingleUseExpressionTempConf;
|
|
102575
|
-
/** builtin functions whose result type follows the type of the argument */
|
|
102576
|
-
const NUMERIC_FUNCTIONS = new Set(["abs", "sign", "ceil", "floor", "trunc", "frac", "ipow", "nmax", "nmin",
|
|
102577
|
-
"round", "rescale"]);
|
|
102578
103433
|
/** constructor expressions that can build the result directly in the target */
|
|
102579
103434
|
const IN_PLACE = new Set(["VALUE", "CORRESPONDING", "COND", "SWITCH", "REDUCE", "FILTER"]);
|
|
103435
|
+
/** constructor expressions with an explicit type: KEYWORD type( ... ) */
|
|
103436
|
+
const CONSTRUCTORS = new Set(["VALUE", "CORRESPONDING", "COND", "SWITCH", "REDUCE", "FILTER", "CONV", "EXACT", "REF"]);
|
|
103437
|
+
/** types that an integer literal converts to without an exception */
|
|
103438
|
+
const LITERAL_CONVERSIONS = new Set(["I", "INT8", "F", "DECFLOAT16", "DECFLOAT34", "STRING"]);
|
|
103439
|
+
/** where the variable is read */
|
|
103440
|
+
var Placement;
|
|
103441
|
+
(function (Placement) {
|
|
103442
|
+
/** y = v. */
|
|
103443
|
+
Placement["Move"] = "move";
|
|
103444
|
+
/** v->m( ) or v->attr */
|
|
103445
|
+
Placement["Receiver"] = "receiver";
|
|
103446
|
+
/** m( v ), m( p = v ), CALL METHOD m EXPORTING p = v, NEW c( p = v ), CREATE OBJECT o EXPORTING p = v */
|
|
103447
|
+
Placement["Parameter"] = "parameter";
|
|
103448
|
+
/** APPEND v TO itab. */
|
|
103449
|
+
Placement["Append"] = "append";
|
|
103450
|
+
/** IF v = x., ELSEIF v = x., xsdbool( v = x ) */
|
|
103451
|
+
Placement["Comparison"] = "comparison";
|
|
103452
|
+
/** |{ v }| */
|
|
103453
|
+
Placement["Template"] = "template";
|
|
103454
|
+
})(Placement || (Placement = {}));
|
|
103455
|
+
var ExpressionKind;
|
|
103456
|
+
(function (ExpressionKind) {
|
|
103457
|
+
/** literal, string template without embeddings, CONV t( literal ) or a constant: the same value everywhere */
|
|
103458
|
+
ExpressionKind["Constant"] = "constant";
|
|
103459
|
+
/** reads only private variables and constants, cannot raise an exception or run other code */
|
|
103460
|
+
ExpressionKind["Pure"] = "pure";
|
|
103461
|
+
/** a data object that other code can change */
|
|
103462
|
+
ExpressionKind["Data"] = "data";
|
|
103463
|
+
/** method calls, NEW and everything else */
|
|
103464
|
+
ExpressionKind["Other"] = "other";
|
|
103465
|
+
})(ExpressionKind || (ExpressionKind = {}));
|
|
102580
103466
|
class SingleUseExpressionTemp {
|
|
102581
103467
|
constructor() {
|
|
102582
103468
|
this.conf = new SingleUseExpressionTempConf();
|
|
@@ -102585,28 +103471,62 @@ class SingleUseExpressionTemp {
|
|
|
102585
103471
|
return {
|
|
102586
103472
|
key: "single_use_expression_temp",
|
|
102587
103473
|
title: "Single use expression temporary",
|
|
102588
|
-
shortDescription: `Finds
|
|
102589
|
-
extendedInformation: `Reports DATA(
|
|
102590
|
-
|
|
102591
|
-
|
|
102592
|
-
|
|
103474
|
+
shortDescription: `Finds a local variable that only passes the value of an expression on to its single use`,
|
|
103475
|
+
extendedInformation: `Reports DATA(v) = <expression>. and DATA v TYPE t. [CLEAR v.] v = <expression>.
|
|
103476
|
+
when all of the following hold:
|
|
103477
|
+
|
|
103478
|
+
* v is a local variable of a METHOD, FORM or FUNCTION, its address is never taken. DATA(v) has no other
|
|
103479
|
+
reference than its single read; DATA v TYPE t. without VALUE and not chained, or DATA(v) = VALUE t( ). with
|
|
103480
|
+
nothing in the parentheses, has exactly one write besides CLEARs, v = <expression>., all CLEARs are before it,
|
|
103481
|
+
and exactly one read after it
|
|
103482
|
+
* the read is one of
|
|
103483
|
+
* the complete source of y = v.
|
|
103484
|
+
* the receiver of a method call or attribute access: v->m( ), v->attr
|
|
103485
|
+
* an actual parameter for an importing parameter: m( v ), m( p = v ), CALL METHOD m EXPORTING p = v,
|
|
103486
|
+
NEW c( p = v ) or CREATE OBJECT o EXPORTING p = v
|
|
103487
|
+
* APPEND v TO itab.
|
|
103488
|
+
* an operand of a comparison with =, <>, <, >, <=, >= or their word forms, in IF, ELSEIF or xsdbool( )
|
|
103489
|
+
* an embedding in a string template: |{ v }|
|
|
103490
|
+
* the read is in the statement directly after the assignment, in the same block, ignoring declarations like
|
|
103491
|
+
DATA and TYPES in between, unless the expression is
|
|
103492
|
+
constant: a literal, a string template without embeddings, CONV t( <integer literal> ) to a type that cannot
|
|
103493
|
+
overflow, or a constant. Then the assignment must be executed before the read on every path: the read is in
|
|
103494
|
+
the block of the assignment or a nested block
|
|
102593
103495
|
* the result type of the expression does not depend on the target: no arithmetic or bit operators, no unary
|
|
102594
|
-
minus, no numeric functions like abs( ) or trunc( ) whose type follows the argument, no CONV or EXACT
|
|
102595
|
-
no # type inference at the top. String templates, && concatenations, literals, method calls, NEW, CAST,
|
|
103496
|
+
minus, no numeric functions like abs( ) or trunc( ) whose type follows the argument, no CONV or EXACT except
|
|
103497
|
+
the constant CONV t( literal ), no # type inference at the top. String templates, && concatenations, literals, method calls, NEW, CAST,
|
|
102596
103498
|
constructor expressions with explicit type and table expressions are fine
|
|
103499
|
+
* for DATA v TYPE t. and DATA(v) = VALUE t( )., the static type of the expression is identical to t. Into y = v. also a reference whose
|
|
103500
|
+
static type is a subtype of t, unless y is an inline declaration, and an expression whose type depends on the
|
|
103501
|
+
target, like arithmetic, if y has a type identical to t
|
|
102597
103502
|
* VALUE, CORRESPONDING, COND, SWITCH, REDUCE and FILTER can build their result directly in the target,
|
|
102598
|
-
they are only
|
|
103503
|
+
they are only moved into a new variable, or a local variable that they do not read and whose address
|
|
102599
103504
|
is never taken
|
|
102600
|
-
*
|
|
103505
|
+
* the order of evaluation does not change: if the expression is not constant, nothing that is evaluated before the
|
|
103506
|
+
read in the same statement calls a method or function, constructs an object, accesses a table or an attribute
|
|
103507
|
+
via a reference, does arithmetic, or reads data other than local variables, pass-by-value parameters and
|
|
103508
|
+
constants; the read is not inside COND, SWITCH, VALUE or other constructor expressions except NEW, and not
|
|
103509
|
+
after AND, OR or EQUIV, where it might not be evaluated. This does not apply to expressions that only read
|
|
103510
|
+
local variables and cannot raise an exception
|
|
103511
|
+
* a data object that other code can change is only moved if it keeps its value until the read, see
|
|
103512
|
+
unnecessary_copy, a data object read by DATA(v) = <data object>. is left for unnecessary_copy, and a local
|
|
103513
|
+
variable copied into y = v. for copy_chain
|
|
103514
|
+
* a character constant in IF, ELSEIF, WHILE, CHECK, CASE or WHEN is left for constant_condition
|
|
102601
103515
|
|
|
102602
103516
|
Objects with syntax errors, macros or unknown statements are skipped, as are procedures with dynamic code,
|
|
102603
103517
|
INCLUDE, test seams, enhancements or native SQL.
|
|
102604
103518
|
|
|
102605
|
-
The quick fix deletes the declaration and
|
|
103519
|
+
The quick fix deletes the declaration, the CLEARs and the assignment, and replaces the read of v with the
|
|
103520
|
+
expression. Moving the expression of DATA v TYPE t. into other places than y = v. requires 7.40 SP02 or above,
|
|
103521
|
+
ABAP Cloud or open-abap.`,
|
|
102606
103522
|
tags: [_irule_1.RuleTag.Quickfix],
|
|
102607
103523
|
badExample: `DATA(lo_conf) = NEW zcl_conf( ).
|
|
102608
|
-
mo_conf = lo_conf
|
|
102609
|
-
|
|
103524
|
+
mo_conf = lo_conf.
|
|
103525
|
+
DATA lv_key TYPE string.
|
|
103526
|
+
lv_key = |abapdoc|.
|
|
103527
|
+
lo_meta = NEW zcl_meta( iv_key = lv_key ).`,
|
|
103528
|
+
goodExample: `mo_conf = NEW zcl_conf( ).
|
|
103529
|
+
lo_meta = NEW zcl_meta( iv_key = |abapdoc| ).`,
|
|
102610
103530
|
};
|
|
102611
103531
|
}
|
|
102612
103532
|
getConfig() {
|
|
@@ -102625,61 +103545,501 @@ mo_conf = lo_conf.`,
|
|
|
102625
103545
|
if (analysis === undefined) {
|
|
102626
103546
|
return [];
|
|
102627
103547
|
}
|
|
103548
|
+
const config = this.reg.getConfig();
|
|
103549
|
+
const expressions = (0, version_1.releaseAtLeast)(config.getRelease(), version_1.Release.v740sp02)
|
|
103550
|
+
|| config.getLanguageVersion() === version_1.LanguageVersion.Cloud || config.isOpenABAP();
|
|
102628
103551
|
const issues = [];
|
|
102629
103552
|
for (const procedure of analysis.procedures) {
|
|
102630
103553
|
if (procedure.supported === false) {
|
|
102631
103554
|
continue;
|
|
102632
103555
|
}
|
|
102633
103556
|
for (const variable of procedure.locals()) {
|
|
102634
|
-
const
|
|
102635
|
-
const
|
|
102636
|
-
|
|
102637
|
-
if (move === undefined || move.operator !== "="
|
|
102638
|
-
|| move.target.getChildren().length !== 1
|
|
102639
|
-
|| move.target.findDirectExpression(Expressions.InlineData) === undefined
|
|
102640
|
-
|| variable.occurrences.length !== 1 || read.kind !== _procedure_analysis_1.OccurrenceKind.Read
|
|
102641
|
-
|| read.statement !== procedure.statements[procedure.index(declaration) + 1]
|
|
102642
|
-
|| procedure.block(read.statement) !== procedure.block(declaration)
|
|
102643
|
-
|| !procedure.isSimple(read.statement)) {
|
|
103557
|
+
const temp = (_a = (variable.inline ? this.inlineTemp(procedure, variable) : undefined)) !== null && _a !== void 0 ? _a : this.declaredTemp(variable);
|
|
103558
|
+
const read = variable.reads()[0];
|
|
103559
|
+
if (temp === undefined || read === undefined) {
|
|
102644
103560
|
continue;
|
|
102645
103561
|
}
|
|
102646
|
-
const
|
|
102647
|
-
if (
|
|
102648
|
-
|| (
|
|
102649
|
-
||
|
|
102650
|
-
|| !this.targetIndependent(procedure, move.source)
|
|
102651
|
-
|| !this.noAliasing(procedure, move.source, use.target)) {
|
|
103562
|
+
const placement = this.placement(procedure, read.statement, read.token);
|
|
103563
|
+
if (placement === undefined
|
|
103564
|
+
|| (!variable.inline && placement !== Placement.Move && expressions === false)
|
|
103565
|
+
|| !this.valid(procedure, temp, read, placement)) {
|
|
102652
103566
|
continue;
|
|
102653
103567
|
}
|
|
102654
|
-
const
|
|
102655
|
-
|
|
102656
|
-
(0, _procedure_analysis_1.deleteStatement)(procedure.file,
|
|
102657
|
-
|
|
102658
|
-
const
|
|
102659
|
-
|
|
103568
|
+
const edits = [edit_helper_1.EditHelper.replaceToken(procedure.file, read.token, (0, _procedure_analysis_1.nodeText)(procedure.file, temp.source))];
|
|
103569
|
+
for (const statement of temp.remove) {
|
|
103570
|
+
edits.push((0, _procedure_analysis_1.deleteStatement)(procedure.file, statement));
|
|
103571
|
+
}
|
|
103572
|
+
const fix = (0, _procedure_analysis_1.mergeEdits)(procedure.file, edits);
|
|
103573
|
+
const message = "Use the expression directly instead of via " + variable.identifier.getName();
|
|
103574
|
+
issues.push(issue_1.Issue.atStatement(procedure.file, temp.write, message, this.getMetadata().key, this.conf.severity, fix));
|
|
102660
103575
|
}
|
|
102661
103576
|
}
|
|
102662
103577
|
return issues;
|
|
102663
103578
|
}
|
|
103579
|
+
/** DATA(v) = <expression>. with a single read, plain data objects are left for unnecessary_copy */
|
|
103580
|
+
inlineTemp(procedure, variable) {
|
|
103581
|
+
const declaration = variable.declaration;
|
|
103582
|
+
const move = (0, _procedure_analysis_1.plainMove)(declaration);
|
|
103583
|
+
if (move === undefined || move.operator !== "="
|
|
103584
|
+
|| move.target.getChildren().length !== 1
|
|
103585
|
+
|| move.target.findDirectExpression(Expressions.InlineData) === undefined
|
|
103586
|
+
|| variable.occurrences.length !== 1 || variable.occurrences[0].kind !== _procedure_analysis_1.OccurrenceKind.Read
|
|
103587
|
+
|| (0, _procedure_analysis_1.dataSource)(procedure, move.source) !== undefined
|
|
103588
|
+
|| !this.targetIndependent(procedure, move.source)) {
|
|
103589
|
+
return undefined;
|
|
103590
|
+
}
|
|
103591
|
+
return { variable, write: declaration, source: move.source, remove: [declaration], typed: false };
|
|
103592
|
+
}
|
|
103593
|
+
/** DATA v TYPE t. or DATA(v) = VALUE t( )., [CLEAR v.] v = <expression>. with a single read after it */
|
|
103594
|
+
declaredTemp(variable) {
|
|
103595
|
+
var _a, _b;
|
|
103596
|
+
const declaration = variable.declaration;
|
|
103597
|
+
if ((0, _procedure_analysis_1.initialDeclaration)(variable) === undefined || declaration.getColon() !== undefined || variable.escapes()) {
|
|
103598
|
+
return undefined;
|
|
103599
|
+
}
|
|
103600
|
+
const clears = [];
|
|
103601
|
+
const writes = [];
|
|
103602
|
+
for (const write of variable.writes()) {
|
|
103603
|
+
if (((_a = (0, _procedure_analysis_1.plainClear)(write.statement)) === null || _a === void 0 ? void 0 : _a.getStart().equals(write.token.getStart())) === true
|
|
103604
|
+
&& write.statement.getColon() === undefined) {
|
|
103605
|
+
clears.push(write);
|
|
103606
|
+
}
|
|
103607
|
+
else {
|
|
103608
|
+
writes.push(write);
|
|
103609
|
+
}
|
|
103610
|
+
}
|
|
103611
|
+
const reads = variable.reads();
|
|
103612
|
+
if (writes.length !== 1 || reads.length !== 1) {
|
|
103613
|
+
return undefined;
|
|
103614
|
+
}
|
|
103615
|
+
const write = writes[0];
|
|
103616
|
+
const move = (0, _procedure_analysis_1.plainMove)(write.statement);
|
|
103617
|
+
if (move === undefined || move.operator !== "="
|
|
103618
|
+
|| ((_b = (0, _procedure_analysis_1.singleTarget)(move.target)) === null || _b === void 0 ? void 0 : _b.getStart().equals(write.token.getStart())) !== true
|
|
103619
|
+
|| clears.some(c => c.index > write.index)
|
|
103620
|
+
|| reads[0].index <= write.index) {
|
|
103621
|
+
return undefined;
|
|
103622
|
+
}
|
|
103623
|
+
return { variable, write: write.statement, source: move.source,
|
|
103624
|
+
remove: [declaration, ...clears.map(c => c.statement), write.statement], typed: true };
|
|
103625
|
+
}
|
|
103626
|
+
placement(procedure, statement, token) {
|
|
103627
|
+
var _a, _b, _c, _d;
|
|
103628
|
+
if (statement.getColon() !== undefined) {
|
|
103629
|
+
return undefined;
|
|
103630
|
+
}
|
|
103631
|
+
const move = (0, _procedure_analysis_1.plainMove)(statement);
|
|
103632
|
+
if (move !== undefined && move.operator === "=" && ((_a = (0, _procedure_analysis_1.singleField)(move.source)) === null || _a === void 0 ? void 0 : _a.getStart().equals(token.getStart())) === true) {
|
|
103633
|
+
return Placement.Move;
|
|
103634
|
+
}
|
|
103635
|
+
const path = (0, _procedure_analysis_1.expressionPath)(statement, token);
|
|
103636
|
+
if (path.some(e => e.get() instanceof Expressions.Target || e.get() instanceof Expressions.MethodSource
|
|
103637
|
+
|| e.get() instanceof Expressions.Dereference)) {
|
|
103638
|
+
return undefined;
|
|
103639
|
+
}
|
|
103640
|
+
const tokens = procedure.tokensOf(statement);
|
|
103641
|
+
const index = tokens.findIndex(t => t.getStart().equals(token.getStart()));
|
|
103642
|
+
if (((_b = tokens[index + 1]) === null || _b === void 0 ? void 0 : _b.getStr()) === "->") {
|
|
103643
|
+
return ((_c = tokens[index + 2]) === null || _c === void 0 ? void 0 : _c.getStr()) === "*" ? undefined : Placement.Receiver;
|
|
103644
|
+
}
|
|
103645
|
+
let sourceIndex = path.length - 1;
|
|
103646
|
+
while (sourceIndex >= 0 && !(path[sourceIndex].get() instanceof Expressions.Source)
|
|
103647
|
+
&& !(path[sourceIndex].get() instanceof Expressions.SimpleSource4)) {
|
|
103648
|
+
sourceIndex--;
|
|
103649
|
+
}
|
|
103650
|
+
const source = path[sourceIndex];
|
|
103651
|
+
if (source === undefined || source.countTokens() !== 1
|
|
103652
|
+
|| source.findDirectExpression(Expressions.FieldChain) === undefined) {
|
|
103653
|
+
return undefined;
|
|
103654
|
+
}
|
|
103655
|
+
const parent = path[sourceIndex - 1];
|
|
103656
|
+
if (parent === undefined) {
|
|
103657
|
+
return statement.get() instanceof Statements.Append && statement.getChildren()[1] === source
|
|
103658
|
+
? Placement.Append : undefined;
|
|
103659
|
+
}
|
|
103660
|
+
else if (parent.get() instanceof Expressions.StringTemplateSource) {
|
|
103661
|
+
return Placement.Template;
|
|
103662
|
+
}
|
|
103663
|
+
else if (parent.get() instanceof Expressions.Compare) {
|
|
103664
|
+
if (parent.findDirectExpression(Expressions.CompareOperator) === undefined) {
|
|
103665
|
+
return undefined;
|
|
103666
|
+
}
|
|
103667
|
+
let owner = sourceIndex - 2;
|
|
103668
|
+
while (((_d = path[owner]) === null || _d === void 0 ? void 0 : _d.get()) instanceof Expressions.Cond) {
|
|
103669
|
+
owner--;
|
|
103670
|
+
}
|
|
103671
|
+
if (owner === sourceIndex - 2) {
|
|
103672
|
+
return undefined;
|
|
103673
|
+
}
|
|
103674
|
+
else if (owner < 0) {
|
|
103675
|
+
const type = statement.get();
|
|
103676
|
+
return type instanceof Statements.If || type instanceof Statements.ElseIf ? Placement.Comparison : undefined;
|
|
103677
|
+
}
|
|
103678
|
+
const keyword = path[owner].getFirstToken().getStr().toUpperCase();
|
|
103679
|
+
return path[owner].get() instanceof Expressions.Source && (keyword === "XSDBOOL" || keyword === "BOOLC")
|
|
103680
|
+
? Placement.Comparison : undefined;
|
|
103681
|
+
}
|
|
103682
|
+
return (0, _procedure_analysis_1.formalParameter)(procedure, statement, token) !== undefined ? Placement.Parameter : undefined;
|
|
103683
|
+
}
|
|
103684
|
+
valid(procedure, temp, read, placement) {
|
|
103685
|
+
const statement = read.statement;
|
|
103686
|
+
const kind = this.kind(procedure, temp.source);
|
|
103687
|
+
if (kind === ExpressionKind.Constant) {
|
|
103688
|
+
if (!procedure.dominates(temp.write, statement)
|
|
103689
|
+
|| (!temp.typed && (0, _procedure_analysis_1.isCondition)(statement) && (0, _procedure_analysis_1.characterConstant)(procedure, temp.source) !== undefined)) {
|
|
103690
|
+
return false;
|
|
103691
|
+
}
|
|
103692
|
+
}
|
|
103693
|
+
else if (statement !== procedure.nextExecuted(temp.write)
|
|
103694
|
+
|| !(procedure.isSimple(statement) || statement.get() instanceof Statements.If)) {
|
|
103695
|
+
return false;
|
|
103696
|
+
}
|
|
103697
|
+
if (!this.typeMatches(procedure, temp, statement, placement)) {
|
|
103698
|
+
return false;
|
|
103699
|
+
}
|
|
103700
|
+
else if (placement === Placement.Receiver && !this.chainable(temp.source)) {
|
|
103701
|
+
return false;
|
|
103702
|
+
}
|
|
103703
|
+
const data = (0, _procedure_analysis_1.dataSource)(procedure, temp.source);
|
|
103704
|
+
if (kind === ExpressionKind.Constant) {
|
|
103705
|
+
return true;
|
|
103706
|
+
}
|
|
103707
|
+
else if ((data === null || data === void 0 ? void 0 : data.kind) === _procedure_analysis_1.SourceKind.Local && (0, _procedure_analysis_1.singleField)(temp.source) !== undefined && placement === Placement.Move) {
|
|
103708
|
+
// left for copy_chain
|
|
103709
|
+
return false;
|
|
103710
|
+
}
|
|
103711
|
+
else if (!this.notWrittenIn(procedure, temp.source, statement)) {
|
|
103712
|
+
return false;
|
|
103713
|
+
}
|
|
103714
|
+
else if (kind === ExpressionKind.Pure) {
|
|
103715
|
+
return true;
|
|
103716
|
+
}
|
|
103717
|
+
else if (!this.evaluatedFirst(procedure, statement, read.token) || !this.alwaysEvaluated(statement, read.token)) {
|
|
103718
|
+
return false;
|
|
103719
|
+
}
|
|
103720
|
+
return data === undefined || (0, _procedure_analysis_1.unchangedBetween)(procedure, data, temp.write, statement, read.token);
|
|
103721
|
+
}
|
|
103722
|
+
kind(procedure, source) {
|
|
103723
|
+
var _a;
|
|
103724
|
+
const data = (0, _procedure_analysis_1.dataSource)(procedure, source);
|
|
103725
|
+
if (this.constant(source) || (data === null || data === void 0 ? void 0 : data.kind) === _procedure_analysis_1.SourceKind.Immutable) {
|
|
103726
|
+
return ExpressionKind.Constant;
|
|
103727
|
+
}
|
|
103728
|
+
else if (((data === null || data === void 0 ? void 0 : data.kind) === _procedure_analysis_1.SourceKind.Local && ((_a = data.base) === null || _a === void 0 ? void 0 : _a.escapes()) === false) || this.pure(procedure, source)) {
|
|
103729
|
+
return ExpressionKind.Pure;
|
|
103730
|
+
}
|
|
103731
|
+
else if (data !== undefined) {
|
|
103732
|
+
return ExpressionKind.Data;
|
|
103733
|
+
}
|
|
103734
|
+
return ExpressionKind.Other;
|
|
103735
|
+
}
|
|
103736
|
+
/** a literal, a string template without embeddings, or CONV t( literal ) that cannot raise an exception */
|
|
103737
|
+
constant(source) {
|
|
103738
|
+
var _a;
|
|
103739
|
+
const children = source.getChildren();
|
|
103740
|
+
const first = children[0];
|
|
103741
|
+
if (children.length === 1 && first instanceof nodes_1.ExpressionNode) {
|
|
103742
|
+
return first.get() instanceof Expressions.Constant
|
|
103743
|
+
|| (first.get() instanceof Expressions.StringTemplate
|
|
103744
|
+
&& first.findDirectExpression(Expressions.StringTemplateSource) === undefined);
|
|
103745
|
+
}
|
|
103746
|
+
if (children.length !== 5 || source.getFirstToken().getStr().toUpperCase() !== "CONV") {
|
|
103747
|
+
return false;
|
|
103748
|
+
}
|
|
103749
|
+
const type = ((_a = source.findDirectExpression(Expressions.TypeNameOrInfer)) === null || _a === void 0 ? void 0 : _a.concatTokens().toUpperCase()) || "";
|
|
103750
|
+
const body = source.findDirectExpression(Expressions.ConvBody);
|
|
103751
|
+
const value = (body === null || body === void 0 ? void 0 : body.getChildren().length) === 1 ? body.findDirectExpression(Expressions.Source) : undefined;
|
|
103752
|
+
const literal = (value === null || value === void 0 ? void 0 : value.getChildren().length) === 1 ? value.findDirectExpression(Expressions.Constant) : undefined;
|
|
103753
|
+
return literal !== undefined && LITERAL_CONVERSIONS.has(type)
|
|
103754
|
+
&& (literal.findDirectExpression(Expressions.Integer) !== undefined || type === "STRING");
|
|
103755
|
+
}
|
|
103756
|
+
/** reads only private variables and constants, and cannot raise an exception: string templates and
|
|
103757
|
+
* concatenations of such fields, xsdbool( ) and boolc( ) of IS INITIAL, IS BOUND, IS INSTANCE OF and
|
|
103758
|
+
* comparisons without conversion */
|
|
103759
|
+
pure(procedure, source) {
|
|
103760
|
+
const children = source.getChildren();
|
|
103761
|
+
const first = children[0];
|
|
103762
|
+
const keyword = first instanceof nodes_1.TokenNode ? first.getFirstToken().getStr().toUpperCase() : "";
|
|
103763
|
+
if (children.length === 1 && first instanceof nodes_1.ExpressionNode) {
|
|
103764
|
+
return this.pureOperand(procedure, first);
|
|
103765
|
+
}
|
|
103766
|
+
else if (children.length === 3 && children[1] instanceof nodes_1.TokenNode && children[1].getFirstToken().getStr() === "&&"
|
|
103767
|
+
&& children[0] instanceof nodes_1.ExpressionNode && children[2] instanceof nodes_1.ExpressionNode) {
|
|
103768
|
+
return this.pureOperand(procedure, children[0]) && this.pure(procedure, children[2]);
|
|
103769
|
+
}
|
|
103770
|
+
else if (children.length === 4 && (keyword === "XSDBOOL" || keyword === "BOOLC")) {
|
|
103771
|
+
const cond = source.findDirectExpression(Expressions.Cond);
|
|
103772
|
+
return cond !== undefined && this.pureCondition(procedure, cond);
|
|
103773
|
+
}
|
|
103774
|
+
return false;
|
|
103775
|
+
}
|
|
103776
|
+
/** a literal, a private variable or constant, or a string template that embeds only those, without formatting */
|
|
103777
|
+
pureOperand(procedure, operand) {
|
|
103778
|
+
if (operand.get() instanceof Expressions.Constant) {
|
|
103779
|
+
return true;
|
|
103780
|
+
}
|
|
103781
|
+
else if (operand.get() instanceof Expressions.FieldChain) {
|
|
103782
|
+
return operand.countTokens() === 1 && this.privateField(procedure, operand.getFirstToken());
|
|
103783
|
+
}
|
|
103784
|
+
else if (operand.get() instanceof Expressions.StringTemplate) {
|
|
103785
|
+
return operand.findDirectExpressions(Expressions.StringTemplateSource).every(s => s.getChildren().length === 1
|
|
103786
|
+
&& this.operandType(procedure, s.findDirectExpression(Expressions.Source)) !== undefined);
|
|
103787
|
+
}
|
|
103788
|
+
return false;
|
|
103789
|
+
}
|
|
103790
|
+
pureCondition(procedure, cond) {
|
|
103791
|
+
for (const child of cond.getChildren()) {
|
|
103792
|
+
if (child instanceof nodes_1.TokenNode) {
|
|
103793
|
+
continue;
|
|
103794
|
+
}
|
|
103795
|
+
else if (child.get() instanceof Expressions.Cond) {
|
|
103796
|
+
if (!this.pureCondition(procedure, child)) {
|
|
103797
|
+
return false;
|
|
103798
|
+
}
|
|
103799
|
+
}
|
|
103800
|
+
else if (child.get() instanceof Expressions.Compare) {
|
|
103801
|
+
const operands = child.findDirectExpressions(Expressions.Source);
|
|
103802
|
+
const words = child.getChildren().filter(c => c instanceof nodes_1.TokenNode).map(c => c.getFirstToken().getStr().toUpperCase());
|
|
103803
|
+
const operator = child.findDirectExpression(Expressions.CompareOperator);
|
|
103804
|
+
const types = operands.map(o => this.operandType(procedure, o));
|
|
103805
|
+
if (types.some(t => t === undefined)) {
|
|
103806
|
+
return false;
|
|
103807
|
+
}
|
|
103808
|
+
else if (operands.length === 1 && words[words.length - 1] !== "SUPPLIED" && words[words.length - 1] !== "REQUESTED"
|
|
103809
|
+
&& words.includes("IS") && child.findDirectExpression(Expressions.CompareOperator) === undefined) {
|
|
103810
|
+
// IS [NOT] INITIAL, IS [NOT] BOUND, IS [NOT] INSTANCE OF
|
|
103811
|
+
continue;
|
|
103812
|
+
}
|
|
103813
|
+
else if (operands.length === 2 && operator !== undefined
|
|
103814
|
+
&& ((0, _procedure_analysis_1.identicalTypes)(types[0], types[1]) || ((0, _procedure_analysis_1.isReferenceType)(types[0]) && (0, _procedure_analysis_1.isReferenceType)(types[1])))) {
|
|
103815
|
+
continue;
|
|
103816
|
+
}
|
|
103817
|
+
return false;
|
|
103818
|
+
}
|
|
103819
|
+
else {
|
|
103820
|
+
return false;
|
|
103821
|
+
}
|
|
103822
|
+
}
|
|
103823
|
+
return true;
|
|
103824
|
+
}
|
|
103825
|
+
/** type of a private variable, a constant or a literal, which can be read without side effects */
|
|
103826
|
+
operandType(procedure, source) {
|
|
103827
|
+
if (source.getChildren().length !== 1 || source.countTokens() !== 1) {
|
|
103828
|
+
return undefined;
|
|
103829
|
+
}
|
|
103830
|
+
const constant = source.findDirectExpression(Expressions.Constant);
|
|
103831
|
+
if (constant !== undefined) {
|
|
103832
|
+
return (0, _procedure_analysis_1.literalType)(constant);
|
|
103833
|
+
}
|
|
103834
|
+
const field = (0, _procedure_analysis_1.singleField)(source);
|
|
103835
|
+
if (field === undefined || !this.privateField(procedure, field)) {
|
|
103836
|
+
return undefined;
|
|
103837
|
+
}
|
|
103838
|
+
return procedure.identifierAt(field).getType();
|
|
103839
|
+
}
|
|
103840
|
+
privateField(procedure, token) {
|
|
103841
|
+
const identifier = procedure.identifierAt(token);
|
|
103842
|
+
return (0, _procedure_analysis_1.isImmutable)(identifier) || procedure.private(identifier) !== undefined;
|
|
103843
|
+
}
|
|
103844
|
+
/** the variables read by the expression are not changed by the statement that reads the temporary,
|
|
103845
|
+
* except as the target of a move, which is written after its source is evaluated */
|
|
103846
|
+
notWrittenIn(procedure, source, statement) {
|
|
103847
|
+
var _a;
|
|
103848
|
+
const target = (_a = (0, _procedure_analysis_1.plainMove)(statement)) === null || _a === void 0 ? void 0 : _a.target;
|
|
103849
|
+
const inTarget = (token) => target !== undefined
|
|
103850
|
+
&& !token.getStart().isBefore(target.getFirstToken().getStart()) && !target.getLastToken().getStart().isBefore(token.getStart());
|
|
103851
|
+
for (const token of source.getTokens()) {
|
|
103852
|
+
const variable = procedure.variable(procedure.identifierAt(token));
|
|
103853
|
+
if ((variable === null || variable === void 0 ? void 0 : variable.occurrences.some(o => o.statement === statement && o.kind !== _procedure_analysis_1.OccurrenceKind.Read && !inTarget(o.token))) === true) {
|
|
103854
|
+
return false;
|
|
103855
|
+
}
|
|
103856
|
+
}
|
|
103857
|
+
return true;
|
|
103858
|
+
}
|
|
103859
|
+
/** nothing evaluated before the token in the statement can run other code, raise an exception or read data that
|
|
103860
|
+
* other code changes. The target of a move is evaluated after its source */
|
|
103861
|
+
evaluatedFirst(procedure, statement, token) {
|
|
103862
|
+
var _a, _b;
|
|
103863
|
+
const position = token.getStart();
|
|
103864
|
+
const before = (node) => node.getLastToken().getStart().isBefore(position);
|
|
103865
|
+
for (const type of [Expressions.MethodCall, Expressions.NewObject, Expressions.Cast, Expressions.TableExpression,
|
|
103866
|
+
Expressions.ArithOperator, Expressions.Dereference]) {
|
|
103867
|
+
if (statement.findAllExpressionsRecursive(type).some(before)) {
|
|
103868
|
+
return false;
|
|
103869
|
+
}
|
|
103870
|
+
}
|
|
103871
|
+
for (const source of statement.findAllExpressionsRecursive(Expressions.Source)) {
|
|
103872
|
+
const keyword = source.getFirstToken().getStr().toUpperCase();
|
|
103873
|
+
if (before(source) && CONSTRUCTORS.has(keyword) && source.findDirectExpression(Expressions.TypeNameOrInfer) !== undefined) {
|
|
103874
|
+
return false;
|
|
103875
|
+
}
|
|
103876
|
+
}
|
|
103877
|
+
// the target of a move or CREATE OBJECT is written after the source and the parameters are evaluated
|
|
103878
|
+
let target = (_a = (0, _procedure_analysis_1.plainMove)(statement)) === null || _a === void 0 ? void 0 : _a.target;
|
|
103879
|
+
if (statement.get() instanceof Statements.CreateObject) {
|
|
103880
|
+
target = statement.findDirectExpression(Expressions.Target);
|
|
103881
|
+
if ((target === null || target === void 0 ? void 0 : target.countTokens()) !== 1) {
|
|
103882
|
+
return false;
|
|
103883
|
+
}
|
|
103884
|
+
}
|
|
103885
|
+
const tokens = procedure.tokensOf(statement);
|
|
103886
|
+
for (let i = 0; i < tokens.length && tokens[i].getStart().isBefore(position); i++) {
|
|
103887
|
+
if (target !== undefined && !tokens[i].getStart().isBefore(target.getFirstToken().getStart())
|
|
103888
|
+
&& !target.getLastToken().getStart().isBefore(tokens[i].getStart())) {
|
|
103889
|
+
continue;
|
|
103890
|
+
}
|
|
103891
|
+
const references = procedure.analysis.referencesAt(procedure.file.getFilename(), tokens[i]);
|
|
103892
|
+
if (references.some(r => r.referenceType === _reference_1.ReferenceType.DataReadReference
|
|
103893
|
+
|| r.referenceType === _reference_1.ReferenceType.DataWriteReference)) {
|
|
103894
|
+
// a private variable or constant, and a reference only to call a method: v->m( ... token ... )
|
|
103895
|
+
if (!this.privateField(procedure, tokens[i])
|
|
103896
|
+
|| (((_b = tokens[i + 1]) === null || _b === void 0 ? void 0 : _b.getStr()) === "->"
|
|
103897
|
+
&& (tokens[i + 2] === undefined || procedure.methodAt(tokens[i + 2]) === undefined))) {
|
|
103898
|
+
return false;
|
|
103899
|
+
}
|
|
103900
|
+
}
|
|
103901
|
+
}
|
|
103902
|
+
return true;
|
|
103903
|
+
}
|
|
103904
|
+
/** the token is evaluated whenever the statement is: not in a branch of COND or SWITCH, not in an iteration of
|
|
103905
|
+
* VALUE, REDUCE or FILTER, and not after AND, OR or EQUIV */
|
|
103906
|
+
alwaysEvaluated(statement, token) {
|
|
103907
|
+
const position = token.getStart();
|
|
103908
|
+
for (const node of (0, _procedure_analysis_1.expressionPath)(statement, token)) {
|
|
103909
|
+
if (node.get() instanceof Expressions.Source) {
|
|
103910
|
+
const keyword = node.getFirstToken().getStr().toUpperCase();
|
|
103911
|
+
if (CONSTRUCTORS.has(keyword) && node.findDirectExpression(Expressions.TypeNameOrInfer) !== undefined) {
|
|
103912
|
+
return false;
|
|
103913
|
+
}
|
|
103914
|
+
}
|
|
103915
|
+
else if (node.get() instanceof Expressions.Cond) {
|
|
103916
|
+
for (const child of node.getChildren()) {
|
|
103917
|
+
const word = child.getFirstToken().getStr().toUpperCase();
|
|
103918
|
+
if (child instanceof nodes_1.TokenNode && child.getFirstToken().getStart().isBefore(position)
|
|
103919
|
+
&& (word === "AND" || word === "OR" || word === "EQUIV")) {
|
|
103920
|
+
return false;
|
|
103921
|
+
}
|
|
103922
|
+
}
|
|
103923
|
+
}
|
|
103924
|
+
else if (node.get() instanceof Expressions.For || node.get() instanceof Expressions.Let) {
|
|
103925
|
+
return false;
|
|
103926
|
+
}
|
|
103927
|
+
}
|
|
103928
|
+
return true;
|
|
103929
|
+
}
|
|
103930
|
+
/** the expression can be followed by -> */
|
|
103931
|
+
chainable(source) {
|
|
103932
|
+
const children = source.getChildren();
|
|
103933
|
+
return children.length === 1 && (children[0].get() instanceof Expressions.FieldChain
|
|
103934
|
+
|| children[0].get() instanceof Expressions.MethodCallChain);
|
|
103935
|
+
}
|
|
103936
|
+
typeMatches(procedure, temp, statement, placement) {
|
|
103937
|
+
const use = placement === Placement.Move ? (0, _procedure_analysis_1.plainMove)(statement) : undefined;
|
|
103938
|
+
if (use !== undefined && !this.noAliasing(procedure, temp.source, use.target)) {
|
|
103939
|
+
return false;
|
|
103940
|
+
}
|
|
103941
|
+
else if (!temp.typed) {
|
|
103942
|
+
// the variable has the type of the expression
|
|
103943
|
+
return true;
|
|
103944
|
+
}
|
|
103945
|
+
const type = temp.variable.identifier.getType();
|
|
103946
|
+
const independent = this.targetIndependent(procedure, temp.source);
|
|
103947
|
+
if (use === undefined) {
|
|
103948
|
+
return independent && this.sameType(procedure, temp, type);
|
|
103949
|
+
}
|
|
103950
|
+
const inline = use.target.findFirstExpression(Expressions.InlineData) !== undefined;
|
|
103951
|
+
if (independent) {
|
|
103952
|
+
if (this.sameType(procedure, temp, type)) {
|
|
103953
|
+
return true;
|
|
103954
|
+
}
|
|
103955
|
+
// an up cast into v, and v into y, is an up cast into y
|
|
103956
|
+
const expression = (0, _procedure_analysis_1.expressionType)(procedure, temp.source);
|
|
103957
|
+
const constructed = this.constructedType(temp.source);
|
|
103958
|
+
const reference = expression === undefined ? (constructed === null || constructed === void 0 ? void 0 : constructed.reference) === true && constructed.name !== "#"
|
|
103959
|
+
: (0, _procedure_analysis_1.isReferenceType)(expression);
|
|
103960
|
+
return inline === false && reference && (0, _procedure_analysis_1.isReferenceType)(type);
|
|
103961
|
+
}
|
|
103962
|
+
// the type of the expression follows the target
|
|
103963
|
+
const target = inline ? undefined : (0, _procedure_analysis_1.targetType)(procedure, use.target);
|
|
103964
|
+
return target !== undefined && (0, _procedure_analysis_1.identicalTypes)(target, type);
|
|
103965
|
+
}
|
|
103966
|
+
/** the expression has exactly the type of the declaration DATA v TYPE t. */
|
|
103967
|
+
sameType(procedure, temp, type) {
|
|
103968
|
+
const expression = (0, _procedure_analysis_1.expressionType)(procedure, temp.source);
|
|
103969
|
+
if (expression !== undefined) {
|
|
103970
|
+
return (0, _procedure_analysis_1.identicalTypes)(expression, type);
|
|
103971
|
+
}
|
|
103972
|
+
// constructor expressions with an explicit type, compared by the name of the type
|
|
103973
|
+
const declared = this.declaredType(temp.variable);
|
|
103974
|
+
const constructed = this.constructedType(temp.source);
|
|
103975
|
+
return declared !== undefined && constructed !== undefined && constructed.name !== "#"
|
|
103976
|
+
&& constructed.name === declared.name && constructed.reference === declared.reference;
|
|
103977
|
+
}
|
|
103978
|
+
/** the type name of DATA v TYPE t., DATA v TYPE REF TO t. or DATA(v) = VALUE t( ). */
|
|
103979
|
+
declaredType(variable) {
|
|
103980
|
+
var _a, _b;
|
|
103981
|
+
const declaration = variable.declaration;
|
|
103982
|
+
if ((0, _procedure_analysis_1.initialDeclaration)(variable) === _procedure_analysis_1.InitialDeclaration.Value) {
|
|
103983
|
+
return this.constructedType((0, _procedure_analysis_1.plainMove)(declaration).source);
|
|
103984
|
+
}
|
|
103985
|
+
const type = (_a = declaration.findDirectExpression(Expressions.DataDefinition)) === null || _a === void 0 ? void 0 : _a.findDirectExpression(Expressions.Type);
|
|
103986
|
+
const name = (_b = type === null || type === void 0 ? void 0 : type.findDirectExpression(Expressions.TypeName)) === null || _b === void 0 ? void 0 : _b.concatTokens().toUpperCase();
|
|
103987
|
+
const words = type === null || type === void 0 ? void 0 : type.getTokens().map(t => t.getStr().toUpperCase()).join(" ");
|
|
103988
|
+
if (name === undefined) {
|
|
103989
|
+
return undefined;
|
|
103990
|
+
}
|
|
103991
|
+
else if (words === "TYPE " + name) {
|
|
103992
|
+
return { name, reference: false };
|
|
103993
|
+
}
|
|
103994
|
+
else if (words === "TYPE REF TO " + name) {
|
|
103995
|
+
return { name, reference: true };
|
|
103996
|
+
}
|
|
103997
|
+
return undefined;
|
|
103998
|
+
}
|
|
103999
|
+
/** VALUE t( ... ), CONV t( ... ) etc., NEW c( ... ) and CAST c( ... ) with an explicit type */
|
|
104000
|
+
constructedType(source) {
|
|
104001
|
+
const children = source.getChildren();
|
|
104002
|
+
const last = children[children.length - 1];
|
|
104003
|
+
const keyword = source.getFirstToken().getStr().toUpperCase();
|
|
104004
|
+
let name;
|
|
104005
|
+
let reference = false;
|
|
104006
|
+
if (CONSTRUCTORS.has(keyword) && keyword !== "REF" && last instanceof nodes_1.TokenNode && last.getFirstToken().getStr() === ")") {
|
|
104007
|
+
name = source.findDirectExpression(Expressions.TypeNameOrInfer);
|
|
104008
|
+
}
|
|
104009
|
+
else if (children.length === 1 && children[0].get() instanceof Expressions.MethodCallChain
|
|
104010
|
+
&& children[0].getChildren().length === 1) {
|
|
104011
|
+
const constructor = children[0].getChildren()[0];
|
|
104012
|
+
if (constructor.get() instanceof Expressions.NewObject || constructor.get() instanceof Expressions.Cast) {
|
|
104013
|
+
name = constructor.findDirectExpression(Expressions.TypeNameOrInfer);
|
|
104014
|
+
reference = true;
|
|
104015
|
+
}
|
|
104016
|
+
}
|
|
104017
|
+
const text = name === null || name === void 0 ? void 0 : name.concatTokens().toUpperCase();
|
|
104018
|
+
return text === undefined ? undefined : { name: text, reference };
|
|
104019
|
+
}
|
|
102664
104020
|
/** the type of the expression does not depend on where it is assigned to */
|
|
102665
104021
|
targetIndependent(procedure, source) {
|
|
102666
|
-
var _a, _b;
|
|
104022
|
+
var _a, _b, _c;
|
|
102667
104023
|
const first = source.getFirstToken().getStr().toUpperCase();
|
|
102668
|
-
if (
|
|
104024
|
+
if (this.constant(source)) {
|
|
104025
|
+
return true;
|
|
104026
|
+
}
|
|
104027
|
+
else if (first === "CONV" || first === "EXACT"
|
|
102669
104028
|
|| ((_a = source.findDirectExpression(Expressions.TypeNameOrInfer)) === null || _a === void 0 ? void 0 : _a.concatTokens()) === "#"
|
|
104029
|
+
|| ((_b = this.constructedType(source)) === null || _b === void 0 ? void 0 : _b.name) === "#"
|
|
102670
104030
|
|| source.findFirstExpression(Expressions.ArithOperator) !== undefined
|
|
102671
104031
|
|| source.getTokens().some(t => t.getStr().toUpperCase().startsWith("BIT-"))
|
|
102672
104032
|
|| !this.concatenationOnly(source)) {
|
|
102673
104033
|
return false;
|
|
102674
104034
|
}
|
|
102675
104035
|
for (const call of source.findAllExpressionsRecursive(Expressions.MethodCall)) {
|
|
102676
|
-
const name = (
|
|
104036
|
+
const name = (_c = call.findDirectExpression(Expressions.MethodName)) === null || _c === void 0 ? void 0 : _c.getFirstToken();
|
|
102677
104037
|
if (name === undefined) {
|
|
102678
104038
|
return false;
|
|
102679
104039
|
}
|
|
102680
104040
|
const builtin = procedure.analysis.referencesAt(procedure.file.getFilename(), name)
|
|
102681
104041
|
.some(r => r.referenceType === _reference_1.ReferenceType.BuiltinMethodReference);
|
|
102682
|
-
if (builtin && NUMERIC_FUNCTIONS.has(name.getStr().toLowerCase())) {
|
|
104042
|
+
if (builtin && _procedure_analysis_1.NUMERIC_FUNCTIONS.has(name.getStr().toLowerCase())) {
|
|
102683
104043
|
return false;
|
|
102684
104044
|
}
|
|
102685
104045
|
}
|
|
@@ -105947,14 +107307,17 @@ class UnnecessaryCopy {
|
|
|
105947
107307
|
extendedInformation: `Reports DATA(a) = b. when all of the following hold:
|
|
105948
107308
|
|
|
105949
107309
|
* a is a local variable of a METHOD, FORM or FUNCTION, and has exactly one more reference: a read,
|
|
105950
|
-
which does not take its address, bind a field symbol to it, or pass it to USING
|
|
107310
|
+
which does not take its address, bind a field symbol to it, or pass it to USING or CHANGING
|
|
105951
107311
|
* b is a plain data object: variable, constant, attribute, or a chain of components and attributes,
|
|
105952
107312
|
without calls, offsets, table expressions, field symbols or ->*
|
|
105953
107313
|
* the declaration is executed before the read on every path: the read is in the block of the declaration
|
|
105954
107314
|
or a nested block, and both are in the same loop
|
|
105955
|
-
* b keeps its value from the declaration until the read: for a local b,
|
|
105956
|
-
|
|
105957
|
-
variables, by value parameters and RETURNING in
|
|
107315
|
+
* b keeps its value from the declaration until the read: for a local b, or a pass-by-value or RETURNING
|
|
107316
|
+
parameter b of a method or form, no write to it and its address is never taken; for other b, in addition no
|
|
107317
|
+
method, function or form call and no write except to local variables, by value parameters and RETURNING in
|
|
107318
|
+
between, and in the statement of the read no call before the read. A method called in that statement could
|
|
107319
|
+
change b while it reads the parameter that b is passed to by reference, so the read may only be the receiver
|
|
107320
|
+
of the call, or the actual parameter of a pass-by-value parameter of the only method called in the statement
|
|
105958
107321
|
|
|
105959
107322
|
a has the type of b, so reading b instead does not change any conversion.
|
|
105960
107323
|
A constant b read in IF, ELSEIF, WHILE, CHECK, CASE or WHEN is not reported, see constant_condition.
|