青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆-341  評(píng)論-2670  文章-0  trackbacks-0
    做編譯器難免會(huì)遇到如何輸出錯(cuò)誤信息的問(wèn)題。這個(gè)問(wèn)題不是那么好解決的,因?yàn)橛锌赡苣阈枰峁┲形摹⒂⑽倪€是其他什么亂七八糟語(yǔ)言的編譯器。于是就要想一種辦法讓錯(cuò)誤信息的語(yǔ)言可以很方便的切換。

    由于同時(shí)提供中文和英文的編譯器其實(shí)沒(méi)什么用,中文的編譯器和英文的編譯器其實(shí)可以是兩個(gè)不同的exe,因此我想寫兩個(gè)宏,譬如說(shuō)中文.bat點(diǎn)擊了之后,代碼里面的錯(cuò)誤信息就被換成中文,英文.bat被點(diǎn)擊之后,代碼里面的錯(cuò)誤信息就被換成英文。選擇完之后再編譯,就可以產(chǎn)生需要的語(yǔ)言種類的編譯器了。

    因此我想到了一個(gè)辦法。這次在Vczh Library++3.0里面實(shí)現(xiàn)了一個(gè)小工具StrGen.exe(代碼也一并上傳了)。StrGen.exe需要有四個(gè)參數(shù):
    1、Library文件夾的位置
    2、字符串資源文件的位置
    3、生成的.h文件的位置
    4、生成的.cpp文件的位置

    首先,StrGen.exe讀入下面這個(gè)文件:
 1 resource:vl.scripting.basiclanguage.BasicErrorMessage
 2 
 3 TypeNameNotExists(type)=Type {type} does not exists.
 4 FunctionAlreadyExists(name)=Function {name} already exists.
 5 VariableAlreadyExists(name)=Variable {name} already exists.
 6 TypeAlreadyExists(name)=Type {name} already exists.
 7 StructureMemberAlreadyExists(name)=Member {name} already exists.
 8 VariableNotExists(name)=Variable {name} not exists.
 9 FailToCast(from,to)=Fail to cast from {from} to {to}.
10 VoidFunctionNotHaveResult=Cannot access function result in a function without return value.
11 GlobalNotHaveResult=Cannot access function result in global definitions.
12 CannotInvokeNonFunctionValue(type)=Cannot invoke a value of {type}.
13 ArgumentNumnerNotMatch=Argument number should not be greater or less than the function required.
14 ArgumentTypeNotMatch(index,from,to)=Cannot implicitly cast argument {index} from {from} to {to}.
15 StructureMemberNotExists(name)=Member {name} not exists.
16 CannotConvertIndexToInt(from,to)=Cannot implicit cast the index from {from} to {to}.
17 CannotSubscribe(type)=Cannot subscribe a value of {type}.
18 UnaryOperandShouldBeLeftValue=Operand should be left value.
19 UnaryTypeNotMatch(op,type)=Unary operator {op} cannot apply to a value of {type}.
20 BinaryLeftOperandShouldBeLeftValue(op)=Left operand of binary operator {op} should be left value.
21 BinaryTypeNotMatch=(op,left,right)=Binary operator {op} cannot apply to values of {left} and {right}.
22 ConditionCannotConvertToBool(from,boolean)=Cannot convert the condition from {from} to {boolean}.
23 BreakShouldBeInLooping(breakStatement)={breakStatement} should be used in a loop.
24 ContinueShouldBeInLooping(continueStatement)={continueStatement} should be used in a loop.
25 InitializerTypeNotMatch(from,to)=Cannot convert the variable initializer from {from} to {to}.
26 ParameterCountNotMatch=Parameter number should not be greater or less than the function required.
27 ParameterAlreadyExists(name)=Parameter (name) already exists.
28 StructureMemberCannotBeUndefinedType(name)=Cannot refer to an undefined structure {name}.
29 LeftOperandShouldBeStructure=Left operand should be a structure.
30 LeftOperandShouldBePointerToStructure=Left operand should be a pointer to a structure.
31 PredeclaredStructureShouldBeDefined(name)=Predeclared structure (name) should be defined.

    第一行resource告訴StrGen生成的類的namespace和類名。然后用如下的命令去生成:
