/*******************************************************************************
- * Copyright (c) 2011-2012 Ericsson, Ecole Polytechnique de Montreal and others
+ * Copyright (c) 2011, 2014 Ericsson, Ecole Polytechnique de Montreal and others
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0 which
// Attributes
// ------------------------------------------------------------------------
- private DeclarationScope parentScope = null;
+ private DeclarationScope fParentScope = null;
- private final Map<String, StructDeclaration> structs = new HashMap<>();
- private final Map<String, EnumDeclaration> enums = new HashMap<>();
- private final Map<String, VariantDeclaration> variants = new HashMap<>();
- private final Map<String, IDeclaration> types = new HashMap<>();
- private final Map<String, IDeclaration> identifiers = new HashMap<>();
+ private final Map<String, StructDeclaration> fStructs = new HashMap<>();
+ private final Map<String, EnumDeclaration> fEnums = new HashMap<>();
+ private final Map<String, VariantDeclaration> fVariants = new HashMap<>();
+ private final Map<String, IDeclaration> fTypes = new HashMap<>();
+ private final Map<String, IDeclaration> fIdentifiers = new HashMap<>();
// ------------------------------------------------------------------------
// Constructors
* The parent of the newly created scope.
*/
public DeclarationScope(DeclarationScope parentScope) {
- this.parentScope = parentScope;
+ fParentScope = parentScope;
}
// ------------------------------------------------------------------------
* @return The parent scope.
*/
public DeclarationScope getParentScope() {
- return parentScope;
+ return fParentScope;
}
// ------------------------------------------------------------------------
public void registerType(String name, IDeclaration declaration)
throws ParseException {
/* Check if the type has been defined in the current scope */
- if (types.containsKey(name)) {
+ if (fTypes.containsKey(name)) {
throw new ParseException("Type has already been defined:" + name); //$NON-NLS-1$
}
/* Add it to the register. */
- types.put(name, declaration);
+ fTypes.put(name, declaration);
}
/**
*/
public void registerIdentifier(String name, IDeclaration declaration) throws ParseException {
/* Check if the type has been defined in the current scope */
- if (identifiers.containsKey(name)) {
+ if (fIdentifiers.containsKey(name)) {
throw new ParseException("Identifier has already been defined:" + name); //$NON-NLS-1$
}
/* Add it to the register. */
- identifiers.put(name, declaration);
+ fIdentifiers.put(name, declaration);
}
/**
public void registerStruct(String name, StructDeclaration declaration)
throws ParseException {
/* Check if the struct has been defined in the current scope. */
- if (structs.containsKey(name)) {
+ if (fStructs.containsKey(name)) {
throw new ParseException("Struct has already been defined:" + name); //$NON-NLS-1$
}
/* Add it to the register. */
- structs.put(name, declaration);
+ fStructs.put(name, declaration);
/* It also defined a new type, so add it to the type declarations. */
String structPrefix = "struct "; //$NON-NLS-1$
}
/* Add it to the register. */
- enums.put(name, declaration);
+ fEnums.put(name, declaration);
/* It also defined a new type, so add it to the type declarations. */
String enumPrefix = "enum "; //$NON-NLS-1$
}
/* Add it to the register. */
- variants.put(name, declaration);
+ fVariants.put(name, declaration);
/* It also defined a new type, so add it to the type declarations. */
String variantPrefix = "variant "; //$NON-NLS-1$
* defined.
*/
public IDeclaration lookupType(String name) {
- return types.get(name);
+ return fTypes.get(name);
}
/**
IDeclaration declaration = lookupType(name);
if (declaration != null) {
return declaration;
- } else if (parentScope != null) {
- return parentScope.lookupTypeRecursive(name);
+ } else if (fParentScope != null) {
+ return fParentScope.lookupTypeRecursive(name);
} else {
return null;
}
* been defined.
*/
public StructDeclaration lookupStruct(String name) {
- return structs.get(name);
+ return fStructs.get(name);
}
/**
StructDeclaration declaration = lookupStruct(name);
if (declaration != null) {
return declaration;
- } else if (parentScope != null) {
- return parentScope.lookupStructRecursive(name);
+ } else if (fParentScope != null) {
+ return fParentScope.lookupStructRecursive(name);
} else {
return null;
}
* defined.
*/
public EnumDeclaration lookupEnum(String name) {
- return enums.get(name);
+ return fEnums.get(name);
}
/**
EnumDeclaration declaration = lookupEnum(name);
if (declaration != null) {
return declaration;
- } else if (parentScope != null) {
- return parentScope.lookupEnumRecursive(name);
+ } else if (fParentScope != null) {
+ return fParentScope.lookupEnumRecursive(name);
} else {
return null;
}
* been defined.
*/
public VariantDeclaration lookupVariant(String name) {
- return variants.get(name);
+ return fVariants.get(name);
}
/**
VariantDeclaration declaration = lookupVariant(name);
if (declaration != null) {
return declaration;
- } else if (parentScope != null) {
- return parentScope.lookupVariantRecursive(name);
+ } else if (fParentScope != null) {
+ return fParentScope.lookupVariantRecursive(name);
} else {
return null;
}
* @return the declaration of the type associated to that identifier
*/
public IDeclaration lookupIdentifier(String identifier) {
- return identifiers.get(identifier);
+ return fIdentifiers.get(identifier);
}
/**
IDeclaration declaration = lookupIdentifier(identifier);
if (declaration != null) {
return declaration;
- } else if (parentScope != null) {
- return parentScope.lookupIdentifierRecursive(identifier);
+ } else if (fParentScope != null) {
+ return fParentScope.lookupIdentifierRecursive(identifier);
}
return null;
}
* @return The type names
*/
public Set<String> getTypeNames() {
- return types.keySet();
+ return fTypes.keySet();
}
/**
* If the type does not exist.
*/
public void replaceType(String name, IDeclaration newType) throws ParseException {
- if (types.containsKey(name)) {
- types.put(name, newType);
+ if (fTypes.containsKey(name)) {
+ fTypes.put(name, newType);
} else {
throw new ParseException("Trace does not contain type:" + name); //$NON-NLS-1$
}