有什么好的工具可以快速开始解析和分析C/C++代码?
特别是,我正在寻找处理C/C++预处理器和语言的开源工具.优选地,这些工具将使用lex/yacc(或flex/bison)用于语法,并且不会太复杂.他们应该处理最新的ANSI C/C++定义.
这是我到目前为止所发现的,但没有详细查看它们(想法?):
我希望将此作为将C/C++源代码翻译成新玩具语言的起点.
谢谢!-Matt
(已添加2/9):只是澄清:除了C/C++代码本身之外,我还希望从预处理器中提取语义信息.我不希望"#define foo 42"消失在整数"42"中,但仍然附加到名称"foo".不幸的是,这排除了几个首先运行预处理器并且只提供C/C++解析树的解决方案.
我有一个Web应用程序项目.我生成了DLL并将其导入另一个项目.我实施了VirtualPathProvider.
我关注了这个网站:http://support.microsoft.com/kb/910441/en-us?spid = 8940&sid = global,一切正常,直到我添加另一个网站管理员.
site_export.master并将其Build Action更改为Embedded Resource.GetManifestResourceStream()null加载时返回site_export.master.GetManifestResourceNames()来检查site_export.masterDLL中是否存在它确实存在.它在列表中.所有名称空间都匹配.我没有在这里列出名称空间.为什么不能GetManifestResourceStream()加载我的新site_export.master?它装site.master得很好.我知道我的DLL已加载,因为我可以看到DLL中的其他文件.
string strName = "John";
public enum Name { John,Peter }
private void DoSomething(string myname)
{
case1:
if(myname.Equals(Name.John) //returns false
{
}
case2:
if(myname == Name.John) //compilation error
{
}
case3:
if(myname.Equals(Name.John.ToString()) //returns true (correct comparision)
{
}
}
Run Code Online (Sandbox Code Playgroud)
当我使用.Equals它时是参考比较,当我使用==它时意味着值比较.
是否有更好的代码而不是将枚举值转换ToString()为比较?因为它破坏了值类型枚举的目的而且,ToString()在枚举上被弃用了?
我有一个枚举,其定义如下:
public enum eRat { A = 0, B=3, C=5, D=8 };
Run Code Online (Sandbox Code Playgroud)
所以给定价值eRat.B,我想得到下一个eRat.C
我看到的解决方案是(没有范围检查)
Array a = Enum.GetValues(typeof(eRat));
int i=0 ;
for (i = 0; i < a.GetLength(); i++)
{
if (a.GetValue(i) == eRat.B)
break;
}
return (eRat)a.GetValue(i+1):
Run Code Online (Sandbox Code Playgroud)
现在这太复杂了,对于那些简单的事情.你知道更好的解决方案吗?有点像eRat.B+1或Enum.Next(Erat.B)?
谢谢
我有(或想要)这样的代码:
IDictionary<string,int> dict = new Dictionary<string,int>();
// ... Add some stuff to the dictionary.
// Try to find an entry by value (if multiple, don't care which one).
var entry = dict.FirstOrDefault(e => e.Value == 1);
if ( entry != null ) {
// ^^^ above gives a compile error:
// Operator '!=' cannot be applied to operands of type 'System.Collections.Generic.KeyValuePair<string,int>' and '<null>'
}
Run Code Online (Sandbox Code Playgroud)
我也试过像这样改变违规行:
if ( entry != default(KeyValuePair<string,int>) )
Run Code Online (Sandbox Code Playgroud)
但是这也会产生编译错误:
Operator '!=' cannot be applied to operands of …Run Code Online (Sandbox Code Playgroud) 我试图了解or运营商的行为.请看下面的例子:
$e = false || true;
var_dump($e);
Run Code Online (Sandbox Code Playgroud)
输出符合预期: bool(true);
$f = false or true;
var_dump($f);
Run Code Online (Sandbox Code Playgroud)
输出如预期:bool(false).我理解这一点的方式是=优先级高于Or,这$f就是分配给它的原因false.
但是下面的代码与我的想法完全相反.我认为$foo将分配给自己5,然后与自己进行比较.但是$foo只有在$foo设置的时候才会被分配,这意味着它正在检查$foo之前是否分配给任何东西,为它分配5.
$foo or $foo = 5;
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释为什么会这样吗?
所以我开始从tryfsharp.org学习F#,我正在使用VS2013..fs(源),.fsx(脚本)和.fsi(签名)有什么区别?
我似乎无法找到一种更有效的方法将嵌入式资源"复制"到磁盘,而不是以下方法:
using (BinaryReader reader = new BinaryReader(
assembly.GetManifestResourceStream(@"Namespace.Resources.File.ext")))
{
using (BinaryWriter writer
= new BinaryWriter(new FileStream(path, FileMode.Create)))
{
long bytesLeft = reader.BaseStream.Length;
while (bytesLeft > 0)
{
// 65535L is < Int32.MaxValue, so no need to test for overflow
byte[] chunk = reader.ReadBytes((int)Math.Min(bytesLeft, 65536L));
writer.Write(chunk);
bytesLeft -= chunk.Length;
}
}
}
Run Code Online (Sandbox Code Playgroud)
似乎没有更直接的方式来复制,除非我遗漏了一些东西......
我有一个WebView(Android 3.0+)的问题,WebView在显示我的黑色背景("闪烁")之前总是显示白色背景.这是我简单的测试代码:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WebView webView = new WebView(this);
webView.setBackgroundColor(Color.BLACK);
setContentView(webView);
loadWebView(webView);
webView.loadDataWithBaseURL("localhost://", "<html><head>" +
"<style>body {background-color: #000}img{max-width:100%}</style></head>" +
"<body>" +
"<img src=\"http://developer.android.com/images/practices/actionbar-phone-splitaction.png\" />" +
"</body></html>",
"text/html", "UTF-8", null);
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试了很多解决方案来摆脱这个问题,但并不幸运.
PS:如果关闭硬件加速,则不会出现此问题.有人有同样的问题并解决了吗?
谢谢.
android webview hardware-acceleration android-3.0-honeycomb android-4.0-ice-cream-sandwich
最新版本的pylint允许使用人类可读消息ID来抑制消息.例如,而不是
class MyTest(unittest.TestCase): # pylint: disable=R0904
...
Run Code Online (Sandbox Code Playgroud)
你可以指定:
class MyTest(unittest.TestCase): # pylint: disable=too-many-public-methods
...
Run Code Online (Sandbox Code Playgroud)
此页面列出了数字消息ID.但是,我正在寻找消息ID的人类可读版本的完整列表.我在哪里可以找到该列表?