1 ..\Tools\StrGen\Debug\StrGen .\ .\Scripting\Languages\BasicErrorMessage_English.txt .\Scripting\Languages\BasicErrorMessage.h .\Scripting\Languages\BasicErrorMessage.cpp
2 pause

    這個(gè)English.bat放在Library目錄下,所以第一個(gè)參數(shù)自然是“.\”。后面的都好理解,就是三個(gè)文件名。那么想替換成中文怎么辦呢?只要寫一個(gè)BasicErrorMessage_Chinese.txt,然后寫一個(gè)Chinese.bat去讀他就好了。bat文件里面可以放很多行,就能批量替換了。實(shí)際上生成的兩個(gè)代碼文件如下:

    首先是BasicErrorMessage.h
 1 /***********************************************************************
 2 Vczh Library++ 3.0
 3 Developer: 陳梓瀚(vczh)
 4 StringResource::BasicErrorMessage
 5 
 6 Classes:
 7     BasicErrorMessage                                    :字符串資源類
 8     
 9 本文件使用Vczh String Resource Code Generator工具自動(dòng)生成
10 ***********************************************************************/
11 
12 #ifndef VCZH_STRING_RESOURCE_CODE_FILE_VL_SCRIPTING_BASICLANGUAGE_BASICERRORMESSAGE
13 #define VCZH_STRING_RESOURCE_CODE_FILE_VL_SCRIPTING_BASICLANGUAGE_BASICERRORMESSAGE
14 
15 #include "..\..\String.h"
16 
17 using namespace vl;
18 
19 namespace vl
20 {
21     namespace scripting
22     {
23         namespace basiclanguage
24         {
25             class BasicErrorMessage
26             {
27             public:
28                 static WString TypeNameNotExists(const WString& type);
29                 static WString FunctionAlreadyExists(const WString& name);
30                 static WString VariableAlreadyExists(const WString& name);
31                 static WString TypeAlreadyExists(const WString& name);
32                 static WString StructureMemberAlreadyExists(const WString& name);
33                 static WString VariableNotExists(const WString& name);
34                 static WString FailToCast(const WString& from, const WString& to);
35                 static WString VoidFunctionNotHaveResult();
36                 static WString GlobalNotHaveResult();
37                 static WString CannotInvokeNonFunctionValue(const WString& type);
38                 static WString ArgumentNumnerNotMatch();
39                 static WString ArgumentTypeNotMatch(const WString& index, const WString& from, const WString& to);
40                 static WString StructureMemberNotExists(const WString& name);
41                 static WString CannotConvertIndexToInt(const WString& from, const WString& to);
42                 static WString CannotSubscribe(const WString& type);
43                 static WString UnaryOperandShouldBeLeftValue();
44                 static WString UnaryTypeNotMatch(const WString& op, const WString& type);
45                 static WString BinaryLeftOperandShouldBeLeftValue(const WString& op);
46                 static WString BinaryTypeNotMatch();
47                 static WString ConditionCannotConvertToBool(const WString& from, const WString& boolean);
48                 static WString BreakShouldBeInLooping(const WString& breakStatement);
49                 static WString ContinueShouldBeInLooping(const WString& continueStatement);
50                 static WString InitializerTypeNotMatch(const WString& from, const WString& to);
51                 static WString ParameterCountNotMatch();
52                 static WString ParameterAlreadyExists(const WString& name);
53                 static WString StructureMemberCannotBeUndefinedType(const WString& name);
54                 static WString LeftOperandShouldBeStructure();
55                 static WString LeftOperandShouldBePointerToStructure();
56                 static WString PredeclaredStructureShouldBeDefined(const WString& name);
57             };
58         }
59     }
60 }
61 
62 #endif

    看到這里一般都知道是怎么一回事了吧。資源的名字被編譯成靜態(tài)函數(shù)。容易想象函數(shù)里面自然是這些內(nèi)容:
  1 #include "BasicErrorMessage.h"
  2 
  3 namespace vl
  4 {
  5     namespace scripting
  6     {
  7         namespace basiclanguage
  8         {
  9             WString BasicErrorMessage::TypeNameNotExists(const WString& type)
 10             {
 11                 return L"Type "+type+L" does not exists.";
 12             }
 13 
 14             WString BasicErrorMessage::FunctionAlreadyExists(const WString& name)
 15             {
 16                 return L"Function "+name+L" already exists.";
 17             }
 18 
 19             WString BasicErrorMessage::VariableAlreadyExists(const WString& name)
 20             {
 21                 return L"Variable "+name+L" already exists.";
 22             }
 23 
 24             WString BasicErrorMessage::TypeAlreadyExists(const WString& name)
 25             {
 26                 return L"Type "+name+L" already exists.";
 27             }
 28 
 29             WString BasicErrorMessage::StructureMemberAlreadyExists(const WString& name)
 30             {
 31                 return L"Member "+name+L" already exists.";
 32             }
 33 
 34             WString BasicErrorMessage::VariableNotExists(const WString& name)
 35             {
 36                 return L"Variable "+name+L" not exists.";
 37             }
 38 
 39             WString BasicErrorMessage::FailToCast(const WString& from, const WString& to)
 40             {
 41                 return L"Fail to cast from "+from+L" to "+to+L".";
 42             }
 43 
 44             WString BasicErrorMessage::VoidFunctionNotHaveResult()
 45             {
 46                 return L"Cannot access function result in a function without return value.";
 47             }
 48 
 49             WString BasicErrorMessage::GlobalNotHaveResult()
 50             {
 51                 return L"Cannot access function result in global definitions.";
 52             }
 53 
 54             WString BasicErrorMessage::CannotInvokeNonFunctionValue(const WString& type)
 55             {
 56                 return L"Cannot invoke a value of "+type+L".";
 57             }
 58 
 59             WString BasicErrorMessage::ArgumentNumnerNotMatch()
 60             {
 61                 return L"Argument number should not be greater or less than the function required.";
 62             }
 63 
 64             WString BasicErrorMessage::ArgumentTypeNotMatch(const WString& index, const WString& from, const WString& to)
 65             {
 66                 return L"Cannot implicitly cast argument "+index+L" from "+from+L" to "+to+L".";
 67             }
 68 
 69             WString BasicErrorMessage::StructureMemberNotExists(const WString& name)
 70             {
 71                 return L"Member "+name+L" not exists.";
 72             }
 73 
 74             WString BasicErrorMessage::CannotConvertIndexToInt(const WString& from, const WString& to)
 75             {
 76                 return L"Cannot implicit cast the index from "+from+L" to "+to+L".";
 77             }
 78 
 79             WString BasicErrorMessage::CannotSubscribe(const WString& type)
 80             {
 81                 return L"Cannot subscribe a value of "+type+L".";
 82             }
 83 
 84             WString BasicErrorMessage::UnaryOperandShouldBeLeftValue()
 85             {
 86                 return L"Operand should be left value.";
 87             }
 88 
 89             WString BasicErrorMessage::UnaryTypeNotMatch(const WString& op, const WString& type)
 90             {
 91                 return L"Unary operator "+op+L" cannot apply to a value of "+type+L".";
 92             }
 93 
 94             WString BasicErrorMessage::BinaryLeftOperandShouldBeLeftValue(const WString& op)
 95             {
 96                 return L"Left operand of binary operator "+op+L" should be left value.";
 97             }
 98 
 99             WString BasicErrorMessage::BinaryTypeNotMatch()
100             {
101                 return L"(op,left,right)=Binary operator "L"{op}"L" cannot apply to values of "L"{left}"L" and "L"{right}"L".";
102             }
103 
104             WString BasicErrorMessage::ConditionCannotConvertToBool(const WString& from, const WString& boolean)
105             {
106                 return L"Cannot convert the condition from "+from+L" to "+boolean+L".";
107             }
108 
109             WString BasicErrorMessage::BreakShouldBeInLooping(const WString& breakStatement)
110             {
111                 return breakStatement+L" should be used in a loop.";
112             }
113 
114             WString BasicErrorMessage::ContinueShouldBeInLooping(const WString& continueStatement)
115             {
116                 return continueStatement+L" should be used in a loop.";
117             }
118 
119             WString BasicErrorMessage::InitializerTypeNotMatch(const WString& from, const WString& to)
120             {
121                 return L"Cannot convert the variable initializer from "+from+L" to "+to+L".";
122             }
123 
124             WString BasicErrorMessage::ParameterCountNotMatch()
125             {
126                 return L"Parameter number should not be greater or less than the function required.";
127             }
128 
129             WString BasicErrorMessage::ParameterAlreadyExists(const WString& name)
130             {
131                 return L"Parameter (name) already exists.";
132             }
133 
134             WString BasicErrorMessage::StructureMemberCannotBeUndefinedType(const WString& name)
135             {
136                 return L"Cannot refer to an undefined structure "+name+L".";
137             }
138 
139             WString BasicErrorMessage::LeftOperandShouldBeStructure()
140             {
141                 return L"Left operand should be a structure.";
142             }
143 
144             WString BasicErrorMessage::LeftOperandShouldBePointerToStructure()
145             {
146                 return L"Left operand should be a pointer to a structure.";
147             }
148 
149             WString BasicErrorMessage::PredeclaredStructureShouldBeDefined(const WString& name)
150             {
151                 return L"Predeclared structure (name) should be defined.";
152             }
153 
154         }
155     }
156 }
157 

    使用的時(shí)候就十分方便了,譬如說(shuō)BasicErrorMessage::VariableNotExists(L"a"),就會(huì)給你一個(gè)相應(yīng)的錯(cuò)誤信息的字符串了。

    在Vczh Library++3.0的目錄.\Tools\StrGen\下面有這個(gè)工具的源代碼。
