2655{
2657
2658 while (parse.GetNext()) {
2659 std::string token = parse.GetLast();
2660 const char *tok = token.c_str();
2661 if (!strncmp(tok, "call{", 5) ||
2662 tok[0] == '#') {
2663 std::string nameiter;
2664 std::string name;
2665
2666 if (tok[0] == '#')
2667 nameiter = token.substr(1);
2668 else
2669 nameiter = parse.GetReference();
2670
2671 const char *ptr;
2672 for (ptr = nameiter.c_str(); *ptr && *ptr != '[' && *ptr != '('; ptr++) name += *ptr;
2673 int iter = 1;
2674
2675
2676
2677
2678
2679
2680
2681
2682 MacroMap::iterator m =
m_macroMap.find(name.c_str());
2687 nLocalsSize = locals->second.m_size;
2688 }
2689
2690 int i;
2691 for (i = 0; i < iter; i++) {
2692 Flatten(flatStr, name, m->second.c_str(), parseStr, nLocalsOffset+nLocalsSize);
2693 }
2694 }
2695 else {
2696 parseStr += "Call to undefined macro '" + name + "'\n";
2697 return false;
2698 }
2699 }
2700 else if (!strncmp(tok, "in{", 3) ||
2701 !strncmp(tok, "out{", 4)) {
2702 std::string op = parse.GetName();
2703 std::string ref = parse.GetReference();
2704 std::string refroot;
2705 for (const char *ptr = ref.c_str(); *ptr && *ptr != ',' && *ptr != '(' && *ptr != '['; ptr++) refroot += *ptr;
2706
2708 int nChan;
2709 if (op == "in") {
2712 }
2713 else {
2716 }
2717
2718 ChanVarMap::iterator ci = pMap->find(refroot);
2719 if (ci == pMap->end()) {
2720 parseStr += "Invalid '" + op + "' operation channel reference '" + refroot + "'\n";
2721 return false;
2722 }
2723 if (refroot != ref) {
2724 std::string select = ref.substr(refroot.size());
2725 int offset = 0;
2726 int size = 1;
2727
2728 if (select[0] == '[' || select[1] == '(') {
2729 const char *ptr;
2730 offset = atoi(select.c_str() + 1);
2731 for (ptr = select.c_str() + 1; *ptr && *ptr != ')' && *ptr != ']'; ptr++);
2732 select = ptr + 1;
2733 }
2734
2735 if (select[0]==',')
2736 size = atoi(select.c_str() + 1);
2737
2738 if (size < 0 || offset<0 || ci->second.first + offset + size >
m_nInputChannels) {
2739 parseStr += "Invalid '" + op + "' operation channel offset or size '" + refroot + "'\n";
2740 return false;
2741 }
2742 char index[80];
2743 sprintf(index, "(%d,%d)", ci->second.first+offset, size);
2744 flatStr += op + index + " ";
2745 }
2746 else if (ci->second.second>1) {
2747 char index[80];
2748 sprintf(index, "(%d,%d)", ci->second.first, ci->second.second);
2749 flatStr += op + index + " ";
2750 }
2751 else {
2752 char index[80];
2753 sprintf(index, "(%d)", ci->second.first);
2754 flatStr += op + index + " ";
2755 }
2756 }
2757 else if (!strncmp(tok, "tget{", 5) ||
2758 !strncmp(tok, "tput{", 5) ||
2759 !strncmp(tok, "tsav{", 5)) {
2760 std::string op = parse.GetName();
2761 std::string ref = parse.GetReference();
2762 std::string refroot;
2763 for (const char *ptr = ref.c_str(); *ptr && *ptr != '[' && *ptr != '('; ptr++) refroot += *ptr;
2764
2765 if (macroName.size() && refroot.size() && refroot[0] == '@') {
2766 std::string localName = refroot.substr(1);
2769 parseStr += "Reference to undeclared local variable '" + localName + "' in macro '" + macroName + "'\n";
2770 return false;
2771 }
2772
2773 unsigned long nLocalOffset = 0;
2774 unsigned long nLocalSize = 0;
2775 TempVarList::iterator m = locals->second.m_members.begin();
2776 for (; m != locals->second.m_members.end(); m++) {
2777 if (localName == m->m_name) {
2778 nLocalOffset = m->m_pos;
2779 nLocalSize = m->m_size;
2780 break;
2781 }
2782 }
2783 if (m == locals->second.m_members.end()) {
2784 parseStr += "Reference to undeclared local variable '" + localName + "' in macro '" + macroName + "'\n";
2785 return false;
2786 }
2787 int voffset, vsize;
2788
2789 if (ref != refroot) {
2791 p2.GetNext();
2793 p2.GetIndex(_voffset, _vsize, 0, 1);
2794 voffset = _voffset;
2795 vsize = _vsize + 1;
2796 }
2797 else {
2798 voffset = 0;
2799 vsize = (int)nLocalSize;
2800 }
2801
2802 if (voffset + vsize > (int)nLocalSize) {
2803 parseStr += "Out of bounds indexing of local '" + refroot + "' in macro '" + macroName + "'\n";
2804 return false;
2805 }
2806
2807 if (nLocalsOffset + nLocalOffset + voffset + vsize > 65536) {
2808 parseStr += "Temporary variable addressing out of bounds\n";
2809 return false;
2810 }
2811 char idx[80];
2812 if (vsize == 1) {
2813 sprintf(idx, "[%lu]", nLocalsOffset + nLocalOffset + voffset);
2814 }
2815 else {
2816 sprintf(idx, "[%lu,%d]", nLocalsOffset + nLocalOffset + voffset, vsize);
2817 }
2818 flatStr += "l";
2819 flatStr += op.substr(1);
2820 flatStr += idx;
2821 flatStr += " ";
2822 }
2823 else {
2824 TempVarMap::iterator var =
m_varMap.find(refroot);
2826 std::string root;
2827 for (const char *ptr = refroot.c_str(); *ptr && *ptr != '.'; ptr++) root += *ptr;
2828
2829 TempVarMap::iterator rootVar =
m_varMap.find(root);
2830 if (refroot != root && rootVar ==
m_varMap.end()) {
2831 parseStr += "Reference to undeclared variable '" + ref + "'\n";
2832 return false;
2833 }
2834
2835 TempDeclVarMap::iterator decl =
m_declVarMap.find(root);
2837 parseStr += "Reference to undeclared variable '" + ref + "'\n";
2838 return false;
2839 }
2840
2841 if (decl->second.m_pos < 0) {
2844
2845 if (strchr(refroot.c_str(), '.')) {
2846 TempVarList::iterator m = decl->second.m_members.begin();
2847 for (; m != decl->second.m_members.end(); m++) {
2848 std::string vm = root + "." + m->m_name;
2850 }
2851 }
2852
2853 if (
m_nNextVar + decl->second.m_size > 65536) {
2854 parseStr += "Temporary variable addressing out of bounds\n";
2855 return false;
2856 }
2858 }
2859 else {
2861
2862 if (strchr(refroot.c_str(), '.')) {
2863 TempVarList::iterator m = decl->second.m_members.begin();
2864 for (; m != decl->second.m_members.end(); m++) {
2865 std::string vm = root + "." + m->m_name;
2867 }
2868 }
2869 if (decl->second.m_pos + decl->second.m_size > 65536) {
2870 parseStr += "Temporary variable addressing out of bounds\n";
2871 return false;
2872 }
2873 }
2874
2877 parseStr += "Reference to undeclared variable '" + refroot + "'\n";
2878 return false;
2879 }
2880 }
2881 int voffset, vsize;
2882
2883 if (ref != refroot) {
2885 p2.GetNext();
2887 p2.GetIndex(_voffset, _vsize, 0, 1);
2888 voffset = _voffset;
2889 vsize = _vsize + 1;
2890 }
2891 else {
2892 voffset = 0;
2893 vsize = var->second.m_size;
2894 }
2895
2896 if (voffset + vsize > var->second.m_size) {
2897 parseStr += "Out of bounds indexing of '" + refroot + "'\n";
2898 return false;
2899 }
2900 if (var->second.m_pos + voffset + vsize > 65536) {
2901 parseStr += "Temporary variable addressing out of bounds\n";
2902 return false;
2903 }
2904 char idx[80];
2905 if (vsize == 1) {
2906 sprintf(idx, "[%d]", var->second.m_pos + voffset);
2907 }
2908 else {
2909 sprintf(idx, "[%d,%d]", var->second.m_pos + voffset, vsize);
2910 }
2911 flatStr += op + idx + " ";
2912 }
2913 }
2914 else if (!strncmp(tok, "elem{", 5) ||
2915 !strncmp(tok, "curv{", 5) ||
2916 !strncmp(tok, "clut{", 5) ||
2917 !strncmp(tok, "mtx{", 4) ||
2918 !strncmp(tok, "fJab{", 5) ||
2919 !strncmp(tok, "tJab{", 5) ||
2920 !strncmp(tok, "calc{", 5) ||
2921 !strncmp(tok, "tint{", 5)) {
2922 std::string op = parse.GetName();
2923 std::string ref = parse.GetReference();
2924 MpePtrMap::iterator e =
m_mpeMap.find(ref);
2926 parseStr += "Unknown sub element reference to " + token + "\n";
2927 return false;
2928 }
2929 if (e->second.m_nIndex<0) {
2930 if (e->second.m_ptr) {
2932 e->second.m_ptr = NULL;
2935 }
2936 else {
2937 parseStr += "Invalid sub-element reference: " + token + "\n";
2938 return false;
2939 }
2940 }
2941 char idx[80];
2942 sprintf(idx, "(%d)", e->second.m_nIndex);
2943 flatStr += op + idx + " ";
2944 }
2945 else {
2946 flatStr += tok;
2947 flatStr += " ";
2948 }
2949 }
2950
2951 return true;
2952}
std::map< std::string, IndexSizePair > ChanVarMap
TempDeclVarMap m_macroLocalMap
bool Flatten(std::string &flatStr, std::string macroName, const char *szFunc, std::string &parseStr, icUInt32Number nLocalsOffset=0)
icUInt16Number m_nOutputChannels
icUInt16Number m_nInputChannels