void V3PreProcImp::define(FileLine* fl, const string& name, const string& value,
			  const string& params, bool cmdline) {
    UINFO(4,"DEFINE '"<<name<<"' as '"<<value<<"' params '"<<params<<"'"<<endl);
    if (defExists(name)) {
	if (!(defValue(name)==value && defParams(name)==params)) {  // Duplicate defs are OK
	    fl->v3warn(REDEFMACRO,"Redefining existing define: "<<name<<", with different value: "<<value<<" "<<params);
	    defFileline(name)->v3warn(REDEFMACRO,"Previous definition is here, with value: "<<defValue(name)<<" "<<defParams(name));
	}
	undef(name);
    }
    m_defines.insert(make_pair(name, V3Define(fl, value, params, cmdline)));
}
string V3PreProcImp::removeDefines(const string& sym) {
    string val = "0_never_match";
    string rtnsym = sym;
    for (int loopprevent=0; loopprevent<100; loopprevent++) {
	string xsym = rtnsym;
	if (xsym.substr(0,1)=="`") xsym.replace(0,1,"");
        if (defExists(xsym)) {
	    val = defValue(xsym);
	    if (val != rtnsym) rtnsym=val;  // Prevent infinite loop if have `define X X
	    else break;
        } else break;
    }
    return rtnsym;  // NA
}
Beispiel #3
0
/*static*/
wxString Domain::trimDefaultValue(const wxString& value)
{
    // Some users reported two spaces before DEFAULT word in source
    // Also, equals sign is also allowed in newer FB versions
    // Trim(false) is trim-left
    wxString defValue(value);
    defValue.Trim(false);
    if (defValue.Upper().StartsWith("DEFAULT"))
        defValue.Remove(0, 7);
    else if (defValue.StartsWith("="))
        defValue.Remove(0, 1);
    defValue.Trim(false);
    return defValue;
}
Beispiel #4
0
CXFA_Node* XFA_CreateUIChild(CXFA_Node* pNode, XFA_ELEMENT& eWidgetType) {
  XFA_ELEMENT eType = pNode->GetClassID();
  eWidgetType = eType;
  if (eType != XFA_ELEMENT_Field && eType != XFA_ELEMENT_Draw) {
    return NULL;
  }
  eWidgetType = XFA_ELEMENT_UNKNOWN;
  XFA_ELEMENT eUIType = XFA_ELEMENT_UNKNOWN;
  CXFA_Value defValue(pNode->GetProperty(0, XFA_ELEMENT_Value, TRUE));
  XFA_ELEMENT eValueType = (XFA_ELEMENT)defValue.GetChildValueClassID();
  switch (eValueType) {
    case XFA_ELEMENT_Boolean:
      eUIType = XFA_ELEMENT_CheckButton;
      break;
    case XFA_ELEMENT_Integer:
    case XFA_ELEMENT_Decimal:
    case XFA_ELEMENT_Float:
      eUIType = XFA_ELEMENT_NumericEdit;
      break;
    case XFA_ELEMENT_ExData:
    case XFA_ELEMENT_Text:
      eUIType = XFA_ELEMENT_TextEdit;
      eWidgetType = XFA_ELEMENT_Text;
      break;
    case XFA_ELEMENT_Date:
    case XFA_ELEMENT_Time:
    case XFA_ELEMENT_DateTime:
      eUIType = XFA_ELEMENT_DateTimeEdit;
      break;
    case XFA_ELEMENT_Image:
      eUIType = XFA_ELEMENT_ImageEdit;
      eWidgetType = XFA_ELEMENT_Image;
      break;
      ;
    case XFA_ELEMENT_Arc:
    case XFA_ELEMENT_Line:
    case XFA_ELEMENT_Rectangle:
      eUIType = XFA_ELEMENT_DefaultUi;
      eWidgetType = eValueType;
      break;
    default:
      break;
  }
  CXFA_Node* pUIChild = NULL;
  CXFA_Node* pUI = pNode->GetProperty(0, XFA_ELEMENT_Ui, TRUE);
  CXFA_Node* pChild = pUI->GetNodeItem(XFA_NODEITEM_FirstChild);
  for (; pChild; pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling)) {
    XFA_ELEMENT eChild = pChild->GetClassID();
    if (eChild == XFA_ELEMENT_Extras || eChild == XFA_ELEMENT_Picture) {
      continue;
    }
    XFA_LPCPROPERTY pProterty =
        XFA_GetPropertyOfElement(XFA_ELEMENT_Ui, eChild, XFA_XDPPACKET_Form);
    if (pProterty && (pProterty->uFlags & XFA_PROPERTYFLAG_OneOf)) {
      pUIChild = pChild;
      break;
    }
  }
  if (eType == XFA_ELEMENT_Draw) {
    XFA_ELEMENT eDraw = pUIChild ? pUIChild->GetClassID() : XFA_ELEMENT_UNKNOWN;
    switch (eDraw) {
      case XFA_ELEMENT_TextEdit:
        eWidgetType = XFA_ELEMENT_Text;
        break;
      case XFA_ELEMENT_ImageEdit:
        eWidgetType = XFA_ELEMENT_Image;
        break;
      default:
        eWidgetType =
            eWidgetType == XFA_ELEMENT_UNKNOWN ? XFA_ELEMENT_Text : eWidgetType;
        break;
    }
  } else {
    if (pUIChild && pUIChild->GetClassID() == XFA_ELEMENT_DefaultUi) {
      eWidgetType = XFA_ELEMENT_TextEdit;
    } else {
      eWidgetType = pUIChild
                        ? pUIChild->GetClassID()
                        : (eUIType == XFA_ELEMENT_UNKNOWN ? XFA_ELEMENT_TextEdit
                                                          : eUIType);
    }
  }
  if (!pUIChild) {
    if (eUIType == XFA_ELEMENT_UNKNOWN) {
      eUIType = XFA_ELEMENT_TextEdit;
      defValue.GetNode()->GetProperty(0, XFA_ELEMENT_Text, TRUE);
    }
    pUIChild = pUI->GetProperty(0, eUIType, TRUE);
  } else if (eUIType == XFA_ELEMENT_UNKNOWN) {
    switch (pUIChild->GetClassID()) {
      case XFA_ELEMENT_CheckButton: {
        eValueType = XFA_ELEMENT_Text;
        if (CXFA_Node* pItems = pNode->GetChild(0, XFA_ELEMENT_Items)) {
          if (CXFA_Node* pItem = pItems->GetChild(0, XFA_ELEMENT_UNKNOWN)) {
            eValueType = pItem->GetClassID();
          }
        }
      } break;
      case XFA_ELEMENT_DateTimeEdit:
        eValueType = XFA_ELEMENT_DateTime;
        break;
      case XFA_ELEMENT_ImageEdit:
        eValueType = XFA_ELEMENT_Image;
        break;
      case XFA_ELEMENT_NumericEdit:
        eValueType = XFA_ELEMENT_Float;
        break;
      case XFA_ELEMENT_ChoiceList: {
        eValueType = (pUIChild->GetEnum(XFA_ATTRIBUTE_Open) ==
                      XFA_ATTRIBUTEENUM_MultiSelect)
                         ? XFA_ELEMENT_ExData
                         : XFA_ELEMENT_Text;
      } break;
      case XFA_ELEMENT_Barcode:
      case XFA_ELEMENT_Button:
      case XFA_ELEMENT_PasswordEdit:
      case XFA_ELEMENT_Signature:
      case XFA_ELEMENT_TextEdit:
      default:
        eValueType = XFA_ELEMENT_Text;
        break;
    }
    defValue.GetNode()->GetProperty(0, eValueType, TRUE);
  }
  return pUIChild;
}
void CalculateDmg::cTdef(int num,int p1atk,int p2def){
	if(num==11){defFail(p1atk);}
	if(num==12){defValue(p1atk,p2def);}
	if(num==13){defATKMiss();}
	if(num==14){defReturn(p1atk);}
}
string V3PreProcImp::defineSubst(V3DefineRef* refp) {
    // Substitute out defines in a define reference.
    // (We also need to call here on non-param defines to handle `")
    // We could push the define text back into the lexer, but that's slow
    // and would make recursive definitions and parameter handling nasty.
    //
    // Note we parse the definition parameters and value here.  If a
    // parametrized define is used many, many times, we could cache the
    // parsed result.
    UINFO(4,"defineSubstIn  `"<<refp->name()<<" "<<refp->params()<<endl);
    for (unsigned i=0; i<refp->args().size(); i++) {
	UINFO(4,"defineArg["<<i<<"] = '"<<refp->args()[i]<<"'"<<endl);
    }
    // Grab value
    string value = defValue(refp->name());
    UINFO(4,"defineValue    '"<<V3PreLex::cleanDbgStrg(value)<<"'"<<endl);

    map<string,string> argValueByName;
    {   // Parse argument list into map
	unsigned numArgs=0;
	string argName;
	int paren = 1;  // (), {} and [] can use same counter, as must be matched pair per spec
	string token;
	bool quote = false;
	bool haveDefault = false;
	// Note there's a leading ( and trailing ), so parens==1 is the base parsing level
	string params = refp->params();  // Must keep in scope
	const char* cp=params.c_str();
	if (*cp == '(') cp++;
	for (; *cp; cp++) {
	    //UINFO(4,"   Parse  Paren="<<paren<<"  Arg="<<numArgs<<"  token='"<<token<<"'  Parse="<<cp<<endl);
	    if (!quote && paren==1) {
		if (*cp==')' || *cp==',') {
		    string value;
		    if (haveDefault) { value=token; } else { argName=token; }
		    argName = trimWhitespace(argName,true);
		    UINFO(4,"    Got Arg="<<numArgs<<"  argName='"<<argName<<"'  default='"<<value<<"'"<<endl);
		    // Parse it
		    if (argName!="") {
			if (refp->args().size() > numArgs) {
			    // A call `def( a ) must be equivelent to `def(a ), so trimWhitespace
			    // At one point we didn't trim trailing whitespace, but this confuses `"
			    string arg = trimWhitespace(refp->args()[numArgs], true);
			    if (arg != "") value = arg;
			} else if (!haveDefault) {
			    error("Define missing argument '"+argName+"' for: "+refp->name()+"\n");
			    return " `"+refp->name()+" ";
			}
			numArgs++;
		    }
		    argValueByName[argName] = value;
		    // Prepare for next
		    argName = "";
		    token = "";
		    haveDefault = false;
		    continue;
		}
		else if (*cp=='=') {
		    haveDefault = true;
		    argName = token;
		    token = "";
		    continue;
		}
	    }
	    if (cp[0]=='\\' && cp[1]) {
		token += cp[0]; // \{any} Put out literal next character
		token += cp[1];
		cp++;
		continue;
	    }
	    if (!quote) {
		if (*cp=='(' || *cp=='{' || *cp=='[') paren++;
		else if (*cp==')' || *cp=='}' || *cp==']') paren--;
	    }
	    if (*cp=='"') quote=!quote;
	    if (*cp) token += *cp;
	}
	if (refp->args().size() > numArgs
	    // `define X() is ok to call with nothing
	    && !(refp->args().size()==1 && numArgs==0 && trimWhitespace(refp->args()[0],false)=="")) {
	    error("Define passed too many arguments: "+refp->name()+"\n");
	    return " `"+refp->name()+" ";
	}
    }

    string out = "";
    {   // Parse substitution define using arguments
	string argName;
	bool quote = false;
	bool backslashesc = false;  // In \.....{space} block
	// Note we go through the loop once more at the NULL end-of-string
	for (const char* cp=value.c_str(); (*cp) || argName!=""; cp=(*cp?cp+1:cp)) {
	    //UINFO(4, "CH "<<*cp<<"  an "<<argName<<endl);
	    if (!quote && *cp == '\\') { backslashesc = true; }
	    else if (isspace(*cp)) { backslashesc = false; }
	    // We don't check for quotes; some simulators expand even inside quotes
	    if ( isalpha(*cp) || *cp=='_'
		 || *cp=='$' // Won't replace system functions, since no $ in argValueByName
		 || (argName!="" && (isdigit(*cp) || *cp=='$'))) {
		argName += *cp;
		continue;
	    }
	    if (argName != "") {
		// Found a possible variable substitution
		map<string,string>::iterator iter = argValueByName.find(argName);
		if (iter != argValueByName.end()) {
		    // Substitute
		    string subst = iter->second;
		    out += subst;
		} else {
		    out += argName;
		}
		argName = "";
	    }
	    if (!quote) {
		// Check for `` only after we've detected end-of-argname
		if (cp[0]=='`' && cp[1]=='`') {
		    if (backslashesc) {
			// Don't put out the ``, we're forming an escape which will not expand further later
		    } else {
			out += "``";   // `` must get removed later, as `FOO```BAR must pre-expand FOO and BAR
		    }
		    cp++;
		    continue;
		}
		else if (cp[0]=='`' && cp[1]=='"') {
		    out += "`\"";  // `" means to put out a " without enabling quote mode (sort of)
		    // however we must expand any macro calls inside it first.
		    // So keep it `", so we don't enter quote mode.
		    cp++;
		    continue;
		}
		else if (cp[0]=='`' && cp[1]=='\\' && cp[2]=='`' && cp[3]=='"') {
		    out += "`\\`\"";   // `\`" means to put out a backslash quote
		    // Leave it literal until we parse the VP_STRIFY string
		    cp+=3;
		    continue;
		}
		else if (cp[0]=='`' && cp[1]=='\\') {
		    out += '\\';   // `\ means to put out a backslash
		    cp++;
		    continue;
		}
		else if (cp[0]=='\\' && cp[1]=='\n') {
		    // We kept the \\n when we lexed because we don't want whitespace
		    // trimming to mis-drop the final \\n
		    // At replacement time we need the standard newline.
		    out += "\n";	 // \\n newline
		    cp++;
		    continue;
		}
	    }
	    if (cp[0]=='\\' && cp[1]=='\"') {
		out += cp[0]; // \{any} Put out literal next character
		out += cp[1];
		cp++;
		continue;
	    }
	    else if (cp[0]=='\\') {
		// Normally \{any} would put out literal next character
		// Instead we allow "`define A(nm) \nm" to expand, per proposed mantis1537
		out += cp[0];
		continue;
	    }
	    if (*cp=='"') quote=!quote;
	    if (*cp) out += *cp;
	}
    }

    UINFO(4,"defineSubstOut '"<<V3PreLex::cleanDbgStrg(out)<<"'"<<endl);
    return out;
}