posted on 2010-03-05 23:08 陳梓瀚(vczh) 閱讀(2532) 評(píng)論(2)  編輯 收藏 引用 所屬分類: VL++3.0開(kāi)發(fā)紀(jì)事

評(píng)論:
# re: Vczh Library++3.0開(kāi)發(fā)紀(jì)事之字符串資源生成器StrGen.exe 2010-03-07 01:12 | Kevin Lynx
對(duì)這種支持多種字符串資源的問(wèn)題,沒(méi)必要自己寫個(gè)程序去生成對(duì)應(yīng)的代碼文件吧?
english_res.txt:
IDS_TYPE_ERROR "XXXXX%s"

const char *s = LoadString( IDS_TYPE_ERROR );
sprintf( buf, s, err );

  回復(fù)  更多評(píng)論
  
# re: Vczh Library++3.0開(kāi)發(fā)紀(jì)事之字符串資源生成器StrGen.exe 2010-03-07 01:31 | 陳梓瀚(vczh)
@Kevin Lynx
我不會(huì)用需要%s這種肯定動(dòng)用printf或者sprintf的類型不安全函數(shù)的方法的。一向來(lái)的風(fēng)格是讓編譯器能夠檢查更多的事情,于是我致力于用類型去表達(dá)程序需要干的事情(而不是語(yǔ)句)。當(dāng)然只好去寫StrGen.exe了。因?yàn)槊恳粋€(gè)資源都是有類型的(指參數(shù),以后可能會(huì)支持更多)。

