-
Notifications
You must be signed in to change notification settings - Fork 4
7.8.80: Neuer SysMLExpressionBasisTypeVisitor für NameExpressions #205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "Neuer-SysMLExpressionBasisTypeVisitor-f\u00FCr-NameExpressions"
Changes from all commits
0d15bf5
1265f52
e393e14
9ce20e9
566a5db
e672405
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,57 @@ | ||||||||
| package de.monticore.lang.sysmlv2.types3; | ||||||||
|
|
||||||||
| import de.monticore.expressions.expressionsbasis._ast.ASTNameExpression; | ||||||||
| import de.monticore.expressions.expressionsbasis.types3.ExpressionBasisTypeVisitor; | ||||||||
| import de.monticore.lang.sysmlv2._symboltable.ISysMLv2Scope; | ||||||||
| import de.monticore.symbols.basicsymbols._symboltable.IBasicSymbolsScope; | ||||||||
| import de.monticore.symbols.basicsymbols._symboltable.TypeSymbol; | ||||||||
| import de.monticore.types.check.SymTypeExpression; | ||||||||
| import de.monticore.types.check.SymTypeExpressionFactory; | ||||||||
| import de.monticore.types3.util.WithinScopeBasicSymbolsResolver; | ||||||||
| import de.se_rwth.commons.logging.Log; | ||||||||
|
|
||||||||
| import java.util.Optional; | ||||||||
|
|
||||||||
| /** | ||||||||
| * SysML-spezifische Erweiterung des Typechecks für NameExpressions, einer | ||||||||
| * Produktion aus der ExpressionBasis.mc4-Grammatik | ||||||||
| */ | ||||||||
| public class SysMLExpressionBasisTypeVisitor extends ExpressionBasisTypeVisitor { | ||||||||
|
|
||||||||
| @Override | ||||||||
| protected Optional<SymTypeExpression> calculateNameExpression(ASTNameExpression expr) { | ||||||||
|
|
||||||||
| if (expr.getEnclosingScope() == null) { | ||||||||
| Log.error("0x10AAA internal error: " | ||||||||
| + "enclosing scope of expression expected", | ||||||||
| expr.get_SourcePositionStart(), | ||||||||
| expr.get_SourcePositionEnd() | ||||||||
| ); | ||||||||
| return Optional.empty(); | ||||||||
| } | ||||||||
|
|
||||||||
| final String name = expr.getName(); | ||||||||
| IBasicSymbolsScope enclosingScope = getAsBasicSymbolsScope(expr.getEnclosingScope()); | ||||||||
|
|
||||||||
| Optional<SymTypeExpression> varResult = | ||||||||
| WithinScopeBasicSymbolsResolver.resolveNameAsExpr(enclosingScope, name); | ||||||||
|
|
||||||||
| if (varResult.isPresent()) { | ||||||||
| return varResult; | ||||||||
| } | ||||||||
|
|
||||||||
|
|
||||||||
| // Dieser If-Block wurde zum vordefinierten calculateNameExpression hinzugefügt | ||||||||
| if (enclosingScope instanceof ISysMLv2Scope) { | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wozu der Check und Cast auf ISysMLv2Scope, das vorhandene BasicSymbolsScope kann bereits nach Types resolven? |
||||||||
| Optional<TypeSymbol> typeSymbol = enclosingScope.resolveType(name); | ||||||||
|
|
||||||||
| if (typeSymbol.isPresent()) { | ||||||||
| return Optional.of( | ||||||||
| SymTypeExpressionFactory.createTypeObject(typeSymbol.get()) | ||||||||
| ); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| return Optional.empty(); | ||||||||
| } | ||||||||
| } | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package cocos; | ||
|
|
||
| import de.monticore.expressions.commonexpressions._ast.ASTFieldAccessExpression; | ||
| import de.monticore.expressions.commonexpressions._visitor.CommonExpressionsVisitor2; | ||
| import de.monticore.expressions.expressionsbasis._ast.ASTNameExpression; | ||
| import de.monticore.lang.sysmlconstraints._ast.ASTConstraintUsage; | ||
| import de.monticore.lang.sysmlv2.SysMLv2Mill; | ||
| import de.monticore.lang.sysmlv2.SysMLv2Tool; | ||
| import de.monticore.lang.sysmlv2._ast.ASTSysMLModel; | ||
| import de.monticore.types3.TypeCheck3; | ||
| import de.se_rwth.commons.logging.Finding; | ||
| import de.se_rwth.commons.logging.Log; | ||
| import de.se_rwth.commons.logging.LogStub; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Path; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class UsingCtrlEnumTypeCheckTest { | ||
|
|
||
| @BeforeEach | ||
| public void setup() { | ||
| LogStub.init(); | ||
| Log.enableFailQuick(false); | ||
| Log.clearFindings(); | ||
| SysMLv2Mill.reset(); | ||
| } | ||
|
|
||
| @Test | ||
| public void tryTypeCheckingCtrlEnumName() throws IOException { | ||
| SysMLv2Tool tool = new SysMLv2Tool(); | ||
| tool.init(); | ||
|
|
||
| var model = "enum def E { enum e; } constraint { E::e }"; | ||
| var ast = SysMLv2Mill.parser().parse_String(model).get(); | ||
|
|
||
| tool.createSymbolTable(ast); | ||
| tool.completeSymbolTable(ast); | ||
| tool.finalizeSymbolTable(ast); | ||
|
|
||
| // extrahiere das "E" aus "enum def ...; constraint { E::e }" im Model | ||
| var expr = ((ASTConstraintUsage) ast.getSysMLElement(1)).getExpression(); | ||
| var E = ((ASTFieldAccessExpression)expr).getExpression(); | ||
|
|
||
| var type = TypeCheck3.typeOf(E); | ||
|
|
||
| assertThat(type.isObscureType()).isFalse(); | ||
| assertThat(type.hasTypeInfo()).isTrue(); | ||
| assertThat(type.getTypeInfo().getFullName()).isEqualTo("E"); | ||
|
|
||
| assertThat(Log.getFindings()) | ||
| .filteredOn(Finding::isError) | ||
| .isEmpty(); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.