Example #1
0
// Check whether the given entity members are legal in their entity
static bool check_members(ast_t* members, int entity_def_index)
{
  assert(members != NULL);
  assert(entity_def_index >= 0 && entity_def_index < DEF_ENTITY_COUNT);
  bool r = true;

  const permission_def_t* def = &_entity_def[entity_def_index];
  ast_t* member = ast_child(members);

  while(member != NULL)
  {
    switch(ast_id(member))
    {
      case TK_FLET:
      case TK_FVAR:
      case TK_EMBED:
        if(def->permissions[ENTITY_FIELD] == 'N')
        {
          ast_error(member, "Can't have fields in %s", def->desc);
          r = false;
        }

        if(!check_id_field(ast_child(member)))
          r = false;
        break;

      case TK_NEW:
        if(!check_method(member, entity_def_index + DEF_NEW))
          r = false;
        break;

      case TK_BE:
      {
        if(!check_method(member, entity_def_index + DEF_BE))
          r = false;
        break;
      }

      case TK_FUN:
      {
        if(!check_method(member, entity_def_index + DEF_FUN))
          r = false;
        break;
      }

      default:
        ast_print(members);
        assert(0);
        return false;
    }

    member = ast_sibling(member);
  }

  return r;
}
Example #2
0
void mark_methods(std::vector<DexClass*>& classes, const CMethodStrs& cMethodStrs,
                  CMethods& methods, int64_t& counter) {
  for (auto const &cls : classes) {
    std::string clsQName = cls->get_name()->c_str();
    for (auto const& dm : cls->get_dmethods()) {
      check_method(cls, clsQName, dm, cMethodStrs, methods, counter);
    }
    for (auto const& vm : cls->get_vmethods()) {
      check_method(cls, clsQName, vm, cMethodStrs, methods, counter);
    }
  }
}
Example #3
0
/*!
 * \param[in,out] sc     Selection collection to registered the method to.
 * \param[in]     name   Name under which the method should be registered.
 * \param[in]     method Method to register.
 * \returns       0 on success, EINVAL if there was something wrong with the
 *   method.
 *
 * \p name does not need to match the name of the method, and the same
 * method can be registered multiple times under different names.
 * If \p name equals some previously registered name,
 * an error message is printed and the method is not registered.
 *
 * The function also performs some sanity checking on the input method,
 * and refuses to register it if there are problems.
 * Some problems only generate warnings.
 * All problems are described to \p stderr.
 */
int
gmx_ana_selmethod_register(struct gmx_ana_selcollection_t *sc,
                           const char *name, gmx_ana_selmethod_t *method)
{
    gmx_bool bOk;

    /* Check the method */
    if (method->flags & SMETH_MODIFIER)
    {
        bOk = check_modifier(stderr, method, sc->symtab);
    }
    else
    {
        bOk = check_method(stderr, method, sc->symtab);
    }
    /* Try to register the method if everything is ok */
    if (bOk)
    {
        if (!_gmx_sel_add_method_symbol(sc->symtab, name, method))
        {
            bOk = FALSE;
        }
    }
    if (!bOk)
    {
        report_error(stderr, name, "warning: not registered");
        return EINVAL;
    }
    return 0;
}
Example #4
0
/*!
 * \param[in,out] symtab Symbol table to register the method to.
 * \param[in]     name   Name under which the method should be registered.
 * \param[in]     method Method to register.
 * \returns       0 on success, -1 if there was something wrong with the
 *   method.
 *
 * \p name does not need to match the name of the method, and the same
 * method can be registered multiple times under different names.
 * If \p name equals some previously registered name,
 * an error message is printed and the method is not registered.
 *
 * The function also performs some sanity checking on the input method,
 * and refuses to register it if there are problems.
 * Some problems only generate warnings.
 * All problems are described to \p stderr.
 */
int
gmx_ana_selmethod_register(gmx::SelectionParserSymbolTable *symtab,
                           const char *name, gmx_ana_selmethod_t *method)
{
    bool bOk;

    /* Check the method */
    if (method->flags & SMETH_MODIFIER)
    {
        bOk = check_modifier(stderr, method, *symtab);
    }
    else
    {
        bOk = check_method(stderr, method, *symtab);
    }
    /* Try to register the method if everything is ok */
    if (bOk)
    {
        try
        {
            symtab->addMethod(name, method);
        }
        catch (const gmx::APIError &ex)
        {
            report_error(stderr, name, ex.what());
            bOk = false;
        }
    }
    if (!bOk)
    {
        report_error(stderr, name, "warning: not registered");
        return -1;
    }
    return 0;
}
Example #5
0
static ast_result_t sugar_new(pass_opt_t* opt, ast_t* ast)
{
  typecheck_t* t = &opt->check;
  AST_GET_CHILDREN(ast, cap, id, typeparams, params, result);

  // Return type default to ref^ for classes, val^ for primitives, and
  // tag^ for actors.
  if(ast_id(result) == TK_NONE)
  {
    token_id tcap = ast_id(cap);

    if(tcap == TK_NONE)
    {
      switch(ast_id(t->frame->type))
      {
        case TK_PRIMITIVE: tcap = TK_VAL; break;
        case TK_ACTOR: tcap = TK_TAG; break;
        default: tcap = TK_REF; break;
      }

      ast_setid(cap, tcap);
    }

    ast_replace(&result, type_for_this(opt, ast, tcap, TK_EPHEMERAL, false));
  }

  sugar_docstring(ast);
  return check_method(ast);
}
Example #6
0
static ast_result_t sugar_be(pass_opt_t* opt, ast_t* ast)
{
  AST_GET_CHILDREN(ast, cap, id, typeparams, params, result, can_error, body);
  ast_setid(cap, TK_TAG);

  if(ast_id(result) == TK_NONE)
  {
    // Return type is This tag
    ast_replace(&result, type_for_this(opt, ast, TK_TAG, TK_NONE, false));
  }

  sugar_docstring(ast);
  return check_method(ast);
}
Example #7
0
void SDIRK_solver::init(int nvar,const char *type) {

	if(initd) destroy();
	nv=nvar;
	nr=new int[nv];
	nc=new int[nv];
	var=new char*[nv];
	reg=new bool[nv];
	y=new matrix[nv];
	dy=new matrix[nv];
	for(int i=0;i<nv;i++) {
		var[i]=new char[32];var[i][0]='\0';
		reg[i]=false;
	}
	step=-1;
	stage=-1;
	
	if(!strcmp(type,"be")) 
		init_be();
	else if(!strcmp(type,"cn"))
		init_cn();
	else if(!strcmp(type,"sdirk2"))
		init_sdirk2();
	else if(!strcmp(type,"sdirk3"))
		init_sdirk3();
	else if(!strcmp(type,"sdirk4"))
		init_sdirk4();
	else if(!strcmp(type,"esdirk3"))
		init_esdirk3();
	else if(!strcmp(type,"esdirk4"))
		init_esdirk4();
	else {
		fprintf(stderr,"SDIRK_solver: Unknown RK method %s\n",type);
		exit(1);
	}
	
	check_method();
	if(nstages>1)
		k=new matrix[nstages-1];
	for(int n=0;n<nstages-1;n++) k[n]=zeros(1,1);
	
	initd=true;
	
}
Example #8
0
void AskParams(struct options* options, int argc, char** argv, int rank) {
    int ret;

    if (rank == 0) {
        printf(
            "============================================================\n");
        printf(
            "Program for calculation of partial differential equations.  \n");
        printf(
            "============================================================\n");
        printf("(c) Dr. Thomas Ludwig, TU München.\n");
        printf("    Thomas A. Zochler, TU München.\n");
        printf("    Andreas C. Schmidt, TU München.\n");
        printf(
            "============================================================\n");
        printf("\n");
    }

    if (argc < 2) {
        /* ----------------------------------------------- */
        /* Get input: method, interlines, func, precision. */
        /* ----------------------------------------------- */
        do {
            printf("\n");
            printf("Select number of threads:\n");
            printf("Number> ");
            fflush(stdout);
            ret = scanf("%" SCNu64, &(options->number));
            while (getchar() != '\n')
                ;
        } while (ret != 1 || !check_number(options));

        do {
            printf("\n");
            printf("Select calculationmethod:\n");
            printf("  %1d: Gauss-Seidel.\n", METH_GAUSS_SEIDEL);
            printf("  %1d: Jacobi.\n", METH_JACOBI);
            printf("method> ");
            fflush(stdout);
            ret = scanf("%" SCNu64, &(options->method));
            while (getchar() != '\n')
                ;
        } while (ret != 1 || !check_method(options));

        do {
            printf("\n");
            printf("Matrixsize = Interlines*8+9\n");
            printf("Interlines> ");
            fflush(stdout);
            ret = scanf("%" SCNu64, &(options->interlines));
            while (getchar() != '\n')
                ;
        } while (ret != 1 || !check_interlines(options));

        do {
            printf("\n");
            printf("Select interferencefunction:\n");
            printf(" %1d: f(x,y)=0.\n", FUNC_F0);
            printf(" %1d: f(x,y)=2pi^2*sin(pi*x)sin(pi*y).\n", FUNC_FPISIN);
            printf("interferencefunction> ");
            fflush(stdout);
            ret = scanf("%" SCNu64, &(options->inf_func));
            while (getchar() != '\n')
                ;
        } while (ret != 1 || !check_inf_func(options));

        do {
            printf("\n");
            printf("Select termination:\n");
            printf(" %1d: sufficient precision.\n", TERM_PREC);
            printf(" %1d: number of iterationes.\n", TERM_ITER);
            printf("termination> ");
            fflush(stdout);
            ret = scanf("%" SCNu64, &(options->termination));
            while (getchar() != '\n')
                ;
        } while (ret != 1 || !check_termination(options));

        if (options->termination == TERM_PREC) {
            do {
                printf("\n");
                printf("Select precision:\n");
                printf("  Range: 1e-4 .. 1e-20.\n");
                printf("precision> ");
                fflush(stdout);
                ret = scanf("%lf", &(options->term_precision));
                while (getchar() != '\n')
                    ;
            } while (ret != 1 || !check_term_precision(options));

            options->term_iteration = MAX_ITERATION;
        } else if (options->termination == TERM_ITER) {
            do {
                printf("\n");
                printf("Select number of iterations:\n");
                printf("  Range: 1 .. %d.\n", MAX_ITERATION);
                printf("Iterations> ");
                fflush(stdout);
                ret = scanf("%" SCNu64, &(options->term_iteration));
                while (getchar() != '\n')
                    ;
            } while (ret != 1 || !check_term_iteration(options));

            options->term_precision = 0;
        }
    } else {
        if (argc < 7 || strcmp(argv[1], "-h") == 0 ||
            strcmp(argv[1], "-?") == 0) {
            usage(argv[0]);
            exit(0);
        }

        ret = sscanf(argv[1], "%" SCNu64, &(options->number));

        if (ret != 1 || !check_number(options)) {
            usage(argv[0]);
            exit(1);
        }

        ret = sscanf(argv[2], "%" SCNu64, &(options->method));

        if (ret != 1 || !check_method(options)) {
            usage(argv[0]);
            exit(1);
        }

        ret = sscanf(argv[3], "%" SCNu64, &(options->interlines));

        if (ret != 1 || !check_interlines(options)) {
            usage(argv[0]);
            exit(1);
        }

        ret = sscanf(argv[4], "%" SCNu64, &(options->inf_func));

        if (ret != 1 || !check_inf_func(options)) {
            usage(argv[0]);
            exit(1);
        }

        ret = sscanf(argv[5], "%" SCNu64, &(options->termination));

        if (ret != 1 || !check_termination(options)) {
            usage(argv[0]);
            exit(1);
        }

        if (options->termination == TERM_PREC) {
            ret = sscanf(argv[6], "%lf", &(options->term_precision));
            options->term_iteration = MAX_ITERATION;

            if (ret != 1 || !check_term_precision(options)) {
                usage(argv[0]);
                exit(1);
            }
        } else {
            ret = sscanf(argv[6], "%" SCNu64, &(options->term_iteration));
            options->term_precision = 0;

            if (ret != 1 || !check_term_iteration(options)) {
                usage(argv[0]);
                exit(1);
            }
        }
    }
}
Example #9
0
// Check whether the given entity members are legal in their entity
static bool check_members(pass_opt_t* opt, ast_t* members, int entity_def_index)
{
  assert(members != NULL);
  assert(entity_def_index >= 0 && entity_def_index < DEF_ENTITY_COUNT);
  bool r = true;

  const permission_def_t* def = &_entity_def[entity_def_index];
  ast_t* member = ast_child(members);

  while(member != NULL)
  {
    switch(ast_id(member))
    {
      case TK_FLET:
      case TK_FVAR:
      case TK_EMBED:
      {
        if(def->permissions[ENTITY_FIELD] == 'N')
        {
          ast_error(opt->check.errors, member,
            "Can't have fields in %s", def->desc);
          r = false;
        }

        if((ast_id(ast_parent(members)) == TK_OBJECT) && \
          (ast_id(ast_childidx(member, 2)) == TK_NONE))
        {
          ast_error(opt->check.errors, member,
            "object literal fields must be initialized");
          r = false;
        }

        if(!check_id_field(opt, ast_child(member)))
          r = false;

        ast_t* delegate_type = ast_childidx(member, 3);
        if(ast_id(delegate_type) != TK_NONE &&
          !check_provides_type(opt, delegate_type, "delegate"))
          r = false;
        break;
      }

      case TK_NEW:
        if(!check_method(opt, member, entity_def_index + DEF_NEW))
          r = false;
        break;

      case TK_BE:
      {
        if(!check_method(opt, member, entity_def_index + DEF_BE))
          r = false;
        break;
      }

      case TK_FUN:
      {
        if(!check_method(opt, member, entity_def_index + DEF_FUN))
          r = false;
        break;
      }

      default:
        ast_print(members);
        assert(0);
        return false;
    }

    member = ast_sibling(member);
  }

  return r;
}
Example #10
0
int
dodecompress(const char *in, char *out, const struct compressor *method,
    int bits, struct stat *sb)
{
	u_char buf[Z_BUFSIZE];
	char oldname[MAXPATHLEN];
	int error, oreg, ifd, ofd;
	void *cookie;
	ssize_t nr;
	struct z_info info;
	struct stat osb;

	oreg = 0;
	error = SUCCESS;
	cookie = NULL;

	if (pipin)
		ifd = dup(STDIN_FILENO);
	else
		ifd = open(in, O_RDONLY);
	if (ifd < 0) {
		if (verbose >= 0)
			warn("%s", in);
		return -1;
	}

	if (!force && isatty(ifd)) {
		if (verbose >= 0)
			warnx("%s: won't read compressed data from terminal",
			    in);
		close (ifd);
		return -1;
	}

	if ((method = check_method(ifd)) == NULL) {
		if (verbose >= 0)
			warnx("%s: unrecognized file format", in);
		close (ifd);
		return -1;
	}

	/* XXX - open constrains outfile to MAXPATHLEN so this is safe */
	oldname[0] = '\0';
	if ((cookie = (*method->open)(ifd, "r", oldname, bits, 0, 1)) == NULL) {
		if (verbose >= 0)
			warn("%s", in);
		close (ifd);
		return (FAILURE);
	}
	if (storename && oldname[0] != '\0') {
		strlcpy(out, oldname, MAXPATHLEN);
		cat = 0;			/* XXX should -c override? */
	}

	if (testmode)
		ofd = -1;
	else {
		if (cat)
			ofd = dup(STDOUT_FILENO);
		else {
			if (stat(out, &osb) == 0) {
				oreg = S_ISREG(osb.st_mode);
				if (!force && oreg && !permission(out)) {
					(void) close(ifd);
					return (WARNING);
				}
			}
			ofd = open(out, O_WRONLY|O_CREAT|O_TRUNC, S_IWUSR);
		}
		if (ofd < 0) {
			if (verbose >= 0)
				warn("%s", in);
			(method->close)(cookie, NULL, NULL, NULL);
			return (FAILURE);
		}
	}

	while ((nr = (method->read)(cookie, buf, sizeof(buf))) > 0) {
		if (ofd != -1 && write(ofd, buf, nr) != nr) {
			if (verbose >= 0)
				warn("%s", out);
			error = FAILURE;
			break;
		}
	}

	if (!error && nr < 0) {
		if (verbose >= 0)
			warnx("%s: %s", in,
			    errno == EINVAL ? "crc error" : strerror(errno));
		error = errno == EINVAL ? WARNING : FAILURE;
	}

	if ((method->close)(cookie, &info, NULL, NULL)) {
		if (!error && verbose >= 0)
			warnx("%s", in);
		error = FAILURE;
	}
	if (storename && !cat) {
		if (info.mtime != 0) {
			sb->st_mtimespec.tv_sec =
			    sb->st_atimespec.tv_sec = info.mtime;
			sb->st_mtimespec.tv_nsec =
			    sb->st_atimespec.tv_nsec = 0;
		} else
			storename = 0;		/* no timestamp to restore */
	}
	if (error == SUCCESS)
		setfile(out, ofd, sb);

	if (ofd != -1 && close(ofd)) {
		if (!error && verbose >= 0)
			warn("%s", out);
		error = FAILURE;
	}

	if (!error) {
		if (list) {
			if (info.mtime == 0)
				info.mtime = (u_int32_t)sb->st_mtime;
			list_stats(out, method, &info);
		} else if (verbose > 0) {
			verbose_info(out, info.total_in, info.total_out,
			    info.hlen);
		}
	}

	/* On error, clean up the file we created but preserve errno. */
	if (error && oreg)
		unlink(out);

	return (error);
}
Example #11
0
static ast_result_t sugar_fun(ast_t* ast)
{
  fun_defaults(ast);
  sugar_docstring(ast);
  return check_method(ast);
}