use of org.abs_models.frontend.ast.FieldDecl in project abstools by abstools.
the class FinalAnnotationTypeExtension method checkAssignStmt.
@Override
public void checkAssignStmt(AssignStmt s) {
VarOrFieldDecl decl = s.getVar().getDecl();
if (decl instanceof TypedVarOrFieldDecl) {
TypedVarOrFieldDecl d = (TypedVarOrFieldDecl) decl;
// Not sure if this code will encounter delta bodies:
if (d.isFinal()) {
String name = d.getName();
boolean isField = (d instanceof FieldDecl);
String kind = isField ? "field" : "variable";
add(new TypeError(s, ErrorMessage.ASSIGN_TO_FINAL, kind, name));
}
} else {
// It's a PatternVarDecl. Assume these are never final.
}
}
use of org.abs_models.frontend.ast.FieldDecl in project abstools by abstools.
the class SchedulerChecker method checkScheduleExp.
private void checkScheduleExp(PureExp sched, ClassDecl class_decl, ASTNode<?> loc) {
if (sched == null)
return;
if (!(sched instanceof FnApp)) {
errors.add(new TypeError(loc, ErrorMessage.WRONG_SCHEDULER_ANNOTATION_TYPE, sched.getType()));
return;
}
FnApp s = (FnApp) sched;
Type scheduler_type = s.getType();
if (s.getDecl().isUnknown()) {
errors.add(new TypeError(loc, ErrorMessage.FUNCTION_NOT_RESOLVABLE, s.getName()));
return;
}
FunctionDecl sd = (FunctionDecl) s.getDecl();
// check scheduling function return type
boolean schedulerTypeCorrect = scheduler_type.isDataType() && ((DataTypeType) scheduler_type).getQualifiedName().equals("ABS.Scheduler.Process");
// check scheduling function first arg, pt.1: are we a list?
boolean schedulerFunFirstArgCorrect = sd.getNumParam() > 0 && sd.getParam(0).getType().getQualifiedName().equals("ABS.StdLib.List");
if (schedulerFunFirstArgCorrect) {
// check scheduling function first arg, pt.2: are we a list of
// processes?
DataTypeType firstArgType = (DataTypeType) sd.getParam(0).getType();
if (firstArgType.numTypeArgs() != 1) {
// should not happen since ABS.StdLib.List takes 1 argument
schedulerFunFirstArgCorrect = false;
} else {
schedulerFunFirstArgCorrect = firstArgType.getTypeArg(0).getQualifiedName().equals("ABS.Scheduler.Process");
}
}
if (!schedulerTypeCorrect || !schedulerFunFirstArgCorrect) {
// emit two messages: one at the annotation location, one for the
// offending scheduler function
errors.add(new TypeError(loc, ErrorMessage.WRONG_SCHEDULER_ANNOTATION_TYPE, "dummy"));
errors.add(new TypeError(sd, ErrorMessage.WRONG_SCHEDULER_FUN_TYPE, s.getName()));
}
if (s.getNumParam() == 0 || !(s.getParam(0) instanceof VarUse) || !((VarUse) s.getParam(0)).getName().equals("queue")) {
// first arg to the scheduler expression must be the magic `queue'
errors.add(new TypeError(loc, ErrorMessage.WRONG_SCHEDULER_FIRST_ARGUMENT, "dummy"));
}
if (s.getNumParam() != sd.getNumParam()) {
errors.add(new TypeError(loc, ErrorMessage.WRONG_NUMBER_OF_ARGS, s.getNumParam(), sd.getNumParam()));
} else {
// start from 1; magic first parameter `queue' already checked
for (int i = 1; i < s.getNumParam(); i++) {
PureExp arg = s.getParam(i);
String argname = "";
if (!(arg instanceof VarOrFieldUse)) {
// argument was not a plain identifier
errors.add(new TypeError(arg, ErrorMessage.WRONG_SCHEDULER_FIELD_ARGUMENT, Integer.toString(i + 1), class_decl.getName()));
} else {
// Check the rest of the parameters against class
// field/param names and argument types of the scheduling
// function. Parts of this could be elided if we verify
// that `VarUse's in scheduler annotation are rewritten to
// `FieldUse's -- then we'd just have to check for the
// presence of `VarUse' in the parameter list to detect
// invalid args. But can't hurt to open-code it (and we
// still have to check the type of all arguments vs the
// scheduling function parameters).
VarOrFieldUse vararg = (VarOrFieldUse) arg;
String name = vararg.getName();
Type argtype = UnknownType.INSTANCE;
for (ParamDecl p : class_decl.getParamList()) {
if (p.getName().equals(name))
argtype = p.getType();
}
for (FieldDecl f : class_decl.getFieldList()) {
if (f.getName().equals(name))
argtype = f.getType();
}
if (argtype.isUnknownType()) {
// identifier, but unknown in the class
errors.add(new TypeError(arg, ErrorMessage.WRONG_SCHEDULER_FIELD_ARGUMENT, "\"" + name + "\"", class_decl.getName()));
} else {
// argtype: field; paramtype: function arg
Type paramtype = sd.getParam(i).getType();
if (!argtype.isAssignableTo(paramtype)) {
errors.add(new TypeError(arg, ErrorMessage.TYPE_MISMATCH, argtype, paramtype));
}
}
}
}
}
if (class_decl.getType().isDeploymentComponentType()) {
errors.add(new TypeError(loc, ErrorMessage.SCHEDULER_ON_DC, "dummy"));
}
}
use of org.abs_models.frontend.ast.FieldDecl in project abstools by abstools.
the class AbsASTBuilderUtil method makeFieldDecl.
public static final FieldDecl makeFieldDecl(TypeUse access, String name) {
FieldDecl fd = new FieldDecl();
fd.setName(name);
fd.setTypeUse(access);
return fd;
}
use of org.abs_models.frontend.ast.FieldDecl in project abstools by abstools.
the class ClassGenerator method generateConstructor.
private void generateConstructor() {
ecs.println("%% --- Constructor: field initializers and init block\n");
ErlUtil.functionHeaderParamsAsList(ecs, "init", generatorClassMatcher(), classDecl.getParamList(), Mask.none);
ecs.println("C=(get(this))#state.class,");
ecs.println("put(vars, #{}),");
Vars vars = Vars.n();
for (ParamDecl p : classDecl.getParamList()) {
ecs.pf("put(this, C:set_val_internal(get(this),'%s',%s)),", p.getName(), "P_" + p.getName());
}
for (FieldDecl p : classDecl.getFields()) {
ErlUtil.emitLocationInformation(ecs, p.getModel(), p.getFileName(), p.getStartLine(), p.getEndLine());
if (p.hasInitExp()) {
ecs.format("put(this, C:set_val_internal(get(this),'%s',", p.getName());
p.getInitExp().generateErlangCode(ecs, vars);
ecs.println(")),");
}
}
if (classDecl.getInitBlock() != null) {
classDecl.getInitBlock().generateErlangCode(ecs, vars);
ecs.println(",");
}
if (classDecl.isActiveClass()) {
ecs.println("cog:task_is_blocked_for_gc(Cog, self(), get(task_info), get(this)),");
ecs.print("cog:add_task(Cog,active_object_task,null,O,[],#task_info{event=#event{type=schedule, local_id=run}, method= <<\"run\"/utf8>>,this=O,destiny=null},");
ecs.print(vars.toStack());
ecs.println("),");
ecs.println("cog:task_is_runnable(Cog,self()),");
ecs.print("task:wait_for_token(Cog,");
ecs.print(vars.toStack());
ecs.println("),");
}
ecs.println("gc:register_object(O),");
ecs.println("O.");
ecs.decIndent();
}
use of org.abs_models.frontend.ast.FieldDecl in project abstools by abstools.
the class ClassDeclGenerator method generateGetFieldValueMethod.
private void generateGetFieldValueMethod() {
stream.println("protected final " + ABSValue.class.getName() + " getFieldValue(java.lang.String __ABS_fieldName) throws java.lang.NoSuchFieldException {");
for (ParamDecl p : decl.getParams()) {
stream.println("if (\"" + p.getName() + "\".equals(__ABS_fieldName)) return " + JavaBackend.getVariableName(p.getName()) + ";");
}
for (FieldDecl f : decl.getFields()) {
stream.println("if (\"" + f.getName() + "\".equals(__ABS_fieldName)) return " + JavaBackend.getVariableName(f.getName()) + ";");
}
stream.println("return super.getFieldValue(__ABS_fieldName);");
stream.println("}");
}
Aggregations