Skip to content

Commit

Permalink
Moves a global list from GamlSyntacticConverter to ISymbolKind
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Feb 19, 2022
1 parent 847443e commit 40010c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Expand Up @@ -58,7 +58,6 @@
import static msi.gama.common.interfaces.IKeyword.WITH;
import static msi.gama.common.interfaces.IKeyword.ZERO;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -129,14 +128,14 @@
*/
public class GamlSyntacticConverter {

/** The Constant builder. */
/** The builder of proto-expressions (not yet compiled). */
final static ExpressionDescriptionBuilder builder = new ExpressionDescriptionBuilder();

/** The synthetic action. */
private static int SYNTHETIC_ACTION = 0;

/**
* Gets the absolute container folder path of.
* Gets the absolute folder path of the resource passed in arguments. Used to get the path to the model files
*
* @param r
* the r
Expand All @@ -158,15 +157,11 @@ public static String getAbsoluteContainerFolderPathOf(final Resource r) {

}

/** The Constant STATEMENTS_WITH_ATTRIBUTES. */
static final List<Integer> STATEMENTS_WITH_ATTRIBUTES =
Arrays.asList(ISymbolKind.SPECIES, ISymbolKind.EXPERIMENT, ISymbolKind.OUTPUT, ISymbolKind.MODEL);

/**
* Builds the syntactic contents.
* Builds the syntactic contents of the root object passed to it.
*
* @param root
* the root
* the root : either a standalone block, an experiment file or a model
* @param errors
* the errors
* @return the i syntactic element
Expand All @@ -191,8 +186,8 @@ public ISyntacticElement buildSyntacticContents(final EObject root, final Set<Di
final List<String> prgm = collectPragmas(m);

final String path = getAbsoluteContainerFolderPathOf(root.eResource());
final SyntacticModelElement model = (SyntacticModelElement) SyntacticFactory.create(MODEL, m,
EGaml.getInstance().hasChildren(m), path/* , imps */);
final SyntacticModelElement model =
(SyntacticModelElement) SyntacticFactory.create(MODEL, m, EGaml.getInstance().hasChildren(m), path);
if (prgm != null) { model.setFacet(IKeyword.PRAGMA, ConstantExpressionDescription.create(prgm)); }
model.setFacet(NAME, convertToLabel(null, m.getName()));
convStatements(model, EGaml.getInstance().getStatementsOf(m), errors);
Expand Down Expand Up @@ -232,7 +227,7 @@ private boolean doesNotDefineAttributes(final String keyword) {
final SymbolProto p = DescriptionFactory.getProto(keyword, null);
if (p == null) return true;
final int kind = p.getKind();
return !STATEMENTS_WITH_ATTRIBUTES.contains(kind);
return !ISymbolKind.STATEMENTS_CONTAINING_ATTRIBUTES.contains(kind);
}

/**
Expand All @@ -254,8 +249,9 @@ private final ISyntacticElement convStatement(final ISyntacticElement upper, fin
"Trying to convert a statement with a null keyword. Please debug to understand the cause.");
keyword = convertKeyword(keyword, upper.getKeyword());

final boolean upperContainsAttributes = !doesNotDefineAttributes(upper.getKeyword());
final boolean isVar = stm instanceof S_Definition && !DescriptionFactory.isStatementProto(keyword)
&& !doesNotDefineAttributes(upper.getKeyword()) && !EGaml.getInstance().hasChildren(stm);
&& upperContainsAttributes && !EGaml.getInstance().hasChildren(stm);

final ISyntacticElement elt = isVar ? SyntacticFactory.createVar(keyword, ((S_Definition) stm).getName(), stm)
: SyntacticFactory.create(keyword, stm, EGaml.getInstance().hasChildren(stm));
Expand All @@ -266,7 +262,7 @@ private final ISyntacticElement convStatement(final ISyntacticElement upper, fin
// If we define a variable with this statement
final TypeRef t = (TypeRef) def.getTkey();
if (t != null) { addFacet(elt, TYPE, convExpr(t, errors), errors); }
if (t != null && doesNotDefineAttributes(upper.getKeyword())) {
if (t != null && !upperContainsAttributes) {
// Translation of "type var ..." to "let var type: type ..." if
// we are not in a
// top-level statement (i.e. not in the declaration of a species
Expand Down Expand Up @@ -764,7 +760,6 @@ private final IExpressionDescription findExpr(final Statement stm, final Set<Dia
*/
private final IExpressionDescription findExpr(final HeadlessExperiment stm, final Set<Diagnostic> errors) {
if (stm == null) return null;
// The order below should be important
return convertToLabel(stm, EGaml.getInstance().getNameOf(stm));

}
Expand Down
@@ -1,12 +1,12 @@
/*******************************************************************************************************
*
* ISymbolKind.java, in ummisco.gama.annotations, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
* ISymbolKind.java, in ummisco.gama.annotations, is part of the source code of the GAMA modeling and simulation
* platform (v.1.8.2).
*
* (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
*
********************************************************************************************************/
package msi.gama.precompiler;

Expand Down Expand Up @@ -103,12 +103,15 @@ public interface Variable {
/** The platform. */
int PLATFORM = 16;

/** The number. */
/** The number. */
// Update this variable when adding a kind of symbol
int __NUMBER__ = 17;

/** The template menu. */
String[] TEMPLATE_MENU = { "Species", "Model", "Statement", "Behavior", "Parameter", "Output", "Layer", "Skill",
"Batch", "Batch", "", "Statement", "Statement", "Experiment", "", "Operator", "" };

/** The Constant STATEMENTS_WITH_ATTRIBUTES. */
Set<Integer> STATEMENTS_CONTAINING_ATTRIBUTES = new HashSet<>(Arrays.asList(SPECIES, EXPERIMENT, OUTPUT, MODEL));

}

0 comments on commit 40010c8

Please sign in to comment.