Commit c2a879f0 authored by Miklos Magyari's avatar Miklos Magyari
Browse files

OOP: improved handling of implicit constructors


Signed-off-by: Miklos Magyari's avatarMiklos Magyari <miklos.magyari@sigmatechnology.se>
parent 1268f8d7
......@@ -1200,9 +1200,11 @@ public final class Def_Function extends Definition implements IParameterisedAssi
}
if (returnType != null) {
if (! (identifier.getName().equals("create") && returnType instanceof Class_Type)) {
returnType.updateSyntax(reparser, false);
reparser.updateLocation(returnType.getLocation());
}
}
if (block != null) {
block.updateSyntax(reparser, false);
......
......@@ -137,9 +137,21 @@ public class FormalParameterList extends TTCN3Scope implements ILocateableNode,
*/
public void addFormalParameterList(FormalParameterList addList) {
for (int i = 0; i < addList.getNofParameters(); i++) {
parameters.add(addList.getParameterByIndex(i));
final FormalParameter fp = addList.getParameterByIndex(i);
if (! isExistingFormalParameter(parameters, fp)) {
parameters.add(fp);
}
}
}
private boolean isExistingFormalParameter(List<FormalParameter> list, FormalParameter fp) {
for (final FormalParameter param : list) {
if (param.getFullName().equals(fp.getFullName())) {
return true;
}
}
return false;
}
@Override
/** {@inheritDoc} */
......
......@@ -262,9 +262,6 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
for (final ClassTypeBody body : bodies) {
final Map<String, Definition> subDefinitionMap = body.getDefinitionMap();
for (final Definition definition : subDefinitionMap.values()) {
if (getOwnDefinitions().contains(definition)) {
continue;
}
final String name = definition.getIdentifier().getName();
if (definitions.hasDefinition(name)) {
final Definition localDefinition = definitions.getDefinition(name);
......@@ -530,7 +527,16 @@ public final class ClassTypeBody extends TTCN3Scope implements IReferenceChainEl
* checks whether the class has an explicit constructor
* @return
*/
public boolean hasConstructor() {
public boolean hasExplicitConstructor() {
return hasExplicitContructor;
}
public boolean hasConstructor() {
for (Definition def : getOwnDefinitions()) {
if (def instanceof Def_Function && def.getIdentifier().getName().equals("create")) {
return true;
}
}
return false;
}
}
\ No newline at end of file
......@@ -302,11 +302,19 @@ public final class ClassTypeReferenceList extends ASTNode implements ILocateable
}
@Override
public void updateSyntax(TTCN3ReparseUpdater reparser, boolean isDamaged) throws ReParseException {
// TODO Auto-generated method stub
/** {@inheritDoc} */
public void updateSyntax(final TTCN3ReparseUpdater reparser, final boolean isDamaged) throws ReParseException {
if (isDamaged) {
throw new ReParseException();
}
for (final Reference reference : classReferences) {
reference.updateSyntax(reparser, false);
reparser.updateLocation(reference.getLocation());
}
}
@Override
protected boolean memberAccept(ASTVisitor v) {
// TODO Auto-generated method stub
......
......@@ -89,11 +89,6 @@ public final class Class_Type extends Type implements ITypeWithComponents {
private Component_Type mtcType;
private Component_Type systemType;
/** Indicates if the class has an explicitly declared constructor
* If not, an implicit default constructor should be generated
*/
private boolean hasExplicitContructor = false;
public Class_Type(ClassTypeBody classBody, boolean isAbstract, boolean isFinal, boolean isTrait, boolean isExternal,
Location modifierLocation, final Reference runsOnRef, final Reference mtcRef, final Reference systemRef,
ClassTypeReferenceList refs, StatementBlock finallyBlock) {
......@@ -296,8 +291,8 @@ public final class Class_Type extends Type implements ITypeWithComponents {
initAttributes(timestamp);
if (classBody != null) {
if (classBody.hasConstructor() == true) {
hasExplicitContructor = true;
if (classBody.hasExplicitConstructor() == true || classBody.hasConstructor()) {
// hasContructor = true;
} else {
// add default implicit constructor
final List<FormalParameter> fpList = new ArrayList<FormalParameter>();
......@@ -329,8 +324,10 @@ public final class Class_Type extends Type implements ITypeWithComponents {
}
if (def instanceof Def_Var) {
defval = ((Def_Var) def).getInitialValue();
if (defval != null) {
template = new SpecificValue_Template(defval);
}
}
TemplateInstance instance = null;
if (template != null) {
instance = new TemplateInstance(null, null, template);
......@@ -573,14 +570,6 @@ public final class Class_Type extends Type implements ITypeWithComponents {
return false;
}
/** checks whether the class has an explicit constructor
*
* @return
*/
public boolean hasExplicitConstructor() {
return hasExplicitContructor;
}
private FormalParameterList getConstructorFormalParameterList() {
if (classBody == null) {
return null;
......
......@@ -277,8 +277,10 @@ public class UndefCreateExpression extends Expression_Value {
final ActualParameterList tempActualParameters = new ActualParameterList();
final Assignment constructorAssignment = classInstance.getClassBody().getAssByIdentifier(timestamp, new Identifier(Identifier_type.ID_TTCN, "create"));
if (constructorAssignment != null) {
FormalParameterList fpList = ((Def_Function)constructorAssignment).getFormalParameterList();
fpList.checkActualParameterList(timestamp, parameters, tempActualParameters);
}
// FIXME : implement
}
}
......
......@@ -9244,7 +9244,10 @@ pr_ClassTypeDef returns[Def_Type def_type]
modifierLocation = getLocation( $cm.start, $cm.stop );
}
i = pr_Identifier
ecd = pr_ExtendsClassDef { refs = $ecd.refList; }
ecd = pr_ExtendsClassDef {
refs = $ecd.refList;
refs.setLocation(getLocation( $ecd.start, $ecd.stop ));
}
(runson = pr_RunsOnSpec[runsonHelper] {
if (runsonHelper.runsonReference != null) {
runsonHelper.runsonReference.setLocation(getLocation($runson.start, $runson.stop));
......
......@@ -179,7 +179,7 @@ public class OOP_Semantic_tests {
private ArrayList<MarkerToCheck> oopNegative_ttcn_initializer() {
//oopNegativeSemanticTest.ttcn
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(101);
ArrayList<MarkerToCheck> markersToCheck = new ArrayList<MarkerToCheck>(102);
int lineNum = 33;
markersToCheck.add(new MarkerToCheck("class type expected", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 10;
......@@ -352,10 +352,11 @@ public class OOP_Semantic_tests {
markersToCheck.add(new MarkerToCheck("Private member is inaccessible due to its protection level", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 2;
markersToCheck.add(new MarkerToCheck("Character string value was expected", lineNum, IMarker.SEVERITY_ERROR));
markersToCheck.add(new MarkerToCheck("Too few parameters: 12 was expected instead of 10", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 3;
markersToCheck.add(new MarkerToCheck("Cannot assign a value to a property without a setter", lineNum, IMarker.SEVERITY_ERROR));
lineNum += 3;
markersToCheck.add(new MarkerToCheck("Too few parameters: at least 4 was expected instaed of 3", lineNum, IMarker.SEVERITY_ERROR));
markersToCheck.add(new MarkerToCheck("Too few parameters: 5 was expected instead of 3", lineNum, IMarker.SEVERITY_ERROR));
markersToCheck.add(new MarkerToCheck("float value was expected", ++lineNum, IMarker.SEVERITY_ERROR));
return markersToCheck;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment