<commit_before>/**
 * 
 */
package edu.umn.cs.crisys.tb.codegen.common.names;

import edu.umn.cs.crisys.tb.TbException;
import edu.umn.cs.crisys.tb.TbFailure;
import edu.umn.cs.crisys.tb.codegen.common.emitters.NameEmitter;
import edu.umn.cs.crisys.tb.model.OSModel;
import edu.umn.cs.crisys.tb.model.type.ArrayType;
import edu.umn.cs.crisys.tb.model.type.ExternalType;
import edu.umn.cs.crisys.tb.model.type.IdType;
import edu.umn.cs.crisys.tb.model.type.PointerType;
import edu.umn.cs.crisys.tb.model.type.RecordType;
import edu.umn.cs.crisys.tb.model.type.Type;
import edu.umn.cs.crisys.tb.model.type.UnitType;

/**
 * @author Whalen
 *
 */
public class TypeNames implements NameEmitter {
  Type t;
  Type t_structural;

  static public Type getStructuralType(Type ty) {
	  try {
		  if (ty instanceof IdType) {
			  Type returnType = ((IdType) ty).getRootType();
			  return returnType;
		  } else return ty;
	  } catch (TbFailure r) {
		  throw new TbException(r.toString());
	  }
  }
  
  public TypeNames(Type t) {
    this.t = t;
    if (t == null) {
      throw new TbException("Unexpected null seen for type when constructing TypeNames object");
    }
    this.t_structural = getStructuralType(t);
  }
  
  public String getWriterFn() {
     return "write_" + t.getCType().typeString();
  }
  
  public boolean getIsUnit() {
    return (t_structural instanceof UnitType); 
  }
  
  public boolean getHasData() {
    return !getIsUnit();
  }

  public boolean getIsBaseType() {
    return t_structural.isBaseType();
  }
  
  ///////////////////////////////////////////////////
  //
  // Naming properties
  //
  ///////////////////////////////////////////////////
  
  public String getName() {
    return t.getCType().typeString(); 
  }

  /* AADL-native types for inputs and outputs + conversion functions 
   * 
   * The way this works is we assume a 'base' type for a declaration that we
   * emit in the code generator.  This declaration may be used as an input or
   * output, in which case its type is adjusted for efficient use of stack
   * resources and C's weird parameter rules (arrays are implicitly passed by 
   * pointer).  
   * 
   * The conversion functions assume that we use the *BASE TYPE* as the 
   * baseline and WILL NOT WORK if you start from the 'adjusted type', e.g.:
   *  Type t = // some base type 
   *  t.getOutputType().getOutputToInput();
   * 
   * Instead use: 
   *  t.getOutputToInput() 
   * 
   * 
   */ 
  public boolean isNativePointerArg() {
	    return (t_structural instanceof PointerType) || 
	           (t_structural instanceof ArrayType);
	  }
  
  public TypeNames getAadlOutputType() { 
    return new TypeNames(isNativePointerArg() ?
        t : new PointerType(t));
  }

  public TypeNames getQueueType() {
    return new TypeNames(new PointerType(t));
  }
  
  public TypeNames getAadlInputType() {
    return getAadlOutputType();
  }
  
  
  public String getAadlInputToAadlOutput() {
    return "";
  }

  public String getValToAadlInput() {
    if (isNativePointerArg()) { return ""; } else { return "&"; }
  }
  
  public String getValToAadlOutput() {<commit_msg>getAadlOutputType was generating the incorrect type for arrays.<commit_after>/**
 * 
 */
package edu.umn.cs.crisys.tb.codegen.common.names;

import edu.umn.cs.crisys.tb.TbException;
import edu.umn.cs.crisys.tb.TbFailure;
import edu.umn.cs.crisys.tb.codegen.common.emitters.NameEmitter;
import edu.umn.cs.crisys.tb.model.OSModel;
import edu.umn.cs.crisys.tb.model.type.ArrayType;
import edu.umn.cs.crisys.tb.model.type.ExternalType;
import edu.umn.cs.crisys.tb.model.type.IdType;
import edu.umn.cs.crisys.tb.model.type.PointerType;
import edu.umn.cs.crisys.tb.model.type.RecordType;
import edu.umn.cs.crisys.tb.model.type.Type;
import edu.umn.cs.crisys.tb.model.type.UnitType;

/**
 * @author Whalen
 *
 */
public class TypeNames implements NameEmitter {
  Type t;
  Type t_structural;

  static public Type getStructuralType(Type ty) {
	  try {
		  if (ty instanceof IdType) {
			  Type returnType = ((IdType) ty).getRootType();
			  return returnType;
		  } else return ty;
	  } catch (TbFailure r) {
		  throw new TbException(r.toString());
	  }
  }
  
  public TypeNames(Type t) {
    this.t = t;
    if (t == null) {
      throw new TbException("Unexpected null seen for type when constructing TypeNames object");
    }
    this.t_structural = getStructuralType(t);
  }
  
  public String getWriterFn() {
     return "write_" + t.getCType().typeString();
  }
  
  public boolean getIsUnit() {
    return (t_structural instanceof UnitType); 
  }
  
  public boolean getHasData() {
    return !getIsUnit();
  }

  public boolean getIsBaseType() {
    return t_structural.isBaseType();
  }
  
  ///////////////////////////////////////////////////
  //
  // Naming properties
  //
  ///////////////////////////////////////////////////
  
  public String getName() {
    return t.getCType().typeString(); 
  }

  /* AADL-native types for inputs and outputs + conversion functions 
   * 
   * The way this works is we assume a 'base' type for a declaration that we
   * emit in the code generator.  This declaration may be used as an input or
   * output, in which case its type is adjusted for efficient use of stack
   * resources and C's weird parameter rules (arrays are implicitly passed by 
   * pointer).  
   * 
   * The conversion functions assume that we use the *BASE TYPE* as the 
   * baseline and WILL NOT WORK if you start from the 'adjusted type', e.g.:
   *  Type t = // some base type 
   *  t.getOutputType().getOutputToInput();
   * 
   * Instead use: 
   *  t.getOutputToInput() 
   * 
   * 
   */ 
  public boolean isNativePointerArg() {
	    return (t_structural instanceof PointerType);
	  }
  
  public TypeNames getAadlOutputType() { 
    return new TypeNames(isNativePointerArg() ?
        t : new PointerType(t));
  }

  public TypeNames getQueueType() {
    return new TypeNames(new PointerType(t));
  }
  
  public TypeNames getAadlInputType() {
    return getAadlOutputType();
  }
  
  
  public String getAadlInputToAadlOutput() {
    return "";
  }

  public String getValToAadlInput() {
    if (isNativePointerArg()) { return ""; } else { return "&"; }
  }
  
  public String getValToAadlOutput() {
{'fraction_non_alphanumeric': 0.14100926221654422, 'fraction_numerical': 0.0, 'mean_word_length': 2.6668618266978923, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2376814', 'n_tokens_mistral': 2117, 'n_tokens_neox': 2019, 'n_words': 512}