/[svn]/linuxsampler/trunk/src/scriptvm/tree.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/scriptvm/tree.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3714 by schoenebeck, Sat Jan 11 20:19:11 2020 UTC revision 3744 by schoenebeck, Sat Feb 15 11:50:02 2020 UTC
# Line 13  Line 13 
13  #include "../common/global_private.h"  #include "../common/global_private.h"
14  #include "../common/RTMath.h"  #include "../common/RTMath.h"
15  #include <assert.h>  #include <assert.h>
16    #include "CoreVMFunctions.h" // for VMIntResult, VMRealResult
17    
18  namespace LinuxSampler {  namespace LinuxSampler {
19            
# Line 122  static String _unitFactorToShortStr(vmfl Line 123  static String _unitFactorToShortStr(vmfl
123      }      }
124  }  }
125    
126  static String _unitToStr(Unit* unit) {  static String _unitToStr(VMUnit* unit) {
127      const StdUnit_t type = unit->unitType();      const StdUnit_t type = unit->unitType();
128      String sType;      String sType;
129      switch (type) {      switch (type) {
# Line 612  VMFnResult* FunctionCall::execVMFn() { Line 613  VMFnResult* FunctionCall::execVMFn() {
613      if (!fn) return NULL;      if (!fn) return NULL;
614      // assuming here that all argument checks (amount and types) have been made      // assuming here that all argument checks (amount and types) have been made
615      // at parse time, to avoid time intensive checks on each function call      // at parse time, to avoid time intensive checks on each function call
616      return fn->exec(dynamic_cast<VMFnArgs*>(&*args));      VMFnResult* res = fn->exec(dynamic_cast<VMFnArgs*>(&*args));
617        if (!res) return res;
618    
619        VMExpr* expr = res->resultValue();
620        if (!expr) return res;
621    
622        // For performance reasons we always only let 'FunctionCall' assign the unit
623        // type to the function's result expression, never by the function
624        // implementation itself, nor by other classes, because a FunctionCall
625        // object solely knows the unit type in O(1).
626        ExprType_t type = expr->exprType();
627        if (type == INT_EXPR) {
628            VMIntResult* intRes = dynamic_cast<VMIntResult*>(res);
629            intRes->unitBaseType = unitType();
630        } else if (type == REAL_EXPR) {
631            VMRealResult* realRes = dynamic_cast<VMRealResult*>(res);
632            realRes->unitBaseType = unitType();
633        }
634    
635        return res;
636  }  }
637    
638  StmtFlags_t FunctionCall::exec() {  StmtFlags_t FunctionCall::exec() {
# Line 685  String FunctionCall::evalCastToStr() { Line 705  String FunctionCall::evalCastToStr() {
705          return strExpr ? strExpr->evalStr() : "";          return strExpr ? strExpr->evalStr() : "";
706      } else if (resultType == REAL_EXPR) {      } else if (resultType == REAL_EXPR) {
707          VMRealExpr* realExpr = dynamic_cast<VMRealExpr*>(result->resultValue());          VMRealExpr* realExpr = dynamic_cast<VMRealExpr*>(result->resultValue());
708          return realExpr ? ToString(realExpr->evalReal()) : "";          return realExpr ? ToString(realExpr->evalReal()) + _unitToStr(realExpr) : "";
709      } else {      } else {
710          VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(result->resultValue());          VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(result->resultValue());
711          return intExpr ? ToString(intExpr->evalInt()) : "";          return intExpr ? ToString(intExpr->evalInt()) + _unitToStr(intExpr) : "";
712      }      }
713  }  }
714    
# Line 1812  ParserContext::~ParserContext() { Line 1832  ParserContext::~ParserContext() {
1832      }      }
1833  }  }
1834    
1835  void ParserContext::addErr(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt) {  void ParserContext::addErr(int firstLine, int lastLine, int firstColumn,
1836                               int lastColumn, int firstByte, int lengthBytes,
1837                               const char* txt)
1838    {
1839      ParserIssue e;      ParserIssue e;
1840      e.type = PARSER_ERROR;      e.type = PARSER_ERROR;
1841      e.txt = txt;      e.txt = txt;
# Line 1820  void ParserContext::addErr(int firstLine Line 1843  void ParserContext::addErr(int firstLine
1843      e.lastLine = lastLine;      e.lastLine = lastLine;
1844      e.firstColumn = firstColumn;      e.firstColumn = firstColumn;
1845      e.lastColumn = lastColumn;      e.lastColumn = lastColumn;
1846        e.firstByte = firstByte;
1847        e.lengthBytes = lengthBytes;
1848      vErrors.push_back(e);      vErrors.push_back(e);
1849      vIssues.push_back(e);      vIssues.push_back(e);
1850  }  }
1851    
1852  void ParserContext::addWrn(int firstLine, int lastLine, int firstColumn, int lastColumn, const char* txt) {  void ParserContext::addWrn(int firstLine, int lastLine, int firstColumn,
1853                               int lastColumn, int firstByte, int lengthBytes,
1854                               const char* txt)
1855    {
1856      ParserIssue w;      ParserIssue w;
1857      w.type = PARSER_WARNING;      w.type = PARSER_WARNING;
1858      w.txt = txt;      w.txt = txt;
# Line 1832  void ParserContext::addWrn(int firstLine Line 1860  void ParserContext::addWrn(int firstLine
1860      w.lastLine = lastLine;      w.lastLine = lastLine;
1861      w.firstColumn = firstColumn;      w.firstColumn = firstColumn;
1862      w.lastColumn = lastColumn;      w.lastColumn = lastColumn;
1863        w.firstByte = firstByte;
1864        w.lengthBytes = lengthBytes;
1865      vWarnings.push_back(w);      vWarnings.push_back(w);
1866      vIssues.push_back(w);      vIssues.push_back(w);
1867  }  }
1868    
1869  void ParserContext::addPreprocessorComment(int firstLine, int lastLine, int firstColumn, int lastColumn) {  void ParserContext::addPreprocessorComment(int firstLine, int lastLine,
1870                                               int firstColumn, int lastColumn,
1871                                               int firstByte, int lengthBytes)
1872    {
1873      CodeBlock block;      CodeBlock block;
1874      block.firstLine = firstLine;      block.firstLine = firstLine;
1875      block.lastLine = lastLine;      block.lastLine = lastLine;
1876      block.firstColumn = firstColumn;      block.firstColumn = firstColumn;
1877      block.lastColumn = lastColumn;      block.lastColumn = lastColumn;
1878        block.firstByte = firstByte;
1879        block.lengthBytes = lengthBytes;
1880      vPreprocessorComments.push_back(block);      vPreprocessorComments.push_back(block);
1881  }  }
1882    

Legend:
Removed from v.3714  
changed lines
  Added in v.3744

  ViewVC Help
Powered by ViewVC