const wxString ecConfigItem::StringValue(ecWhereType where) const { wxString str; switch(where){ case ecInName: str=GetName(); break; case ecInMacro: str=GetMacro(); break; case ecInDesc: str=GetDescription(); break; case ecInCurrentValue: if (ecOptionTypeNone==GetOptionType()) str = wxEmptyString; else str = StringValue(CdlValueSource_Current); break; case ecInDefaultValue: if (ecOptionTypeNone==GetOptionType()) str = wxEmptyString; else str = StringValue(CdlValueSource_Default); break; default: wxASSERT(FALSE); break; } return str; }
void CXBindingsCppObjectsGenerator::DoGenerateMacroForChildEnumerator( CXBindingsRuleInfo& ruleInfo , CXBindingsArrayGrammarChildInfo& childs , CXBindings& , CXBindingsGeneratorOptions& ) { /** @todo manage here enumaration for types different from a string */ if( childs.size() > 0 ) { std::string child_enum_list; std::string child_string_enum_list; for( unsigned int i = 0; i < childs.size() ; ++i ) { if( i == 0 ) child_enum_list += "\t$(ns)" + childs[i].properties[ruleInfo.variable.content] + " = 0,\n" ; else child_enum_list += "\t$(ns)" + childs[i].properties[ruleInfo.variable.content] + ",\n" ; std::string str = GetMacro("string_composer") ; SetMacro("content",childs[i].properties[ruleInfo.variable.content]) ; DoReplaceMacros( str ); if( i < childs.size()-1 ) child_string_enum_list += "\t" + str + ",\n" ; else child_string_enum_list += "\t" + str; } SetMacro( "child_enum_list" , child_enum_list ) ; SetMacro( "child_string_enum_list" , child_string_enum_list ) ; } }
// FIXME: I need to unit test this class in order to validate the new regex system int CXBindingsGenerator::DoReplaceMacros( std::string& str ) { boost::regex re( "\\$([a-z_A-Z0-9]*)" , boost::regex::basic|boost::regex::icase); std::string text=str; int notfound = 0; boost::cmatch what; str = text; boost::sregex_token_iterator iter(text.begin(), text.end(), re, boost::match_default); boost::sregex_token_iterator end; for( ; iter != end; ++iter ) { std::string macroName = *iter; if( macroName[0] == '$' ){ std::string temp; for( unsigned int i = 0; i < macroName.size(); ++i ) if( macroName[i] != '$' && macroName[i] != '(' && macroName[i] != ')' ) temp += macroName[i]; macroName = temp; } std::string macroValue = GetMacro( macroName ); DoReplaceMacros(macroValue); if( !MacroExists(macroName) ) CXB_THROW( "Error missing macro (preventing infinity loops): "+ macroName ); else { boost::replace_all(str, "$(" + macroName + ")" , macroValue ) ; } } return notfound; }
CC_STRING CMaExpander::TryExpand() { CToken token; CC_STRING outs; static int debug_level; CC_STRING saved_inStr = inStr; debug_level++; while(1) { const char *const last_pos = pos; IgnoreSpaces(); if( ! get_token(tc, &pos, &token, for_include) ) break; if( token.attr == CToken::TA_IDENT ) { CMacro *ma; CC_STRING tmp; ma = GetMacro(token.id); if( IS_MACRO(ma) && ! in_defined_context() ) { if( IS_FLM(ma) ) { skip_blanks(pos); if( *pos == '(' ) { tmp = Expand_FLM(ma); } else goto do_cat; } else { tmp = Expand_OLM(ma); } const ssize_t offset = last_pos - inStr.c_str(); CC_STRING newStr; newStr.strcat(inStr.c_str(), last_pos); newStr += tmp; newStr += pos; inStr = newStr; pos = inStr.c_str() + offset; } else goto do_cat; } else { do_cat: outs.strcat(last_pos, pos); } last_ids[0] = last_ids[1]; last_ids[1] = token.id; } // printf("Leave [%u] %s\n", debug_level, outs.c_str()); --debug_level; // fprintf(stderr, "*** %u: %s => %s\n", debug_level, saved_inStr.c_str(), outs.c_str()); return outs; }
void D_CODE::DrawFlashedShape( GERBER_DRAW_ITEM* aParent, EDA_RECT* aClipBox, wxDC* aDC, COLOR4D aColor, wxPoint aShapePos, bool aFilledShape ) { int radius; switch( m_Shape ) { case APT_MACRO: GetMacro()->DrawApertureMacroShape( aParent, aClipBox, aDC, aColor, aShapePos, aFilledShape); break; case APT_CIRCLE: radius = m_Size.x >> 1; if( !aFilledShape ) GRCircle( aClipBox, aDC, aParent->GetABPosition(aShapePos), radius, 0, aColor ); else if( m_DrillShape == APT_DEF_NO_HOLE ) { GRFilledCircle( aClipBox, aDC, aParent->GetABPosition(aShapePos), radius, aColor ); } else if( m_DrillShape == APT_DEF_ROUND_HOLE ) // round hole in shape { int width = (m_Size.x - m_Drill.x ) / 2; GRCircle( aClipBox, aDC, aParent->GetABPosition(aShapePos), radius - (width / 2), width, aColor ); } else // rectangular hole { if( m_Polygon.OutlineCount() == 0 ) ConvertShapeToPolygon(); DrawFlashedPolygon( aParent, aClipBox, aDC, aColor, aFilledShape, aShapePos ); } break; case APT_RECT: { wxPoint start; start.x = aShapePos.x - m_Size.x / 2; start.y = aShapePos.y - m_Size.y / 2; wxPoint end = start + m_Size; start = aParent->GetABPosition( start ); end = aParent->GetABPosition( end ); if( !aFilledShape ) { GRRect( aClipBox, aDC, start.x, start.y, end.x, end.y, 0, aColor ); } else if( m_DrillShape == APT_DEF_NO_HOLE ) { GRFilledRect( aClipBox, aDC, start.x, start.y, end.x, end.y, 0, aColor, aColor ); } else { if( m_Polygon.OutlineCount() == 0 ) ConvertShapeToPolygon(); DrawFlashedPolygon( aParent, aClipBox, aDC, aColor, aFilledShape, aShapePos ); } } break; case APT_OVAL: { wxPoint start = aShapePos; wxPoint end = aShapePos; if( m_Size.x > m_Size.y ) // horizontal oval { int delta = (m_Size.x - m_Size.y) / 2; start.x -= delta; end.x += delta; radius = m_Size.y; } else // horizontal oval { int delta = (m_Size.y - m_Size.x) / 2; start.y -= delta; end.y += delta; radius = m_Size.x; } start = aParent->GetABPosition( start ); end = aParent->GetABPosition( end ); if( !aFilledShape ) { GRCSegm( aClipBox, aDC, start.x, start.y, end.x, end.y, radius, aColor ); } else if( m_DrillShape == APT_DEF_NO_HOLE ) { GRFillCSegm( aClipBox, aDC, start.x, start.y, end.x, end.y, radius, aColor ); } else { if( m_Polygon.OutlineCount() == 0 ) ConvertShapeToPolygon(); DrawFlashedPolygon( aParent, aClipBox, aDC, aColor, aFilledShape, aShapePos ); } } break; case APT_POLYGON: if( m_Polygon.OutlineCount() == 0 ) ConvertShapeToPolygon(); DrawFlashedPolygon( aParent, aClipBox, aDC, aColor, aFilledShape, aShapePos ); break; } }
bool CXBindingsCppObjectsGenerator::DoGenerateCode( CXBindingsGeneratorOptions& options ) { /* for each element in the info object of the grammar */ CXBindings& grammar = m_interpreterInfo.grammar; CXBindingsInfo& info = grammar.GetInfo(); CXBindingsArrayString genOrder = info.GetGeneration().GetObjects(); CXBindingsArrayString templates = info.GetGeneration().GetTemplates(); /* The first thing to do is to estabilsh the generation objects dependecy list * So that object will be generated in the right order... */ CXBindingsArrayString dependencies = DoCreateDependencyList( options ); /** @todo here generate object in their dependencies order is this really usefull .??? */ for( unsigned int k = 0; k < dependencies.size() ; ++k ) { for( unsigned int i = 0; i < genOrder.size() ; ++i ) { CXBindingsArrayGrammarObjectInfoMap& objectsInfoMap = m_interpreterInfo.objects; CXBindingsArrayGrammarObjectInfo& objectsInfo = objectsInfoMap[genOrder[i]]; for( unsigned int j = 0; j < objectsInfo.size() ; ++j ) { std::string realName = objectsInfo[j].properties["name"]; realName = GetRealType( realName , options ); if( realName == dependencies[k] ) { DoGenerateCodeFor( objectsInfo[j] , grammar , options ); break; } } } } /** The last step is to generate the globals file and the other files for given objects */ std::string hdrDir = options.genDir + "/include" ; std::string srcDir = options.genDir + "/src" ; CXBindingsMakeDirRecursively(hdrDir+"/") ; CXBindingsMakeDirRecursively(srcDir+"/") ; /* First generate globals file definitions */ std::string global_file = GetMacro( "global_file") ; std::string global_file_src = GetMacro( "global_file_src") ; std::string filename = options.ns + "_globals" ; SetMacro( "filename" , filename) ; SetMacro( "globals_code" , m_globalInfo.headerPublicInfo) ; SetMacro( "globals_code_src" , m_globalInfo.srcInfo) ; DoReplaceMacros( global_file ); DoReplaceMacros( global_file_src ); SaveFile( hdrDir + "/" + filename + ".h" , global_file ); SaveFile( srcDir + "/" + filename + ".cpp" , global_file_src) ; // Generate additional files CXBindingsArrayGrammarGeneratorFileAddin& addins = m_genfile->GetAddins(); for( unsigned int i = 0; i < addins.size() ; ++i ) { std::string fname = addins[i].GetName(); std::string header = addins[i].GetHeader(); std::string source = addins[i].GetSource(); if( !header.empty() ) { DoReplaceMacros( header ); SaveFile( hdrDir + "/" + fname + ".h" , header) ; } if( !source.empty() ) { DoReplaceMacros( source ); SaveFile( srcDir + "/" + fname + ".cpp" , source) ; } } // Save generated objects code CXBindingsFileInfoMap::iterator it = m_objectInfos.begin(); for( ; it != m_objectInfos.end() ; ++it ) { if( m_objectFiles[it->first] !=filename && !m_objectFiles[it->first].empty() ) { std::string srcFile = srcDir + "/" + m_objectFiles[it->first] + ".cpp" ; std::string hdrFile = hdrDir + "/" + m_objectFiles[it->first] + ".h" ; if( !it->second.srcInfo.empty() ) { SaveFile( srcFile , it->second.srcInfo ); } SaveFile( hdrFile , it->second.headerPublicInfo ); } } return false; }
void CXBindingsCppObjectsGenerator::DoCreateParametersMacrosFor( CXBindingsFileInfo& file , CXBindingsFileParametersMacros& parameters , CXBindingsGeneratorOptions& options ) { for( unsigned int i = 0; i < file.properties.size() ; ++i ) { std::string pName = file.properties[i].first; std::string pType = file.properties[i].second; //wxLogMessage( pName + " - ") + pType ; std::string nameExt = GetPropertyExtension( pName , options ); SetMacro( "content_type" , pType) ; SetMacro( "content" , pName) ; SetMacro( "content_ext" , nameExt) ; std::string str,str2; str = GetMacro("ctor_var_composer") ; str2 = GetMacro( "ctor_var_composer2") ; DoReplaceMacros(str); DoReplaceMacros(str2); if( parameters.parameters_copy_list.empty() && !str.empty() ) { parameters.parameters_ctor_list += str; parameters.parameters_ctor_list2 += str2; } else if( !str.empty() ) { parameters.parameters_ctor_list += " ," + str; parameters.parameters_ctor_list2 += " ," + str2; } str = GetMacro("var_eqop_composer") ; DoReplaceMacros(str); parameters.parameters_eqop_list += str; str = GetMacro("var_definit_composer") ; DoReplaceMacros(str); parameters.parameters_default_init_list += str; str = GetMacro("var_init_composer") ; DoReplaceMacros(str); parameters.parameters_init_list += str; str = GetMacro("var_copy_composer") ; DoReplaceMacros(str); parameters.parameters_copy_list += str; str = GetMacro("var_doc_composer") ; DoReplaceMacros(str); parameters.parameters_doc_list += str; str = GetMacro("var_property_composer") ; DoReplaceMacros(str); parameters.parameters_property_table += str; if( i < file.properties.size()-1 ) parameters.parameters_property_table += "\n" ; str = GetMacro("var_eqeqop_composer") ; DoReplaceMacros(str); if( i == 0 && parameters.parameters_eqeqop_list.empty() ) { parameters.parameters_eqeqop_list += "\t" + str; } else { parameters.parameters_eqeqop_list += " &&\n\t" + str; } } }
void RunVPMacro ( char *directory ) { GuiVertProfileObjectType *vpt; KeyListType *fdf, *macro=NULL; char *subdir, *model; char *current_directory; char *plot_type_key; char chapter[81]; char keyName[1024], value[1024]; int i, err, plot_type; vpt = GetGuiVertProfileDialog(); fdf = GetVPGuiFdfInfo(); /* * Save default directory in case the directory is redefined in a * macro. */ current_directory = strdup ( directory ); /* * Read macro into a key list which allows for duplicate * entries. */ if ( GetVPGridType ( vpt ) == SCALARGRIDOBJECT ) subdir = strdup ( GetModelVPScalarDir ( vpt ) ); else subdir = strdup ( GetModelVPVectorDir ( vpt ) ); model = strdup ( GetModelTypeVP ( vpt ) ); if ( err = GetMacro ( fdf->fileName, fdf->path, subdir, model, ¯o ) ) return; /* * Put key/value pairs into FDF and then display it. */ for ( i=0; i<macro->numKeys; i++ ) { strcpy ( keyName, macro->keys[i].keyName ); strcpy ( value, macro->keys[i].value ); ToUpper ( keyName ); ToUpper ( value ); /* * Update GUI and build metObjects. */ if ( strcmp ( keyName, "OPERATION" ) == 0 && strcmp ( value, "RUN" ) == 0 ) { SetVPFdfFallbackValues ( fdf ); SetVPGridWidgets ( fdf, fdf->fileName ); BuildVPGrid(); } /* * Save the directory holding the current FDF. */ else if ( strcmp ( keyName, "DIRECTORY" ) == 0 ) { Free ( current_directory ); current_directory = GetConfigValue ( macro->keys[i].value ); } /* * Save the chapter holding the current FDF. */ else if ( strcmp ( keyName, "CHAPTER" ) == 0 ) { strcpy ( chapter, macro->keys[i].value ); } /* * Read in FDF. Save plot type. */ else if ( strcmp ( keyName, "FDF" ) == 0 ) { GetVPModelField ( macro->keys[i].value, chapter, current_directory ); fdf = GetVPGuiFdfInfo(); /* * Save plot type. */ plot_type_key = GetFdfKeyValue ( fdf, "type" ); ToUpper ( plot_type_key ); plot_type = SCALARGRIDOBJECT; if ( strcmp ( plot_type_key, "VECTOR" ) == 0 ) plot_type = VECTORGRIDOBJECT; SetVPGridType ( vpt, plot_type ); Free ( plot_type_key ); } /* * Put modifications into FDF. */ else PutInFDF ( macro->keys[i].keyName, macro->keys[i].value, fdf, OVERWRITE ); } /* * Restore current macro settings. */ CopyFdf ( macro, fdf ); if ( macro != NULL ) DestroyFDF ( macro ); /* * Free. */ Free ( model ); Free ( subdir ); Free ( current_directory ); }
wxString ecConfigItem::GetItemNameOrMacro() const { return (wxGetApp().GetSettings().m_showMacroNames && !GetMacro().IsEmpty() ? GetMacro() : GetName()); }