-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Value Object constructor evaluation (#464)
- Loading branch information
1 parent
a042a65
commit 03f3ea8
Showing
17 changed files
with
309 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...st/core/BitloopsVisitor/helpers/expression/evaluation/valueObejctConstructorEvaluation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Bitloops Language CLI | ||
* Copyright (C) 2022 Bitloops S.A. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* For further information you can contact legal(at)bitloops.com. | ||
*/ | ||
|
||
import BitloopsVisitor from '../../../BitloopsVisitor.js'; | ||
import BitloopsParser from '../../../../../../parser/core/grammar/BitloopsParser.js'; | ||
import { produceMetadata } from '../../../metadata.js'; | ||
import { DomainEvaluationNodeBuilder } from '../../../../intermediate-ast/builders/expressions/evaluation/DomainEvaluation/DomainEvaluationNodeBuilder.js'; | ||
import { ValueObjectConstructorEvaluationNode } from '../../../../intermediate-ast/nodes/Expression/Evaluation/ValueObjectConstructorEvaluationNode.js'; | ||
import { ValueObjectConstructorEvaluationNodeBuilder } from '../../../../intermediate-ast/builders/expressions/evaluation/ValueObjectConstructorEvaluationNodeBuilder.js'; | ||
|
||
export const valueObjectConstructorEvaluationVisitor = ( | ||
thisVisitor: BitloopsVisitor, | ||
ctx: BitloopsParser.ValueObjectConstructorEvaluationContext, | ||
): ValueObjectConstructorEvaluationNode => { | ||
const props = thisVisitor.visit(ctx.domainEvaluationInput()); | ||
const valueObjectIdentifier = thisVisitor.visit(ctx.valueObjectIdentifier()); | ||
|
||
const metadata = produceMetadata(ctx, thisVisitor); | ||
const domainEvaluation = new DomainEvaluationNodeBuilder(metadata) | ||
.withIdentifier(valueObjectIdentifier) | ||
.withProps(props) | ||
.build(); | ||
|
||
const node = new ValueObjectConstructorEvaluationNodeBuilder(metadata) | ||
.withEvaluation(domainEvaluation) | ||
.build(); | ||
return node; | ||
}; |
49 changes: 49 additions & 0 deletions
49
...ediate-ast/builders/expressions/evaluation/ValueObjectConstructorEvaluationNodeBuilder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Bitloops Language CLI | ||
* Copyright (C) 2022 Bitloops S.A. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* For further information you can contact legal(at)bitloops.com. | ||
*/ | ||
import { DomainEvaluationNode } from '../../../nodes/Expression/Evaluation/DomainEvaluation/DomainEvaluation.js'; | ||
import { ValueObjectConstructorEvaluationNode } from '../../../nodes/Expression/Evaluation/ValueObjectConstructorEvaluationNode.js'; | ||
import { TNodeMetadata } from '../../../nodes/IntermediateASTNode.js'; | ||
import { IBuilder } from '../../IBuilder.js'; | ||
|
||
export class ValueObjectConstructorEvaluationNodeBuilder | ||
implements IBuilder<ValueObjectConstructorEvaluationNode> | ||
{ | ||
private valueObjectConstructorEvaluationNode: ValueObjectConstructorEvaluationNode; | ||
private evaluation: DomainEvaluationNode; | ||
|
||
constructor(metadata?: TNodeMetadata) { | ||
this.valueObjectConstructorEvaluationNode = new ValueObjectConstructorEvaluationNode(metadata); | ||
} | ||
|
||
public withEvaluation( | ||
evaluation: DomainEvaluationNode, | ||
): ValueObjectConstructorEvaluationNodeBuilder { | ||
this.evaluation = evaluation; | ||
return this; | ||
} | ||
|
||
public build(): ValueObjectConstructorEvaluationNode { | ||
this.valueObjectConstructorEvaluationNode.addChild(this.evaluation); | ||
|
||
this.valueObjectConstructorEvaluationNode.buildObjectValue(); | ||
|
||
return this.valueObjectConstructorEvaluationNode; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...core/intermediate-ast/nodes/Expression/Evaluation/ValueObjectConstructorEvaluationNode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* Bitloops Language CLI | ||
* Copyright (C) 2022 Bitloops S.A. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* For further information you can contact legal(at)bitloops.com. | ||
*/ | ||
import { BitloopsTypesMapping } from '../../../../../../helpers/mappings.js'; | ||
import { TNodeMetadata } from '../../IntermediateASTNode.js'; | ||
import { ValueObjectIdentifierNode } from '../../valueObject/ValueObjectIdentifierNode.js'; | ||
import { DomainEvaluationNode } from './DomainEvaluation/DomainEvaluation.js'; | ||
import { EvaluationNode } from './EvaluationNode.js'; | ||
|
||
export class ValueObjectConstructorEvaluationNode extends EvaluationNode { | ||
private static nodeName = 'valueObjectConstructor'; | ||
|
||
constructor(metadata?: TNodeMetadata) { | ||
super(metadata); | ||
this.nodeType = BitloopsTypesMapping.TValueObjectConstructorEvaluation; | ||
this.classNodeName = ValueObjectConstructorEvaluationNode.nodeName; | ||
} | ||
public override getIdentifierNode(): ValueObjectIdentifierNode { | ||
const domainEvaluationNode = this.getChildNodeByType<DomainEvaluationNode>( | ||
BitloopsTypesMapping.TDomainEvaluation, | ||
); | ||
const identifier = domainEvaluationNode.getChildren().find((child) => { | ||
return child.getNodeType() === BitloopsTypesMapping.TValueObjectIdentifier; | ||
}) as ValueObjectIdentifierNode; | ||
return identifier; | ||
} | ||
|
||
public getInferredType(): string { | ||
const valueObjectEvaluationIdentifier = | ||
this.getIdentifierNode().getValue().valueObjectIdentifier; | ||
return valueObjectEvaluationIdentifier; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...nest/core/components/statements/expression/evaluation/valueObjectConstructorEvaluation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Bitloops Language | ||
* Copyright (C) 2022 Bitloops S.A. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
* | ||
* For further information you can contact legal(at)bitloops.com. | ||
*/ | ||
|
||
import { | ||
TDomainEvaluation, | ||
TValueObjectConstructorEvaluation, | ||
TTargetDependenciesTypeScript, | ||
} from '../../../../../../../types.js'; | ||
import { BitloopsTypesMapping } from '../../../../../../../helpers/mappings.js'; | ||
import { modelToTargetLanguage } from '../../../../modelToTargetLanguage.js'; | ||
import { DomainEvaluationPropsTypeIdentifiers } from '../../../../type-identifiers/domainEvaluationProps.js'; | ||
import { getDomainName } from './entityConstructorEvaluation.js'; | ||
|
||
export const valueObjectConstructorEvaluationToTargetLanguage = ( | ||
evaluation: TValueObjectConstructorEvaluation, | ||
): TTargetDependenciesTypeScript => { | ||
const valueObjectEvaluation = evaluation.valueObjectConstructor; | ||
|
||
const result = domainEvaluationToTargetLanguage(valueObjectEvaluation); | ||
|
||
return result; | ||
}; | ||
|
||
export const domainEvaluationToTargetLanguage = ( | ||
evaluation: TDomainEvaluation, | ||
): TTargetDependenciesTypeScript => { | ||
const domainProperties = evaluation.domainEvaluation.props; | ||
|
||
let resultDomainProps: TTargetDependenciesTypeScript; | ||
if (DomainEvaluationPropsTypeIdentifiers.isExpression(domainProperties)) { | ||
resultDomainProps = modelToTargetLanguage({ | ||
type: BitloopsTypesMapping.TExpression, | ||
value: domainProperties, | ||
}); | ||
} else { | ||
resultDomainProps = modelToTargetLanguage({ | ||
type: BitloopsTypesMapping.TEvaluationFields, | ||
value: domainProperties.fields, | ||
}); | ||
} | ||
|
||
const dependencies = [...resultDomainProps.dependencies]; | ||
const domainName = getDomainName(evaluation); | ||
|
||
return { | ||
output: `new ${domainName}(${resultDomainProps.output})`, | ||
dependencies, | ||
}; | ||
}; |
Oops, something went wrong.