而且從另外一個(gè)觀點(diǎn)看,如果寫一個(gè)類庫(kù)出來(lái)需要外部文件的支持,其實(shí)是很危險(xiǎn)的……當(dāng)然寫應(yīng)用程序是另外一回事了。  回復(fù)  更多評(píng)論
  
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲女人小视频在线观看| 久久成人在线| 亚洲一区二区网站| 亚洲婷婷综合久久一本伊一区| 亚洲精品社区| 亚洲视频1区| 亚洲欧美日韩爽爽影院| 午夜精品999| 久久精品国产99| 久久综合狠狠| 欧美经典一区二区| 国产精品成人一区二区网站软件 | 一区二区欧美在线观看| 一区二区电影免费在线观看| 亚洲网址在线| 欧美在线电影| 欧美.www| 亚洲精品一区二区三区蜜桃久| 一本到12不卡视频在线dvd| 中文在线不卡| 久久精品中文字幕一区| 麻豆av一区二区三区久久| 欧美激情中文字幕一区二区| 欧美午夜宅男影院| 国产一区二区三区在线免费观看| 伊人春色精品| 一区二区不卡在线视频 午夜欧美不卡在 | 欧美亚洲视频在线看网址| 久久婷婷影院| 欧美香蕉大胸在线视频观看| 国产三级欧美三级| 亚洲精品国产精品国产自| 亚洲香蕉成视频在线观看| 久久九九有精品国产23| 亚洲二区视频| 亚洲深夜影院| 久久一区二区三区超碰国产精品| 欧美日韩中文在线观看| 国产亚洲欧美日韩精品| 亚洲精品中文字幕在线| 欧美一区二区高清在线观看| 蘑菇福利视频一区播放| 一区二区三区四区国产| 久久精品在线观看| 欧美喷水视频| 红桃视频欧美| 亚洲午夜久久久久久久久电影网| 久久久久综合网| 亚洲精品在线观看视频| 欧美在线播放一区| 欧美日韩一区二区三区四区在线观看 | 欧美激情综合五月色丁香| 国产欧美日韩精品在线| 日韩一区二区精品葵司在线| 久久国产精彩视频| 亚洲伦理在线| 久久永久免费| 国产三区精品| 亚洲免费一区二区| 亚洲国产精品999| 午夜性色一区二区三区免费视频| 欧美精品麻豆| 一区二区亚洲精品| 欧美一区二区在线| 99精品视频免费观看| 久久在线免费观看| 国产一本一道久久香蕉| 亚洲一区二区三区四区在线观看 | 欧美mv日韩mv国产网站app| 国产精品综合不卡av| 亚洲视频一区二区| 欧美国产91| 欧美在线亚洲| 国产视频久久| 午夜伦理片一区| 99精品视频免费| 欧美精品一区二区三区四区| 在线观看日韩一区| 可以看av的网站久久看| 欧美亚洲一级片| 国产精品美女一区二区| 亚洲伊人一本大道中文字幕| 91久久国产自产拍夜夜嗨 | 精品成人一区二区三区| 欧美中文字幕第一页| 一区二区三区国产| 欧美日韩一区二区三区高清| 亚洲精品字幕| 亚洲国产天堂久久综合网| 久久综合一区二区| 在线日本成人| 麻豆成人av| 看片网站欧美日韩| 亚洲国产精品成人一区二区| 久久综合图片| 久久综合成人精品亚洲另类欧美| 韩国v欧美v日本v亚洲v| 久久久精品国产免费观看同学| 午夜激情亚洲| 国产综合第一页| 老司机精品久久| 狂野欧美一区| 亚洲精品日产精品乱码不卡| 亚洲国产欧美国产综合一区| 欧美精品粉嫩高潮一区二区| 99在线热播精品免费99热| 亚洲精品永久免费精品| 欧美日韩一区二区视频在线观看| 亚洲视频碰碰| 亚洲午夜黄色| 国产一本一道久久香蕉| 老鸭窝91久久精品色噜噜导演| 久久这里有精品视频| 亚洲狼人精品一区二区三区| 亚洲理论在线| 国产精品久久久一本精品| 午夜精品一区二区三区在线视| 欧美一二三区在线观看| 国内自拍视频一区二区三区| 亚洲第一在线| 欧美日一区二区在线观看| 欧美一区二区三区男人的天堂 | 亚洲午夜精品视频| 亚洲欧美日本国产专区一区| 国产视频一区欧美| 麻豆成人综合网| 欧美激情小视频| 亚洲欧美日韩国产一区| 久久精品人人| 亚洲人体1000| 亚洲欧美激情一区二区| 樱桃国产成人精品视频| 亚洲日本va午夜在线影院| 国产美女精品在线| 免费看精品久久片| 欧美日韩日日骚| 久久精品一区二区国产| 欧美久久久久| 久久久精品一区二区三区| 免费黄网站欧美| 午夜精品久久久久久久久久久久 | 亚洲国产小视频在线观看| 国产精品婷婷| 亚洲成人在线网站| 国产精品免费aⅴ片在线观看| 久久久亚洲成人| 欧美日韩在线播放一区二区| 久久久福利视频| 欧美日韩一区二区三区在线观看免| 久久国产精品久久w女人spa| 欧美激情第五页| 欧美在线视频免费| 欧美片在线观看| 久久综合色播五月| 国产精品视频1区| 亚洲国产视频一区二区| 国产一区二区三区高清| 99国产精品久久久久久久久久| 伊人久久亚洲热| 亚洲婷婷免费| 夜夜狂射影院欧美极品| 久久精品天堂| 午夜精品视频在线观看| 欧美激情成人在线| 麻豆av一区二区三区久久| 国产精品亚洲аv天堂网| 亚洲欧洲一区二区三区| 在线日韩欧美视频| 亚洲欧美国产日韩天堂区| 一本色道精品久久一区二区三区| 久久久999精品视频| 午夜精品久久久久久久99樱桃| 欧美精品在线一区二区| 老巨人导航500精品| 国产精品一二| 亚洲最新在线| 日韩午夜精品视频| 久久综合电影一区| 久久久国产一区二区| 国产精品一区二区三区观看| 一区二区三区日韩精品视频| 亚洲片国产一区一级在线观看| 久久动漫亚洲| 久久大逼视频| 国产精品一区免费视频| 亚洲视频第一页| 中文亚洲欧美| 欧美日韩精品二区| 亚洲韩国精品一区| 亚洲乱码日产精品bd| 欧美高清视频一区二区三区在线观看 | 欧美激情一级片一区二区| 免费成人美女女| 极品尤物一区二区三区| 欧美一区三区二区在线观看| 香蕉乱码成人久久天堂爱免费 | 日韩视频在线一区| 亚洲免费观看高清完整版在线观看熊 | 国产亚洲欧洲| 欧美影院视频|