Skip to content
Snippets Groups Projects
Commit ee935cca authored by Johannes Mey's avatar Johannes Mey
Browse files

add type analysis for DataRef

parent 6a9042d2
No related branches found
No related tags found
No related merge requests found
aspect ExpressionHandling {
syn boolean Expr.isPrimary();
eq Expr.isPrimary() = false;
eq Primary.isPrimary() = true;
syn Primary Expr.primary();
eq Expr.primary() = null;
eq Primary.primary() = this;
syn boolean Expr.isFunctionReference();
eq Expr.isFunctionReference() = false;
eq FunctionReference.isFunctionReference() = true;
syn FunctionReference Expr.functionReference();
eq Expr.functionReference() = null;
eq FunctionReference.functionReference() = this;
}
\ No newline at end of file
aspect SlotTypes {
// ===============================================================================================
// Variable and Designator RESOLVING
// ===============================================================================================
// syn ASTNode Variable.declaration();
eq SlotVariable.declaration() = null;
// syn ASTNode Designator.declaration();
eq SlotDesignator.declaration() = null;
}
\ No newline at end of file
aspect Types {
// ===============================================================================================
// Variable and Designator RESOLVING
// ===============================================================================================
syn ASTNode Variable.declaration();
eq Designator_Variable.declaration() = getDesignator().declaration();
eq Expr_Variable.declaration() {
// C602 (R602) expr shall be a reference to a function that has a data pointer result.
// if (getExpr().isPrimary()) {
// if (getExpr().primary().isFunctionReference()) {
// return getExpr().primary().functionReference().getProcedureDesignator().getDataRef().lookup();
// }
// }
// this case cannot be solved easily. the data object returned by the function call has no fixed
// definition.
return null;
}
syn ASTNode Designator.declaration();
eq ObjectName_Designator.declaration() = getObjectName().declaration();
eq Substring_Designator.declaration() = getSubstring().getParentString().declaration();
eq ArrayElement_Designator.declaration() = getArrayElement().declaration();
eq ArraySection_Designator.declaration() = getArraySection().declaration();
syn ASTNode ObjectName.declaration() = getName().lookup();
syn ASTNode ParentString.declaration();
eq VariableNameParentString.declaration() = getVariableName().declaration();
eq ArrayElementParentString.declaration() = getArrayElement().declaration();
eq CoindexedNamedObjectParentString.declaration() = getCoindexedNamedObject().declaration();
eq StructureComponentParentString.declaration() = getStructureComponent().declaration();
eq ConstantParentString.declaration() = getConstant().declaration();
syn ASTNode VariableName.declaration() = getName().lookup();
syn ASTNode ArrayElement.declaration() = getDataRef().lookup();
syn ASTNode ArraySection.declaration() = getDataRef().lookup();
syn ASTNode CoindexedNamedObject.declaration() = getDataRef().lookup();
syn ASTNode StructureComponent.declaration() = getDataRef().lookup();
syn ASTNode Constant.declaration();
eq LiteralConstant.declaration() = null;
eq NamedConstant.declaration() = getName().lookup();
// ===============================================================================================
// DECLARATIONS
// ===============================================================================================
syn ASTNode Name.declaration();
eq Name.declaration() {
java.util.Set<ASTNode> decls = enclosingScope().localDeclarations();
syn ASTNode Name.lookup();
eq Name.lookup() {
ASTNode scope = this.enclosingScope();
while (scope != null) {
java.util.Set<ASTNode> decls = scope.localDeclarations();
for(ASTNode decl : decls) {
java.util.Set<Name> names = decl.declaredSimpleNames();
for (Name name : names) {
......@@ -17,9 +71,153 @@ aspect Types {
}
}
}
scope = scope.enclosingScope();
}
// TODO look into COMMON blocks
return null;
}
syn ASTNode DataRef.lookup() {
ASTNode dataObject;
// a DataRef has at least one PartRef. first, the first PartRef is resolved with a lookup that
// should return
// - a DerivedTypeDef if it is no the last PartRef if in DataRef
// - any type otherwise
// C609 (R611) Each part-name except the rightmost shall be of derived type.
// [defined type, i.e. lookup() returns DerivedTypeDef]
// those reference a derived type.
int index = 0;
DerivedTypeDef currentTypeDef = null;
// in the first PartRef, the name is the name of a variable that can be looked up normally.
ASTNode declaration = getPartRef(0).getName().lookup();
// if the first PartRef is the only one, we are done and just return the lookup result
if (getPartRefList().numChildren() == 1) {
} else {
// otherwise, we extract the name from the lookup result that, incidentally, is the name
// of a data component. We can do this as follows because we know it MUST be a derived
// type
Name dataComponentName = declaration.typeDeclarationStmt().derivedType().getName();
// now, for the "inner" PartRefs, we loop the following:
// * find the definition of the derived type
// * find the correct component (comparing with the PartRefs name)
// * find the name of next derived type
for (index = 1; index < getPartRefList().numChildren() - 1; index++) {
// * find the definition of the derived type
DerivedTypeDef derivedType = dataComponentName.lookupType();
// * find the correct component (comparing with the PartRefs name)
ComponentDecl componentDecl = null;
for (DataComponentDefStmt def : derivedType.dataComponentDefs()) {
// iterate over all names in the DataComponentDefStmts
for (ComponentDecl cDecl : def.getComponentDeclList()) {
if (cDecl.getName().getString().equals(getPartRef(index).getName().getString())) {
componentDecl = cDecl;
}
}
}
// * find the name of next derived type
dataComponentName = componentDecl.typeSpec().getDeclarationTypeSpec().derivedType().getName();
}
// now we have the name of the last type spec we need to investigate and only need to look
// up the final Component's type
DerivedTypeDef derivedType = dataComponentName.lookupType();
// * find the correct component (comparing with the PartRefs name)
ComponentDecl componentDecl = null;
for (DataComponentDefStmt def : derivedType.dataComponentDefs()) {
// iterate over all names in the DataComponentDefStmts
for (ComponentDecl cDecl : def.getComponentDeclList()) {
if (cDecl.getName().getString().equals(getPartRef(index).getName().getString())) {
componentDecl = cDecl;
}
}
}
return componentDecl.typeSpec();
}
return null;
}
inh DerivedTypeDef DataComponentDefStmt.containingTypeDef();
eq DerivedTypeDef.getComponentPart().containingTypeDef() = this;
coll java.util.Set<DataComponentDefStmt> DerivedTypeDef.dataComponentDefs() [new java.util.HashSet<DataComponentDefStmt>()] with add;
DataComponentDefStmt
contributes this
to DerivedTypeDef.dataComponentDefs()
for containingTypeDef();
// ===============================================================================================
// LOCAL TYPE DECLARATIONS
// ===============================================================================================
// collection attribute to collect all type declarations in the local scope
coll java.util.Set<DerivedTypeDef> ASTNode.localDerivedTypeDefs() [new java.util.HashSet<DerivedTypeDef>()] with add;
DerivedTypeDef contributes this
to ASTNode.localDerivedTypeDefs()
for enclosingScope();
syn DerivedTypeDef Name.lookupType();
eq Name.lookupType() {
ASTNode scope = this.enclosingScope();
while (scope != null) {
java.util.Set<DerivedTypeDef> decls = scope.localDerivedTypeDefs();
for(DerivedTypeDef decl : decls) {
Name name = decl.getDerivedTypeStmt().getTypeName();
if (name.getString().equals(this.getString())) {
return decl;
}
}
scope = scope.enclosingScope();
}
return null;
}
inh DataComponentDefStmt ComponentDecl.typeSpec();
eq DataComponentDefStmt.getComponentDecl(int i).typeSpec() = this;
// ===============================================================================================
// LOCAL DECLARATIONS WITH TYPES
// ===============================================================================================
syn boolean ASTNode.isTypeDeclaration();
eq ASTNode.isTypeDeclaration() = false;
eq TypeDeclarationStmt.isTypeDeclaration() = true;
syn TypeDeclarationStmt ASTNode.typeDeclarationStmt();
eq ASTNode.typeDeclarationStmt() = null;
eq TypeDeclarationStmt.typeDeclarationStmt() = this;
syn boolean TypeDeclarationStmt.isDerivedType();
eq TypeDeclarationStmt.isDerivedType() = getDeclarationTypeSpec().isDerivedType();
syn DerivedTypeSpec TypeDeclarationStmt.derivedType();
eq TypeDeclarationStmt.derivedType() = getDeclarationTypeSpec().derivedType();
syn boolean DeclarationTypeSpec.isDerivedType();
eq SimpleDeclarationTypeSpec.isDerivedType() = false;
eq TypeDeclarationTypeSpec.isDerivedType() = getTypeSpec().isDerivedType();
eq ClassDeclarationTypeSpec.isDerivedType() = hasDerivedTypeSpec();
syn DerivedTypeSpec DeclarationTypeSpec.derivedType();
eq SimpleDeclarationTypeSpec.derivedType() = null;
eq TypeDeclarationTypeSpec.derivedType() = getTypeSpec().derivedType();
eq ClassDeclarationTypeSpec.derivedType() = hasDerivedTypeSpec() ? getDerivedTypeSpec() : null;
syn boolean TypeSpec.isDerivedType();
eq TypeSpec.isDerivedType() = false;
eq DerivedTypeSpec.isDerivedType() = true;
syn DerivedTypeSpec TypeSpec.derivedType();
eq TypeSpec.derivedType() = null;
eq DerivedTypeSpec.derivedType() = this;
// ===============================================================================================
// LOCAL DECLARATIONS
// ===============================================================================================
......
real :: a(10)
a(2) = a(1)
TYPE FULLNAME
CHARACTER (LEN = 50) FIRST,LAST
END TYPE PERSON
TYPE PERSON
INTEGER AGE
TYPE (FULLNAME) NAME
END TYPE PERSON
TYPE (PERSON) :: CHAIRMAN
CHAIRMAN%NAME%FIRST = 10
CHAIRMAN%NAME = 10
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment