<commit_before> /*
    csound_orc_expressions.c:

    Copyright (C) 2006
    <NAME>

    This file is part of Csound.

    The Csound Library is free software; you can redistribute it
    and/or modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    Csound is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with Csound; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA
*/

#include "csoundCore.h"
#include "csound_orc.h"

extern char argtyp2(char *);
extern void print_tree(CSOUND *, char *, TREE *);
extern void handle_polymorphic_opcode(CSOUND*, TREE *);
extern void handle_optional_args(CSOUND *, TREE *);
extern ORCTOKEN *make_token(CSOUND *, char *);
extern ORCTOKEN *make_label(CSOUND *, char *);
extern int find_opcode(CSOUND *csound, char *opname);

TREE* create_boolean_expression(CSOUND*, TREE*, int, int);
TREE * create_expression(CSOUND *, TREE *, int, int);

static int genlabs = 300;

char *create_out_arg(CSOUND *csound, char outype)
{
    char* s = (char *)csound->Malloc(csound, 16);
    switch(outype) {
    case 'a': sprintf(s, "#a%d", csound->acount++); break;
    case 'K':
    case 'k': sprintf(s, "#k%d", csound->kcount++); break;
    case 'B': sprintf(s, "#B%d", csound->Bcount++); break;
    case 'b': sprintf(s, "#b%d", csound->bcount++); break;
    case 't': sprintf(s, "#t%d", csound->tcount++); break;
    default:  sprintf(s, "#i%d", csound->icount++); break;
    }
    return s;
}

/**
 * Handles expression opcode type, appending to passed in opname
 * returns outarg type
 */
char *set_expression_type(CSOUND *csound, char * op, char arg1, char arg2)
{
    char outype, *s;

    if (arg1 == 'a') {
      if (arg2 == 'a') {
        strncat(op,".aa",80);
      }
      else {
        strncat(op,".ak",80);
      }
      outype = 'a';
    }
    else if (arg2 == 'a') {
      strncat(op,".ka",80);
      outype = 'a';
    }
    else if (arg1 == 'k' || arg2 == 'k') {
      strncat(op,".kk",80);
      outype = 'k';
    }
    else if (arg1 == 't' || arg2 == 't') {
      //strncat(op,".kk",80);
      outype = 't';
    }
    else {
      strncat(op,".ii",80);
      outype = 'i';
    }

    s = create_out_arg(csound, outype);

    if (UNLIKELY(PARSER_DEBUG))
      csound->Message(csound, "SET_EXPRESSION_TYPE: %s : %s\n", op, s);

    return s;
}

char * get_boolean_arg(CSOUND *csound, int type)
{
    char* s = (char *)csound->Malloc(csound, 8);
    sprintf(s, "#%c%d", type?'B':'b',csound->Bcount++);

    return s;
}

int get_expression_ans_type(char * ans)
{
//    char * t = ans;
//    t++;
//
//    switch(*t) {
//    case 'a':
//      return T_IDENT_A;
//    case 'k':
//      return T_IDENT_K;
//    case 'B':
//      return T_IDENT_B;
//    case 'b':
//      return T_IDENT_b;
//    default:
//      return T_IDENT_I;
//    }
    return T_IDENT;
}

TREE *create_empty_token(CSOUND *csound)
{
    TREE *ans;
    ans = (TREE*)mmalloc(csound, sizeof(TREE));
    if (UNLIKELY(ans==NULL)) {
      /* fprintf(stderr, "Out of memory\n"); */
      exit(1);
    }
    ans->type = -1;
    ans->left = NULL;
    ans->right = NULL;
    ans->next = NULL;
    ans->len = 0;
    ans->rate = -1;
    ans->value = NULL;
    return ans;
}

TREE *create_minus_token(CSOUND *csound)
{
    TREE *ans;
    ans = (TREE*)mmalloc(csound, sizeof(TREE));
    if (UNLIKELY(ans==NULL)) {
      /* fprintf(stderr, "Out of memory\n"); */
      exit(1);
    }
    ans->type = INTEGER_TOKEN;
    ans->left = NULL;<commit_msg>initialise value field<commit_after> /*
    csound_orc_expressions.c:

    Copyright (C) 2006
    <NAME>

    This file is part of Csound.

    The Csound Library is free software; you can redistribute it
    and/or modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    Csound is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with Csound; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA
*/

#include "csoundCore.h"
#include "csound_orc.h"

extern char argtyp2(char *);
extern void print_tree(CSOUND *, char *, TREE *);
extern void handle_polymorphic_opcode(CSOUND*, TREE *);
extern void handle_optional_args(CSOUND *, TREE *);
extern ORCTOKEN *make_token(CSOUND *, char *);
extern ORCTOKEN *make_label(CSOUND *, char *);
extern int find_opcode(CSOUND *csound, char *opname);

TREE* create_boolean_expression(CSOUND*, TREE*, int, int);
TREE * create_expression(CSOUND *, TREE *, int, int);

static int genlabs = 300;

char *create_out_arg(CSOUND *csound, char outype)
{
    char* s = (char *)csound->Malloc(csound, 16);
    switch(outype) {
    case 'a': sprintf(s, "#a%d", csound->acount++); break;
    case 'K':
    case 'k': sprintf(s, "#k%d", csound->kcount++); break;
    case 'B': sprintf(s, "#B%d", csound->Bcount++); break;
    case 'b': sprintf(s, "#b%d", csound->bcount++); break;
    case 't': sprintf(s, "#t%d", csound->tcount++); break;
    default:  sprintf(s, "#i%d", csound->icount++); break;
    }
    return s;
}

/**
 * Handles expression opcode type, appending to passed in opname
 * returns outarg type
 */
char *set_expression_type(CSOUND *csound, char * op, char arg1, char arg2)
{
    char outype, *s;

    if (arg1 == 'a') {
      if (arg2 == 'a') {
        strncat(op,".aa",80);
      }
      else {
        strncat(op,".ak",80);
      }
      outype = 'a';
    }
    else if (arg2 == 'a') {
      strncat(op,".ka",80);
      outype = 'a';
    }
    else if (arg1 == 'k' || arg2 == 'k') {
      strncat(op,".kk",80);
      outype = 'k';
    }
    else if (arg1 == 't' || arg2 == 't') {
      //strncat(op,".kk",80);
      outype = 't';
    }
    else {
      strncat(op,".ii",80);
      outype = 'i';
    }

    s = create_out_arg(csound, outype);

    if (UNLIKELY(PARSER_DEBUG))
      csound->Message(csound, "SET_EXPRESSION_TYPE: %s : %s\n", op, s);

    return s;
}

char * get_boolean_arg(CSOUND *csound, int type)
{
    char* s = (char *)csound->Malloc(csound, 8);
    sprintf(s, "#%c%d", type?'B':'b',csound->Bcount++);

    return s;
}

int get_expression_ans_type(char * ans)
{
//    char * t = ans;
//    t++;
//
//    switch(*t) {
//    case 'a':
//      return T_IDENT_A;
//    case 'k':
//      return T_IDENT_K;
//    case 'B':
//      return T_IDENT_B;
//    case 'b':
//      return T_IDENT_b;
//    default:
//      return T_IDENT_I;
//    }
    return T_IDENT;
}

TREE *create_empty_token(CSOUND *csound)
{
    TREE *ans;
    ans = (TREE*)mmalloc(csound, sizeof(TREE));
    if (UNLIKELY(ans==NULL)) {
      /* fprintf(stderr, "Out of memory\n"); */
      exit(1);
    }
    ans->type = -1;
    ans->left = NULL;
    ans->right = NULL;
    ans->next = NULL;
    ans->len = 0;
    ans->rate = -1;
    ans->line = 0;
    ans->locn  = 0;
    ans->value = NULL;
    return ans;
}

TREE *create_minus_token(CSOUND *csound)
{
    TREE *ans;
    ans = (TREE*)mmalloc(csound, sizeof(TREE));
    if (UNLIKELY(ans==NULL)) {
      /* fprintf(stderr, "Out of memory\n"); */
      exit(1);
    }
    ans->type = INTEGER_TOKEN;
    ans->left = NULL;
{'fraction_non_alphanumeric': 0.16020278833967047, 'fraction_numerical': 0.013688212927756654, 'mean_word_length': 2.771988527724665, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3721418', 'n_tokens_mistral': 2978, 'n_tokens_neox': 2868, 'n_words': 797}